From 414d651c9c0f12d48ba2f998ede156f38f8c719a Mon Sep 17 00:00:00 2001 From: Kobi Gurkan Date: Thu, 9 Aug 2018 16:20:39 +0300 Subject: [PATCH] pedersen_hash: adds tests for Daniel's vector --- zcash_primitives/src/pedersen_hash.rs | 4 ++++ zcash_proofs/src/circuit/pedersen_hash.rs | 26 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/zcash_primitives/src/pedersen_hash.rs b/zcash_primitives/src/pedersen_hash.rs index f760a1f6d..f49fcb70a 100644 --- a/zcash_primitives/src/pedersen_hash.rs +++ b/zcash_primitives/src/pedersen_hash.rs @@ -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] + } } } } diff --git a/zcash_proofs/src/circuit/pedersen_hash.rs b/zcash_proofs/src/circuit/pedersen_hash.rs index 67d05c507..82703fa98 100644 --- a/zcash_proofs/src/circuit/pedersen_hash.rs +++ b/zcash_proofs/src/circuit/pedersen_hash.rs @@ -208,4 +208,30 @@ mod test { } } } + + #[test] + fn test_pedersen_hash_alternative() { + let params = &JubjubBls12::new(); + + let mut input: Vec = 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::::new(); + + let input_bools: Vec = 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()); + + } }