Skip to content

Commit

Permalink
commit: fix merkle tree commit id generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Feb 1, 2024
1 parent ec9b66e commit bce2b34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 2 additions & 5 deletions commit_verify/src/mpc/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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())
}
Expand All @@ -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())
}
}
Expand All @@ -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())
}
}
Expand Down
9 changes: 5 additions & 4 deletions commit_verify/src/mpc/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit bce2b34

Please sign in to comment.