Skip to content

Commit

Permalink
Merge pull request #76 from brave-experiments/clippy
Browse files Browse the repository at this point in the history
Replace explicit loop counters
  • Loading branch information
rillian authored Jul 29, 2024
2 parents fe483d9 + 415f21d commit 88c7f94
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 26 deletions.
1 change: 1 addition & 0 deletions bulletproofs/src/inner_product_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl<G: AffineRepr> InnerProductProof<G> {
///
/// The lengths of the vectors must all be the same, and must all be
/// either 0 or a power of 2.
#[allow(clippy::too_many_arguments)]
pub fn create(
transcript: &mut Transcript,
Q: &G,
Expand Down
1 change: 1 addition & 0 deletions bulletproofs/src/linear_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl<G: AffineRepr> LinearProof<G> {
///
/// The lengths of the vectors must all be the same, and must all be either 0 or a power of 2.
/// The proof is created with respect to the bases \\(G\\).
#[allow(clippy::too_many_arguments)]
pub fn create<R: Rng>(
transcript: &mut Transcript,
rng: &mut R,
Expand Down
25 changes: 15 additions & 10 deletions bulletproofs/src/r1cs/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,8 @@ impl<'g, G: AffineRepr, T: BorrowMut<Transcript>> Prover<'g, G, T> {
let mut l_poly = util::VecPoly3::<G>::zero(n);
let mut r_poly = util::VecPoly3::<G>::zero(n);

let mut exp_y = G::ScalarField::one(); // y^n starting at n=0
// y^n starting at n=0
let mut exp_y_iter = util::exp_iter::<G>(y);
let y_inv = y.inverse().unwrap();
let exp_y_inv = util::exp_iter::<G>(y_inv)
.take(padded_n)
Expand All @@ -682,6 +683,10 @@ impl<'g, G: AffineRepr, T: BorrowMut<Transcript>> Prover<'g, G, T> {
.chain(s_L2.iter())
.zip(s_R1.iter().chain(s_R2.iter()));
for (i, (sl, sr)) in sLsR.enumerate() {
// y^i -> y^(i+1)
let exp_y = exp_y_iter
.next()
.expect("exponentional iterator shouldn't terminate");
// l_poly.0 = 0
// l_poly.1 = a_L + y^-n * (z * z^Q * W_R)
l_poly.1[i] = self.secrets.a_L[i] + exp_y_inv[i] * wR[i];
Expand All @@ -696,8 +701,6 @@ impl<'g, G: AffineRepr, T: BorrowMut<Transcript>> Prover<'g, G, T> {
// r_poly.2 = 0
// r_poly.3 = y^n * s_R
r_poly.3[i] = exp_y * sr;

exp_y *= y; // y^i -> y^(i+1)
}

let t_poly = util::VecPoly3::special_inner_product(&l_poly, &r_poly);
Expand Down Expand Up @@ -744,16 +747,18 @@ impl<'g, G: AffineRepr, T: BorrowMut<Transcript>> Prover<'g, G, T> {
let t_x = t_poly.eval(x);
let t_x_blinding = t_blinding_poly.eval(x);
let mut l_vec = l_poly.eval(x);
l_vec.append(&mut vec![G::ScalarField::zero(); pad]);
// Pad out to the nearest power of two with zeros
l_vec.resize(padded_n, G::ScalarField::zero());

let mut r_vec = r_poly.eval(x);
r_vec.append(&mut vec![G::ScalarField::zero(); pad]);

// Pad out with additional powers of y
// XXX this should refer to the notes to explain why this is correct
for i in n..padded_n {
r_vec[i] = -exp_y;
exp_y *= y; // y^i -> y^(i+1)
}
r_vec.resize_with(padded_n, || {
let exp_y = exp_y_iter
.next()
.expect("exponentional iterator shouldn't terminate");
-exp_y
});

let i_blinding = i_blinding1 + u * i_blinding2;
let o_blinding = o_blinding1 + u * o_blinding2;
Expand Down
1 change: 1 addition & 0 deletions bulletproofs/src/range_proof/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl<G: AffineRepr> ProofShare<G> {

/// Audit an individual proof share to determine whether it is
/// malformed.
#[allow(clippy::too_many_arguments)]
pub(super) fn audit_share(
&self,
bp_gens: &BulletproofGens<G>,
Expand Down
5 changes: 1 addition & 4 deletions bulletproofs/src/range_proof/party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ impl<'a, G: AffineRepr> PartyAwaitingPosition<'a, G> {
// Compute A = <a_L, G> + <a_R, H> + a_blinding * B_blinding
let mut A = self.pc_gens.B_blinding.mul(a_blinding);

let mut i = 0;

for (G_i, H_i) in bp_share.G(self.n).zip(bp_share.H(self.n)) {
for (i, (G_i, H_i)) in bp_share.G(self.n).zip(bp_share.H(self.n)).enumerate() {
// If v_i = 0, we add a_L[i] * G[i] + a_R[i] * H[i] = - H[i]
// If v_i = 1, we add a_L[i] * G[i] + a_R[i] * H[i] = G[i]
let v_i: bool = (self.v >> i) & 1 == 1;
Expand All @@ -116,7 +114,6 @@ impl<'a, G: AffineRepr> PartyAwaitingPosition<'a, G> {
} else {
A.add_assign(H_i.into_group().neg());
}
i += 1;
}

let s_blinding = G::ScalarField::rand(rng);
Expand Down
32 changes: 20 additions & 12 deletions bulletproofs/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ impl<G: AffineRepr> VecPoly1<G> {
Poly2(t0, t1, t2)
}

/// Evalutate the vector polynomial at the given field point
pub fn eval(&self, x: G::ScalarField) -> Vec<G::ScalarField> {
let n = self.0.len();
let mut out = vec![G::ScalarField::zero(); n];
for i in 0..n {
out[i] = self.0[i] + self.1[i] * x;
}
out
// Each coefficient is indexed separately, so zip them
// together to produce a sequence of ordered pairs
// for evaluation.
self.0
.iter()
.zip(self.1.iter())
.map(|(&a, &b)| a + b * x)
.collect()
}
}

Expand Down Expand Up @@ -133,12 +136,17 @@ impl<G: AffineRepr> VecPoly3<G> {
}

pub fn eval(&self, x: G::ScalarField) -> Vec<G::ScalarField> {
let n = self.0.len();
let mut out = vec![G::ScalarField::zero(); n];
for i in 0..n {
out[i] = self.0[i] + x * (self.1[i] + x * (self.2[i] + x * self.3[i]));
}
out
// Each coefficient is indexed separately, so zip them
// together to produce a sequence for evaluation. The
// nesting is necessary because the std::iter API only
// does pairs.
self.0
.iter()
.zip(self.1.iter())
.zip(self.2.iter())
.zip(self.3.iter())
.map(|(((&a, &b), &c), &d)| a + x * (b + x * (c + x * d)))
.collect()
}
}

Expand Down
1 change: 1 addition & 0 deletions rewards-proof/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ where
}

/// Verifies the rewards proofs
#[allow(clippy::too_many_arguments)]
pub fn rewards_proof_verification_multiple<C>(
pedersen_gens: &[PedersenGens<C>],
bulletproof_gens: &[BulletproofGens<C>],
Expand Down

0 comments on commit 88c7f94

Please sign in to comment.