Skip to content

Commit d8508f3

Browse files
committed
fix clippy errors
1 parent c867c5b commit d8508f3

File tree

8 files changed

+72
-91
lines changed

8 files changed

+72
-91
lines changed

src/circuits/bigint/mul.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ impl<const N_BITS: usize> BigIntImpl<N_BITS> {
2323
let addition_wires_1 =
2424
circuit.extend(Self::self_or_zero(a_wires.clone(), b_wires[i].clone()));
2525
let new_bits = circuit.extend(Self::add(addition_wires_0, addition_wires_1));
26-
for j in i..=(i + N_BITS) {
27-
circuit.0[j] = new_bits[j - i].clone();
28-
}
26+
circuit.0[i..(i + N_BITS + 1)].clone_from_slice(&new_bits[..((i + N_BITS - i) + 1)]);
2927
}
3028
circuit
3129
}
@@ -53,9 +51,7 @@ impl<const N_BITS: usize> BigIntImpl<N_BITS> {
5351
addition_wires.push(circuit.0[j].clone());
5452
}
5553
let new_bits = circuit.extend(Self::add(a_wires.clone(), addition_wires));
56-
for j in i..=(i + N_BITS) {
57-
circuit.0[j] = new_bits[j - i].clone();
58-
}
54+
circuit.0[i..(i + N_BITS + 1)].clone_from_slice(&new_bits[..((i + N_BITS - i) + 1)]);
5955
}
6056
}
6157

