Browse Source

edits to address clippy with the latest Rust (#90)

main
Srinath Setty 2 years ago
committed by GitHub
parent
commit
e373f4633d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 27 deletions
  1. +6
    -6
      src/bellperson/mod.rs
  2. +9
    -9
      src/bellperson/shape_cs.rs
  3. +4
    -5
      src/circuit.rs
  4. +6
    -6
      src/gadgets/ecc.rs
  5. +1
    -1
      src/poseidon.rs

+ 6
- 6
src/bellperson/mod.rs

@ -158,7 +158,7 @@ mod tests {
n_limbs, n_limbs,
)?; )?;
let _ = a1.equal_when_carried(cs.namespace(|| "check equal"), &a2)?;
a1.equal_when_carried(cs.namespace(|| "check equal"), &a2)?;
Ok(()) Ok(())
} }
@ -182,7 +182,7 @@ mod tests {
limb_width, limb_width,
n_limbs, n_limbs,
)?; )?;
let _ = m.inputize(cs.namespace(|| "modulus m"))?;
m.inputize(cs.namespace(|| "modulus m"))?;
let a = BigNat::from_num( let a = BigNat::from_num(
cs.namespace(|| "allocate a_limbs"), cs.namespace(|| "allocate a_limbs"),
@ -228,14 +228,14 @@ mod tests {
limb_width, limb_width,
n_limbs, n_limbs,
)?; )?;
let _ = a.inputize(cs.namespace(|| "input a"))?;
a.inputize(cs.namespace(|| "input a"))?;
let b = BigNat::alloc_from_nat( let b = BigNat::alloc_from_nat(
cs.namespace(|| "b"), cs.namespace(|| "b"),
|| Ok(b_val.clone()), || Ok(b_val.clone()),
limb_width, limb_width,
n_limbs, n_limbs,
)?; )?;
let _ = b.inputize(cs.namespace(|| "input b"))?;
b.inputize(cs.namespace(|| "input b"))?;
let c = BigNat::alloc_from_nat( let c = BigNat::alloc_from_nat(
cs.namespace(|| "c"), cs.namespace(|| "c"),
|| Ok(c_val.clone()), || Ok(c_val.clone()),
@ -262,14 +262,14 @@ mod tests {
limb_width, limb_width,
n_limbs, n_limbs,
)?; )?;
let _ = a.inputize(cs.namespace(|| "input a"))?;
a.inputize(cs.namespace(|| "input a"))?;
let b = BigNat::alloc_from_nat( let b = BigNat::alloc_from_nat(
cs.namespace(|| "b"), cs.namespace(|| "b"),
|| Ok(b_val.clone()), || Ok(b_val.clone()),
limb_width, limb_width,
n_limbs, n_limbs,
)?; )?;
let _ = b.inputize(cs.namespace(|| "input b"))?;
b.inputize(cs.namespace(|| "input b"))?;
let c = BigNat::alloc_from_nat( let c = BigNat::alloc_from_nat(
cs.namespace(|| "c"), cs.namespace(|| "c"),
|| Ok(c_val.clone()), || Ok(c_val.clone()),

+ 9
- 9
src/bellperson/shape_cs.rs

@ -6,9 +6,9 @@ use std::{
}; };
use crate::traits::Group; use crate::traits::Group;
use ff::{Field, PrimeField};
use bellperson::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable}; use bellperson::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};
use core::fmt::Write;
use ff::{Field, PrimeField};
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
struct OrderedVariable(Variable); struct OrderedVariable(Variable);
@ -141,7 +141,7 @@ where
let mut s = String::new(); let mut s = String::new();
for input in &self.inputs { for input in &self.inputs {
s.push_str(&format!("INPUT {}\n", &input))
writeln!(s, "INPUT {}", &input).unwrap()
} }
let negone = -<G::Scalar>::one(); let negone = -<G::Scalar>::one();
@ -164,20 +164,20 @@ where
if coeff != <G::Scalar>::one() && coeff != negone { if coeff != <G::Scalar>::one() && coeff != negone {
for (i, x) in powers_of_two.iter().enumerate() { for (i, x) in powers_of_two.iter().enumerate() {
if x == &coeff { if x == &coeff {
s.push_str(&format!("2^{} . ", i));
write!(s, "2^{} . ", i).unwrap();
break; break;
} }
} }
s.push_str(&format!("{:?} . ", coeff))
write!(s, "{:?} . ", coeff).unwrap()
} }
match var.0.get_unchecked() { match var.0.get_unchecked() {
Index::Input(i) => { Index::Input(i) => {
s.push_str(&format!("`I{}`", &self.inputs[i]));
write!(s, "`I{}`", &self.inputs[i]).unwrap();
} }
Index::Aux(i) => { Index::Aux(i) => {
s.push_str(&format!("`A{}`", &self.aux[i]));
write!(s, "`A{}`", &self.aux[i]).unwrap();
} }
} }
} }
@ -191,9 +191,9 @@ where
for &(ref a, ref b, ref c, ref name) in &self.constraints { for &(ref a, ref b, ref c, ref name) in &self.constraints {
s.push('\n'); s.push('\n');
s.push_str(&format!("{}: ", name));
write!(s, "{}: ", name).unwrap();
pp(&mut s, a); pp(&mut s, a);
s.push_str(" * ");
write!(s, " * ").unwrap();
pp(&mut s, b); pp(&mut s, b);
s.push_str(" = "); s.push_str(" = ");
pp(&mut s, c); pp(&mut s, c);

+ 4
- 5
src/circuit.rs

@ -225,7 +225,7 @@ where
ro.absorb(i); ro.absorb(i);
ro.absorb(z_0); ro.absorb(z_0);
ro.absorb(z_i); ro.absorb(z_i);
let _ = U.absorb_in_ro(cs.namespace(|| "absorb U"), &mut ro)?;
U.absorb_in_ro(cs.namespace(|| "absorb U"), &mut ro)?;
let hash_bits = ro.get_hash(cs.namespace(|| "Input hash"))?; let hash_bits = ro.get_hash(cs.namespace(|| "Input hash"))?;
let hash = le_bits_to_num(cs.namespace(|| "bits to hash"), hash_bits)?; let hash = le_bits_to_num(cs.namespace(|| "bits to hash"), hash_bits)?;
@ -332,15 +332,14 @@ where
ro.absorb(i_new.clone()); ro.absorb(i_new.clone());
ro.absorb(z_0); ro.absorb(z_0);
ro.absorb(z_next); ro.absorb(z_next);
let _ = Unew.absorb_in_ro(cs.namespace(|| "absorb U_new"), &mut ro)?;
Unew.absorb_in_ro(cs.namespace(|| "absorb U_new"), &mut ro)?;
let hash_bits = ro.get_hash(cs.namespace(|| "output hash bits"))?; let hash_bits = ro.get_hash(cs.namespace(|| "output hash bits"))?;
let hash = le_bits_to_num(cs.namespace(|| "convert hash to num"), hash_bits)?; let hash = le_bits_to_num(cs.namespace(|| "convert hash to num"), hash_bits)?;
// Outputs the computed hash and u.X[1] that corresponds to the hash of the other circuit // Outputs the computed hash and u.X[1] that corresponds to the hash of the other circuit
let _ = u
.X1
u.X1
.inputize(cs.namespace(|| "Output unmodified hash of the other circuit"))?; .inputize(cs.namespace(|| "Output unmodified hash of the other circuit"))?;
let _ = hash.inputize(cs.namespace(|| "output new hash of this circuit"))?;
hash.inputize(cs.namespace(|| "output new hash of this circuit"))?;
Ok(()) Ok(())
} }

