From 026cccb508209d384ffd21a10dabc3db301b5657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Mon, 12 Feb 2024 10:39:20 -0500 Subject: [PATCH] refactor: Remove testing boilerplate - Refactored tests for improved modularity and readability. - Streamlined testing procedure by calling one function within another. --- src/lib.rs | 114 ++++++++++++++--------------------------------------- 1 file changed, 30 insertions(+), 84 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8c22d682a..83eb263f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1291,24 +1291,24 @@ mod tests { test_ivc_nontrivial_with::(); } - fn test_ivc_nontrivial_with_compression_with() + fn test_ivc_nontrivial_with_some_compression_with() where E1: CurveCycleEquipped, - EE1: EvaluationEngineTrait, - EE2: EvaluationEngineTrait>, // this is due to the reliance on Abomonation ::Repr: Abomonation, < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + S1: RelaxedR1CSSNARKTrait, + S2: RelaxedR1CSSNARKTrait>, { let circuit_primary = TrivialCircuit::default(); let circuit_secondary = CubicCircuit::default(); - // produce public parameters + // produce public parameters, which we'll maybe use with a preprocessing compressed SNARK let pp = PublicParams::::setup( &circuit_primary, &circuit_secondary, - &*default_ck_hint(), - &*default_ck_hint(), + &*S1::ck_floor(), + &*S2::ck_floor(), ); let num_steps = 3; @@ -1351,22 +1351,36 @@ mod tests { vec![ as Engine>::Scalar::from(2460515u64)] ); + // run the compressed snark // produce the prover and verifier keys for compressed snark - let (pk, vk) = CompressedSNARK::<_, S, S<_, EE2>>::setup(&pp).unwrap(); + let (pk, vk) = CompressedSNARK::<_, S1, S2>::setup(&pp).unwrap(); // produce a compressed SNARK - let res = CompressedSNARK::<_, S, S<_, EE2>>::prove(&pp, &pk, &recursive_snark); + let res = CompressedSNARK::<_, S1, S2>::prove(&pp, &pk, &recursive_snark); assert!(res.is_ok()); let compressed_snark = res.unwrap(); // verify the compressed SNARK - let res = compressed_snark.verify( - &vk, - num_steps, - &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], - ); - assert!(res.is_ok()); + compressed_snark + .verify( + &vk, + num_steps, + &[::Scalar::ONE], + &[ as Engine>::Scalar::ZERO], + ) + .unwrap(); + } + + fn test_ivc_nontrivial_with_compression_with() + where + E1: CurveCycleEquipped, + EE1: EvaluationEngineTrait, + EE2: EvaluationEngineTrait>, + // this is due to the reliance on Abomonation + ::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + { + test_ivc_nontrivial_with_some_compression_with::, S<_, EE2>>() } #[test] @@ -1391,75 +1405,7 @@ mod tests { ::Repr: Abomonation, < as Engine>::Scalar as PrimeField>::Repr: Abomonation, { - let circuit_primary = TrivialCircuit::default(); - let circuit_secondary = CubicCircuit::default(); - - // produce public parameters, which we'll use with a spark-compressed SNARK - let pp = PublicParams::::setup( - &circuit_primary, - &circuit_secondary, - &*SPrime::::ck_floor(), - &*SPrime::<_, EE2>::ck_floor(), - ); - - let num_steps = 3; - - // produce a recursive SNARK - let mut recursive_snark = RecursiveSNARK::::new( - &pp, - &circuit_primary, - &circuit_secondary, - &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], - ) - .unwrap(); - - for _i in 0..num_steps { - let res = recursive_snark.prove_step(&pp, &circuit_primary, &circuit_secondary); - assert!(res.is_ok()); - } - - // verify the recursive SNARK - let res = recursive_snark.verify( - &pp, - num_steps, - &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], - ); - assert!(res.is_ok()); - - let (zn_primary, zn_secondary) = res.unwrap(); - - // sanity: check the claimed output with a direct computation of the same - assert_eq!(zn_primary, vec![::Scalar::ONE]); - let mut zn_secondary_direct = vec![ as Engine>::Scalar::ZERO]; - for _i in 0..num_steps { - zn_secondary_direct = CubicCircuit::default().output(&zn_secondary_direct); - } - assert_eq!(zn_secondary, zn_secondary_direct); - assert_eq!( - zn_secondary, - vec![ as Engine>::Scalar::from(2460515u64)] - ); - - // run the compressed snark with Spark compiler - // produce the prover and verifier keys for compressed snark - let (pk, vk) = CompressedSNARK::<_, SPrime, SPrime<_, EE2>>::setup(&pp).unwrap(); - - // produce a compressed SNARK - let res = - CompressedSNARK::<_, SPrime, SPrime<_, EE2>>::prove(&pp, &pk, &recursive_snark); - assert!(res.is_ok()); - let compressed_snark = res.unwrap(); - - // verify the compressed SNARK - let res = compressed_snark.verify( - &vk, - num_steps, - &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], - ); - assert!(res.is_ok()); + test_ivc_nontrivial_with_some_compression_with::, SPrime<_, EE2>>() } #[test]