src/circuits/bigint/utils.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ pub fn random_u254() -> BigUint {
1515

1616
pub fn bits_from_biguint(u: BigUint) -> Vec<bool> {
1717
let mut bytes = u.to_bytes_le();
18-
for _ in bytes.len()..32 {
19-
bytes.push(0_u8);
20-
}
18+
bytes.extend(vec![0_u8; 32 - bytes.len()]);
2119
let mut bits = Vec::new();
2220
for byte in bytes {
2321
for i in 0..8 {
@@ -87,6 +85,8 @@ pub fn change_to_neg_pos_decomposition(bits: Vec<bool>) -> Vec<i8> {
8785

8886
#[cfg(test)]
8987
pub mod tests {
88+
use std::cmp::Ordering;
89+
9090
use super::*;
9191

9292
#[test]
@@ -113,10 +113,10 @@ pub mod tests {
113113
}
114114

115115
for i in (0..len).rev() {
116-
if d[i] > 0 {
117-
res += pw[i].clone();
118-
} else if d[i] < 0 {
119-
res -= pw[i].clone();
116+
match d[i].cmp(&0) {
117+
Ordering::Less => { res -= pw[i].clone(); },
118+
Ordering::Equal => (),
119+
Ordering::Greater => { res += pw[i].clone(); },
120120
}
121121
}
122122

src/circuits/bn254/finalexp.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,26 @@ pub fn final_exponentiation(f: ark_bn254::Fq12) -> ark_bn254::Fq12 {
110110
let y0 = exp_by_neg_x(r);
111111
let y1 = y0.square();
112112
let y2 = y1.square();
113-
let y3 = y2 * &y1;
113+
let y3 = y2 * y1;
114114
let y4 = exp_by_neg_x(y3);
115115
let y5 = y4.square();
116116
let y6 = exp_by_neg_x(y5);
117117
let y7 = conjugate(y3);
118118
let y8 = conjugate(y6);
119-
let y9 = y8 * &y4;
120-
let y10 = y9 * &y7;
121-
let y11 = y10 * &y1;
122-
let y12 = y10 * &y4;
123-
let y13 = y12 * &r;
119+
let y9 = y8 * y4;
120+
let y10 = y9 * y7;
121+
let y11 = y10 * y1;
122+
let y12 = y10 * y4;
123+
let y13 = y12 * r;
124124
let y14 = y11.frobenius_map(1);
125-
let y15 = y14 * &y13;
125+
let y15 = y14 * y13;
126126
let y16 = y10.frobenius_map(2);
127-
let y17 = y16 * &y15;
127+
let y17 = y16 * y15;
128128
let r2 = conjugate(r);
129-
let y18 = r2 * &y11;
129+
let y18 = r2 * y11;
130130
let y19 = y18.frobenius_map(3);
131131

132-
y19 * &y17
132+
y19 * y17
133133
}
134134

135135
pub fn final_exponentiation_evaluate_fast(f: Wires) -> (Wires, GateCount) {

src/circuits/bn254/fq12.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Fq12 {
1818
assert_eq!(a.len(), Self::N_BITS);
1919
let mut circuit = Circuit::empty();
2020

21-
let a0 = a[0 * Fq::N_BITS..Fq::N_BITS].to_vec();
21+
let a0 = a[..Fq::N_BITS].to_vec();
2222
let a1 = a[Fq::N_BITS..2 * Fq::N_BITS].to_vec();
2323
let a2 = a[2 * Fq::N_BITS..3 * Fq::N_BITS].to_vec();
2424
let a3 = a[3 * Fq::N_BITS..4 * Fq::N_BITS].to_vec();
@@ -43,7 +43,7 @@ impl Fq12 {
4343

4444
let mut wire = results[0].clone();
4545

46-
for next in results[1..].to_vec() {
46+
for next in results[1..].iter().cloned() {
4747
let new_wire = Rc::new(RefCell::new(Wire::new()));
4848
circuit.add(Gate::and(wire, next, new_wire.clone()));
4949
wire = new_wire;

src/circuits/bn254/pairing.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ pub fn double_in_place(
1919
r: &mut ark_bn254::G2Projective,
2020
) -> (ark_bn254::Fq2, ark_bn254::Fq2, ark_bn254::Fq2) {
2121
let half = ark_bn254::Fq::from(Fq::half_modulus());
22-
let mut a = r.x * &r.y;
22+
let mut a = r.x * r.y;
2323
a.mul_assign_by_fp(&half);
2424
let b = r.y.square();
2525
let c = r.z.square();
26-
let e = ark_bn254::g2::Config::COEFF_B * &(c.double() + &c);
27-
let f = e.double() + &e;
28-
let mut g = b + &f;
26+
let e = ark_bn254::g2::Config::COEFF_B * (c.double() + c);
27+
let f = e.double() + e;
28+
let mut g = b + f;
2929
g.mul_assign_by_fp(&half);
30-
let h = (r.y + &r.z).square() - &(b + &c);
31-
let i = e - &b;
30+
let h = (r.y + r.z).square() - (b + c);
31+
let i = e - b;
3232
let j = r.x.square();
3333
let e_square = e.square();
3434

3535
let new_r = ark_bn254::G2Projective {
36-
x: a * &(b - &f),
37-
y: g.square() - &(e_square.double() + &e_square),
38-
z: b * &h,
36+
x: a * (b - f),
37+
y: g.square() - (e_square.double() + e_square),
38+
z: b * h,
3939
};
4040
*r = new_r;
41-
(-h, j.double() + &j, i)
41+
(-h, j.double() + j, i)
4242
}
4343

4444
pub fn double_in_place2(
@@ -48,25 +48,25 @@ pub fn double_in_place2(
4848
(ark_bn254::Fq2, ark_bn254::Fq2, ark_bn254::Fq2),
4949
) {
5050
let half = ark_bn254::Fq::from(Fq::half_modulus());
51-
let mut a = r.x * &r.y;
51+
let mut a = r.x * r.y;
5252
a.mul_assign_by_fp(&half);
5353
let b = r.y.square();
5454
let c = r.z.square();
55-
let e = ark_bn254::g2::Config::COEFF_B * &(c.double() + &c);
56-
let f = e.double() + &e;
57-
let mut g = b + &f;
55+
let e = ark_bn254::g2::Config::COEFF_B * (c.double() + c);
56+
let f = e.double() + e;
57+
let mut g = b + f;
5858
g.mul_assign_by_fp(&half);
59-
let h = (r.y + &r.z).square() - &(b + &c);
60-
let i = e - &b;
59+
let h = (r.y + r.z).square() - (b + c);
60+
let i = e - b;
6161
let j = r.x.square();
6262
let e_square = e.square();
6363

6464
let new_r = ark_bn254::G2Projective {
65-
x: a * &(b - &f),
66-
y: g.square() - &(e_square.double() + &e_square),
67-
z: b * &h,
65+
x: a * (b - f),
66+
y: g.square() - (e_square.double() + e_square),
67+
z: b * h,
6868
};
69-
(new_r, (-h, j.double() + &j, i))
69+
(new_r, (-h, j.double() + j, i))
7070
}
7171

7272
pub fn double_in_place_circuit(r: Wires) -> Circuit {
@@ -131,20 +131,20 @@ pub fn add_in_place(
131131
r: &mut ark_bn254::G2Projective,
132132
q: &ark_bn254::G2Affine,
133133
) -> (ark_bn254::Fq2, ark_bn254::Fq2, ark_bn254::Fq2) {
134-
let theta = r.y - &(q.y * &r.z);
135-
let lambda = r.x - &(q.x * &r.z);
134+
let theta = r.y - (q.y * r.z);
135+
let lambda = r.x - (q.x * r.z);
136136
let c = theta.square();
137137
let d = lambda.square();
138-
let e = lambda * &d;
139-
let f = r.z * &c;
140-
let g = r.x * &d;
141-
let h = e + &f - &g.double();
142-
let j = theta * &q.x - &(lambda * &q.y);
138+
let e = lambda * d;
139+
let f = r.z * c;
140+
let g = r.x * d;
141+
let h = e + f - g.double();
142+
let j = theta * q.x - (lambda * q.y);
143143

144144
let new_r = ark_bn254::G2Projective {
145-
x: lambda * &h,
146-
y: theta * &(g - &h) - &(e * &r.y),
147-
z: r.z * &e,
145+
x: lambda * h,
146+
y: theta * (g - h) - (e * r.y),
147+
z: r.z * e,
148148
};
149149
*r = new_r;
150150

@@ -158,20 +158,20 @@ pub fn add_in_place2(
158158
ark_bn254::G2Projective,
159159
(ark_bn254::Fq2, ark_bn254::Fq2, ark_bn254::Fq2),
160160
) {
161-
let theta = r.y - &(q.y * &r.z);
162-
let lambda = r.x - &(q.x * &r.z);
161+
let theta = r.y - (q.y * r.z);
162+
let lambda = r.x - (q.x * r.z);
163163
let c = theta.square();
164164
let d = lambda.square();
165-
let e = lambda * &d;
166-
let f = r.z * &c;
167-
let g = r.x * &d;
168-
let h = e + &f - &g.double();
169-
let j = theta * &q.x - &(lambda * &q.y);
165+
let e = lambda * d;
166+
let f = r.z * c;
167+
let g = r.x * d;
168+
let h = e + f - g.double();
169+
let j = theta * q.x - (lambda * q.y);
170170

171171
let new_r = ark_bn254::G2Projective {
172-
x: lambda * &h,
173-
y: theta * &(g - &h) - &(e * &r.y),
174-
z: r.z * &e,
172+
x: lambda * h,
173+
y: theta * (g - h) - (e * r.y),
174+
z: r.z * e,
175175
};
176176

177177
(new_r, (lambda, -theta, j))
@@ -1044,7 +1044,7 @@ mod tests {
10441044
let c1 = fq2_from_wires(circuit.0[Fq2::N_BITS..2 * Fq2::N_BITS].to_vec());
10451045
let c2 = fq2_from_wires(circuit.0[2 * Fq2::N_BITS..3 * Fq2::N_BITS].to_vec());
10461046
let new_r_x = fq2_from_wires(
1047-
circuit.0[3 * Fq2::N_BITS + 0 * Fq2::N_BITS..3 * Fq2::N_BITS + Fq2::N_BITS]
1047+
circuit.0[3 * Fq2::N_BITS..3 * Fq2::N_BITS + Fq2::N_BITS]
10481048
.to_vec(),
10491049
);
10501050
let new_r_y = fq2_from_wires(

src/circuits/bn254/utils.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ pub fn random_fq() -> ark_bn254::Fq {
1818

1919
pub fn bits_from_fq(u: ark_bn254::Fq) -> Vec<bool> {
2020
let mut bytes = BigUint::from(u).to_bytes_le();
21-
for _ in bytes.len()..32 {
22-
bytes.push(0_u8);
23-
}
21+
bytes.extend(vec![0_u8; 32 - bytes.len()]);
2422
let mut bits = Vec::new();
2523
for byte in bytes {
2624
for i in 0..8 {
@@ -235,9 +233,7 @@ pub fn random_fr() -> ark_bn254::Fr {
235233

236234
pub fn bits_from_fr(u: ark_bn254::Fr) -> Vec<bool> {
237235
let mut bytes = BigUint::from(u).to_bytes_le();
238-
for _ in bytes.len()..32 {
239-
bytes.push(0_u8);
240-
}
236+
bytes.extend(vec![0_u8; 32 - bytes.len()]);
241237
let mut bits = Vec::new();
242238
for byte in bytes {
243239
for i in 0..8 {
@@ -376,9 +372,9 @@ fn extended_gcd(a: &BigInt, b: &BigInt) -> (BigInt, BigInt, BigInt) {
376372
while !b1.is_zero() {
377373
let q = &a1 / &b1;
378374

379-
(x, x1) = (x1.clone(), &x - &q * &x1);
380-
(y, y1) = (y1.clone(), &y - &q * &y1);
381-
(a1, b1) = (b1.clone(), &a1 - &q * &b1);
375+
(x, x1) = (x1.clone(), &x - q.clone() * x1);
376+
(y, y1) = (y1.clone(), &y - q.clone() * y1);
377+
(a1, b1) = (b1.clone(), &a1 - q.clone() * b1);
382378
}
383379

384380
(a1, x, y)
@@ -391,11 +387,11 @@ pub fn calculate_montgomery_constants(modulus: BigUint, r: BigUint) -> (BigUint,
391387
let (gcd, r_inv_signed, n_inv_signed) = extended_gcd(&r_signed, &modulus_signed);
392388
assert_eq!(gcd, BigInt::one(), "r and modulus must be coprime");
393389

394-
let r_inv = ((r_inv_signed % &modulus_signed + &modulus_signed) % &modulus_signed)
390+
let r_inv = ((r_inv_signed % modulus_signed.clone() + modulus_signed.clone()) % modulus_signed.clone())
395391
.to_biguint()
396392
.unwrap();
397393

398-
let n_prime = ((n_inv_signed % &r_signed + &r_signed) % &r_signed)
394+
let n_prime = ((n_inv_signed % r_signed.clone() + r_signed.clone()) % r_signed.clone())
399395
.to_biguint()
400396
.unwrap();
401397

src/circuits/groth16.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,14 @@ mod tests {
9797
test_rng,
9898
};
9999

100-
#[derive(Copy)]
100+
#[derive(Copy, Clone)]
101101
struct DummyCircuit<F: PrimeField> {
102102
pub a: Option<F>,
103103
pub b: Option<F>,
104104
pub num_variables: usize,
105105
pub num_constraints: usize,
106106
}
107107

108-
impl<F: PrimeField> Clone for DummyCircuit<F> {
109-
fn clone(&self) -> Self {
110-
DummyCircuit {
111-
a: self.a,
112-
b: self.b,
113-
num_variables: self.num_variables,
114-
num_constraints: self.num_constraints,
115-
}
116-
}
117-
}
118-
119108
impl<F: PrimeField> ConstraintSynthesizer<F> for DummyCircuit<F> {
120109
fn generate_constraints(self, cs: ConstraintSystemRef<F>) -> Result<(), SynthesisError> {
121110
let a = cs.new_witness_variable(|| self.a.ok_or(SynthesisError::AssignmentMissing))?;

src/core/s.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ impl S {
1818

1919
pub fn neg(&self) -> Self {
2020
let mut s = self.0;
21-
for i in 0..32 {
22-
s[i] = 255 - self.0[i];
21+
for (i, si) in s.iter_mut().enumerate() {
22+
*si = 255 - self.0[i];
2323
}
2424
Self(s) + Self::one()
2525
}

0 commit comments

Comments
 (0)