From a3530b0eeddcc59baa1d99b1dd36452ca0207800 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Wed, 5 Aug 2020 22:39:30 -0400 Subject: [PATCH] Move pedersen_hash() to go with the other Sapling hash functions, for now --- zebra-chain/src/commitments/sapling.rs | 10 ++++++++-- zebra-chain/src/treestate/note_commitment_tree.rs | 10 +--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/zebra-chain/src/commitments/sapling.rs b/zebra-chain/src/commitments/sapling.rs index b8e38e79..b56e1e2a 100644 --- a/zebra-chain/src/commitments/sapling.rs +++ b/zebra-chain/src/commitments/sapling.rs @@ -55,8 +55,6 @@ pub fn pedersen_hash_to_point(domain: [u8; 8], M: &BitVec) -> jubjub:: /// ⟨Mᵢ⟩ /// /// Σ j={0,k-1}: (1 - 2x₂)⋅(1 + x₀ + 2x₁)⋅2^(4⋅j) - // XXX: Are internal functions doc'd? - // // This is less efficient than it could be so that it can match the math // closely. fn M_i(segment: &BitSlice) -> jubjub::Fr { @@ -115,6 +113,14 @@ pub fn pedersen_hash_to_point(domain: [u8; 8], M: &BitVec) -> jubjub:: result } +/// Pedersen Hash Function +/// +/// https://zips.z.cash/protocol/protocol.pdf#concretepedersenhash +#[allow(non_snake_case)] +pub fn pedersen_hash(domain: [u8; 8], M: &BitVec) -> jubjub::Fq { + jubjub::AffinePoint::from(pedersen_hash_to_point(domain, M)).get_u() +} + /// Mixing Pedersen Hash Function /// /// Used to compute ρ from a note commitment and its position in the note diff --git a/zebra-chain/src/treestate/note_commitment_tree.rs b/zebra-chain/src/treestate/note_commitment_tree.rs index d83e4f04..5d503e90 100644 --- a/zebra-chain/src/treestate/note_commitment_tree.rs +++ b/zebra-chain/src/treestate/note_commitment_tree.rs @@ -20,18 +20,10 @@ use bitvec::prelude::*; use proptest_derive::Arbitrary; use crate::{ - commitments::sapling::pedersen_hash_to_point, + commitments::sapling::pedersen_hash, serialization::{SerializationError, ZcashDeserialize, ZcashSerialize}, }; -/// Pedersen Hash Function -/// -/// https://zips.z.cash/protocol/protocol.pdf#concretepedersenhash -#[allow(non_snake_case)] -fn pedersen_hash(domain: [u8; 8], M: &BitVec) -> jubjub::Fq { - jubjub::AffinePoint::from(pedersen_hash_to_point(domain, M)).get_u() -} - /// MerkleCRH^Sapling Hash Function /// /// MerkleCRH^Sapling(layer, left, right) := PedersenHash(“Zcash_PH”, l || left ||right)