+ 6
- 6
src/gadgets/ecc.rs

@ -740,7 +740,7 @@ mod tests {
CS: ConstraintSystem<Fp>, CS: ConstraintSystem<Fp>,
{ {
let a = AllocatedPoint::<Fp>::random_vartime(cs.namespace(|| "a")).unwrap(); let a = AllocatedPoint::<Fp>::random_vartime(cs.namespace(|| "a")).unwrap();
let _ = a.inputize(cs.namespace(|| "inputize a")).unwrap();
a.inputize(cs.namespace(|| "inputize a")).unwrap();
let s = Fq::random(&mut OsRng); let s = Fq::random(&mut OsRng);
// Allocate random bits and only keep 128 bits // Allocate random bits and only keep 128 bits
let bits: Vec<AllocatedBit> = s let bits: Vec<AllocatedBit> = s
@ -751,7 +751,7 @@ mod tests {
.collect::<Result<Vec<AllocatedBit>, SynthesisError>>() .collect::<Result<Vec<AllocatedBit>, SynthesisError>>()
.unwrap(); .unwrap();
let e = a.scalar_mul(cs.namespace(|| "Scalar Mul"), bits).unwrap(); let e = a.scalar_mul(cs.namespace(|| "Scalar Mul"), bits).unwrap();
let _ = e.inputize(cs.namespace(|| "inputize e")).unwrap();
e.inputize(cs.namespace(|| "inputize e")).unwrap();
(a, e, s) (a, e, s)
} }
@ -792,9 +792,9 @@ mod tests {
CS: ConstraintSystem<Fp>, CS: ConstraintSystem<Fp>,
{ {
let a = AllocatedPoint::<Fp>::random_vartime(cs.namespace(|| "a")).unwrap(); let a = AllocatedPoint::<Fp>::random_vartime(cs.namespace(|| "a")).unwrap();
let _ = a.inputize(cs.namespace(|| "inputize a")).unwrap();
a.inputize(cs.namespace(|| "inputize a")).unwrap();
let e = a.add(cs.namespace(|| "add a to a"), &a).unwrap(); let e = a.add(cs.namespace(|| "add a to a"), &a).unwrap();
let _ = e.inputize(cs.namespace(|| "inputize e")).unwrap();
e.inputize(cs.namespace(|| "inputize e")).unwrap();
(a, e) (a, e)
} }
@ -834,11 +834,11 @@ mod tests {
CS: ConstraintSystem<Fp>, CS: ConstraintSystem<Fp>,
{ {
let a = AllocatedPoint::<Fp>::random_vartime(cs.namespace(|| "a")).unwrap(); let a = AllocatedPoint::<Fp>::random_vartime(cs.namespace(|| "a")).unwrap();
let _ = a.inputize(cs.namespace(|| "inputize a")).unwrap();
a.inputize(cs.namespace(|| "inputize a")).unwrap();
let mut b = a.clone(); let mut b = a.clone();
b.y = b.y =
AllocatedNum::alloc(cs.namespace(|| "allocate negation of a"), || Ok(Fp::zero())).unwrap(); AllocatedNum::alloc(cs.namespace(|| "allocate negation of a"), || Ok(Fp::zero())).unwrap();
let _ = b.inputize(cs.namespace(|| "inputize b")).unwrap();
b.inputize(cs.namespace(|| "inputize b")).unwrap();
let e = a.add(cs.namespace(|| "add a to b"), &b).unwrap(); let e = a.add(cs.namespace(|| "add a to b"), &b).unwrap();
e e
} }

+ 1
- 1
src/poseidon.rs

@ -244,7 +244,7 @@ mod tests {
ro.absorb(num); ro.absorb(num);
let num_gadget = let num_gadget =
AllocatedNum::alloc(cs.namespace(|| format!("data {}", i)), || Ok(num)).unwrap(); AllocatedNum::alloc(cs.namespace(|| format!("data {}", i)), || Ok(num)).unwrap();
let _ = num_gadget
num_gadget
.inputize(&mut cs.namespace(|| format!("input {}", i))) .inputize(&mut cs.namespace(|| format!("input {}", i)))
.unwrap(); .unwrap();
ro_gadget.absorb(num_gadget); ro_gadget.absorb(num_gadget);

Loading…
Cancel
Save