arnaucube
arnaucube/miden-cryptoPublic Self-hosted repository
Merge pull request #175 from 0xPolygonMiden/hacka-tsmt-proof-basic-traits

TSMT proof basic traits
Augusto Hack hack.augusto@gmail.com
Thu, 03 Aug 2023 15:54:29 +0200
commit

3dfcc0810f428e402da482c1326a27ff1e83ac00

parent

b6eb1f9134d995f3d15038ae01aa071d6186ec9a

1 files changed, 11 insertions(+), 1 deletions(-)

jump to
M src/merkle/tiered_smt/proof.rs → src/merkle/tiered_smt/proof.rs

@@ -21,6 +21,7 @@ ///

/// The proof consists of a Merkle path and one or more key-value entries which describe the node /// located at the base of the path. If the node at the base of the path resolves to [ZERO; 4], /// the entries will contain a single item with value set to [ZERO; 4]. +#[derive(PartialEq, Eq, Debug)] pub struct TieredSmtProof { path: MerklePath, entries: Vec<(RpoDigest, Word)>,

@@ -38,7 +39,11 @@ /// - Entries is an empty vector.

/// - Entries contains more than 1 item, but the length of the path is not 64. /// - Entries contains more than 1 item, and one of the items has value set to [ZERO; 4]. /// - Entries contains multiple items with keys which don't share the same 64-bit prefix. - pub fn new(path: MerklePath, entries: Vec<(RpoDigest, Word)>) -> Self { + pub fn new<I>(path: MerklePath, entries: I) -> Self + where + I: IntoIterator<Item = (RpoDigest, Word)>, + { + let entries: Vec<(RpoDigest, Word)> = entries.into_iter().collect(); assert!(path.depth() <= MAX_DEPTH); assert!(!entries.is_empty()); if entries.len() > 1 {

@@ -108,6 +113,11 @@ let index = LeafNodeIndex::from_key(&self.entries[0].0, self.path.depth());

self.path .compute_root(index.value(), node) .expect("failed to compute Merkle path root") + } + + /// Consume the proof and returns its parts. + pub fn into_parts(self) -> (MerklePath, Vec<(RpoDigest, Word)>) { + (self.path, self.entries) } // HELPER METHODS