diff --git a/src/keccak_chain.rs b/src/keccak_chain.rs index c062868..7eb8f64 100644 --- a/src/keccak_chain.rs +++ b/src/keccak_chain.rs @@ -57,7 +57,7 @@ mod tests { #[test] fn full_flow() { // set how many steps of folding we want to compute - let n_steps = 1000; + let n_steps = 50; // set the initial state let z_0_aux: Vec = vec![0_u32; 32 * 8]; @@ -93,8 +93,9 @@ mod tests { assert!(cs.is_satisfied().unwrap()); // ---------------- - // define type aliases to avoid writting the whole type each time - pub type N = + // define type aliases for the FoldingScheme (FS) and Decider (D), to avoid writting the + // whole type each time + pub type FS = Nova, KZG<'static, Bn254>, Pedersen, false>; pub type D = DeciderEth< G1, @@ -105,7 +106,7 @@ mod tests { KZG<'static, Bn254>, Pedersen, Groth16, - N, + FS, >; let poseidon_config = poseidon_canonical_config::(); @@ -114,16 +115,11 @@ mod tests { // prepare the Nova prover & verifier params let nova_preprocess_params = PreprocessorParam::new(poseidon_config, f_circuit.clone()); let start = Instant::now(); - let nova_params = N::preprocess(&mut rng, &nova_preprocess_params).unwrap(); + let nova_params = FS::preprocess(&mut rng, &nova_preprocess_params).unwrap(); println!("Nova params generated: {:?}", start.elapsed()); // initialize the folding scheme engine, in our case we use Nova - let mut nova = N::init(&nova_params, f_circuit.clone(), z_0.clone()).unwrap(); - - // prepare the Decider prover & verifier params - let start = Instant::now(); - let (decider_pp, decider_vp) = D::preprocess(&mut rng, &nova_params, nova.clone()).unwrap(); - println!("Decider params generated: {:?}", start.elapsed()); + let mut nova = FS::init(&nova_params, f_circuit.clone(), z_0.clone()).unwrap(); // run n steps of the folding iteration let start_full = Instant::now(); @@ -145,7 +141,7 @@ mod tests { // perform the hash chain natively in rust (which uses a rust Keccak256 library) let mut z_i_native = z_0.clone(); for i in 0..n_steps { - z_i_native = rust_native_step(i, z_i_native.clone(), vec![]).unwrap(); + z_i_native = rust_native_step(i, z_i_native, vec![]).unwrap(); } // check that the value of the last folding state (nova.z_i) computed through folding, is // equal to the natively computed hash using the rust_native_step method @@ -156,8 +152,8 @@ mod tests { // The following lines contain a sanity check that checks the IVC proof (before going into // the zkSNARK proof) let (running_instance, incoming_instance, cyclefold_instance) = nova.instances(); - N::verify( - nova_params.1, // Nova's verifier params + FS::verify( + nova_params.1.clone(), // Nova's verifier params z_0, nova.z_i.clone(), nova.i, @@ -168,6 +164,11 @@ mod tests { .unwrap(); // ---------------- + // prepare the Decider prover & verifier params + let start = Instant::now(); + let (decider_pp, decider_vp) = D::preprocess(&mut rng, &nova_params, nova.clone()).unwrap(); + println!("Decider params generated: {:?}", start.elapsed()); + let rng = rand::rngs::OsRng; let start = Instant::now(); let proof = D::prove(rng, decider_pp, nova.clone()).unwrap(); diff --git a/src/naive_approach_sha_chain.rs b/src/naive_approach_sha_chain.rs index 032963e..840647f 100644 --- a/src/naive_approach_sha_chain.rs +++ b/src/naive_approach_sha_chain.rs @@ -85,7 +85,7 @@ mod tests { fn full_flow() { // set how many iterations of the SHA256ChainCircuit circuit internal loop we want to // compute - const N_STEPS: usize = 50; + const N_STEPS: usize = 100; const HASHES_PER_STEP: usize = 10; println!("running the 'naive' SHA256ChainCircuit, with N_STEPS={}, HASHES_PER_STEP={}. Total hashes = {}", N_STEPS, HASHES_PER_STEP, N_STEPS* HASHES_PER_STEP); @@ -105,8 +105,8 @@ mod tests { let cs = ConstraintSystem::::new_ref(); circuit.clone().generate_constraints(cs.clone()).unwrap(); println!( - "number of constraints of the (naive) SHA256ChainCircuit with N={} hash iterations: {}", - N_STEPS, + "number of constraints of the (naive) SHA256ChainCircuit with N_STEPS*HASHES_PER_STEP={} sha256 hashes in total: {}", + N_STEPS * HASHES_PER_STEP, cs.num_constraints() ); diff --git a/src/sha_chain.rs b/src/sha_chain.rs index c5f559b..3124abd 100644 --- a/src/sha_chain.rs +++ b/src/sha_chain.rs @@ -145,8 +145,9 @@ mod tests { ); // ---------------- - // define type aliases to avoid writting the whole type each time - pub type N = Nova< + // define type aliases for the FoldingScheme (FS) and Decider (D), to avoid writting the + // whole type each time + pub type FS = Nova< G1, GVar, G2, @@ -165,7 +166,7 @@ mod tests { KZG<'static, Bn254>, Pedersen, Groth16, - N, + FS, >; let poseidon_config = poseidon_canonical_config::(); @@ -174,16 +175,11 @@ mod tests { // prepare the Nova prover & verifier params let nova_preprocess_params = PreprocessorParam::new(poseidon_config, f_circuit); let start = Instant::now(); - let nova_params = N::preprocess(&mut rng, &nova_preprocess_params).unwrap(); + let nova_params = FS::preprocess(&mut rng, &nova_preprocess_params).unwrap(); println!("Nova params generated: {:?}", start.elapsed()); // initialize the folding scheme engine, in our case we use Nova - let mut nova = N::init(&nova_params, f_circuit, z_0.clone()).unwrap(); - - // prepare the Decider prover & verifier params - let start = Instant::now(); - let (decider_pp, decider_vp) = D::preprocess(&mut rng, &nova_params, nova.clone()).unwrap(); - println!("Decider params generated: {:?}", start.elapsed()); + let mut nova = FS::init(&nova_params, f_circuit, z_0.clone()).unwrap(); // run n steps of the folding iteration let start_full = Instant::now(); @@ -207,8 +203,8 @@ mod tests { // The following lines contain a sanity check that checks the IVC proof (before going into // the zkSNARK proof) let (running_instance, incoming_instance, cyclefold_instance) = nova.instances(); - N::verify( - nova_params.1, // Nova's verifier params + FS::verify( + nova_params.1.clone(), // Nova's verifier params z_0, nova.z_i.clone(), nova.i, @@ -219,6 +215,11 @@ mod tests { .unwrap(); // ---------------- + // prepare the Decider prover & verifier params + let start = Instant::now(); + let (decider_pp, decider_vp) = D::preprocess(&mut rng, &nova_params, nova.clone()).unwrap(); + println!("Decider params generated: {:?}", start.elapsed()); + let rng = rand::rngs::OsRng; let start = Instant::now(); let proof = D::prove(rng, decider_pp, nova.clone()).unwrap();