|
1 |
| -use crate::{hash::sponge::DuplexSponge, IOPattern, UnitTranscript}; |
| 1 | +use crate::{hash::sponge::DuplexSponge, DefaultHash, DuplexHash, IOPattern, Unit, UnitTranscript}; |
2 | 2 | use ark_bls12_381::Fr;
|
3 | 3 | use ark_ff::{MontFp, Zero};
|
4 | 4 |
|
5 | 5 | use super::poseidon::PoseidonSponge;
|
6 | 6 |
|
7 |
| -type H = DuplexSponge<PoseidonSponge<Fr, 2, 3>>; |
8 |
| -type F = Fr; |
| 7 | +/// Test that the algebraic hashes do use the IV generated from the IO Pattern. |
| 8 | +fn check_iv_is_used<H: DuplexHash<F>, F: Unit + Copy + Default + Eq + core::fmt::Debug>() { |
| 9 | + let io1 = IOPattern::<H, F>::new("test").squeeze(1, "out"); |
| 10 | + let io2 = IOPattern::<H, F>::new("another_test").squeeze(1, "out"); |
9 | 11 |
|
| 12 | + let [mut arthur1, mut arthur2] = [io1.to_arthur(), io2.to_arthur()]; |
| 13 | + let mut c = [F::default(); 2]; |
| 14 | + arthur1.fill_challenge_units(&mut c[0..1]).unwrap(); |
| 15 | + arthur2.fill_challenge_units(&mut c[1..2]).unwrap(); |
| 16 | + assert_ne!(c[0], c[1]); |
| 17 | +} |
| 18 | + |
| 19 | +#[test] |
| 20 | +fn test_iv_is_used() { |
| 21 | + check_iv_is_used::<DefaultHash, u8>(); |
| 22 | + check_iv_is_used::<DuplexSponge<PoseidonSponge<Fr, 2, 3>>, Fr>(); |
| 23 | +} |
| 24 | + |
| 25 | +/// Check that poseidon can indeed be instantiated and doesn't do terribly stupid things like give 0 challenges. |
10 | 26 | #[test]
|
11 | 27 | fn test_poseidon_basic() {
|
| 28 | + type F = Fr; |
| 29 | + type H = DuplexSponge<PoseidonSponge<F, 2, 3>>; |
| 30 | + |
12 | 31 | let io = IOPattern::<H, F>::new("test")
|
13 | 32 | .absorb(1, "in")
|
14 | 33 | .squeeze(10, "out");
|
|
0 commit comments