At least fewer M_i() rounds for test cases

This commit is contained in:
Deirdre Connolly 2020-08-02 16:17:19 -04:00 committed by Deirdre Connolly
parent 41c8076dab
commit be22ef64e5
2 changed files with 293 additions and 279 deletions

View File

@ -65,6 +65,8 @@ pub fn pedersen_hash_to_point(domain: [u8; 8], M: &BitVec<Lsb0, u8>) -> jubjub::
let mut m_i = jubjub::Fr::zero();
for (j, chunk) in segment.chunks(3).enumerate() {
println!("{:?}", m_i);
// Pad each chunk with zeros.
let mut store = 0u8;
let bits = store.bits_mut::<Lsb0>();
@ -73,6 +75,8 @@ pub fn pedersen_hash_to_point(domain: [u8; 8], M: &BitVec<Lsb0, u8>) -> jubjub::
.enumerate()
.for_each(|(i, bit)| bits.set(i, *bit));
println!("{:?}", chunk);
let mut tmp = jubjub::Fr::one();
if bits[0] {
@ -323,28 +327,21 @@ impl ValueCommitment {
mod tests {
use super::*;
// use crate::commitments::sapling::test_vectors::TEST_VECTORS;
use crate::commitments::sapling::test_vectors::TEST_VECTORS;
#[test]
fn pedersen_hash_to_point_test_vectors() {
const D: [u8; 8] = *b"Zcash_PH";
let result =
pedersen_hash_to_point(D, &BitVec::<Lsb0, u8>::from_vec(vec![1, 1, 1, 1, 1, 1]));
for test_vector in TEST_VECTORS.iter() {
let result = jubjub::AffinePoint::from(pedersen_hash_to_point(
D,
&test_vector.input_bits.clone(),
));
let point = jubjub::AffinePoint::from(result);
println!("{:?}", point);
//println!("u: ");
// for test_vector in TEST_VECTORS.iter() {
// let result = pedersen_hash_to_point(
// D,
// &BitVec::<Lsb0, u8>::from_vec(test_vector.input_bits.clone()),
// );
println!("{:?}", result);
//assert_eq!(jubjub::AffinePoint::from(result), test_vector.hash_point);
// }
}
}
}

View File

@ -4,22 +4,39 @@
// These vectors in particular correspond to the Personalization::NoteCommitment
// enum variant from the original source.
use hex::FromHex;
#![allow(dead_code)]
use bitvec::prelude::*;
use jubjub::{AffinePoint, Fq};
use lazy_static::lazy_static;
pub struct TestVector {
pub input_bits: Vec<u8>,
pub hash_point: AffinePoint,
fn point_from_hex<T: AsRef<[u8]>>(u_in_hex: T, v_in_hex: T) -> AffinePoint {
let mut u_bytes = [0u8; 32];
let _ = hex::decode_to_slice(u_in_hex, &mut u_bytes);
let u_scalar = Fq::from_bytes(&u_bytes).unwrap();
let mut v_bytes = [0u8; 32];
let _ = hex::decode_to_slice(v_in_hex, &mut v_bytes);
let v_scalar = Fq::from_bytes(&v_bytes).unwrap();
AffinePoint::from_raw_unchecked(u_scalar, v_scalar)
}
// lazy_static! {
// pub static ref TEST_VECTORS: [TestVector; 1] = [
// TestVector {
// input_bits: vec![1, 1, 1, 1, 1, 1],
// hash_x: "Fr(0x06b1187c11ca4fb4383b2e0d0dbbde3ad3617338b5029187ec65a5eaed5e4d0b)",
// hash_y: "Fr(0x3ce70f536652f0dea496393a1e55c4e08b9d55508e16d11e5db40d4810cbc982)",
// },
pub struct TestVector {
pub input_bits: BitVec<Lsb0, u8>,
pub hash_x: &'static str,
pub hash_y: &'static str,
}
lazy_static! {
pub static ref TEST_VECTORS: [TestVector; 1] = [
TestVector {
input_bits: bitvec![Lsb0, u8; 1, 1, 1, 1, 1, 1],
hash_x: "06b1187c11ca4fb4383b2e0d0dbbde3ad3617338b5029187ec65a5eaed5e4d0b",
hash_y: "3ce70f536652f0dea496393a1e55c4e08b9d55508e16d11e5db40d4810cbc982"
},
// TestVector {
// input_bits: vec![1, 1, 1, 1, 1, 1, 0],
// hash_x: "Fr(0x2fc3bc454c337f71d4f04f86304262fcbfc9ecd808716b92fc42cbe6827f7f1a)",
@ -270,5 +287,5 @@ pub struct TestVector {
// "Fr(0x471d2109656afcb96d0609b371b132b97efcf72c6051064dd19fdc004799bfa9)"
// ),
// },
// ];
// }
];
}