Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DanieleDiBenedetto committed Jan 25, 2021
1 parent 676e934 commit 3eec3f4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/ipa_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ impl<G: AffineCurve, D: Digest> InnerProductArgPC<G, D> {
supported_degree: usize,
p: &LabeledPolynomial<G::ScalarField>,
) -> 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,
Expand Down Expand Up @@ -1085,6 +1083,12 @@ mod tests {
type PC<E, D> = InnerProductArgPC<E, D>;
type PC_DEE = PC<Affine, Blake2s>;

#[test]
fn constant_poly_test() {
use crate::tests::*;
constant_poly_test::<_, PC_DEE>().expect("test failed for tweedle_dee-blake2s");
}

#[test]
fn single_poly_test() {
use crate::tests::*;
Expand Down
30 changes: 27 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,11 @@ pub mod tests {
let pp = PC::setup(max_degree, rng)?;

for _ in 0..num_iters {
let supported_degree = supported_degree
.unwrap_or(rand::distributions::Uniform::from(1..=max_degree).sample(rng));
let supported_degree = match supported_degree {
Some(0) => 0,
Some(d) => d,
None => rand::distributions::Uniform::from(1..=max_degree).sample(rng)
};
assert!(
max_degree >= supported_degree,
"max_degree < supported_degree"
Expand All @@ -777,7 +780,11 @@ pub mod tests {
for i in 0..num_polynomials {
let label = format!("Test{}", i);
labels.push(label.clone());
let degree = rand::distributions::Uniform::from(1..=supported_degree).sample(rng);
let degree = if supported_degree > 0 {
rand::distributions::Uniform::from(1..=supported_degree).sample(rng)
} else {
0
};
let poly = Polynomial::rand(degree, rng);

let degree_bound = if let Some(degree_bounds) = &mut degree_bounds {
Expand Down Expand Up @@ -1042,6 +1049,23 @@ pub mod tests {
Ok(())
}

pub fn constant_poly_test<F, PC>() -> Result<(), PC::Error>
where
F: Field,
PC: PolynomialCommitment<F>,
{
let info = TestInfo {
num_iters: 100,
max_degree: None,
supported_degree: Some(0),
num_polynomials: 1,
enforce_degree_bounds: false,
max_num_queries: 1,
..Default::default()
};
test_template::<F, PC>(info)
}

pub fn single_poly_test<F, PC>() -> Result<(), PC::Error>
where
F: Field,
Expand Down

0 comments on commit 3eec3f4

Please sign in to comment.