From b467a75e08fd1c559998ce9d7f38826da8ebbf23 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 28 Aug 2020 04:22:40 -0400 Subject: [PATCH] Rename tree::*NoteTreeRootHash to tree::Root --- zebra-chain/src/block/root_hash.rs | 6 +++--- zebra-chain/src/sapling/spend.rs | 8 +++----- zebra-chain/src/sapling/tests/arbitrary.rs | 2 +- zebra-chain/src/sapling/tree.rs | 10 ++++------ zebra-chain/src/sprout/joinsplit.rs | 4 ++-- zebra-chain/src/sprout/tests/arbitrary.rs | 2 +- zebra-chain/src/sprout/tree.rs | 16 +++++++--------- 7 files changed, 21 insertions(+), 27 deletions(-) diff --git a/zebra-chain/src/block/root_hash.rs b/zebra-chain/src/block/root_hash.rs index 5438f30fa..3c6030fe9 100644 --- a/zebra-chain/src/block/root_hash.rs +++ b/zebra-chain/src/block/root_hash.rs @@ -1,7 +1,7 @@ //! The LightClientRootHash enum, used for the corresponding block header field. use crate::parameters::{Network, NetworkUpgrade, NetworkUpgrade::*}; -use crate::sapling::tree::SaplingNoteTreeRootHash; +use crate::sapling::tree::Root; use super::Height; @@ -21,7 +21,7 @@ pub enum RootHash { /// /// The root LEBS2OSP256(rt) of the Sapling note commitment tree /// corresponding to the final Sapling treestate of this block. - FinalSaplingRoot(SaplingNoteTreeRootHash), + FinalSaplingRoot(Root), /// [Heartwood activation block] Reserved field. /// @@ -51,7 +51,7 @@ impl RootHash { match NetworkUpgrade::current(network, height) { Genesis | BeforeOverwinter | Overwinter => PreSaplingReserved(bytes), - Sapling | Blossom => FinalSaplingRoot(SaplingNoteTreeRootHash(bytes)), + Sapling | Blossom => FinalSaplingRoot(Root(bytes)), Heartwood if Some(height) == Heartwood.activation_height(network) => { ChainHistoryActivationReserved(bytes) } diff --git a/zebra-chain/src/sapling/spend.rs b/zebra-chain/src/sapling/spend.rs index da8bf5201..de9a2dd65 100644 --- a/zebra-chain/src/sapling/spend.rs +++ b/zebra-chain/src/sapling/spend.rs @@ -20,7 +20,7 @@ pub struct Spend { /// A value commitment to the value of the input note. pub cv: commitment::ValueCommitment, /// A root of the Sapling note commitment tree at some block height in the past. - pub anchor: tree::SaplingNoteTreeRootHash, + pub anchor: tree::Root, /// The nullifier of the input note. pub nullifier: note::Nullifier, /// The randomized public key for `spend_auth_sig`. @@ -45,12 +45,10 @@ impl ZcashSerialize for Spend { impl ZcashDeserialize for Spend { fn zcash_deserialize(mut reader: R) -> Result { - use crate::sapling::{ - commitment::ValueCommitment, note::Nullifier, tree::SaplingNoteTreeRootHash, - }; + use crate::sapling::{commitment::ValueCommitment, note::Nullifier}; Ok(Spend { cv: ValueCommitment::zcash_deserialize(&mut reader)?, - anchor: SaplingNoteTreeRootHash(reader.read_32_bytes()?), + anchor: tree::Root(reader.read_32_bytes()?), nullifier: Nullifier::from(reader.read_32_bytes()?), rk: reader.read_32_bytes()?.into(), zkproof: Groth16Proof::zcash_deserialize(&mut reader)?, diff --git a/zebra-chain/src/sapling/tests/arbitrary.rs b/zebra-chain/src/sapling/tests/arbitrary.rs index aae8edbe8..a0b485e71 100644 --- a/zebra-chain/src/sapling/tests/arbitrary.rs +++ b/zebra-chain/src/sapling/tests/arbitrary.rs @@ -9,7 +9,7 @@ impl Arbitrary for Spend { fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { ( - any::(), + any::(), any::(), any::(), array::uniform32(any::()), diff --git a/zebra-chain/src/sapling/tree.rs b/zebra-chain/src/sapling/tree.rs index dd75b0a38..5fd939a24 100644 --- a/zebra-chain/src/sapling/tree.rs +++ b/zebra-chain/src/sapling/tree.rs @@ -64,17 +64,15 @@ pub struct SaplingNoteCommitmentTree; /// each treestate. #[derive(Clone, Copy, Default, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] -pub struct SaplingNoteTreeRootHash(pub [u8; 32]); +pub struct Root(pub [u8; 32]); -impl fmt::Debug for SaplingNoteTreeRootHash { +impl fmt::Debug for Root { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_tuple("SaplingNoteTreeRootHash") - .field(&hex::encode(&self.0)) - .finish() + f.debug_tuple("Root").field(&hex::encode(&self.0)).finish() } } -impl From for SaplingNoteTreeRootHash { +impl From for Root { fn from(_tree: SaplingNoteCommitmentTree) -> Self { // TODO: The Sapling note commitment tree requires a Pedersen // hash function, not SHA256. diff --git a/zebra-chain/src/sprout/joinsplit.rs b/zebra-chain/src/sprout/joinsplit.rs index fbd432d60..21cb82bac 100644 --- a/zebra-chain/src/sprout/joinsplit.rs +++ b/zebra-chain/src/sprout/joinsplit.rs @@ -28,7 +28,7 @@ pub struct JoinSplit { /// A root of the Sprout note commitment tree at some block height in the /// past, or the root produced by a previous JoinSplit transfer in this /// transaction. - pub anchor: tree::NoteTreeRootHash, + pub anchor: tree::Root, /// A nullifier for the input notes. pub nullifiers: [note::Nullifier; 2], /// A note commitment for this output note. @@ -93,7 +93,7 @@ impl ZcashDeserialize for JoinSplit

