Skip to content

Commit

Permalink
Increase the number of pedersen hash generators, exercise all test ve…
Browse files Browse the repository at this point in the history
…ctors.
  • Loading branch information
defuse authored and str4d committed Sep 16, 2019
1 parent 4dff805 commit 3701c2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion zcash_primitives/src/jubjub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl JubjubBls12 {
{
let mut pedersen_hash_generators = vec![];

for m in 0..5 {
for m in 0..6 {
use byteorder::{LittleEndian, WriteBytesExt};

let mut segment_number = [0u8; 4];
Expand Down
26 changes: 16 additions & 10 deletions zcash_primitives/src/pedersen_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,25 @@ pub mod test {
fn test_pedersen_hash_points() {
let test_vectors = pedersen_hash_vectors::get_vectors();

let params = &JubjubBls12::new();
assert!(test_vectors.len() > 0);

let v = &test_vectors[0];
let input_bools: Vec<bool> = v.input_bits.iter().map(|&i| i == 1).collect();
for v in test_vectors.iter() {
let params = &JubjubBls12::new();

// The 6 bits prefix is handled separately
assert_eq!(v.personalization.get_bits(), &input_bools[..6]);
let input_bools: Vec<bool> = v.input_bits.iter().map(|&i| i == 1).collect();

let (x, y) =
pedersen_hash::<Bls12, _>(v.personalization, input_bools.into_iter().skip(6), params)
.to_xy();
// The 6 bits prefix is handled separately
assert_eq!(v.personalization.get_bits(), &input_bools[..6]);

assert_eq!(x.to_string(), v.hash_x);
assert_eq!(y.to_string(), v.hash_y);
let (x, y) = pedersen_hash::<Bls12, _>(
v.personalization,
input_bools.into_iter().skip(6),
params,
)
.to_xy();

assert_eq!(x.to_string(), v.hash_x);
assert_eq!(y.to_string(), v.hash_y);
}
}
}

0 comments on commit 3701c2b

Please sign in to comment.