Skip to content

Commit

Permalink
chore: fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed May 3, 2024
1 parent a4ead79 commit 30ddd39
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 28 deletions.
2 changes: 1 addition & 1 deletion benches/compressed-snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<F: PrimeField> StepCircuit<F> for NonTrivialCircuit<F> {
let mut y = x.clone();
for i in 0..self.num_cons {
y = x.square(cs.namespace(|| format!("x_sq_{i}")))?;
x = y.clone();
x.clone_from(&y);
}
Ok(vec![y])
}
Expand Down
2 changes: 1 addition & 1 deletion benches/compute-digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<F: PrimeField> StepCircuit<F> for NonTrivialCircuit<F> {
let mut y = x.clone();
for i in 0..self.num_cons {
y = x.square(cs.namespace(|| format!("x_sq_{i}")))?;
x = y.clone();
x.clone_from(&y);
}
Ok(vec![y])
}
Expand Down
2 changes: 1 addition & 1 deletion benches/ppsnark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<F: PrimeField> StepCircuit<F> for NonTrivialCircuit<F> {
let mut y = z[0].clone();
for i in 0..self.num_cons {
y = x.square(cs.namespace(|| format!("x_sq_{i}")))?;
x = y.clone();
x.clone_from(&y);
}
Ok(vec![y])
}
Expand Down
2 changes: 1 addition & 1 deletion benches/recursive-snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<F: PrimeField> StepCircuit<F> for NonTrivialCircuit<F> {
let mut y = x.clone();
for i in 0..self.num_cons {
y = x.square(cs.namespace(|| format!("x_sq_{i}")))?;
x = y.clone();
x.clone_from(&y);
}
Ok(vec![y])
}
Expand Down
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
3 changes: 0 additions & 3 deletions src/gadgets/nonnative/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use std::io::{self, Write};
pub struct Bit<Scalar: PrimeField> {
/// The linear combination which constrain the value of the bit
pub bit: LinearCombination<Scalar>,
/// The value of the bit (filled at witness-time)
pub value: Option<bool>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -58,7 +56,6 @@ impl<Scalar: PrimeField> Bit<Scalar> {

Ok(Self {
bit: LinearCombination::zero() + var,
value,
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/provider/hyperkzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ mod tests {
}

#[test]
#[allow(clippy::assigning_clones)]
fn test_hyperkzg_small() {
let n = 4;

Expand Down Expand Up @@ -765,7 +766,9 @@ 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 mut verifier_transcript2 = Keccak256Transcript::new(b"TestEval");
assert!(EvaluationEngine::verify(
&vk,
Expand All @@ -779,6 +782,7 @@ mod tests {
}

#[test]
#[allow(clippy::assigning_clones)]
fn test_hyperkzg_large() {
// test the hyperkzg prover and verifier with random instances (derived from a seed)
for ell in [4, 5, 6] {
Expand Down Expand Up @@ -808,7 +812,9 @@ 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 mut verifier_tr2 = Keccak256Transcript::new(b"TestEval");
assert!(
EvaluationEngine::verify(&vk, &mut verifier_tr2, &C, &point, &eval, &bad_proof).is_err()
Expand Down
2 changes: 1 addition & 1 deletion src/r1cs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ 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

0 comments on commit 30ddd39

Please sign in to comment.