mmr: added partial mmr

This commit is contained in:
Augusto F. Hack
2023-10-17 17:38:18 +02:00
parent 78aa714b89
commit bde20f9752
13 changed files with 1130 additions and 136 deletions

View File

@@ -28,6 +28,11 @@ impl MerklePath {
self.nodes.len() as u8
}
/// Returns a reference to the [MerklePath]'s nodes.
pub fn nodes(&self) -> &[RpoDigest] {
&self.nodes
}
/// Computes the merkle root for this opening.
pub fn compute_root(&self, index: u64, node: RpoDigest) -> Result<RpoDigest, MerkleError> {
let mut index = NodeIndex::new(self.depth(), index)?;
@@ -69,6 +74,9 @@ impl MerklePath {
}
}
// CONVERSIONS
// ================================================================================================
impl From<MerklePath> for Vec<RpoDigest> {
fn from(path: MerklePath) -> Self {
path.nodes
@@ -81,6 +89,12 @@ impl From<Vec<RpoDigest>> for MerklePath {
}
}
impl From<&[RpoDigest]> for MerklePath {
fn from(path: &[RpoDigest]) -> Self {
Self::new(path.to_vec())
}
}
impl Deref for MerklePath {
// we use `Vec` here instead of slice so we can call vector mutation methods directly from the
// merkle path (example: `Vec::remove`).