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

View File

@ -107,7 +107,10 @@ pub(crate) fn prove<F: Extendable<D>, const D: usize>(
.into_par_iter() .into_par_iter()
.flat_map(|mut quotient_poly| { .flat_map(|mut quotient_poly| {
quotient_poly.trim(); 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. // Split t into degree-n chunks.
quotient_poly.chunks(degree) quotient_poly.chunks(degree)
}) })