Skip to content

Commit

Permalink
mpc: add MerkleTree::into_proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 22, 2024
1 parent b5ea9ab commit 01ed41f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
19 changes: 19 additions & 0 deletions commit_verify/src/mpc/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,13 @@ Changed commitment id: {}",
/// `2 ^ depth - cofactor`.
pub fn factored_width(&self) -> u32 { self.width_limit() - self.cofactor as u32 }

pub fn known_protocol_ids(&self) -> impl Iterator<Item = ProtocolId> + '_ {
self.cross_section.iter().filter_map(|item| match item {
TreeNode::ConcealedNode { .. } => None,
TreeNode::CommitmentLeaf { protocol_id, .. } => Some(*protocol_id),
})
}

/// Constructs [`MessageMap`] for revealed protocols and messages.
pub fn to_known_message_map(&self) -> MessageMap {
Confined::try_from_iter(
Expand All @@ -617,6 +624,18 @@ Changed commitment id: {}",
)
.expect("same collection size")
}

pub fn into_known_proofs(self) -> impl Iterator<Item = (ProtocolId, MerkleProof)> {
self.known_protocol_ids()
.collect::<Vec<_>>()
.into_iter()
.map(move |id| {
let proof = self
.to_merkle_proof(id)
.expect("protocol ids must strictly match");
(id, proof)
})
}
}

impl Conceal for MerkleBlock {
Expand Down
8 changes: 7 additions & 1 deletion commit_verify/src/mpc/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub use self::commit::Error;
use crate::merkle::MerkleHash;
use crate::mpc::atoms::Leaf;
use crate::mpc::{
Commitment, MerkleBlock, MerkleConcealed, Message, MessageMap, Method, Proof, ProtocolId,
Commitment, MerkleBlock, MerkleConcealed, MerkleProof, Message, MessageMap, Method, Proof,
ProtocolId,
};
use crate::{CommitId, Conceal, LIB_NAME_COMMIT_VERIFY};

Expand Down Expand Up @@ -205,6 +206,11 @@ impl MerkleTree {
pub fn cofactor(&self) -> u16 { self.cofactor }

pub fn entropy(&self) -> u64 { self.entropy }

pub fn into_proofs(self) -> impl Iterator<Item = (ProtocolId, MerkleProof)> {
let block = MerkleBlock::from(self);
block.into_known_proofs()
}
}

#[cfg(test)]
Expand Down

0 comments on commit 01ed41f

Please sign in to comment.