diff --git a/field/src/fft.rs b/field/src/fft.rs index 7e9deae5..6ede8af6 100644 --- a/field/src/fft.rs +++ b/field/src/fft.rs @@ -61,7 +61,7 @@ pub fn fft_with_options( ) -> PolynomialValues { let PolynomialCoeffs { coeffs: mut buffer } = poly; fft_dispatch(&mut buffer, zero_factor, root_table); - PolynomialValues { values: buffer } + PolynomialValues::new(buffer) } #[inline] diff --git a/field/src/interpolation.rs b/field/src/interpolation.rs index d0675715..8f64e9d7 100644 --- a/field/src/interpolation.rs +++ b/field/src/interpolation.rs @@ -19,9 +19,7 @@ pub fn interpolant(points: &[(F, F)]) -> PolynomialCoeffs { .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 } diff --git a/field/src/polynomial/mod.rs b/field/src/polynomial/mod.rs index 82c4a41c..20f1c318 100644 --- a/field/src/polynomial/mod.rs +++ b/field/src/polynomial/mod.rs @@ -24,6 +24,8 @@ pub struct PolynomialValues { impl PolynomialValues { pub fn new(values: Vec) -> 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 PolynomialCoeffs { PolynomialCoeffs { coeffs } } + /// The empty list of coefficients, which is the smallest encoding of the zero polynomial. pub fn empty() -> Self { Self::new(Vec::new()) }