From bf5b0e3255f65312ff154b6c21ff250063b961af Mon Sep 17 00:00:00 2001 From: Qyriad Date: Fri, 4 Apr 2025 13:56:29 +0200 Subject: [PATCH] MerklePath: document indexing order of nodes I've left the iteration order of `MerklePath::inner_nodes()` unspecified, but other methods of iteration and indexing are now specified to be in order of deepest to shallowest. --- miden-crypto/src/merkle/path.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/miden-crypto/src/merkle/path.rs b/miden-crypto/src/merkle/path.rs index ee35c31..8ddf63c 100644 --- a/miden-crypto/src/merkle/path.rs +++ b/miden-crypto/src/merkle/path.rs @@ -11,6 +11,9 @@ use crate::{ // ================================================================================================ /// A merkle path container, composed of a sequence of nodes of a Merkle tree. +/// +/// Indexing into this type starts at the deepest part of the path and gets shallower. That is, +/// the node at index `0` is deeper than the node at index `self.len() - 1`. #[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct MerklePath { @@ -22,6 +25,8 @@ impl MerklePath { // -------------------------------------------------------------------------------------------- /// Creates a new Merkle path from a list of nodes. + /// + /// The list is assumed to be in order of deepest to shallowest. pub fn new(nodes: Vec) -> Self { assert!(nodes.len() <= u8::MAX.into(), "MerklePath may have at most 256 items"); Self { nodes } @@ -35,7 +40,7 @@ impl MerklePath { self.nodes.len() as u8 } - /// Returns a reference to the [MerklePath]'s nodes. + /// Returns a reference to the [MerklePath]'s nodes, in order of deepest to shallowest. pub fn nodes(&self) -> &[RpoDigest] { &self.nodes }