From 1554e36bb16158b1186adbe1f28d77100b59d4f6 Mon Sep 17 00:00:00 2001 From: Torben Poguntke Date: Sat, 1 Nov 2025 17:42:37 +0100 Subject: [PATCH 1/2] allow custom byte parsers implementations --- .../src/aggregate_signature/aggregate_key.rs | 13 +++++++++++++ .../src/aggregate_signature/signature.rs | 18 ++++++++++++++++++ mithril-stm/src/lib.rs | 2 ++ mithril-stm/src/merkle_tree/commitment.rs | 8 +++++++- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/mithril-stm/src/aggregate_signature/aggregate_key.rs b/mithril-stm/src/aggregate_signature/aggregate_key.rs index e7be9328cf6..89463252403 100644 --- a/mithril-stm/src/aggregate_signature/aggregate_key.rs +++ b/mithril-stm/src/aggregate_signature/aggregate_key.rs @@ -17,14 +17,27 @@ pub struct AggregateVerificationKey { } impl AggregateVerificationKey { + /// Constructor for creating AggregateVerificationKey from components + /// introduced with the risc0 custom serialization features + pub fn new(mt_commitment: MerkleTreeBatchCommitment, total_stake: Stake) -> Self { + Self { + mt_commitment, + total_stake, + } + } + pub(crate) fn get_merkle_tree_batch_commitment(&self) -> MerkleTreeBatchCommitment { 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 { Self::get_merkle_tree_batch_commitment(self) } diff --git a/mithril-stm/src/aggregate_signature/signature.rs b/mithril-stm/src/aggregate_signature/signature.rs index 24bb7a848f9..dd9c1f3771c 100644 --- a/mithril-stm/src/aggregate_signature/signature.rs +++ b/mithril-stm/src/aggregate_signature/signature.rs @@ -25,6 +25,18 @@ pub struct AggregateSignature { } impl AggregateSignature { + /// Create a new AggregateSignature from components + /// This is useful for deserialization and testing purposes + pub fn new( + signatures: Vec, + batch_proof: MerkleBatchPath, + ) -> 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`. @@ -129,6 +141,12 @@ impl AggregateSignature { 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) diff --git a/mithril-stm/src/lib.rs b/mithril-stm/src/lib.rs index 2b18368bc94..34d0c7af7ca 100644 --- a/mithril-stm/src/lib.rs +++ b/mithril-stm/src/lib.rs @@ -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}; diff --git a/mithril-stm/src/merkle_tree/commitment.rs b/mithril-stm/src/merkle_tree/commitment.rs index a700bcb4990..72ad4b674c9 100644 --- a/mithril-stm/src/merkle_tree/commitment.rs +++ b/mithril-stm/src/merkle_tree/commitment.rs @@ -108,7 +108,8 @@ pub struct MerkleTreeBatchCommitment { } impl MerkleTreeBatchCommitment { - pub(crate) fn new(root: Vec, nr_leaves: usize) -> Self { + // Made function public for reconstruction of AVK in custom serializer for risc0 + pub fn new(root: Vec, nr_leaves: usize) -> Self { Self { root, nr_leaves, @@ -116,6 +117,11 @@ impl MerkleTreeBatchCommitment { } } + /// 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 { From 36fd7f8818f0ff14b10336fa7f855d52698e40a8 Mon Sep 17 00:00:00 2001 From: Torben Poguntke Date: Sun, 2 Nov 2025 16:08:43 +0100 Subject: [PATCH 2/2] cahnged dalek version --- mithril-common/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 3c54662c771..8a989a80c89 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -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 = [