smt: change SimpleSmt::open() to return a sparse path
This commit is contained in:
parent
5685f6d4b6
commit
5ab7980fbc
1 changed files with 11 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
||||||
use alloc::collections::BTreeSet;
|
use alloc::collections::BTreeSet;
|
||||||
|
|
||||||
|
use crate::merkle::{SparseMerklePath, SparseValuePath};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
super::ValuePath, EMPTY_WORD, EmptySubtreeRoots, InnerNode, InnerNodeInfo, InnerNodes,
|
super::ValuePath, EMPTY_WORD, EmptySubtreeRoots, InnerNode, InnerNodeInfo, InnerNodes,
|
||||||
LeafIndex, MerkleError, MerklePath, MutationSet, NodeIndex, RpoDigest, SMT_MAX_DEPTH,
|
LeafIndex, MerkleError, MerklePath, MutationSet, NodeIndex, RpoDigest, SMT_MAX_DEPTH,
|
||||||
|
@ -169,8 +171,15 @@ impl<const DEPTH: u8> SimpleSmt<DEPTH> {
|
||||||
|
|
||||||
/// Returns an opening of the leaf associated with `key`. Conceptually, an opening is a Merkle
|
/// 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.
|
/// path to the leaf, as well as the leaf itself.
|
||||||
pub fn open(&self, key: &LeafIndex<DEPTH>) -> ValuePath {
|
pub fn open(&self, key: &LeafIndex<DEPTH>) -> SparseValuePath {
|
||||||
<Self as SparseMerkleTree<DEPTH>>::open(self, key)
|
let value = RpoDigest::new(self.get_value(key));
|
||||||
|
let nodes = key.index.proof_indices().map(|index| self.get_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.
|
/// Returns a boolean value indicating whether the SMT is empty.
|
||||||
|
|
Loading…
Add table
Reference in a new issue