Merge pull request #681 from mir-protocol/poly_values_check

Check each `PolynomialValues` len
This commit is contained in:
Daniel Lubarov 2022-08-22 11:32:53 -07:00 committed by GitHub
commit 776b93e1ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View File

@ -61,7 +61,7 @@ pub fn fft_with_options<F: Field>(
) -> PolynomialValues<F> {
let PolynomialCoeffs { coeffs: mut buffer } = poly;
fft_dispatch(&mut buffer, zero_factor, root_table);
PolynomialValues { values: buffer }
PolynomialValues::new(buffer)
}
#[inline]

View File

@ -19,9 +19,7 @@ pub fn interpolant<F: Field>(points: &[(F, F)]) -> PolynomialCoeffs<F> {
.map(|x| interpolate(points, x, &barycentric_weights))
.collect();
let mut coeffs = ifft(PolynomialValues {
values: subgroup_evals,
});
let mut coeffs = ifft(PolynomialValues::new(subgroup_evals));
coeffs.trim();
coeffs
}

View File

@ -24,6 +24,8 @@ pub struct PolynomialValues<F: Field> {
impl<F: Field> PolynomialValues<F> {
pub fn new(values: Vec<F>) -> Self {
// Check that a subgroup exists of this size, which should be a power of two.
debug_assert!(log2_strict(values.len()) <= F::TWO_ADICITY);
PolynomialValues { values }
}
@ -116,6 +118,7 @@ impl<F: Field> PolynomialCoeffs<F> {
PolynomialCoeffs { coeffs }
}
/// The empty list of coefficients, which is the smallest encoding of the zero polynomial.
pub fn empty() -> Self {
Self::new(Vec::new())
}