diff --git a/src/ipa_pc/mod.rs b/src/ipa_pc/mod.rs index f3479fa7..2bdbfed6 100644 --- a/src/ipa_pc/mod.rs +++ b/src/ipa_pc/mod.rs @@ -188,9 +188,7 @@ impl> InnerProductArg supported_degree: usize, p: &LabeledPolynomial, ) -> Result<(), Error> { - if p.degree() < 1 { - return Err(Error::DegreeIsZero); - } else if p.degree() > supported_degree { + if p.degree() > supported_degree { return Err(Error::TooManyCoefficients { num_coefficients: p.degree() + 1, num_powers: supported_degree + 1, @@ -1051,6 +1049,14 @@ mod tests { DensePoly::rand(degree, rng) } + fn constant_poly( + _: usize, + _: Option, + rng: &mut rand::prelude::StdRng, + ) -> DensePoly { + DensePoly::from_coefficients_slice(&[F::rand(rng)]) + } + fn rand_point(_: Option, rng: &mut rand::prelude::StdRng) -> F { F::rand(rng) } @@ -1062,6 +1068,13 @@ mod tests { .expect("test failed for ed_on_bls12_381-blake2s"); } + #[test] + fn constant_poly_test() { + use crate::tests::*; + single_poly_test::<_, _, PC_JJB2S>(None, constant_poly::, rand_point::) + .expect("test failed for ed_on_bls12_381-blake2s"); + } + #[test] fn quadratic_poly_degree_bound_multiple_queries_test() { use crate::tests::*; diff --git a/src/kzg10/mod.rs b/src/kzg10/mod.rs index 4eb61899..2007141f 100644 --- a/src/kzg10/mod.rs +++ b/src/kzg10/mod.rs @@ -149,7 +149,7 @@ where hiding_bound: Option, rng: Option<&mut dyn RngCore>, ) -> Result<(Commitment, Randomness), Error> { - Self::check_degree_is_within_bounds(polynomial.degree(), powers.size())?; + Self::check_degree_is_too_large(polynomial.degree(), powers.size())?; let commit_time = start_timer!(|| format!( "Committing to polynomial of degree {} with hiding_bound: {:?}", @@ -276,7 +276,7 @@ where point: P::Point, rand: &Randomness, ) -> Result, Error> { - Self::check_degree_is_within_bounds(p.degree(), powers.size())?; + Self::check_degree_is_too_large(p.degree(), powers.size())?; let open_time = start_timer!(|| format!("Opening polynomial of degree {}", p.degree())); let witness_time = start_timer!(|| "Computing witness polynomials"); @@ -377,18 +377,6 @@ where Ok(result) } - // Functions for checking errors - pub(crate) fn check_degree_is_within_bounds( - num_coefficients: usize, - num_powers: usize, - ) -> Result<(), Error> { - if num_coefficients < 1 { - Err(Error::DegreeIsZero) - } else { - Self::check_degree_is_too_large(num_coefficients, num_powers) - } - } - pub(crate) fn check_degree_is_too_large( num_coefficients: usize, num_powers: usize, @@ -454,7 +442,7 @@ fn skip_leading_zeros_and_convert_to_bigints>( p: &P, ) -> (usize, Vec) { let mut num_leading_zeros = 0; - while p.coeffs()[num_leading_zeros].is_zero() && num_leading_zeros < p.coeffs().len() { + while num_leading_zeros < p.coeffs().len() && p.coeffs()[num_leading_zeros].is_zero() { num_leading_zeros += 1; } let coeffs = convert_to_bigints(&p.coeffs()[num_leading_zeros..]); diff --git a/src/marlin_pc/mod.rs b/src/marlin_pc/mod.rs index 31592fe3..74d818be 100644 --- a/src/marlin_pc/mod.rs +++ b/src/marlin_pc/mod.rs @@ -840,6 +840,14 @@ mod tests { DensePoly::::rand(degree, rng) } + fn constant_poly( + _: usize, + _: Option, + rng: &mut rand::prelude::StdRng, + ) -> DensePoly { + DensePoly::::from_coefficients_slice(&[E::Fr::rand(rng)]) + } + fn rand_point(_: Option, rng: &mut rand::prelude::StdRng) -> E::Fr { E::Fr::rand(rng) } @@ -861,6 +869,23 @@ mod tests { .expect("test failed for bls12-381"); } + #[test] + fn constant_poly_test() { + use crate::tests::*; + single_poly_test::<_, _, PC_Bls12_377>( + None, + constant_poly::, + rand_point::, + ) + .expect("test failed for bls12-377"); + single_poly_test::<_, _, PC_Bls12_381>( + None, + constant_poly::, + rand_point::, + ) + .expect("test failed for bls12-381"); + } + #[test] fn quadratic_poly_degree_bound_multiple_queries_test() { use crate::tests::*;