From 0acc94674ef68e1827a660fc571d69a8faa9dba4 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 8 Mar 2023 15:49:41 +0000 Subject: [PATCH 1/7] add necessary trait bounds to bmt --- base_layer/mmr/src/balanced_binary_merkle_proof.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base_layer/mmr/src/balanced_binary_merkle_proof.rs b/base_layer/mmr/src/balanced_binary_merkle_proof.rs index 4d5feaf42d..f401da2786 100644 --- a/base_layer/mmr/src/balanced_binary_merkle_proof.rs +++ b/base_layer/mmr/src/balanced_binary_merkle_proof.rs @@ -23,13 +23,14 @@ use std::{collections::HashMap, convert::TryInto, marker::PhantomData}; use digest::Digest; +use serde::{Deserialize, Serialize}; use tari_common::DomainDigest; use tari_utilities::ByteArray; use thiserror::Error; use crate::{common::hash_together, BalancedBinaryMerkleTree, Hash}; -#[derive(Debug)] +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] pub struct BalancedBinaryMerkleProof { pub path: Vec, pub node_index: usize, From 41004b985c2c60313702d8ac21a40a308c46e844 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 8 Mar 2023 15:55:53 +0000 Subject: [PATCH 2/7] add further trait bounds --- base_layer/mmr/src/balanced_binary_merkle_proof.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_layer/mmr/src/balanced_binary_merkle_proof.rs b/base_layer/mmr/src/balanced_binary_merkle_proof.rs index f401da2786..5aea034f0d 100644 --- a/base_layer/mmr/src/balanced_binary_merkle_proof.rs +++ b/base_layer/mmr/src/balanced_binary_merkle_proof.rs @@ -30,7 +30,7 @@ use thiserror::Error; use crate::{common::hash_together, BalancedBinaryMerkleTree, Hash}; -#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)] pub struct BalancedBinaryMerkleProof { pub path: Vec, pub node_index: usize, From 511744f304d1d1cf3f8350ca6db10c3d817a0f1c Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 8 Mar 2023 16:16:23 +0000 Subject: [PATCH 3/7] refactor use of usize to u32 in bmt, add borsh derives to bmt proof type --- Cargo.lock | 1 + base_layer/mmr/Cargo.toml | 1 + .../mmr/src/balanced_binary_merkle_proof.rs | 17 +++++++++-------- .../mmr/src/balanced_binary_merkle_tree.rs | 4 ++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f88436dd4..97b0104831 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5752,6 +5752,7 @@ version = "0.48.0-pre.0" dependencies = [ "bincode", "blake2 0.9.2", + "borsh", "criterion 0.2.11", "croaring", "digest 0.9.0", diff --git a/base_layer/mmr/Cargo.toml b/base_layer/mmr/Cargo.toml index 82cb4f7a27..6e6cb0916c 100644 --- a/base_layer/mmr/Cargo.toml +++ b/base_layer/mmr/Cargo.toml @@ -17,6 +17,7 @@ tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", t tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.7" } tari_common = {path = "../../common"} thiserror = "1.0.26" +borsh = "0.9.3" digest = "0.9.0" log = "0.4" serde = { version = "1.0.97", features = ["derive"] } diff --git a/base_layer/mmr/src/balanced_binary_merkle_proof.rs b/base_layer/mmr/src/balanced_binary_merkle_proof.rs index 5aea034f0d..2955993b98 100644 --- a/base_layer/mmr/src/balanced_binary_merkle_proof.rs +++ b/base_layer/mmr/src/balanced_binary_merkle_proof.rs @@ -22,6 +22,7 @@ use std::{collections::HashMap, convert::TryInto, marker::PhantomData}; +use borsh::{BorshDeserialize, BorshSerialize}; use digest::Digest; use serde::{Deserialize, Serialize}; use tari_common::DomainDigest; @@ -30,10 +31,10 @@ use thiserror::Error; use crate::{common::hash_together, BalancedBinaryMerkleTree, Hash}; -#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)] +#[derive(BorshDeserialize, BorshSerialize, Deserialize, Serialize, Clone, Debug, Default, PartialEq, Eq)] pub struct BalancedBinaryMerkleProof { pub path: Vec, - pub node_index: usize, + pub node_index: u32, _phantom: PhantomData, } @@ -70,7 +71,7 @@ where D: Digest + DomainDigest } Self { path: proof, - node_index: tree.get_node_index(leaf_index), + node_index: tree.get_node_index(leaf_index) as u32, _phantom: PhantomData, } } @@ -95,8 +96,8 @@ pub enum MergedBalancedBinaryMerkleDataType { #[derive(Debug)] pub struct MergedBalancedBinaryMerkleProof { pub paths: Vec)>>, // these tuples can contain indexes or hashes! - pub node_indices: Vec, - pub heights: Vec, + pub node_indices: Vec, + pub heights: Vec, _phantom: PhantomData, } @@ -106,7 +107,7 @@ where D: Digest + DomainDigest pub fn create_from_proofs( proofs: Vec>, ) -> Result { - let heights = proofs.iter().map(|proof| proof.path.len()).collect::>(); + let heights = proofs.iter().map(|proof| proof.path.len() as u32).collect::>(); let max_height = heights .iter() .max() @@ -118,7 +119,7 @@ where D: Digest + DomainDigest let mut hash_map = HashMap::new(); for (index, proof) in proofs.iter().enumerate() { // If this path was already joined ignore it. - if join_indices[index].is_none() && proof.path.len() > height { + if join_indices[index].is_none() && proof.path.len() > height as usize { let parent = (indices[index] - 1) >> 1; if let Some(other_proof) = hash_map.insert(parent, index) { join_indices[index] = Some(other_proof); @@ -130,7 +131,7 @@ where D: Digest + DomainDigest 0, ( MergedBalancedBinaryMerkleDataType::Hash, - proof.path[proof.path.len() - 1 - height].clone(), + proof.path[proof.path.len() - 1 - height as usize].clone(), ), ); } diff --git a/base_layer/mmr/src/balanced_binary_merkle_tree.rs b/base_layer/mmr/src/balanced_binary_merkle_tree.rs index 08770ea653..bbaa99a0c9 100644 --- a/base_layer/mmr/src/balanced_binary_merkle_tree.rs +++ b/base_layer/mmr/src/balanced_binary_merkle_tree.rs @@ -92,7 +92,7 @@ where D: Digest + DomainDigest leaf_index + (self.hashes.len() >> 1) } - pub fn find_leaf_index_for_hash(&self, hash: &Hash) -> Result { + pub fn find_leaf_index_for_hash(&self, hash: &Hash) -> Result { let pos = self .hashes .position(hash) @@ -102,7 +102,7 @@ where D: Digest + DomainDigest // The hash provided was not for leaf, but for node. Err(BalancedBinaryMerkleTreeError::LeafNotFound) } else { - Ok(pos - (self.hashes.len() >> 1)) + Ok(pos as u32 - (self.hashes.len() as u32 >> 1)) } } } From 7f68268e87cdd410fa142db2140e913e8cbcb91d Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 9 Mar 2023 08:39:31 +0000 Subject: [PATCH 4/7] merge development and remove u32 as cast --- .../mmr/src/balanced_binary_merkle_proof.rs | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/base_layer/mmr/src/balanced_binary_merkle_proof.rs b/base_layer/mmr/src/balanced_binary_merkle_proof.rs index 2955993b98..da6aee57f8 100644 --- a/base_layer/mmr/src/balanced_binary_merkle_proof.rs +++ b/base_layer/mmr/src/balanced_binary_merkle_proof.rs @@ -20,7 +20,11 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::{collections::HashMap, convert::TryInto, marker::PhantomData}; +use std::{ + collections::HashMap, + convert::{TryFrom, TryInto}, + marker::PhantomData, +}; use borsh::{BorshDeserialize, BorshSerialize}; use digest::Digest; @@ -57,7 +61,10 @@ where D: Digest + DomainDigest &computed_root == root } - pub fn generate_proof(tree: &BalancedBinaryMerkleTree, leaf_index: usize) -> Self { + pub fn generate_proof( + tree: &BalancedBinaryMerkleTree, + leaf_index: usize, + ) -> Result { let mut node_index = tree.get_node_index(leaf_index); let mut proof = Vec::new(); while node_index > 0 { @@ -69,11 +76,12 @@ where D: Digest + DomainDigest // Traverse to parent node_index = parent; } - Self { + Ok(Self { path: proof, - node_index: tree.get_node_index(leaf_index) as u32, + node_index: u32::try_from(tree.get_node_index(leaf_index)) + .map_err(|_| MergedBalancedBinaryMerkleProofError::MathOverflow)?, _phantom: PhantomData, - } + }) } } @@ -83,6 +91,8 @@ pub enum MergedBalancedBinaryMerkleProofError { CantMergeZeroProofs, #[error("Bad proof semantics")] BadProofSemantics, + #[error("Math overflow")] + MathOverflow, } /// Flag to indicate if proof data represents an index or a node hash @@ -107,7 +117,16 @@ where D: Digest + DomainDigest pub fn create_from_proofs( proofs: Vec>, ) -> Result { - let heights = proofs.iter().map(|proof| proof.path.len() as u32).collect::>(); + let heights = proofs + .iter() + .map(|proof| { + proof + .path + .len() + .try_into() + .map_err(|_| MergedBalancedBinaryMerkleProofError::MathOverflow) + }) + .collect::, _>>()?; let max_height = heights .iter() .max() @@ -225,11 +244,11 @@ mod test { let hash_last = leaves[n - 1].clone(); let bmt = BalancedBinaryMerkleTree::>::create(leaves); let root = bmt.get_merkle_root(); - let proof = BalancedBinaryMerkleProof::generate_proof(&bmt, 0); + let proof = BalancedBinaryMerkleProof::generate_proof(&bmt, 0).unwrap(); assert!(proof.verify(&root, hash_0)); - let proof = BalancedBinaryMerkleProof::generate_proof(&bmt, n / 2); + let proof = BalancedBinaryMerkleProof::generate_proof(&bmt, n / 2).unwrap(); assert!(proof.verify(&root, hash_n_half)); - let proof = BalancedBinaryMerkleProof::generate_proof(&bmt, n - 1); + let proof = BalancedBinaryMerkleProof::generate_proof(&bmt, n - 1).unwrap(); assert!(proof.verify(&root, hash_last)); } } @@ -243,7 +262,8 @@ mod test { let proofs = indices .iter() .map(|i| BalancedBinaryMerkleProof::generate_proof(&bmt, *i)) - .collect::>(); + .collect::, _>>() + .unwrap(); let merged_proof = MergedBalancedBinaryMerkleProof::create_from_proofs(proofs).unwrap(); assert!(merged_proof .verify_consume(&root, indices.iter().map(|i| leaves[*i].clone()).collect::>()) @@ -257,7 +277,8 @@ mod test { let root = bmt.get_merkle_root(); let proofs = (0..255) .map(|i| BalancedBinaryMerkleProof::generate_proof(&bmt, i)) - .collect::>(); + .collect::, _>>() + .unwrap(); let merged_proof = MergedBalancedBinaryMerkleProof::create_from_proofs(proofs).unwrap(); assert!(merged_proof.verify_consume(&root, leaves).unwrap()); } From 8b5ae4686d0871f07942adaae53140586b7641b1 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 9 Mar 2023 17:58:58 +0000 Subject: [PATCH 5/7] simplified u32 cast logic and address PR comments --- base_layer/mmr/src/balanced_binary_merkle_proof.rs | 13 +++---------- base_layer/mmr/src/balanced_binary_merkle_tree.rs | 8 +++++--- base_layer/mmr/src/lib.rs | 5 +++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/base_layer/mmr/src/balanced_binary_merkle_proof.rs b/base_layer/mmr/src/balanced_binary_merkle_proof.rs index da6aee57f8..e8dc8d8e57 100644 --- a/base_layer/mmr/src/balanced_binary_merkle_proof.rs +++ b/base_layer/mmr/src/balanced_binary_merkle_proof.rs @@ -33,7 +33,7 @@ use tari_common::DomainDigest; use tari_utilities::ByteArray; use thiserror::Error; -use crate::{common::hash_together, BalancedBinaryMerkleTree, Hash}; +use crate::{cast_to_u32, common::hash_together, BalancedBinaryMerkleTree, Hash}; #[derive(BorshDeserialize, BorshSerialize, Deserialize, Serialize, Clone, Debug, Default, PartialEq, Eq)] pub struct BalancedBinaryMerkleProof { @@ -78,8 +78,7 @@ where D: Digest + DomainDigest } Ok(Self { path: proof, - node_index: u32::try_from(tree.get_node_index(leaf_index)) - .map_err(|_| MergedBalancedBinaryMerkleProofError::MathOverflow)?, + node_index: cast_to_u32(tree.get_node_index(leaf_index))?, _phantom: PhantomData, }) } @@ -119,13 +118,7 @@ where D: Digest + DomainDigest ) -> Result { let heights = proofs .iter() - .map(|proof| { - proof - .path - .len() - .try_into() - .map_err(|_| MergedBalancedBinaryMerkleProofError::MathOverflow) - }) + .map(|proof| cast_to_u32(proof.path.len())?) .collect::, _>>()?; let max_height = heights .iter() diff --git a/base_layer/mmr/src/balanced_binary_merkle_tree.rs b/base_layer/mmr/src/balanced_binary_merkle_tree.rs index bbaa99a0c9..42cca82c41 100644 --- a/base_layer/mmr/src/balanced_binary_merkle_tree.rs +++ b/base_layer/mmr/src/balanced_binary_merkle_tree.rs @@ -20,18 +20,20 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::marker::PhantomData; +use std::{convert::TryFrom, marker::PhantomData}; use digest::Digest; use tari_common::DomainDigest; use thiserror::Error; -use crate::{common::hash_together, ArrayLike, Hash}; +use crate::{cast_to_u32, common::hash_together, ArrayLike, Hash}; #[derive(Clone, Debug, PartialEq, Eq, Error)] pub enum BalancedBinaryMerkleTreeError { #[error("There is no leaf with the hash provided.")] LeafNotFound, + #[error("Math overflow")] + MathoverFlow, } // The hashes are perfectly balanced binary tree, so parent at index `i` (0-based) has children at positions `2*i+1` and @@ -102,7 +104,7 @@ where D: Digest + DomainDigest // The hash provided was not for leaf, but for node. Err(BalancedBinaryMerkleTreeError::LeafNotFound) } else { - Ok(pos as u32 - (self.hashes.len() as u32 >> 1)) + Ok(cast_to_u32(pos - (self.hashes.len() >> 1))?) } } } diff --git a/base_layer/mmr/src/lib.rs b/base_layer/mmr/src/lib.rs index 107fc83e5f..5bd37ddafc 100644 --- a/base_layer/mmr/src/lib.rs +++ b/base_layer/mmr/src/lib.rs @@ -131,6 +131,7 @@ //! 0 1 2 3 4 5 6 7 8 9 10 11 12 <-- Leaf node indices //! ---------------------------------- //! ``` +use std::convert::TryFrom; pub type Hash = Vec; pub type HashSlice = [u8]; @@ -191,3 +192,7 @@ if_native_bitmap! { /// A data structure for storing all the data required to restore the state of an MMR. pub use mutable_mmr_leaf_nodes::MutableMmrLeafNodes; } + +pub(crate) fn cast_to_u32(value: usize) -> Result { + u32::try_from(value).map_err(|_| BalancedBinaryMerkleTreeError::MathoverFlow) +} From 65d1354a6a3f5cba914967df1d7a3a2779f5867c Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 9 Mar 2023 18:12:52 +0000 Subject: [PATCH 6/7] address failing ci --- base_layer/mmr/src/balanced_binary_merkle_proof.rs | 8 ++++++-- base_layer/mmr/src/balanced_binary_merkle_tree.rs | 8 ++++++-- base_layer/mmr/src/lib.rs | 5 ----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/base_layer/mmr/src/balanced_binary_merkle_proof.rs b/base_layer/mmr/src/balanced_binary_merkle_proof.rs index e8dc8d8e57..e193db4601 100644 --- a/base_layer/mmr/src/balanced_binary_merkle_proof.rs +++ b/base_layer/mmr/src/balanced_binary_merkle_proof.rs @@ -33,7 +33,11 @@ use tari_common::DomainDigest; use tari_utilities::ByteArray; use thiserror::Error; -use crate::{cast_to_u32, common::hash_together, BalancedBinaryMerkleTree, Hash}; +use crate::{common::hash_together, BalancedBinaryMerkleTree, Hash}; + +pub(crate) fn cast_to_u32(value: usize) -> Result { + u32::try_from(value).map_err(|_| MergedBalancedBinaryMerkleProofError::MathOverflow) +} #[derive(BorshDeserialize, BorshSerialize, Deserialize, Serialize, Clone, Debug, Default, PartialEq, Eq)] pub struct BalancedBinaryMerkleProof { @@ -118,7 +122,7 @@ where D: Digest + DomainDigest ) -> Result { let heights = proofs .iter() - .map(|proof| cast_to_u32(proof.path.len())?) + .map(|proof| cast_to_u32(proof.path.len())) .collect::, _>>()?; let max_height = heights .iter() diff --git a/base_layer/mmr/src/balanced_binary_merkle_tree.rs b/base_layer/mmr/src/balanced_binary_merkle_tree.rs index 42cca82c41..488ad22397 100644 --- a/base_layer/mmr/src/balanced_binary_merkle_tree.rs +++ b/base_layer/mmr/src/balanced_binary_merkle_tree.rs @@ -26,14 +26,18 @@ use digest::Digest; use tari_common::DomainDigest; use thiserror::Error; -use crate::{cast_to_u32, common::hash_together, ArrayLike, Hash}; +use crate::{common::hash_together, ArrayLike, Hash}; + +pub(crate) fn cast_to_u32(value: usize) -> Result { + u32::try_from(value).map_err(|_| BalancedBinaryMerkleTreeError::MathOverFlow) +} #[derive(Clone, Debug, PartialEq, Eq, Error)] pub enum BalancedBinaryMerkleTreeError { #[error("There is no leaf with the hash provided.")] LeafNotFound, #[error("Math overflow")] - MathoverFlow, + MathOverFlow, } // The hashes are perfectly balanced binary tree, so parent at index `i` (0-based) has children at positions `2*i+1` and diff --git a/base_layer/mmr/src/lib.rs b/base_layer/mmr/src/lib.rs index 5bd37ddafc..107fc83e5f 100644 --- a/base_layer/mmr/src/lib.rs +++ b/base_layer/mmr/src/lib.rs @@ -131,7 +131,6 @@ //! 0 1 2 3 4 5 6 7 8 9 10 11 12 <-- Leaf node indices //! ---------------------------------- //! ``` -use std::convert::TryFrom; pub type Hash = Vec; pub type HashSlice = [u8]; @@ -192,7 +191,3 @@ if_native_bitmap! { /// A data structure for storing all the data required to restore the state of an MMR. pub use mutable_mmr_leaf_nodes::MutableMmrLeafNodes; } - -pub(crate) fn cast_to_u32(value: usize) -> Result { - u32::try_from(value).map_err(|_| BalancedBinaryMerkleTreeError::MathoverFlow) -} From c23530137a89544b78a25e4b108198be48ea2bc7 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 9 Mar 2023 18:27:51 +0000 Subject: [PATCH 7/7] renaming bbm proof error type --- .../mmr/src/balanced_binary_merkle_proof.rs | 22 +++++++++---------- base_layer/mmr/src/lib.rs | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/base_layer/mmr/src/balanced_binary_merkle_proof.rs b/base_layer/mmr/src/balanced_binary_merkle_proof.rs index e193db4601..3db26431b8 100644 --- a/base_layer/mmr/src/balanced_binary_merkle_proof.rs +++ b/base_layer/mmr/src/balanced_binary_merkle_proof.rs @@ -35,8 +35,8 @@ use thiserror::Error; use crate::{common::hash_together, BalancedBinaryMerkleTree, Hash}; -pub(crate) fn cast_to_u32(value: usize) -> Result { - u32::try_from(value).map_err(|_| MergedBalancedBinaryMerkleProofError::MathOverflow) +pub(crate) fn cast_to_u32(value: usize) -> Result { + u32::try_from(value).map_err(|_| BalancedBinaryMerkleProofError::MathOverflow) } #[derive(BorshDeserialize, BorshSerialize, Deserialize, Serialize, Clone, Debug, Default, PartialEq, Eq)] @@ -68,7 +68,7 @@ where D: Digest + DomainDigest pub fn generate_proof( tree: &BalancedBinaryMerkleTree, leaf_index: usize, - ) -> Result { + ) -> Result { let mut node_index = tree.get_node_index(leaf_index); let mut proof = Vec::new(); while node_index > 0 { @@ -89,7 +89,7 @@ where D: Digest + DomainDigest } #[derive(Debug, Error)] -pub enum MergedBalancedBinaryMerkleProofError { +pub enum BalancedBinaryMerkleProofError { #[error("Can't merge zero proofs.")] CantMergeZeroProofs, #[error("Bad proof semantics")] @@ -119,7 +119,7 @@ where D: Digest + DomainDigest { pub fn create_from_proofs( proofs: Vec>, - ) -> Result { + ) -> Result { let heights = proofs .iter() .map(|proof| cast_to_u32(proof.path.len())) @@ -127,7 +127,7 @@ where D: Digest + DomainDigest let max_height = heights .iter() .max() - .ok_or(MergedBalancedBinaryMerkleProofError::CantMergeZeroProofs)?; + .ok_or(BalancedBinaryMerkleProofError::CantMergeZeroProofs)?; let mut indices = proofs.iter().map(|proof| proof.node_index).collect::>(); let mut paths = vec![Vec::new(); proofs.len()]; let mut join_indices = vec![None; proofs.len()]; @@ -167,11 +167,11 @@ where D: Digest + DomainDigest mut self, root: &Hash, leaves_hashes: Vec, - ) -> Result { + ) -> Result { // Check that the proof and verifier data match let n = self.node_indices.len(); // number of merged proofs if self.paths.len() != n || leaves_hashes.len() != n { - return Err(MergedBalancedBinaryMerkleProofError::BadProofSemantics); + return Err(BalancedBinaryMerkleProofError::BadProofSemantics); } let mut computed_hashes = leaves_hashes; @@ -179,7 +179,7 @@ where D: Digest + DomainDigest .heights .iter() .max() - .ok_or(MergedBalancedBinaryMerkleProofError::CantMergeZeroProofs)?; + .ok_or(BalancedBinaryMerkleProofError::CantMergeZeroProofs)?; // We need to compute the hashes row by row to be sure they are processed correctly. for height in (0..*max_height).rev() { @@ -195,14 +195,14 @@ where D: Digest + DomainDigest .1 .as_bytes() .try_into() - .map_err(|_| MergedBalancedBinaryMerkleProofError::BadProofSemantics)?, + .map_err(|_| BalancedBinaryMerkleProofError::BadProofSemantics)?, ); // The index must also point to one of the proofs if index < hashes.len() { &hashes[index] } else { - return Err(MergedBalancedBinaryMerkleProofError::BadProofSemantics); + return Err(BalancedBinaryMerkleProofError::BadProofSemantics); } }, MergedBalancedBinaryMerkleDataType::Hash => &hash_or_index.1, diff --git a/base_layer/mmr/src/lib.rs b/base_layer/mmr/src/lib.rs index 107fc83e5f..6588712897 100644 --- a/base_layer/mmr/src/lib.rs +++ b/base_layer/mmr/src/lib.rs @@ -154,8 +154,8 @@ pub mod pruned_hashset; pub use backend::{ArrayLike, ArrayLikeExt}; pub use balanced_binary_merkle_proof::{ BalancedBinaryMerkleProof, + BalancedBinaryMerkleProofError, MergedBalancedBinaryMerkleProof, - MergedBalancedBinaryMerkleProofError, }; pub use balanced_binary_merkle_tree::{BalancedBinaryMerkleTree, BalancedBinaryMerkleTreeError}; /// MemBackendVec is a shareable, memory only, vector that can be be used with MmrCache to store checkpoints.