Skip to content

Commit

Permalink
Fix serializing
Browse files Browse the repository at this point in the history
  • Loading branch information
AllFi committed Mar 6, 2023
1 parent e3f3ea5 commit 79ef770
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions fawkes-crypto/src/native/poseidon/optimized/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ use crate::native::poseidon::unoptimized::params::PoseidonParams as OriginalPose
serde(try_from = "OriginalPoseidonParams<Fr>")
)]
pub struct PoseidonParams<Fr: PrimeField> {
pub m: Vec<Vec<Num<Fr>>>,
pub c: Vec<Vec<Num<Fr>>>,
pub m: Vec<Vec<Num<Fr>>>,
pub t: usize,
pub f: usize,
pub p: usize,
pub t: usize,

#[cfg_attr(feature = "serde_support", serde(skip_serializing))]
pub mds_matrices: MdsMatrices<Fr>,
#[cfg_attr(feature = "serde_support", serde(skip_serializing))]
pub round_constants: Vec<Vec<Num<Fr>>>,
}

Expand All @@ -49,13 +51,13 @@ impl<Fr: PrimeField> PoseidonParams<Fr> {
let round_constants = calc_equivalent_constants(&params.c, m, f, p, t);

PoseidonParams {
m: params.m,
c: params.c,
mds_matrices,
round_constants,
m: params.m,
t,
f,
p,
t,
mds_matrices,
round_constants,
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions fawkes-crypto/tests/optimized_poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ fn test_optimized_poseidon() {

#[test]
fn test_optimized_poseidon_params_serialization() {
let params_str = include_str!("./res/poseidon_params_t_3.json");
let t = Instant::now();
let params: unoptimized::params::PoseidonParams<Fr> = serde_json::from_str(include_str!("./res/poseidon_params_t_3.json")).unwrap();
let params: unoptimized::params::PoseidonParams<Fr> = serde_json::from_str(params_str).unwrap();
println!("Unoptimized: {:?}", t.elapsed());

let t = Instant::now();
let optimized_params: optimized::params::PoseidonParams<Fr> = serde_json::from_str(include_str!("./res/poseidon_params_t_3.json")).unwrap();
let optimized_params: optimized::params::PoseidonParams<Fr> = serde_json::from_str(params_str).unwrap();
println!("Optimized: {:?}", t.elapsed());

let params_serialized = serde_json::to_string(&optimized_params).unwrap();
assert_eq!(&params_str.replace(" ", ""), &params_serialized);

let m = [Num::from(5), Num::from(3)];
let hash = unoptimized::poseidon::poseidon(&m, &params);
let optimized_hash = optimized::poseidon::poseidon(&m, &optimized_params);
Expand Down

0 comments on commit 79ef770

Please sign in to comment.