From 53af1d39a83a39fe693d160de18c6cf808784822 Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Fri, 3 May 2024 16:57:28 -0700 Subject: [PATCH 1/3] avoid calls to pp.digest in prove methods --- src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a999f127..0d6c3dc7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,7 +185,7 @@ where return Err(NovaError::InvalidStepCircuitIO); } - Ok(PublicParams { + let pp = PublicParams { F_arity_primary, F_arity_secondary, ro_consts_primary, @@ -200,7 +200,12 @@ where augmented_circuit_params_secondary, digest: OnceCell::new(), _p: Default::default(), - }) + }; + + // call pp.digest() so the digest is computed here rather than in RecursiveSNARK methods + let _ = pp.digest(); + + Ok(pp) } /// Retrieve the digest of the public parameters. From e8fc0f18e9d981c99fa3f806c77d82ac4d60ef5a Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Fri, 3 May 2024 17:04:53 -0700 Subject: [PATCH 2/3] remove unused --- src/gadgets/nonnative/mod.rs | 4 ---- src/spartan/math.rs | 15 --------------- 2 files changed, 19 deletions(-) diff --git a/src/gadgets/nonnative/mod.rs b/src/gadgets/nonnative/mod.rs index 8167e5a7..4d611cbb 100644 --- a/src/gadgets/nonnative/mod.rs +++ b/src/gadgets/nonnative/mod.rs @@ -6,16 +6,12 @@ use ff::PrimeField; trait OptionExt { fn grab(&self) -> Result<&T, SynthesisError>; - fn grab_mut(&mut self) -> Result<&mut T, SynthesisError>; } impl OptionExt for Option { fn grab(&self) -> Result<&T, SynthesisError> { self.as_ref().ok_or(SynthesisError::AssignmentMissing) } - fn grab_mut(&mut self) -> Result<&mut T, SynthesisError> { - self.as_mut().ok_or(SynthesisError::AssignmentMissing) - } } trait BitAccess { diff --git a/src/spartan/math.rs b/src/spartan/math.rs index 691fec5d..22dbce17 100644 --- a/src/spartan/math.rs +++ b/src/spartan/math.rs @@ -1,23 +1,8 @@ pub trait Math { - fn pow2(self) -> usize; - fn get_bits(self, num_bits: usize) -> Vec; fn log_2(self) -> usize; } impl Math for usize { - #[inline] - fn pow2(self) -> usize { - let base: usize = 2; - base.pow(self as u32) - } - - /// Returns the `num_bits` from n in a canonical order - fn get_bits(self, num_bits: usize) -> Vec { - (0..num_bits) - .map(|shift_amount| ((self & (1 << (num_bits - shift_amount - 1))) > 0)) - .collect::>() - } - fn log_2(self) -> usize { assert_ne!(self, 0); From 30ae7a8983235465d75b1a0250ab3b197dd136e5 Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Fri, 3 May 2024 17:12:09 -0700 Subject: [PATCH 3/3] address clippy --- src/provider/hyperkzg.rs | 6 ++++-- src/r1cs/mod.rs | 3 ++- src/spartan/direct.rs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/provider/hyperkzg.rs b/src/provider/hyperkzg.rs index 6afc9a53..30d9d395 100644 --- a/src/provider/hyperkzg.rs +++ b/src/provider/hyperkzg.rs @@ -765,7 +765,8 @@ mod tests { // Change the proof and expect verification to fail let mut bad_proof = proof.clone(); - bad_proof.v[0] = bad_proof.v[1].clone(); + let v1 = bad_proof.v[1].clone(); + bad_proof.v[0].clone_from(&v1); let mut verifier_transcript2 = Keccak256Transcript::new(b"TestEval"); assert!(EvaluationEngine::verify( &vk, @@ -808,7 +809,8 @@ mod tests { // Change the proof and expect verification to fail let mut bad_proof = proof.clone(); - bad_proof.v[0] = bad_proof.v[1].clone(); + let v1 = bad_proof.v[1].clone(); + bad_proof.v[0].clone_from(&v1); let mut verifier_tr2 = Keccak256Transcript::new(b"TestEval"); assert!( EvaluationEngine::verify(&vk, &mut verifier_tr2, &C, &point, &eval, &bad_proof).is_err() diff --git a/src/r1cs/mod.rs b/src/r1cs/mod.rs index 56ef1394..b70b1876 100644 --- a/src/r1cs/mod.rs +++ b/src/r1cs/mod.rs @@ -480,7 +480,8 @@ impl RelaxedR1CSInstance { let mut r_instance = RelaxedR1CSInstance::default(ck, S); r_instance.comm_W = instance.comm_W; r_instance.u = E::Scalar::ONE; - r_instance.X = instance.X.clone(); + r_instance.X.clone_from(&instance.X); + r_instance } diff --git a/src/spartan/direct.rs b/src/spartan/direct.rs index 80986a2a..83cad2c3 100644 --- a/src/spartan/direct.rs +++ b/src/spartan/direct.rs @@ -277,7 +277,7 @@ mod tests { assert!(res.is_ok()); // set input to the next step - z_i = z_i_plus_one.clone(); + z_i.clone_from(&z_i_plus_one); } // sanity: check the claimed output with a direct computation of the same