Browse Source

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

master
Sean Bowe 7 years ago
parent
commit
849f330441
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
  1. 25
      src/circuit/pedersen_hash.rs

25
src/circuit/pedersen_hash.rs

@ -206,6 +206,31 @@ mod test {
use ::circuit::test::*; use ::circuit::test::*;
use ::circuit::boolean::{Boolean, AllocatedBit}; use ::circuit::boolean::{Boolean, AllocatedBit};
use pairing::bls12_381::{Bls12, Fr}; 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] #[test]
fn test_pedersen_hash() { fn test_pedersen_hash() {

Loading…
Cancel
Save