Skip to content

Commit

Permalink
Merge pull request #2999 from o1-labs/sponge/test-rate
Browse files Browse the repository at this point in the history
Poseidon/tests: squeeze/check state
  • Loading branch information
dannywillems authored Feb 4, 2025
2 parents 4c820f1 + 27404af commit f15858d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions poseidon/tests/poseidon_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,43 @@ fn test_poseidon_vesta_absorb_point_to_infinity() {
let exp_output = [Fq::from(0); 3];
assert_eq!(sponge.sponge.state, exp_output);
}

#[test]
fn test_poseidon_challenge_multiple_times_without_absorbtion() {
let mut sponge = DefaultFqSponge::<VestaParameters, PlonkSpongeConstantsKimchi>::new(
fq_kimchi::static_params(),
);
let mut rng = o1_utils::tests::make_test_rng(None);
let random_n = rng.gen_range(10..50);

let mut old_state = sponge.sponge.state.clone();
let mut new_state = sponge.sponge.state.clone();
// Only to avoid a warning. old_state must be used.
assert_eq!(
old_state, new_state,
"States must be the same after initialization"
);
let mut challenges: Vec<_> = vec![];

for i in 0..random_n {
old_state.clone_from(&new_state);
new_state.clone_from(&sponge.sponge.state);
let chal = sponge.challenge();
if i % 2 == 0 {
assert_eq!(
old_state, new_state,
"States must be the same after squeezing an even number of times"
);
} else {
assert_ne!(
old_state, new_state,
"States must not be the same after squeezing an odd number of times"
);
}
assert!(
!challenges.contains(&chal),
"Challenges must always be different, even without any absorbtion"
);
challenges.push(chal);
}
}

0 comments on commit f15858d

Please sign in to comment.