arnaucube
arnaucube/NovaPublic Self-hosted repository
Clippy formatting (#131)

* Clippy with Rust 1.67

* Clippy/Rustfmt with Rust 1.66.1
Samuel Burnham 45365069+samuelburnham@users.noreply.github.com
Tue, 31 Jan 2023 17:53:15 -0500
commit

b2adab610a084c7b40691d34b542f25ee493bffe

parent

74501936c3a692852f5318de46331ecdd216eaa6

M Cargo.toml → Cargo.toml

@@ -12,7 +12,7 @@ keywords = ["zkSNARKs", "cryptography", "proofs"]

[dependencies] bellperson = { version = "0.24", default-features = false } -ff = { version = "0.12.0", features = ["derive"]} +ff = { version = "0.12.0", features = ["derive"] } merlin = "2.0.0" digest = "0.8.1" sha3 = "0.8.2"

@@ -49,4 +49,4 @@ name = "compressed-snark"

harness = false [features] -default = [ "bellperson/default", "neptune/default" ] +default = []
M benches/compressed-snark.rs → benches/compressed-snark.rs

@@ -38,7 +38,7 @@ {

// number of constraints in the step circuit let num_cons = num_cons_in_augmented_circuit - num_cons_verifier_circuit_primary; - let mut group = c.benchmark_group(format!("CompressedSNARK-StepCircuitSize-{}", num_cons)); + let mut group = c.benchmark_group(format!("CompressedSNARK-StepCircuitSize-{num_cons}")); group.sample_size(num_samples); // Produce public parameters

@@ -143,7 +143,7 @@ // Consider a an equation: `x^2 = y`, where `x` and `y` are respectively the input and output.

let mut x = z[0].clone(); let mut y = x.clone(); for i in 0..self.num_cons { - y = x.square(cs.namespace(|| format!("x_sq_{}", i)))?; + y = x.square(cs.namespace(|| format!("x_sq_{i}")))?; x = y.clone(); } Ok(vec![y])
M benches/recursive-snark.rs → benches/recursive-snark.rs

@@ -35,7 +35,7 @@ {

// number of constraints in the step circuit let num_cons = num_cons_in_augmented_circuit - num_cons_verifier_circuit_primary; - let mut group = c.benchmark_group(format!("RecursiveSNARK-StepCircuitSize-{}", num_cons)); + let mut group = c.benchmark_group(format!("RecursiveSNARK-StepCircuitSize-{num_cons}")); group.sample_size(10); // Produce public parameters

@@ -144,7 +144,7 @@ // Consider a an equation: `x^2 = y`, where `x` and `y` are respectively the input and output.

let mut x = z[0].clone(); let mut y = x.clone(); for i in 0..self.num_cons { - y = x.square(cs.namespace(|| format!("x_sq_{}", i)))?; + y = x.square(cs.namespace(|| format!("x_sq_{i}")))?; x = y.clone(); } Ok(vec![y])
M examples/minroot.rs → examples/minroot.rs

@@ -97,7 +97,7 @@ let mut y_i = y_0;

for i in 0..self.seq.len() { // non deterministic advice let x_i_plus_1 = - AllocatedNum::alloc(cs.namespace(|| format!("x_i_plus_1_iter_{}", i)), || { + AllocatedNum::alloc(cs.namespace(|| format!("x_i_plus_1_iter_{i}")), || { Ok(self.seq[i].x_i_plus_1) })?;

@@ -106,12 +106,11 @@ // (i) x_i_plus_1 = (x_i + y_i)^{1/5}, which can be more easily checked with x_i_plus_1^5 = x_i + y_i

// (ii) y_i_plus_1 = x_i // (1) constraints for condition (i) are below // (2) constraints for condition (ii) is avoided because we just used x_i wherever y_i_plus_1 is used - let x_i_plus_1_sq = - x_i_plus_1.square(cs.namespace(|| format!("x_i_plus_1_sq_iter_{}", i)))?; + let x_i_plus_1_sq = x_i_plus_1.square(cs.namespace(|| format!("x_i_plus_1_sq_iter_{i}")))?; let x_i_plus_1_quad = - x_i_plus_1_sq.square(cs.namespace(|| format!("x_i_plus_1_quad_{}", i)))?; + x_i_plus_1_sq.square(cs.namespace(|| format!("x_i_plus_1_quad_{i}")))?; cs.enforce( - || format!("x_i_plus_1_quad * x_i_plus_1 = x_i + y_i_iter_{}", i), + || format!("x_i_plus_1_quad * x_i_plus_1 = x_i + y_i_iter_{i}"), |lc| lc + x_i_plus_1_quad.get_variable(), |lc| lc + x_i_plus_1.get_variable(), |lc| lc + x_i.get_variable() + y_i.get_variable(),

@@ -163,10 +162,7 @@ };

let circuit_secondary = TrivialTestCircuit::default(); - println!( - "Proving {} iterations of MinRoot per step", - num_iters_per_step - ); + println!("Proving {num_iters_per_step} iterations of MinRoot per step"); // produce public parameters let start = Instant::now();
M examples/signature.rs → examples/signature.rs

@@ -185,7 +185,7 @@ (0..F::NUM_BITS)

.into_iter() .map(|i| { AllocatedBit::alloc( - cs.namespace(|| format!("bit {}", i)), + cs.namespace(|| format!("bit {i}")), Some(bits.as_ref().unwrap()[i as usize]), ) })
M src/bellperson/shape_cs.rs → src/bellperson/shape_cs.rs

@@ -122,13 +122,13 @@ pub fn pretty_print_list(&self) -> Vec<String> {

let mut result = Vec::new(); for input in &self.inputs { - result.push(format!("INPUT {}", input)); + result.push(format!("INPUT {input}")); } for aux in &self.aux { - result.push(format!("AUX {}", aux)); + result.push(format!("AUX {aux}")); } - for &(ref _a, ref _b, ref _c, ref name) in &self.constraints { + for (_a, _b, _c, name) in &self.constraints { result.push(name.to_string()); }

@@ -164,12 +164,12 @@

if coeff != <G::Scalar>::one() && coeff != negone { for (i, x) in powers_of_two.iter().enumerate() { if x == &coeff { - write!(s, "2^{} . ", i).unwrap(); + write!(s, "2^{i} . ").unwrap(); break; } } - write!(s, "{:?} . ", coeff).unwrap() + write!(s, "{coeff:?} . ").unwrap() } match var.0.get_unchecked() {

@@ -188,10 +188,10 @@ }

s.push(')'); }; - for &(ref a, ref b, ref c, ref name) in &self.constraints { + for (a, b, c, name) in &self.constraints { s.push('\n'); - write!(s, "{}: ", name).unwrap(); + write!(s, "{name}: ").unwrap(); pp(&mut s, a); write!(s, " * ").unwrap(); pp(&mut s, b);

@@ -209,8 +209,7 @@ /// `path` must not already have an associated object.

fn set_named_obj(&mut self, path: String, to: NamedObject) { assert!( !self.named_objects.contains_key(&path), - "tried to create object at existing path: {}", - path + "tried to create object at existing path: {path}" ); self.named_objects.insert(path, to);
M src/bellperson/solver.rs → src/bellperson/solver.rs

@@ -43,7 +43,7 @@ "a",

&self .a .iter() - .map(|v| format!("Fr({:?})", v)) + .map(|v| format!("Fr({v:?})")) .collect::<Vec<_>>(), ) .field(

@@ -51,7 +51,7 @@ "b",

&self .b .iter() - .map(|v| format!("Fr({:?})", v)) + .map(|v| format!("Fr({v:?})")) .collect::<Vec<_>>(), ) .field(

@@ -59,7 +59,7 @@ "c",

&self .c .iter() - .map(|v| format!("Fr({:?})", v)) + .map(|v| format!("Fr({v:?})")) .collect::<Vec<_>>(), ) .field("input_assignment", &self.input_assignment)
M src/circuit.rs → src/circuit.rs

@@ -148,7 +148,7 @@

// Allocate z0 let z_0 = (0..arity) .map(|i| { - AllocatedNum::alloc(cs.namespace(|| format!("z0_{}", i)), || { + AllocatedNum::alloc(cs.namespace(|| format!("z0_{i}")), || { Ok(self.inputs.get()?.z0[i]) }) })

@@ -158,7 +158,7 @@ // Allocate zi. If inputs.zi is not provided (base case) allocate default value 0

let zero = vec![G::Base::zero(); arity]; let z_i = (0..arity) .map(|i| { - AllocatedNum::alloc(cs.namespace(|| format!("zi_{}", i)), || { + AllocatedNum::alloc(cs.namespace(|| format!("zi_{i}")), || { Ok(self.inputs.get()?.zi.as_ref().unwrap_or(&zero)[i]) }) })
M src/gadgets/ecc.rs → src/gadgets/ecc.rs

@@ -444,15 +444,15 @@ p = p.double_incomplete(cs.namespace(|| "double"))?;

// perform the double-and-add loop to compute the scalar mul using incomplete addition law for (i, bit) in incomplete_bits.iter().enumerate().skip(1) { - let temp = acc.add_incomplete(cs.namespace(|| format!("add {}", i)), &p)?; + let temp = acc.add_incomplete(cs.namespace(|| format!("add {i}")), &p)?; acc = AllocatedPointNonInfinity::conditionally_select( - cs.namespace(|| format!("acc_iteration_{}", i)), + cs.namespace(|| format!("acc_iteration_{i}")), &temp, &acc, &Boolean::from(bit.clone()), )?; - p = p.double_incomplete(cs.namespace(|| format!("double {}", i)))?; + p = p.double_incomplete(cs.namespace(|| format!("double {i}")))?; } // convert back to AllocatedPoint

@@ -500,15 +500,15 @@ };

let mut p_complete = p.to_allocated_point(&self.is_infinity)?; for (i, bit) in complete_bits.iter().enumerate() { - let temp = acc.add(cs.namespace(|| format!("add_complete {}", i)), &p_complete)?; + let temp = acc.add(cs.namespace(|| format!("add_complete {i}")), &p_complete)?; acc = AllocatedPoint::conditionally_select( - cs.namespace(|| format!("acc_complete_iteration_{}", i)), + cs.namespace(|| format!("acc_complete_iteration_{i}")), &temp, &acc, &Boolean::from(bit.clone()), )?; - p_complete = p_complete.double(cs.namespace(|| format!("double_complete {}", i)))?; + p_complete = p_complete.double(cs.namespace(|| format!("double_complete {i}")))?; } Ok(acc)

@@ -961,7 +961,7 @@ let bits: Vec<AllocatedBit> = s

.to_le_bits() .into_iter() .enumerate() - .map(|(i, bit)| AllocatedBit::alloc(cs.namespace(|| format!("bit {}", i)), Some(bit))) + .map(|(i, bit)| AllocatedBit::alloc(cs.namespace(|| format!("bit {i}")), Some(bit))) .collect::<Result<Vec<AllocatedBit>, SynthesisError>>() .unwrap(); let e = a.scalar_mul(cs.namespace(|| "Scalar Mul"), bits).unwrap();
M src/gadgets/nonnative/bignat.rs → src/gadgets/nonnative/bignat.rs

@@ -52,10 +52,7 @@ })

.collect(), ) } else { - eprintln!( - "nat {} does not fit in {} limbs of width {}", - nat, n_limbs, limb_width - ); + eprintln!("nat {nat} does not fit in {n_limbs} limbs of width {limb_width}"); Err(SynthesisError::Unsatisfiable) } }

@@ -131,7 +128,7 @@ let mut limb_values = None;

let limbs = (0..n_limbs) .map(|limb_i| { cs.alloc( - || format!("limb {}", limb_i), + || format!("limb {limb_i}"), || match values_cell { Ok(ref vs) => { if vs.len() != n_limbs {

@@ -149,7 +146,7 @@ }

// Hack b/c SynthesisError and io::Error don't implement Clone Err(ref e) => Err(SynthesisError::from(std::io::Error::new( std::io::ErrorKind::Other, - format!("{}", e), + format!("{e}"), ))), }, )

@@ -189,7 +186,7 @@ let mut limb_values = Vec::new();

let limbs = (0..n_limbs) .map(|limb_i| { cs.alloc( - || format!("limb {}", limb_i), + || format!("limb {limb_i}"), || match all_values_cell { Ok((ref vs, ref v)) => { if value.is_none() {

@@ -201,7 +198,7 @@ }

// Hack b/c SynthesisError and io::Error don't implement Clone Err(ref e) => Err(SynthesisError::from(std::io::Error::new( std::io::ErrorKind::Other, - format!("{}", e), + format!("{e}"), ))), }, )

@@ -272,7 +269,7 @@ let limb_values_split =

(0..self.limbs.len()).map(|i| self.limb_values.as_ref().map(|vs| vs[i])); for (i, (limb, limb_value)) in self.limbs.iter().zip(limb_values_split).enumerate() { Num::new(limb_value, limb.clone()) - .fits_in_bits(cs.namespace(|| format!("{}", i)), self.params.limb_width)?; + .fits_in_bits(cs.namespace(|| format!("{i}")), self.params.limb_width)?; } Ok(()) }

@@ -291,7 +288,7 @@ .zip(limb_values_split)

.enumerate() .map(|(i, (limb, limb_value))| { Num::new(limb_value, limb.clone()).decompose( - cs.namespace(|| format!("subdecmop {}", i)), + cs.namespace(|| format!("subdecmop {i}")), self.params.limb_width, ) })

@@ -370,7 +367,7 @@ + 0.1) as usize;

let mut carry_in = Num::new(Some(Scalar::zero()), LinearCombination::zero()); for i in 0..n { - let carry = Num::alloc(cs.namespace(|| format!("carry value {}", i)), || { + let carry = Num::alloc(cs.namespace(|| format!("carry value {i}")), || { Ok( nat_to_f( &((f_to_nat(&self.limb_values.grab()?[i])

@@ -385,7 +382,7 @@ })?;

accumulated_extra += max_word; cs.enforce( - || format!("carry {}", i), + || format!("carry {i}"), |lc| lc, |lc| lc, |lc| {

@@ -402,10 +399,10 @@

accumulated_extra /= &target_base; if i < n - 1 { - carry.fits_in_bits(cs.namespace(|| format!("carry {} decomp", i)), carry_bits)?; + carry.fits_in_bits(cs.namespace(|| format!("carry {i} decomp")), carry_bits)?; } else { cs.enforce( - || format!("carry {} is out", i), + || format!("carry {i} is out"), |lc| lc, |lc| lc, |lc| lc + &carry.num - (nat_to_f(&accumulated_extra).unwrap(), CS::one()),

@@ -416,7 +413,7 @@ }

for (i, zero_limb) in self.limbs.iter().enumerate().skip(n) { cs.enforce( - || format!("zero self {}", i), + || format!("zero self {i}"), |lc| lc, |lc| lc, |lc| lc + zero_limb,

@@ -424,7 +421,7 @@ );

} for (i, zero_limb) in other.limbs.iter().enumerate().skip(n) { cs.enforce( - || format!("zero other {}", i), + || format!("zero other {i}"), |lc| lc, |lc| lc, |lc| lc + zero_limb,

@@ -707,10 +704,7 @@ })

}); let coefficients = (0..n_product_coeffs) .map(|i| { - Ok( - LinearCombination::zero() - + cs.alloc(|| format!("prod {}", i), || Ok(values.grab()?[i]))?, - ) + Ok(LinearCombination::zero() + cs.alloc(|| format!("prod {i}"), || Ok(values.grab()?[i]))?) }) .collect::<Result<Vec<LinearCombination<Scalar>>, SynthesisError>>()?; let product = Polynomial {

@@ -722,7 +716,7 @@ let mut x = Scalar::zero();

for _ in 1..(n_product_coeffs + 1) { x.add_assign(&one); cs.enforce( - || format!("pointwise product @ {:?}", x), + || format!("pointwise product @ {x:?}"), |lc| { let mut i = Scalar::one(); self.coefficients.iter().fold(lc, |lc, c| {

@@ -807,7 +801,7 @@ .a

.iter() .enumerate() .map(|(i, x)| { - Ok(LinearCombination::zero() + cs.alloc(|| format!("coeff_a {}", i), || Ok(*x))?) + Ok(LinearCombination::zero() + cs.alloc(|| format!("coeff_a {i}"), || Ok(*x))?) }) .collect::<Result<Vec<LinearCombination<Scalar>>, SynthesisError>>()?, values: Some(self.a),

@@ -818,7 +812,7 @@ .b

.iter() .enumerate() .map(|(i, x)| { - Ok(LinearCombination::zero() + cs.alloc(|| format!("coeff_b {}", i), || Ok(*x))?) + Ok(LinearCombination::zero() + cs.alloc(|| format!("coeff_b {i}"), || Ok(*x))?) }) .collect::<Result<Vec<LinearCombination<Scalar>>, SynthesisError>>()?, values: Some(self.b),
M src/gadgets/nonnative/util.rs → src/gadgets/nonnative/util.rs

@@ -106,7 +106,7 @@ // Allocate all but the first bit.

let bits: Vec<Variable> = (1..n_bits) .map(|i| { cs.alloc( - || format!("bit {}", i), + || format!("bit {i}"), || { let r = if *v.grab()?.get_bit(i).grab()? { Scalar::one()

@@ -121,7 +121,7 @@ .collect::<Result<_, _>>()?;

for (i, v) in bits.iter().enumerate() { cs.enforce( - || format!("{} is bit", i), + || format!("{i} is bit"), |lc| lc + *v, |lc| lc + CS::one() - *v, |lc| lc,

@@ -191,7 +191,7 @@ });

let allocations: Vec<Bit<Scalar>> = (0..n_bits) .map(|bit_i| { Bit::alloc( - cs.namespace(|| format!("bit{}", bit_i)), + cs.namespace(|| format!("bit{bit_i}")), values.as_ref().map(|vs| vs[bit_i]), ) })

@@ -257,5 +257,5 @@

/// Convert a natural number to a field element. /// Returns `None` if the number is too big for the field. pub fn nat_to_f<Scalar: PrimeField>(n: &BigInt) -> Option<Scalar> { - Scalar::from_str_vartime(&format!("{}", n)) + Scalar::from_str_vartime(&format!("{n}")) }
M src/gadgets/r1cs.rs → src/gadgets/r1cs.rs

@@ -225,7 +225,7 @@ .as_limbs::<CS>()

.iter() .enumerate() .map(|(i, limb)| { - limb.as_allocated_num(cs.namespace(|| format!("convert limb {} of X_r[0] to num", i))) + limb.as_allocated_num(cs.namespace(|| format!("convert limb {i} of X_r[0] to num"))) }) .collect::<Result<Vec<AllocatedNum<G::Base>>, _>>()?;

@@ -241,7 +241,7 @@ .as_limbs::<CS>()

.iter() .enumerate() .map(|(i, limb)| { - limb.as_allocated_num(cs.namespace(|| format!("convert limb {} of X_r[1] to num", i))) + limb.as_allocated_num(cs.namespace(|| format!("convert limb {i} of X_r[1] to num"))) }) .collect::<Result<Vec<AllocatedNum<G::Base>>, _>>()?;
M src/gadgets/utils.rs → src/gadgets/utils.rs

@@ -131,7 +131,7 @@ // Now enforce that the limbs are all equal to the constants

#[allow(clippy::needless_range_loop)] for i in 0..n_limbs { cs.enforce( - || format!("check limb {}", i), + || format!("check limb {i}"), |lc| lc + &bignat.limbs[i], |lc| lc + CS::one(), |lc| lc + (limbs[i], CS::one()),

@@ -222,7 +222,7 @@ a.iter()

.zip(b.iter()) .enumerate() .map(|(i, (a, b))| { - conditionally_select(cs.namespace(|| format!("select_{}", i)), a, b, condition) + conditionally_select(cs.namespace(|| format!("select_{i}")), a, b, condition) }) .collect::<Result<Vec<AllocatedNum<F>>, SynthesisError>>() }

@@ -252,7 +252,7 @@ // a * condition + b*(1-condition) = c ->

// a * condition - b*condition = c - b for i in 0..c.limbs.len() { cs.enforce( - || format!("conditional select constraint {}", i), + || format!("conditional select constraint {i}"), |lc| lc + &a.limbs[i] - &b.limbs[i], |_| condition.lc(CS::one(), F::one()), |lc| lc + &c.limbs[i] - &b.limbs[i],
M src/poseidon.rs → src/poseidon.rs

@@ -224,9 +224,9 @@ for i in 0..num_absorbs {

let num = S::random(&mut csprng); ro.absorb(num); let num_gadget = - AllocatedNum::alloc(cs.namespace(|| format!("data {}", i)), || Ok(num)).unwrap(); + AllocatedNum::alloc(cs.namespace(|| format!("data {i}")), || Ok(num)).unwrap(); num_gadget - .inputize(&mut cs.namespace(|| format!("input {}", i))) + .inputize(&mut cs.namespace(|| format!("input {i}"))) .unwrap(); ro_gadget.absorb(num_gadget); }