small polishing
arnaucube root@arnaucube.com
Thu, 08 Aug 2024 18:18:06 +0200
3 files changed,
31 insertions(+),
29 deletions(-)
M
src/keccak_chain.rs
→
src/keccak_chain.rs
@@ -57,7 +57,7 @@
#[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<u32> = vec![0_u32; 32 * 8];@@ -93,8 +93,9 @@ // check that the constraint system is satisfied
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<G1, GVar, G2, GVar2, CircomFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>, false>; pub type D = DeciderEth< G1,@@ -105,7 +106,7 @@ CircomFCircuit<Fr>,
KZG<'static, Bn254>, Pedersen<G2>, Groth16<Bn254>, - N, + FS, >; let poseidon_config = poseidon_canonical_config::<Fr>();@@ -114,16 +115,11 @@
// 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 @@
// 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 @@ // Sanity check
// 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,@@ -167,6 +163,11 @@ cyclefold_instance,
) .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();
M
src/naive_approach_sha_chain.rs
→
src/naive_approach_sha_chain.rs
@@ -85,7 +85,7 @@ #[test]
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 @@
let cs = ConstraintSystem::<Fr>::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() );
M
src/sha_chain.rs
→
src/sha_chain.rs
@@ -145,8 +145,9 @@ cs.num_constraints()
); // ---------------- - // 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 @@ SHA256FoldStepCircuit<Fr, HASHES_PER_STEP>,
KZG<'static, Bn254>, Pedersen<G2>, Groth16<Bn254>, - N, + FS, >; let poseidon_config = poseidon_canonical_config::<Fr>();@@ -174,16 +175,11 @@
// 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 @@ // Sanity check
// 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,@@ -218,6 +214,11 @@ cyclefold_instance,
) .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();