zebra/zebra-chain/src/sprout/tree.rs

48 lines
1.5 KiB
Rust
Raw Normal View History

//! Note Commitment Trees.
//!
//! A note commitment tree is an incremental Merkle tree of fixed depth
//! used to store note commitments that JoinSplit transfers or Spend
//! transfers produce. Just as the unspent transaction output set (UTXO
//! set) used in Bitcoin, it is used to express the existence of value and
//! the capability to spend it. However, unlike the UTXO set, it is not
//! the job of this tree to protect against double-spending, as it is
//! append-only.
//!
//! A root of a note commitment tree is associated with each treestate.
#![allow(clippy::unit_arg)]
use std::fmt;
#[cfg(test)]
use proptest_derive::Arbitrary;
/// Sprout note commitment tree root node hash.
///
/// The root hash in LEBS2OSP256(rt) encoding of the Sprout note
/// commitment tree corresponding to the final Sprout treestate of
/// this block. A root of a note commitment tree is associated with
/// each treestate.
#[derive(Clone, Copy, Default, Eq, PartialEq, Serialize, Deserialize)]
#[cfg_attr(test, derive(Arbitrary))]
pub struct NoteTreeRootHash([u8; 32]);
impl fmt::Debug for NoteTreeRootHash {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("SproutNoteTreeRootHash")
.field(&hex::encode(&self.0))
.finish()
}
}
impl From<[u8; 32]> for NoteTreeRootHash {
fn from(bytes: [u8; 32]) -> NoteTreeRootHash {
Self(bytes)
}
}
impl From<NoteTreeRootHash> for [u8; 32] {
fn from(rt: NoteTreeRootHash) -> [u8; 32] {
rt.0
}
}