From bce2b34fe5af1be06b47243f8bf897ae5d130b8a Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Thu, 1 Feb 2024 02:00:53 +0100 Subject: [PATCH] commit: fix merkle tree commit id generation --- commit_verify/src/mpc/block.rs | 7 ++----- commit_verify/src/mpc/tree.rs | 9 +++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/commit_verify/src/mpc/block.rs b/commit_verify/src/mpc/block.rs index 1b0be34e..a6419f70 100644 --- a/commit_verify/src/mpc/block.rs +++ b/commit_verify/src/mpc/block.rs @@ -562,7 +562,7 @@ Changed commitment id: {}", } impl Conceal for MerkleBlock { - type Concealed = MerkleHash; + type Concealed = Self; /// Reduces merkle tree into merkle tree root. fn conceal(&self) -> Self::Concealed { @@ -571,7 +571,7 @@ impl Conceal for MerkleBlock { .conceal_except([]) .expect("broken internal MerkleBlock structure"); debug_assert_eq!(concealed.cross_section.len(), 1); - concealed.cross_section[0].to_merkle_node() + concealed } } @@ -662,7 +662,6 @@ mod test { assert_eq!(cid1, cid2); assert_eq!(tree.conceal(), block.conceal()); - assert_eq!(tree.root(), block.conceal()); assert_eq!(tree.root(), cid1); assert_eq!(tree.commit_id(), block.commit_id()) } @@ -675,7 +674,6 @@ mod test { let block = MerkleBlock::from(&tree); assert_eq!(tree.conceal(), block.conceal()); - assert_eq!(tree.root(), block.conceal()); assert_eq!(tree.commit_id(), block.commit_id()) } } @@ -688,7 +686,6 @@ mod test { let block = MerkleBlock::from(&tree); assert_eq!(tree.conceal(), block.conceal()); - assert_eq!(tree.root(), block.conceal()); assert_eq!(tree.commit_id(), block.commit_id()) } } diff --git a/commit_verify/src/mpc/tree.rs b/commit_verify/src/mpc/tree.rs index d9d9f110..0b2939fe 100644 --- a/commit_verify/src/mpc/tree.rs +++ b/commit_verify/src/mpc/tree.rs @@ -26,7 +26,7 @@ use amplify::Wrapper; pub use self::commit::Error; use crate::merkle::MerkleHash; use crate::mpc::atoms::Leaf; -use crate::mpc::{Commitment, Message, MessageMap, Proof, ProtocolId}; +use crate::mpc::{Commitment, MerkleBlock, Message, MessageMap, Proof, ProtocolId}; use crate::{Conceal, LIB_NAME_COMMIT_VERIFY}; /// Number of cofactor variants tried before moving to the next tree depth. @@ -74,9 +74,9 @@ impl MerkleTree { } impl Conceal for MerkleTree { - type Concealed = MerkleHash; + type Concealed = MerkleBlock; - fn conceal(&self) -> Self::Concealed { self.root() } + fn conceal(&self) -> Self::Concealed { MerkleBlock::from(self.clone()).conceal() } } mod commit { @@ -249,6 +249,7 @@ mod test { use strict_encoding::StrictEncode; use crate::mpc::tree::test_helpers::{make_random_messages, make_random_tree}; + use crate::mpc::MerkleBlock; use crate::{CommitId, Conceal}; #[test] @@ -309,7 +310,7 @@ mod test { fn tree_conceal() { let msgs = make_random_messages(9); let tree = make_random_tree(&msgs); - assert_eq!(tree.conceal(), tree.root()); + assert_eq!(tree.conceal(), MerkleBlock::from(tree.clone()).conceal()); } #[test]