From bbf70c90edfa3d07810c9d94f5119061f9658930 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Fri, 4 Apr 2025 15:14:27 +0200 Subject: [PATCH] smt: change SimpleSmt::open() to return a sparse path --- miden-crypto/src/merkle/smt/simple/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/miden-crypto/src/merkle/smt/simple/mod.rs b/miden-crypto/src/merkle/smt/simple/mod.rs index 6773cd1..abdd80b 100644 --- a/miden-crypto/src/merkle/smt/simple/mod.rs +++ b/miden-crypto/src/merkle/smt/simple/mod.rs @@ -5,6 +5,7 @@ use super::{ LeafIndex, MerkleError, MerklePath, MutationSet, NodeIndex, RpoDigest, SMT_MAX_DEPTH, SMT_MIN_DEPTH, SparseMerkleTree, Word, }; +use crate::merkle::{SparseMerklePath, SparseValuePath}; #[cfg(test)] mod tests; @@ -169,8 +170,15 @@ impl SimpleSmt { /// Returns an opening of the leaf associated with `key`. Conceptually, an opening is a Merkle /// path to the leaf, as well as the leaf itself. - pub fn open(&self, key: &LeafIndex) -> ValuePath { - >::open(self, key) + pub fn open(&self, key: &LeafIndex) -> SparseValuePath { + let value = RpoDigest::new(self.get_value(key)); + let nodes = key.index.proof_indices().map(|index| self.get_node_hash(index)); + // `from_sized_iter()` returns an error if there are more nodes than `SMT_MAX_DEPTH`, but + // this could only happen if we have more levels than `SMT_MAX_DEPTH` ourselves, which is + // guarded against in `SimpleSmt::new()`. + let path = SparseMerklePath::from_sized_iter(nodes).unwrap(); + + SparseValuePath { value, path } } /// Returns a boolean value indicating whether the SMT is empty.