Fix exclusive range, shift up enumerate() indexes with map()

This commit is contained in:
Deirdre Connolly 2020-08-04 04:52:18 -04:00 committed by Deirdre Connolly
parent be22ef64e5
commit 425275ad35
1 changed files with 9 additions and 6 deletions

View File

@ -91,9 +91,9 @@ pub fn pedersen_hash_to_point(domain: [u8; 8], M: &BitVec<Lsb0, u8>) -> jubjub::
tmp -= tmp.double(); tmp -= tmp.double();
} }
// tmp * 2^(4*j)
if j > 0 { if j > 0 {
tmp *= (1..(4 * j)).fold(jubjub::Fr::one(), |acc, _| acc.double()); // Inclusive range!
tmp *= (1..=(4 * j)).fold(jubjub::Fr::one(), |acc, _| acc.double());
} }
m_i += tmp; m_i += tmp;
@ -108,8 +108,13 @@ pub fn pedersen_hash_to_point(domain: [u8; 8], M: &BitVec<Lsb0, u8>) -> jubjub::
// segment with zeros. // segment with zeros.
// //
// https://zips.z.cash/protocol/protocol.pdf#concretepedersenhash // https://zips.z.cash/protocol/protocol.pdf#concretepedersenhash
for (i, segment) in M.chunks(189).enumerate() { for (i, segment) in M.chunks(189).enumerate().map(|(j, seg)| (j + 1, seg)) {
result += I_i(domain, i) * M_i(&segment) println!(
"I_i: {:?}",
jubjub::AffinePoint::from(I_i(domain, i)).to_bytes()
);
result += I_i(domain, i) * M_i(&segment);
println!("result: {:?}", jubjub::AffinePoint::from(result).to_bytes())
} }
result result
@ -339,8 +344,6 @@ mod tests {
&test_vector.input_bits.clone(), &test_vector.input_bits.clone(),
)); ));
println!("{:?}", result);
//assert_eq!(jubjub::AffinePoint::from(result), test_vector.hash_point); //assert_eq!(jubjub::AffinePoint::from(result), test_vector.hash_point);
} }
} }