From 22b33ed8b625a6855dcbb8c11ba1400cc8126518 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Fri, 4 Apr 2025 14:38:41 +0200 Subject: [PATCH] SparseMerklePath: add SparseValuePath container --- miden-crypto/src/merkle/sparse_path.rs | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/miden-crypto/src/merkle/sparse_path.rs b/miden-crypto/src/merkle/sparse_path.rs index eb9fd31..af836c9 100644 --- a/miden-crypto/src/merkle/sparse_path.rs +++ b/miden-crypto/src/merkle/sparse_path.rs @@ -254,6 +254,33 @@ impl DoubleEndedIterator for SparseMerkleIter { } } +// SPARSE MERKLE PATH CONTAINERS +// ================================================================================================ +/// A container for a [crate::Word] value and its [SparseMerklePath] opening. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct SparseValuePath { + /// The node value opening for `path`. + pub value: RpoDigest, + /// The path from `value` to `root` (exclusive), using an efficient memory representation for + /// empty nodes. + pub path: SparseMerklePath, +} + +impl SparseValuePath { + /// Convenience function to construct a [SparseValuePath]. + /// + /// `value` is the value `path` leads to, in the tree. + pub fn new(value: RpoDigest, path: SparseMerklePath) -> Self { + Self { value, path } + } +} + +impl From<(SparseMerklePath, Word)> for SparseValuePath { + fn from((path, value): (SparseMerklePath, Word)) -> Self { + SparseValuePath::new(value.into(), path) + } +} + // SERIALIZATION // ================================================================================================