mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-02-12 10:05:47 +00:00
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:
parent
e9c9618ef4
commit
849f330441
@ -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…
x
Reference in New Issue
Block a user