{ Ok(JoinSplit::

{ vpub_old: reader.read_u64::()?.try_into()?, vpub_new: reader.read_u64::()?.try_into()?, - anchor: tree::NoteTreeRootHash::from(reader.read_32_bytes()?), + anchor: tree::Root::from(reader.read_32_bytes()?), nullifiers: [ reader.read_32_bytes()?.into(), reader.read_32_bytes()?.into(), diff --git a/zebra-chain/src/sprout/tests/arbitrary.rs b/zebra-chain/src/sprout/tests/arbitrary.rs index 681913791..c1aac7004 100644 --- a/zebra-chain/src/sprout/tests/arbitrary.rs +++ b/zebra-chain/src/sprout/tests/arbitrary.rs @@ -14,7 +14,7 @@ impl Arbitrary for JoinSplit

{ ( any::>(), any::>(), - any::(), + any::(), array::uniform2(any::()), array::uniform2(any::()), array::uniform32(any::()), diff --git a/zebra-chain/src/sprout/tree.rs b/zebra-chain/src/sprout/tree.rs index 113377427..58e9b23c5 100644 --- a/zebra-chain/src/sprout/tree.rs +++ b/zebra-chain/src/sprout/tree.rs @@ -24,24 +24,22 @@ use proptest_derive::Arbitrary; /// each treestate. #[derive(Clone, Copy, Default, Eq, PartialEq, Serialize, Deserialize)] #[cfg_attr(test, derive(Arbitrary))] -pub struct NoteTreeRootHash([u8; 32]); +pub struct Root([u8; 32]); -impl fmt::Debug for NoteTreeRootHash { +impl fmt::Debug for Root { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_tuple("SproutNoteTreeRootHash") - .field(&hex::encode(&self.0)) - .finish() + f.debug_tuple("Root").field(&hex::encode(&self.0)).finish() } } -impl From<[u8; 32]> for NoteTreeRootHash { - fn from(bytes: [u8; 32]) -> NoteTreeRootHash { +impl From<[u8; 32]> for Root { + fn from(bytes: [u8; 32]) -> Root { Self(bytes) } } -impl From for [u8; 32] { - fn from(rt: NoteTreeRootHash) -> [u8; 32] { +impl From for [u8; 32] { + fn from(rt: Root) -> [u8; 32] { rt.0 } }