Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid calls to pp.digest in prove methods #320

Merged
merged 3 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/gadgets/nonnative/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ use ff::PrimeField;

trait OptionExt<T> {
fn grab(&self) -> Result<&T, SynthesisError>;
fn grab_mut(&mut self) -> Result<&mut T, SynthesisError>;
}

impl<T> OptionExt<T> for Option<T> {
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 {
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ where
return Err(NovaError::InvalidStepCircuitIO);
}

Ok(PublicParams {
let pp = PublicParams {
F_arity_primary,
F_arity_secondary,
ro_consts_primary,
Expand All @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions src/provider/hyperkzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/r1cs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ impl<E: Engine> RelaxedR1CSInstance<E> {
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
}

Expand Down
2 changes: 1 addition & 1 deletion src/spartan/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions src/spartan/math.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
pub trait Math {
fn pow2(self) -> usize;
fn get_bits(self, num_bits: usize) -> Vec<bool>;
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<bool> {
(0..num_bits)
.map(|shift_amount| ((self & (1 << (num_bits - shift_amount - 1))) > 0))
.collect::<Vec<bool>>()
}

fn log_2(self) -> usize {
assert_ne!(self, 0);

Expand Down
Loading