Skip to content

Commit

Permalink
Add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnevadoc committed May 6, 2022
1 parent cb7512a commit 2ed6f87
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions plonk-core/src/proof_system/pi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,66 @@ where
DensePolynomial::from_coefficients_vec(domain.ifft(&evals))
}
}

#[cfg(test)]
mod test {
use super::*;
use crate::batch_field_test;
use ark_bls12_377::Fr as Bls12_377_scalar_field;
use ark_bls12_381::Fr as Bls12_381_scalar_field;

// Checks PI representation is not affected by insertion order
// or extra zeros.
fn test_pi_unique_repr<F>()
where
F: FftField,
{
let mut pi_1 = PI::new(8);

pi_1.insert(2, F::from(2u64));
pi_1.insert(5, F::from(5u64));
pi_1.insert(6, F::from(6u64));

let mut pi_2 = PI::new(8);

pi_2.insert(6, F::from(6u64));
pi_2.insert(5, F::from(5u64));
pi_2.insert(2, F::from(2u64));

pi_2.insert(0, F::zero());
pi_2.insert(1, F::zero());
assert_eq!(pi_1, pi_2);
}

// Checks PI does not allow to override already inserted values.
fn test_pi_dup_insertion<F>()
where
F: FftField,
{
let mut pi_1 = PI::new(8);

pi_1.insert(2, F::from(2u64));
pi_1.insert(5, F::from(5u64));
pi_1.insert(5, F::from(2u64));
}

// Bls12-381 tests
batch_field_test!(
[
test_pi_unique_repr
],
[
test_pi_dup_insertion
] => Bls12_381_scalar_field
);

// Bls12-377 tests
batch_field_test!(
[
test_pi_unique_repr
],
[
test_pi_dup_insertion
] => Bls12_377_scalar_field
);
}

0 comments on commit 2ed6f87

Please sign in to comment.