Skip to content

Commit

Permalink
PolyComm: implement iterator to abstract access to field
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Oct 4, 2024
1 parent 4a994c8 commit 7055072
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions poly-commitment/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ where
}
}

impl<'a, G> IntoIterator for &'a PolyComm<G> {
type Item = &'a G;
type IntoIter = std::slice::Iter<'a, G>;

fn into_iter(self) -> Self::IntoIter {
self.chunks.iter()
}
}

/// A commitment to a polynomial with some blinding factors.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct BlindedCommitment<G>
Expand Down
8 changes: 4 additions & 4 deletions poly-commitment/src/ipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ pub fn combine_polys<G: CommitmentCurve, D: EvaluationDomain<G::ScalarField>>(
.for_each(|(i, x)| {
*x += scale * evals[i * stride];
});
for j in 0..omegas.len() {
omega += &(omegas.chunks[j] * scale);
for chunk in omegas.into_iter() {
omega += &(*chunk * scale);
scale *= &polyscale;
}
}
Expand All @@ -172,12 +172,12 @@ pub fn combine_polys<G: CommitmentCurve, D: EvaluationDomain<G::ScalarField>>(
DensePolynomialOrEvaluations::DensePolynomial(p_i) => {
let mut offset = 0;
// iterating over chunks of the polynomial
for j in 0..omegas.len() {
for chunk in omegas.into_iter() {
let segment = &p_i.coeffs[std::cmp::min(offset, p_i.coeffs.len())
..std::cmp::min(offset + srs_length, p_i.coeffs.len())];
plnm_coefficients.add_poly(scale, segment);

omega += &(omegas.chunks[j] * scale);
omega += &(*chunk * scale);
scale *= &polyscale;
offset += srs_length;
}
Expand Down

0 comments on commit 7055072

Please sign in to comment.