diff --git a/src/supernova/snark.rs b/src/supernova/snark.rs index 8645ee0ec..ccb39d24d 100644 --- a/src/supernova/snark.rs +++ b/src/supernova/snark.rs @@ -458,65 +458,6 @@ mod test { } } - fn test_nivc_trivial_with_compression_with() - where - E1: CurveCycleEquipped, - S1: BatchedRelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, - ::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, - { - const NUM_STEPS: usize = 6; - - let secondary_circuit = TrivialSecondaryCircuit::default(); - let test_circuits = TestCircuit::new(NUM_STEPS); - - let pp = PublicParams::setup(&test_circuits[0], &*S1::ck_floor(), &*S2::ck_floor()); - - let z0_primary = vec![E1::Scalar::from(17u64)]; - let z0_secondary = vec![ as Engine>::Scalar::ZERO]; - - let mut recursive_snark = RecursiveSNARK::new( - &pp, - &test_circuits[0], - &test_circuits[0], - &secondary_circuit, - &z0_primary, - &z0_secondary, - ) - .unwrap(); - - for circuit in test_circuits.iter().take(NUM_STEPS) { - recursive_snark - .prove_step(&pp, circuit, &secondary_circuit) - .unwrap(); - - recursive_snark - .verify(&pp, &z0_primary, &z0_secondary) - .unwrap(); - } - - let (prover_key, verifier_key) = CompressedSNARK::<_, S1, S2>::setup(&pp).unwrap(); - - let compressed_snark = CompressedSNARK::prove(&pp, &prover_key, &recursive_snark).unwrap(); - - compressed_snark - .verify(&pp, &verifier_key, &z0_primary, &z0_secondary) - .unwrap(); - } - - #[test] - fn test_nivc_trivial_with_compression() { - // ppSNARK - test_nivc_trivial_with_compression_with::, S2<_>>(); - test_nivc_trivial_with_compression_with::, S2<_>>(); - test_nivc_trivial_with_compression_with::, S2<_>>(); - // classic SNARK - test_nivc_trivial_with_compression_with::, S2<_>>(); - test_nivc_trivial_with_compression_with::, S2<_>>(); - test_nivc_trivial_with_compression_with::, S2<_>>(); - } - #[derive(Clone)] struct BigPowerCircuit { _p: PhantomData, @@ -637,62 +578,83 @@ mod test { } } - fn test_compression_with_circuit_size_difference_with() - where - E1: CurveCycleEquipped, - S1: BatchedRelaxedR1CSSNARKTrait, - S2: RelaxedR1CSSNARKTrait>, - ::Repr: Abomonation, - < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + fn test_compression_with( + num_steps: usize, + circuits_factory: F, + ) where + E1: CurveCycleEquipped, + S1: BatchedRelaxedR1CSSNARKTrait, + S2: RelaxedR1CSSNARKTrait>, + ::Repr: Abomonation, + < as Engine>::Scalar as PrimeField>::Repr: Abomonation, + C: NonUniformCircuit as Engine>::Scalar>> + StepCircuit, + F: Fn(usize) -> Vec, { - const NUM_STEPS: usize = 4; - - let secondary_circuit = TrivialSecondaryCircuit::default(); - let test_circuits = BigTestCircuit::new(NUM_STEPS); - - let pp = PublicParams::setup(&test_circuits[0], &*S1::ck_floor(), &*S2::ck_floor()); - - let z0_primary = vec![E1::Scalar::from(17u64)]; - let z0_secondary = vec![ as Engine>::Scalar::ZERO]; - - let mut recursive_snark = RecursiveSNARK::new( - &pp, - &test_circuits[0], - &test_circuits[0], - &secondary_circuit, - &z0_primary, - &z0_secondary, - ) - .unwrap(); - - for circuit in test_circuits.iter().take(NUM_STEPS) { - recursive_snark - .prove_step(&pp, circuit, &secondary_circuit) - .unwrap(); - - recursive_snark - .verify(&pp, &z0_primary, &z0_secondary) - .unwrap(); - } + let secondary_circuit = TrivialSecondaryCircuit::default(); + let test_circuits = circuits_factory(num_steps); - let (prover_key, verifier_key) = CompressedSNARK::<_, S1, S2>::setup(&pp).unwrap(); + let pp = PublicParams::setup(&test_circuits[0], &*S1::ck_floor(), &*S2::ck_floor()); - let compressed_snark = CompressedSNARK::prove(&pp, &prover_key, &recursive_snark).unwrap(); + let z0_primary = vec![E1::Scalar::from(17u64)]; + let z0_secondary = vec![ as Engine>::Scalar::ZERO]; - compressed_snark - .verify(&pp, &verifier_key, &z0_primary, &z0_secondary) + let mut recursive_snark = RecursiveSNARK::new( + &pp, + &test_circuits[0], + &test_circuits[0], + &secondary_circuit, + &z0_primary, + &z0_secondary, + ) .unwrap(); + + for circuit in test_circuits.iter().take(num_steps) { + recursive_snark + .prove_step(&pp, circuit, &secondary_circuit) + .unwrap(); + + recursive_snark + .verify(&pp, &z0_primary, &z0_secondary) + .unwrap(); + } + + let (prover_key, verifier_key) = CompressedSNARK::<_, S1, S2>::setup(&pp).unwrap(); + + let compressed_snark = CompressedSNARK::prove(&pp, &prover_key, &recursive_snark).unwrap(); + + compressed_snark + .verify(&pp, &verifier_key, &z0_primary, &z0_secondary) + .unwrap(); + } + + #[test] + fn test_nivc_trivial_with_compression() { + const NUM_STEPS: usize = 6; + + // ppSNARK + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| TestCircuit::new(n)); + + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| TestCircuit::new(n)); + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| TestCircuit::new(n)); + + // classic SNARK + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| TestCircuit::new(n)); + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| TestCircuit::new(n)); + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| TestCircuit::new(n)); } #[test] fn test_compression_with_circuit_size_difference() { - // ppSNARK - test_compression_with_circuit_size_difference_with::, S2<_>>(); - test_compression_with_circuit_size_difference_with::, S2<_>>(); - test_compression_with_circuit_size_difference_with::, S2<_>>(); - // classic SNARK - test_compression_with_circuit_size_difference_with::, S2<_>>(); - test_compression_with_circuit_size_difference_with::, S2<_>>(); - test_compression_with_circuit_size_difference_with::, S2<_>>(); + const NUM_STEPS: usize = 4; + + // ppSNARK + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| BigTestCircuit::new(n)); + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| BigTestCircuit::new(n)); + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| BigTestCircuit::new(n)); + + // classic SNARK + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| BigTestCircuit::new(n)); + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| BigTestCircuit::new(n)); + test_compression_with::, S2<_>, _, _>(NUM_STEPS, |n| BigTestCircuit::new(n)); } }