diff --git a/src/merkle/smt/full/mod.rs b/src/merkle/smt/full/mod.rs index 2fc774a..e39f3d2 100644 --- a/src/merkle/smt/full/mod.rs +++ b/src/merkle/smt/full/mod.rs @@ -263,6 +263,13 @@ impl SparseMerkleTree for Smt { leaf.hash() } + fn is_leaf_empty(leaf: &SmtLeaf) -> bool { + match leaf { + SmtLeaf::Empty(_) => true, + _ => false, + } + } + fn hash_prospective_leaf(&self, key: &RpoDigest, value: &Word) -> RpoDigest { // Future work could avoid cloning the leaf by mirroring some of the insertion logic and // hashing without an intermediate leaf, but cloning is only expensive for multi-leaves, diff --git a/src/merkle/smt/mod.rs b/src/merkle/smt/mod.rs index 95a2457..739f4a0 100644 --- a/src/merkle/smt/mod.rs +++ b/src/merkle/smt/mod.rs @@ -167,6 +167,10 @@ pub(crate) trait SparseMerkleTree { /// Returns the hash of a leaf fn hash_leaf(leaf: &Self::Leaf) -> RpoDigest; + /// Returns true if a leaf is completely sparse and does not hold any key-value pairs. + #[allow(dead_code)] + fn is_leaf_empty(leaf: &Self::Leaf) -> bool; + /// Returns the hash of a leaf if the leaf WERE inserted into the tree, /// without performing any insertion or other mutation. /// diff --git a/src/merkle/smt/simple/mod.rs b/src/merkle/smt/simple/mod.rs index 53bc797..dd12566 100644 --- a/src/merkle/smt/simple/mod.rs +++ b/src/merkle/smt/simple/mod.rs @@ -302,6 +302,10 @@ impl SparseMerkleTree for SimpleSmt { leaf.into() } + fn is_leaf_empty(leaf: &Word) -> bool { + *leaf == Self::EMPTY_VALUE + } + fn hash_prospective_leaf(&self, _key: &LeafIndex, value: &Word) -> RpoDigest { Self::hash_leaf(value) }