Skip to content

Commit 6defa7e

Browse files
committed
clippy + comments
1 parent aa3f222 commit 6defa7e

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/circuit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ pub(crate) mod tests {
576576
pub(crate) fn linear_constraint_rhs<FE: CodecFieldElement>(&self) -> Vec<FE> {
577577
self.linear_rhs
578578
.iter()
579-
.map(|element| FE::try_from(hex::decode(&element).unwrap().as_slice()).unwrap())
579+
.map(|element| FE::try_from(hex::decode(element).unwrap().as_slice()).unwrap())
580580
.collect()
581581
}
582582
}

src/fields/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ pub trait CodecFieldElement:
119119

120120
/// Elements of a field in which we can interpolate polynomials up to degree three. We precompute
121121
/// the denominators of the basis polynomials to avoid needing division.
122+
///
123+
/// # Bugs
124+
///
125+
/// The methods `sumcheck_p2_mul_inv`, `one_minus_sumcheck_p2_mul_inv`,
126+
/// `sumcheck_p2_squared_minus_sumcheck_p2_mul_inv` should be constants ([1]).
127+
///
128+
/// [1]: https://github.com/abetterinternet/zk-cred-longfellow/issues/40
122129
pub trait LagrangePolynomialFieldElement: FieldElement {
123130
/// Evaluate the ith Lagrange basis polynomial at x. From [Section 6.6][1]:
124131
///

src/sumcheck/bind.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,15 @@ impl<FE: FieldElement> ElementwiseSum for FE {
247247
}
248248
}
249249

250-
/// Naive implementation of bindeq() from 6.2. This binds `input` of length `l` to the implicit
251-
/// `EQ_2^l` array.
250+
/// Naive implementation of bindeq() from 6.2 ([1]). This binds `input` of length `l` to the
251+
/// implicit `EQ_2^l` array.
252252
///
253-
/// We should rework this to avoid recursion.
253+
/// # Bugs
254+
///
255+
/// We should rework this to avoid recursion ([2]).
256+
///
257+
/// [1]: https://datatracker.ietf.org/doc/html/draft-google-cfrg-libzk-01#section-6.2
258+
/// [2]: https://github.com/abetterinternet/zk-cred-longfellow/issues/41
254259
pub fn bindeq<FE: FieldElement>(input: &[FE]) -> Vec<FE> {
255260
let output_len = 2usize.pow(
256261
input
@@ -725,9 +730,10 @@ mod tests {
725730
// 6.2: bindv(EQ_{n}, X) = bindeq(l, X) for n = 2^l
726731
fn construct_eq(n: usize) -> Vec<Vec<FieldP256>> {
727732
let mut eq_n = vec![vec![FieldP256::ZERO; n]; n];
728-
for i in 0..n {
729-
for j in 0..n {
730-
eq_n[i][j] = if i == j {
733+
734+
for (i, row) in eq_n.iter_mut().enumerate() {
735+
for (j, element) in row.iter_mut().enumerate() {
736+
*element = if i == j {
731737
FieldP256::ONE
732738
} else {
733739
FieldP256::ZERO

src/sumcheck/constraints.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ use crate::{
1515
};
1616
use serde::Deserialize;
1717

18-
/// A term of a linear constraint consisting of a triple (c, j, k), per [4.4.2][1]. This is one
18+
/// A term of a linear constraint consisting of a triple (c, j, k), per [4.4.2][1]. This is one
1919
/// element of the the constraint matrix A for verifying that A * W = b. Several of these terms sum
2020
/// together into one of the elements of `ProofConstraints::linear_constraint_rhs`.
2121
///
2222
/// [1]: https://datatracker.ietf.org/doc/html/draft-google-cfrg-libzk-01#section-4.4.2
23-
// We don't yet examine these outside of test code, so allow dead code for now.
24-
#[allow(dead_code)]
2523
#[derive(Debug, Clone, PartialEq, Eq)]
2624
pub struct LinearConstraintLhsTerm<FieldElement> {
2725
/// The constraint number or row of A. This is an index into the vector `b`, which we represent
@@ -63,7 +61,11 @@ impl<FE: CodecFieldElement + LagrangePolynomialFieldElement> ProofConstraints<FE
6361
/// `sym_private_inputs`, but since the whole point is that we don't know what those values are,
6462
/// it doesn't make sense to represent them as arguments.
6563
///
64+
/// `ligero_commitment` is the commitment computed per [4.3][1], which is needed to initialize
65+
/// the transcript.
66+
///
6667
/// [1]: https://datatracker.ietf.org/doc/html/draft-google-cfrg-libzk-01#section-6.6
68+
/// [2]: https://datatracker.ietf.org/doc/html/draft-google-cfrg-libzk-01#section-4.3
6769
pub fn from_proof(
6870
circuit: &Circuit,
6971
public_inputs: &[FE],
@@ -139,15 +141,15 @@ impl<FE: CodecFieldElement + LagrangePolynomialFieldElement> ProofConstraints<FE
139141
// =
140142
// Q * layer_proof.vl * layer_proof.vl - known_part
141143
//
142-
// The LHS of this constraint will consist of two LinearConstraintTerms (p0 and p2) for
143-
// each polynomial (for the symbolic manipulations needed to compute symbolic_part),\
144-
// plus three more terms for this layer's vl, vr, vl*vr.
144+
// The LHS of this constraint will consist of two LinearConstraintTerms for the previous
145+
// layer's vl and vr (to compute this layer's claims), plus two terms (p0 and p2) for
146+
// each polynomial in the layer, plus three more terms for this layer's vl, vr, vl*vr.
145147
//
146148
// The RHS can be computed straightforwardly and so we get one element per layer.
147149
//
148150
// Q is the quad once reduced down to a single value, which is bound_quad[0][0] for us.
149151

150-
// Known portion of initial claim.
152+
// Known portion of layer's initial claim.
151153
let mut claim_known = claims[0] + alpha * claims[1];
152154

153155
if layer_index > 0 {
@@ -478,7 +480,7 @@ mod tests {
478480

479481
let test_vector_constraints = test_vector.constraints.unwrap();
480482
let test_vector_ligero_commitment =
481-
hex::decode(&test_vector.ligero_commitment.as_ref().unwrap()).unwrap();
483+
hex::decode(test_vector.ligero_commitment.as_ref().unwrap()).unwrap();
482484

483485
let evaluation: Evaluation<FieldP128> = circuit
484486
.evaluate(&test_vector.valid_inputs.unwrap())

0 commit comments

Comments
 (0)