From ec6d5de7418a8d06dfc45bcc8626f70d21216cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=C5=9Awirski?= Date: Wed, 16 Apr 2025 10:26:46 +0200 Subject: [PATCH] keep at_depth and at_idx consistent wrt ownership --- miden-crypto/src/merkle/path.rs | 8 ++++---- miden-crypto/src/merkle/sparse_path.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/miden-crypto/src/merkle/path.rs b/miden-crypto/src/merkle/path.rs index 564d0ae..0005029 100644 --- a/miden-crypto/src/merkle/path.rs +++ b/miden-crypto/src/merkle/path.rs @@ -43,9 +43,9 @@ impl MerklePath { /// The `depth` parameter is defined in terms of `self.depth()`. Merkle paths conventionally do /// not include the root, so the shallowest depth is `1`, and the deepest depth is /// `self.depth()`. - pub fn at_depth(&self, depth: NonZero) -> Option<&RpoDigest> { + pub fn at_depth(&self, depth: NonZero) -> Option { let index = u8::checked_sub(self.depth(), depth.get())?; - self.nodes.get(index as usize) + self.nodes.get(index as usize).copied() } /// Returns a reference to the path node at the specified index, or [None] if the index is out @@ -54,8 +54,8 @@ impl MerklePath { /// The node at index 0 is the deepest part of the path. /// /// This is a checked version of using the indexing operator `[]`. - pub fn at_idx(&self, index: usize) -> Option<&RpoDigest> { - self.nodes.get(index) + pub fn at_idx(&self, index: usize) -> Option { + self.nodes.get(index).copied() } /// Returns the depth in which this Merkle path proof is valid. diff --git a/miden-crypto/src/merkle/sparse_path.rs b/miden-crypto/src/merkle/sparse_path.rs index 1763da4..22d5a9d 100644 --- a/miden-crypto/src/merkle/sparse_path.rs +++ b/miden-crypto/src/merkle/sparse_path.rs @@ -760,7 +760,7 @@ mod tests { // Test random access by depth. for depth in path_depth_iter(control_path.depth()) { - let &control_node = control_path.at_depth(depth).unwrap(); + let control_node = control_path.at_depth(depth).unwrap(); let sparse_node = sparse_path.at_depth(depth).unwrap(); assert_eq!(control_node, sparse_node, "at depth {depth} for entry {i}"); } @@ -769,7 +769,7 @@ mod tests { // Letting index get to `control_path.len()` will test that both sides correctly return // `None` for out of bounds access. for index in 0..=(control_path.len()) { - let control_node = control_path.at_idx(index).copied(); + let control_node = control_path.at_idx(index); let sparse_node = sparse_path.at_idx(index); assert_eq!(control_node, sparse_node); }