pedersen_hash: adds tests for Daniel's vector

This commit is contained in:
Kobi Gurkan 2018-08-09 16:20:39 +03:00 committed by Jack Grigg
parent 8541b2bde4
commit 414d651c9c
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
2 changed files with 30 additions and 0 deletions

View File

@ -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]
}
}
}
}

View File

@ -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());
}
}