Browse Source

Merge pull request #175 from 0xPolygonMiden/hacka-tsmt-proof-basic-traits

TSMT proof basic traits
al-gkr-basic-workflow
Augusto Hack 1 year ago
committed by GitHub
parent
commit
3dfcc0810f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions
  1. +11
    -1
      src/merkle/tiered_smt/proof.rs

+ 11
- 1
src/merkle/tiered_smt/proof.rs

@ -21,6 +21,7 @@ pub const EMPTY_VALUE: Word = super::TieredSmt::EMPTY_VALUE;
/// 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 @@ impl TieredSmtProof {
/// - 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 {
@ -110,6 +115,11 @@ impl TieredSmtProof {
.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
// --------------------------------------------------------------------------------------------

Loading…
Cancel
Save