Add test to monitor the number of constraints consumed by the pedersen hash (in the context of a merkle tree).

This commit is contained in:
Sean Bowe 2017-12-28 12:00:22 -07:00
parent e9c9618ef4
commit 849f330441
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
1 changed files with 25 additions and 0 deletions

View File

@ -206,6 +206,31 @@ mod test {
use ::circuit::test::*;
use ::circuit::boolean::{Boolean, AllocatedBit};
use pairing::bls12_381::{Bls12, Fr};
use pairing::PrimeField;
#[test]
fn test_pedersen_hash_constraints() {
let mut rng = XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let params = &JubjubBls12::new();
let mut cs = TestConstraintSystem::<Bls12>::new();
let input: Vec<bool> = (0..(Fr::NUM_BITS * 2)).map(|_| rng.gen()).collect();
let input_bools: Vec<Boolean<_>> = input.iter().enumerate().map(|(i, b)| {
Boolean::from(
AllocatedBit::alloc(cs.namespace(|| format!("input {}", i)), Some(*b)).unwrap()
)
}).collect();
pedersen_hash(
cs.namespace(|| "pedersen hash"),
&input_bools,
params
).unwrap();
assert!(cs.is_satisfied());
assert_eq!(cs.num_constraints(), 1539);
}
#[test]
fn test_pedersen_hash() {