Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ chrono = { workspace = true }
ciborium = "0.2.2"
ckb-merkle-mountain-range = "0.6.1"
digest = { workspace = true }
ed25519-dalek = { version = "2.2.0", features = ["rand_core", "serde"] }
# ed25519-dalek for compatibility with risc0 downgraded from 2.2.0 to 2.1.1
ed25519-dalek = { version = "2.1.1", features = ["rand_core", "serde"] }
fixed = "1.29.0"
hex = { workspace = true }
kes-summed-ed25519 = { version = "0.2.1", features = [
Expand Down
13 changes: 13 additions & 0 deletions mithril-stm/src/aggregate_signature/aggregate_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,27 @@ pub struct AggregateVerificationKey<D: Clone + Digest + FixedOutput> {
}

impl<D: Digest + Clone + FixedOutput> AggregateVerificationKey<D> {
/// Constructor for creating AggregateVerificationKey from components
/// introduced with the risc0 custom serialization features
pub fn new(mt_commitment: MerkleTreeBatchCommitment<D>, total_stake: Stake) -> Self {
Self {
mt_commitment,
total_stake,
}
}

pub(crate) fn get_merkle_tree_batch_commitment(&self) -> MerkleTreeBatchCommitment<D> {
self.mt_commitment.clone()
}

/// this is depricated but risc0 custom serialization features require public access
/// for that reas the deprication is taken out
/*
#[deprecated(
since = "0.5.0",
note = "Use `get_merkle_tree_batch_commitment` instead"
)]
*/
pub fn get_mt_commitment(&self) -> MerkleTreeBatchCommitment<D> {
Self::get_merkle_tree_batch_commitment(self)
}
Expand Down
18 changes: 18 additions & 0 deletions mithril-stm/src/aggregate_signature/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ pub struct AggregateSignature<D: Clone + Digest + FixedOutput> {
}

impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
/// Create a new AggregateSignature from components
/// This is useful for deserialization and testing purposes
pub fn new(
signatures: Vec<SingleSignatureWithRegisteredParty>,
batch_proof: MerkleBatchPath<D>,
) -> Self {
Self {
signatures,
batch_proof,
}
}

/// Verify all checks from signatures, except for the signature verification itself.
///
/// Indices and quorum are checked by `BasicVerifier::preliminary_verify` with `msgp`.
Expand Down Expand Up @@ -129,6 +141,12 @@ impl<D: Clone + Digest + FixedOutput + Send + Sync> AggregateSignature<D> {
Ok(())
}

/// Public Getter to retrieve signatures for third party implementations
/// This is used for the risc0 mithril custom parser
pub fn signatures(&self) -> &[SingleSignatureWithRegisteredParty] {
&self.signatures
}

/// Convert multi signature to bytes
/// # Layout
/// * Aggregate signature type (u8)
Expand Down
2 changes: 2 additions & 0 deletions mithril-stm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub use error::{
StmSignatureError,
};
pub use key_registration::{ClosedKeyRegistration, KeyRegistration};
// export merkle_tree public types for custom serializer / deserializer for risc0
pub use merkle_tree::{MerkleBatchPath, MerkleTreeBatchCommitment, MerkleTreeLeaf};
pub use parameters::Parameters;
pub use participant::{Initializer, Signer, VerificationKey, VerificationKeyProofOfPossession};
pub use single_signature::{SingleSignature, SingleSignatureWithRegisteredParty};
Expand Down
8 changes: 7 additions & 1 deletion mithril-stm/src/merkle_tree/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,20 @@ pub struct MerkleTreeBatchCommitment<D: Digest> {
}

impl<D: Digest> MerkleTreeBatchCommitment<D> {
pub(crate) fn new(root: Vec<u8>, nr_leaves: usize) -> Self {
// Made function public for reconstruction of AVK in custom serializer for risc0
pub fn new(root: Vec<u8>, nr_leaves: usize) -> Self {
Self {
root,
nr_leaves,
hasher: Default::default(),
}
}

/// Get the number of leaves (needed for risc0 custom serialization, to not create breaking changes we introduce another getter)
pub fn nr_leaves(&self) -> usize {
self.nr_leaves
}

#[cfg(test)]
/// Used in property test of `tree`: `test_bytes_tree_commitment_batch_compat`
pub(crate) fn get_number_of_leaves(&self) -> usize {
Expand Down