pedersen_hash: adds tests for Daniel's vector
This commit is contained in:
parent
8541b2bde4
commit
414d651c9c
|
@ -5,6 +5,7 @@ use ff::{Field, PrimeField, PrimeFieldRepr};
|
|||
pub enum Personalization {
|
||||
NoteCommitment,
|
||||
MerkleTree(usize),
|
||||
Empty,
|
||||
}
|
||||
|
||||
impl Personalization {
|
||||
|
@ -16,6 +17,9 @@ impl Personalization {
|
|||
|
||||
(0..6).map(|i| (num >> i) & 1 == 1).collect()
|
||||
}
|
||||
Personalization::Empty => {
|
||||
vec![true, true, true, false, false, false]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -208,4 +208,30 @@ mod test {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pedersen_hash_alternative() {
|
||||
let params = &JubjubBls12::new();
|
||||
|
||||
let mut input: Vec<bool> = vec![true, true, true, false, false, false, true, true, true, false, false, false, true, true, true, false, false, false, true, true, true, false, false, false, true, true, true, false, false, false, true, true, true, false, false, false, true, true, true, false, true, false, true, true, true, true, true, false, true, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, true, true, true, false, false, true, true, false, true, true, true, true, true, false, true, true, false, true, true, false, true, false, true, false, true, true, false, true, false, true, true, false, false, false, false, false, true, true, false, true, false, true, true, true, true, false, true, false, true, false, false, false, false, true, true, true, false, true, true, true, false, true, false, false, true, false, true, true, true, false, false, false, true, true];
|
||||
|
||||
let mut cs = TestConstraintSystem::<Bls12>::new();
|
||||
|
||||
let input_bools: Vec<Boolean> = input.iter().enumerate().map(|(i, b)| {
|
||||
Boolean::from(
|
||||
AllocatedBit::alloc(cs.namespace(|| format!("input {}", i)), Some(*b)).unwrap()
|
||||
)
|
||||
}).collect();
|
||||
|
||||
let res = pedersen_hash(
|
||||
cs.namespace(|| "pedersen hash"),
|
||||
Personalization::Empty,
|
||||
&input_bools,
|
||||
params
|
||||
).unwrap();
|
||||
|
||||
assert!(cs.is_satisfied());
|
||||
println!("x={},y={}", res.get_x().get_value().unwrap(), res.get_y().get_value().unwrap());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue