Better error message when quotient hasn't correct degree

This commit is contained in:
wborgeaud 2021-06-25 09:56:15 +02:00
parent 3ce9183970
commit 2e9d3f768e
2 changed files with 10 additions and 4 deletions

View File

@ -2,6 +2,8 @@ use std::cmp::max;
use std::iter::Sum;
use std::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign};
use anyhow::{ensure, Result};
use crate::field::extension_field::Extendable;
use crate::field::fft::{fft, ifft};
use crate::field::field::Field;
@ -139,19 +141,20 @@ impl<F: Field> PolynomialCoeffs<F> {
self.padded(self.len() << rate_bits)
}
pub(crate) fn pad(&mut self, new_len: usize) {
assert!(
pub(crate) fn pad(&mut self, new_len: usize) -> Result<()> {
ensure!(
new_len >= self.len(),
"Trying to pad a polynomial of length {} to a length of {}.",
self.len(),
new_len
);
self.coeffs.resize(new_len, F::ZERO);
Ok(())
}
pub(crate) fn padded(&self, new_len: usize) -> Self {
let mut poly = self.clone();
poly.pad(new_len);
poly.pad(new_len).unwrap();
poly
}

View File

@ -107,7 +107,10 @@ pub(crate) fn prove<F: Extendable<D>, const D: usize>(
.into_par_iter()
.flat_map(|mut quotient_poly| {
quotient_poly.trim();
quotient_poly.pad(quotient_degree);
quotient_poly.pad(quotient_degree).expect(
"The quotient polynomial doesn't have the right degree.\
This may be because the `Z`s polynomials are still too high degree.",
);
// Split t into degree-n chunks.
quotient_poly.chunks(degree)
})