Skip to content

Commit

Permalink
Merge pull request #759 from erikareale/iterators_for_Polynomial
Browse files Browse the repository at this point in the history
Implement Iter and IntoIter for Polynomial
  • Loading branch information
Eduardo Leegwater Simões authored Aug 17, 2023
2 parents 8691d2b + 2bd78ea commit 5eabd2c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/commitment_scheme/kzg10/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl CommitKey {
// Compute commitment
Ok(Commitment::from(msm_variable_base(
&self.powers_of_g,
&polynomial.coeffs,
polynomial,
)))
}

Expand Down
16 changes: 15 additions & 1 deletion src/fft/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use rkyv::{
pub(crate) struct Polynomial {
/// The coefficient of `x^i` is stored at location `i` in `self.coeffs`.
#[cfg_attr(feature = "rkyv-impl", omit_bounds)]
pub(crate) coeffs: Vec<BlsScalar>,
coeffs: Vec<BlsScalar>,
}

impl Deref for Polynomial {
Expand All @@ -51,6 +51,15 @@ impl DerefMut for Polynomial {
}
}

impl IntoIterator for Polynomial {
type Item = BlsScalar;
type IntoIter = <Vec<BlsScalar> as IntoIterator>::IntoIter;

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

impl Polynomial {
/// Returns the zero polynomial.
pub(crate) const fn zero() -> Self {
Expand Down Expand Up @@ -141,6 +150,11 @@ impl Polynomial {

Ok(Polynomial { coeffs })
}

/// Returns an iterator over the polynomial coefficients.
fn iter(&self) -> impl Iterator<Item = &BlsScalar> {
self.coeffs.iter()
}
}

use core::iter::Sum;
Expand Down
2 changes: 1 addition & 1 deletion src/proof_system/quotient_poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn compute_permutation_checks(
let domain_8n = EvaluationDomain::new(8 * domain.size()).unwrap();
let l1_poly_alpha =
compute_first_lagrange_poly_scaled(domain, alpha.square());
let l1_alpha_sq_evals = domain_8n.coset_fft(&l1_poly_alpha.coeffs);
let l1_alpha_sq_evals = domain_8n.coset_fft(&l1_poly_alpha);

#[cfg(not(feature = "std"))]
let range = (0..domain_8n.size()).into_iter();
Expand Down
2 changes: 1 addition & 1 deletion src/proof_system/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ pub(crate) mod alloc {
// If the announced len is zero, simply return an empty poly
// and leave the buffer intact.
if serialized_poly_len == 0 {
return Ok(Polynomial { coeffs: vec![] });
return Ok(Polynomial::zero());
}
let (a, b) = buf.split_at(serialized_poly_len);
let poly = Polynomial::from_slice(a);
Expand Down

0 comments on commit 5eabd2c

Please sign in to comment.