From 5853b02f3e7178d38f037463f64613706574e303 Mon Sep 17 00:00:00 2001 From: Dam Date: Tue, 9 Dec 2025 12:33:27 +0100 Subject: [PATCH 1/5] started moving error in corresponding module --- mithril-common/src/protocol/multi_signer.rs | 10 +- mithril-stm/src/lib.rs | 1 + .../merkle_tree/commitment.rs | 4 +- .../merkle_tree/error.rs | 15 ++ .../membership_commitment/merkle_tree/leaf.rs | 6 +- .../membership_commitment/merkle_tree/mod.rs | 2 + .../membership_commitment/merkle_tree/path.rs | 3 +- .../membership_commitment/merkle_tree/tree.rs | 6 +- .../aggregate_signature/basic_verifier.rs | 5 +- .../src/protocol/aggregate_signature/clerk.rs | 2 +- .../src/protocol/aggregate_signature/error.rs | 32 +++ .../src/protocol/aggregate_signature/mod.rs | 8 +- .../protocol/aggregate_signature/signature.rs | 6 +- mithril-stm/src/protocol/error.rs | 188 +++++++++--------- mithril-stm/src/protocol/mod.rs | 9 +- .../bls_multi_signature/error.rs | 68 +++++++ .../bls_multi_signature/helper.rs | 2 +- .../bls_multi_signature/mod.rs | 21 +- .../proof_of_possession.rs | 8 +- .../bls_multi_signature/signature.rs | 10 +- .../bls_multi_signature/signing_key.rs | 6 +- .../bls_multi_signature/verification_key.rs | 15 +- 22 files changed, 277 insertions(+), 150 deletions(-) create mode 100644 mithril-stm/src/membership_commitment/merkle_tree/error.rs create mode 100644 mithril-stm/src/protocol/aggregate_signature/error.rs create mode 100644 mithril-stm/src/signature_scheme/bls_multi_signature/error.rs diff --git a/mithril-common/src/protocol/multi_signer.rs b/mithril-common/src/protocol/multi_signer.rs index b3476640263..4973cc847b1 100644 --- a/mithril-common/src/protocol/multi_signer.rs +++ b/mithril-common/src/protocol/multi_signer.rs @@ -91,7 +91,7 @@ impl MultiSigner { #[cfg(test)] mod test { - use mithril_stm::MultiSignatureError; + use mithril_stm::BlsSignatureError; use crate::{ crypto_helper::ProtocolAggregationError, @@ -195,8 +195,8 @@ mod test { "Verify single signature should fail if the signer isn't in the registered parties", ); - match error.downcast_ref::() { - Some(MultiSignatureError::SignatureInvalid(_)) => (), + match error.downcast_ref::() { + Some(BlsSignatureError::SignatureInvalid(_)) => (), _ => panic!("Expected an SignatureInvalid error, got: {error:?}"), } } @@ -221,8 +221,8 @@ mod test { .verify_single_signature(&ProtocolMessage::default(), &single_signature) .expect_err("Verify single signature should fail"); - match error.downcast_ref::() { - Some(MultiSignatureError::SignatureInvalid(_)) => (), + match error.downcast_ref::() { + Some(BlsSignatureError::SignatureInvalid(_)) => (), _ => panic!("Expected an SignatureInvalid error, got: {error:?}"), } } diff --git a/mithril-stm/src/lib.rs b/mithril-stm/src/lib.rs index a6b06f0f9ca..bf4864635e9 100644 --- a/mithril-stm/src/lib.rs +++ b/mithril-stm/src/lib.rs @@ -117,6 +117,7 @@ mod protocol; mod signature_scheme; pub use protocol::*; +pub use signature_scheme::BlsSignatureError; #[cfg(feature = "benchmark-internals")] pub use signature_scheme::{ diff --git a/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs b/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs index 561c9038380..d618b21c59d 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs @@ -3,8 +3,8 @@ use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; use std::marker::PhantomData; -use super::{MerkleBatchPath, MerklePath, MerkleTreeLeaf, parent, sibling}; -use crate::{MerkleTreeError, StmResult}; +use super::{MerkleBatchPath, MerklePath, MerkleTreeError, MerkleTreeLeaf, parent, sibling}; +use crate::StmResult; /// `MerkleTree` commitment. /// This structure differs from `MerkleTree` in that it does not contain all elements, which are not always necessary. diff --git a/mithril-stm/src/membership_commitment/merkle_tree/error.rs b/mithril-stm/src/membership_commitment/merkle_tree/error.rs new file mode 100644 index 00000000000..f1af9f82471 --- /dev/null +++ b/mithril-stm/src/membership_commitment/merkle_tree/error.rs @@ -0,0 +1,15 @@ +/// Error types related to merkle trees. +#[derive(Debug, Clone, thiserror::Error)] +pub enum MerkleTreeError { + /// Serialization error + #[error("Serialization of a merkle tree failed")] + SerializationError, + + /// Invalid merkle path + #[error("Path does not verify against root")] + PathInvalid(Vec), + + /// Invalid merkle batch path + #[error("Batch path does not verify against root")] + BatchPathInvalid(Vec), +} diff --git a/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs b/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs index 0a77e907405..0bd9aeb8af2 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs @@ -2,9 +2,9 @@ use std::cmp::Ordering; use serde::{Deserialize, Serialize}; -use crate::{ - MerkleTreeError, Stake, StmResult, VerificationKey, signature_scheme::BlsVerificationKey, -}; +use super::MerkleTreeError; + +use crate::{Stake, StmResult, VerificationKey, signature_scheme::BlsVerificationKey}; /// The values that are committed in the Merkle Tree. /// Namely, a verified `VerificationKey` and its corresponding stake. diff --git a/mithril-stm/src/membership_commitment/merkle_tree/mod.rs b/mithril-stm/src/membership_commitment/merkle_tree/mod.rs index 1b14c4a3c80..89f5e07f1e3 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/mod.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/mod.rs @@ -1,11 +1,13 @@ //! Merkle tree implementation for STM mod commitment; +mod error; mod leaf; mod path; mod tree; pub use commitment::*; +pub use error::*; pub use leaf::*; pub use path::*; pub use tree::*; diff --git a/mithril-stm/src/membership_commitment/merkle_tree/path.rs b/mithril-stm/src/membership_commitment/merkle_tree/path.rs index 80aaa9c0c89..494e979e3fa 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/path.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/path.rs @@ -2,7 +2,8 @@ use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; use std::marker::PhantomData; -use crate::{MerkleTreeError, StmResult}; +use super::MerkleTreeError; +use crate::StmResult; /// Path of hashes from root to leaf in a Merkle Tree. /// Contains all hashes on the path, and the index of the leaf. diff --git a/mithril-stm/src/membership_commitment/merkle_tree/tree.rs b/mithril-stm/src/membership_commitment/merkle_tree/tree.rs index acd4de54247..471e384243a 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/tree.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/tree.rs @@ -3,10 +3,10 @@ use serde::{Deserialize, Serialize}; use std::marker::PhantomData; use super::{ - MerkleBatchPath, MerklePath, MerkleTreeBatchCommitment, MerkleTreeCommitment, MerkleTreeLeaf, - left_child, parent, right_child, sibling, + MerkleBatchPath, MerklePath, MerkleTreeBatchCommitment, MerkleTreeCommitment, MerkleTreeError, + MerkleTreeLeaf, left_child, parent, right_child, sibling, }; -use crate::{MerkleTreeError, StmResult}; +use crate::StmResult; /// Tree of hashes, providing a commitment of data and its ordering. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs b/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs index b398b773fc0..a1242ea388b 100644 --- a/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs +++ b/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs @@ -1,9 +1,10 @@ use anyhow::{Context, anyhow}; use std::collections::{BTreeMap, HashMap, HashSet}; +use super::AggregationError; use crate::{ - AggregationError, Index, Parameters, RegisteredParty, SingleSignature, - SingleSignatureWithRegisteredParty, Stake, StmResult, + Index, Parameters, RegisteredParty, SingleSignature, SingleSignatureWithRegisteredParty, Stake, + StmResult, membership_commitment::MerkleTreeLeaf, signature_scheme::{BlsSignature, BlsVerificationKey}, }; diff --git a/mithril-stm/src/protocol/aggregate_signature/clerk.rs b/mithril-stm/src/protocol/aggregate_signature/clerk.rs index d4d6ea05fd0..c7e2f4371b4 100644 --- a/mithril-stm/src/protocol/aggregate_signature/clerk.rs +++ b/mithril-stm/src/protocol/aggregate_signature/clerk.rs @@ -5,7 +5,7 @@ use blake2::digest::{Digest, FixedOutput}; use anyhow::anyhow; #[cfg(feature = "future_proof_system")] -use crate::AggregationError; +use super::AggregationError; use super::{AggregateSignature, AggregateSignatureType, AggregateVerificationKey}; use crate::{ diff --git a/mithril-stm/src/protocol/aggregate_signature/error.rs b/mithril-stm/src/protocol/aggregate_signature/error.rs new file mode 100644 index 00000000000..d6d8e7931f8 --- /dev/null +++ b/mithril-stm/src/protocol/aggregate_signature/error.rs @@ -0,0 +1,32 @@ +use crate::AggregateSignatureType; + +/// Error types for aggregation. +#[derive(Debug, Clone, thiserror::Error)] +pub enum AggregationError { + /// Not enough signatures were collected, got this many instead. + #[error("Not enough signatures. Got only {0} out of {1}.")] + NotEnoughSignatures(u64, u64), + + #[error("Unsupported proof system: {0}")] + UnsupportedProofSystem(AggregateSignatureType), + + /// There is a duplicate index + #[error("Indices are not unique.")] + IndexNotUnique, +} + +/// Errors which can be output by Mithril aggregate verification. +#[derive(Debug, Clone, thiserror::Error)] +pub enum AggregateSignatureError { + /// This error occurs when the the serialization of the raw bytes failed + #[error("Invalid bytes")] + SerializationError, + + /// Batch verification of STM aggregate signatures failed + #[error("Batch verification of STM aggregate signatures failed")] + BatchInvalid, + + /// The proof system used in the aggregate signature is not supported + #[error("Unsupported proof system: {0}")] + UnsupportedProofSystem(AggregateSignatureType), +} diff --git a/mithril-stm/src/protocol/aggregate_signature/mod.rs b/mithril-stm/src/protocol/aggregate_signature/mod.rs index 317afb68ba4..451209b5c93 100644 --- a/mithril-stm/src/protocol/aggregate_signature/mod.rs +++ b/mithril-stm/src/protocol/aggregate_signature/mod.rs @@ -1,11 +1,13 @@ mod aggregate_key; mod basic_verifier; mod clerk; +mod error; mod signature; pub use aggregate_key::*; pub use basic_verifier::*; pub use clerk::*; +pub use error::*; pub use signature::*; #[cfg(test)] @@ -20,9 +22,11 @@ mod tests { use rand_core::{RngCore, SeedableRng}; use std::collections::{HashMap, HashSet}; - use super::{AggregateSignature, AggregateSignatureType, BasicVerifier, Clerk}; + use super::{ + AggregateSignature, AggregateSignatureType, AggregationError, BasicVerifier, Clerk, + }; use crate::{ - AggregationError, Initializer, KeyRegistration, Parameters, Signer, SingleSignature, + Initializer, KeyRegistration, Parameters, Signer, SingleSignature, SingleSignatureWithRegisteredParty, Stake, StmResult, membership_commitment::MerkleBatchPath, signature_scheme::BlsVerificationKey, }; diff --git a/mithril-stm/src/protocol/aggregate_signature/signature.rs b/mithril-stm/src/protocol/aggregate_signature/signature.rs index f0b4aa53f1c..f4fe3609cf8 100644 --- a/mithril-stm/src/protocol/aggregate_signature/signature.rs +++ b/mithril-stm/src/protocol/aggregate_signature/signature.rs @@ -4,10 +4,10 @@ use anyhow::anyhow; use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; -use super::AggregateVerificationKey; +use super::{AggregateSignatureError, AggregateVerificationKey}; use crate::{ - AggregateSignatureError, Parameters, StmError, StmResult, - membership_commitment::MerkleBatchPath, proof_system::ConcatenationProof, + Parameters, StmError, StmResult, membership_commitment::MerkleBatchPath, + proof_system::ConcatenationProof, }; /// The type of STM aggregate signature. diff --git a/mithril-stm/src/protocol/error.rs b/mithril-stm/src/protocol/error.rs index 8bb8e12309c..920de4553bb 100644 --- a/mithril-stm/src/protocol/error.rs +++ b/mithril-stm/src/protocol/error.rs @@ -8,52 +8,52 @@ use crate::{ }; /// Error types for multi signatures. -#[derive(Debug, thiserror::Error, Eq, PartialEq)] -pub enum MultiSignatureError { - /// Invalid Single signature - #[error("Invalid single signature")] - SignatureInvalid(BlsSignature), +// #[derive(Debug, thiserror::Error, Eq, PartialEq)] +// pub enum MultiSignatureError { +// /// Invalid Single signature +// #[error("Invalid single signature")] +// SignatureInvalid(BlsSignature), - /// Invalid aggregate signature - #[error("Invalid aggregated signature")] - AggregateSignatureInvalid, +// /// Invalid aggregate signature +// #[error("Invalid aggregated signature")] +// AggregateSignatureInvalid, - /// This error occurs when the the serialization of the raw bytes failed - #[error("Invalid bytes")] - SerializationError, +// /// This error occurs when the the serialization of the raw bytes failed +// #[error("Invalid bytes")] +// SerializationError, - /// Incorrect proof of possession - #[error("Key with invalid PoP")] - KeyInvalid(Box), +// /// Incorrect proof of possession +// #[error("Key with invalid PoP")] +// KeyInvalid(Box), - /// At least one signature in the batch is invalid - #[error("One signature in the batch is invalid")] - BatchInvalid, +// /// At least one signature in the batch is invalid +// #[error("One signature in the batch is invalid")] +// BatchInvalid, - /// Single signature is the infinity - #[error("Single signature is the infinity")] - SignatureInfinity(BlsSignature), +// /// Single signature is the infinity +// #[error("Single signature is the infinity")] +// SignatureInfinity(BlsSignature), - /// Verification key is the infinity - #[error("Verification key is the infinity")] - VerificationKeyInfinity(Box), -} +// /// Verification key is the infinity +// #[error("Verification key is the infinity")] +// VerificationKeyInfinity(Box), +// } /// Error types related to merkle trees. -#[derive(Debug, Clone, thiserror::Error)] -pub enum MerkleTreeError { - /// Serialization error - #[error("Serialization of a merkle tree failed")] - SerializationError, +// #[derive(Debug, Clone, thiserror::Error)] +// pub enum MerkleTreeError { +// /// Serialization error +// #[error("Serialization of a merkle tree failed")] +// SerializationError, - /// Invalid merkle path - #[error("Path does not verify against root")] - PathInvalid(Vec), +// /// Invalid merkle path +// #[error("Path does not verify against root")] +// PathInvalid(Vec), - /// Invalid merkle batch path - #[error("Batch path does not verify against root")] - BatchPathInvalid(Vec), -} +// /// Invalid merkle batch path +// #[error("Batch path does not verify against root")] +// BatchPathInvalid(Vec), +// } /// Errors which can be output by Mithril single signature verification. #[derive(Debug, Clone, thiserror::Error)] @@ -71,36 +71,36 @@ pub enum SignatureError { SerializationError, } -/// Error types for aggregation. -#[derive(Debug, Clone, thiserror::Error)] -pub enum AggregationError { - /// Not enough signatures were collected, got this many instead. - #[error("Not enough signatures. Got only {0} out of {1}.")] - NotEnoughSignatures(u64, u64), - - #[error("Unsupported proof system: {0}")] - UnsupportedProofSystem(AggregateSignatureType), - - /// There is a duplicate index - #[error("Indices are not unique.")] - IndexNotUnique, -} - -/// Errors which can be output by Mithril aggregate verification. -#[derive(Debug, Clone, thiserror::Error)] -pub enum AggregateSignatureError { - /// This error occurs when the the serialization of the raw bytes failed - #[error("Invalid bytes")] - SerializationError, - - /// Batch verification of STM aggregate signatures failed - #[error("Batch verification of STM aggregate signatures failed")] - BatchInvalid, - - /// The proof system used in the aggregate signature is not supported - #[error("Unsupported proof system: {0}")] - UnsupportedProofSystem(AggregateSignatureType), -} +// /// Error types for aggregation. +// #[derive(Debug, Clone, thiserror::Error)] +// pub enum AggregationError { +// /// Not enough signatures were collected, got this many instead. +// #[error("Not enough signatures. Got only {0} out of {1}.")] +// NotEnoughSignatures(u64, u64), + +// #[error("Unsupported proof system: {0}")] +// UnsupportedProofSystem(AggregateSignatureType), + +// /// There is a duplicate index +// #[error("Indices are not unique.")] +// IndexNotUnique, +// } + +// /// Errors which can be output by Mithril aggregate verification. +// #[derive(Debug, Clone, thiserror::Error)] +// pub enum AggregateSignatureError { +// /// This error occurs when the the serialization of the raw bytes failed +// #[error("Invalid bytes")] +// SerializationError, + +// /// Batch verification of STM aggregate signatures failed +// #[error("Batch verification of STM aggregate signatures failed")] +// BatchInvalid, + +// /// The proof system used in the aggregate signature is not supported +// #[error("Unsupported proof system: {0}")] +// UnsupportedProofSystem(AggregateSignatureType), +// } /// Errors which can be outputted by key registration. #[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)] @@ -122,31 +122,31 @@ pub enum RegisterError { UnregisteredInitializer, } -pub fn blst_error_to_stm_error( - e: BLST_ERROR, - sig: Option, - key: Option, -) -> StmResult<()> { - match e { - BLST_ERROR::BLST_SUCCESS => Ok(()), - BLST_ERROR::BLST_PK_IS_INFINITY => { - if let Some(s) = sig { - return Err(anyhow!(MultiSignatureError::SignatureInfinity(s))); - } - if let Some(vk) = key { - return Err(anyhow!(MultiSignatureError::VerificationKeyInfinity( - Box::new(vk) - ))); - } - Err(anyhow!(MultiSignatureError::SerializationError)) - } - BLST_ERROR::BLST_VERIFY_FAIL => { - if let Some(s) = sig { - Err(anyhow!(MultiSignatureError::SignatureInvalid(s))) - } else { - Err(anyhow!(MultiSignatureError::AggregateSignatureInvalid)) - } - } - _ => Err(anyhow!(MultiSignatureError::SerializationError)), - } -} +// pub fn blst_error_to_stm_error( +// e: BLST_ERROR, +// sig: Option, +// key: Option, +// ) -> StmResult<()> { +// match e { +// BLST_ERROR::BLST_SUCCESS => Ok(()), +// BLST_ERROR::BLST_PK_IS_INFINITY => { +// if let Some(s) = sig { +// return Err(anyhow!(MultiSignatureError::SignatureInfinity(s))); +// } +// if let Some(vk) = key { +// return Err(anyhow!(MultiSignatureError::VerificationKeyInfinity( +// Box::new(vk) +// ))); +// } +// Err(anyhow!(MultiSignatureError::SerializationError)) +// } +// BLST_ERROR::BLST_VERIFY_FAIL => { +// if let Some(s) = sig { +// Err(anyhow!(MultiSignatureError::SignatureInvalid(s))) +// } else { +// Err(anyhow!(MultiSignatureError::AggregateSignatureInvalid)) +// } +// } +// _ => Err(anyhow!(MultiSignatureError::SerializationError)), +// } +// } diff --git a/mithril-stm/src/protocol/mod.rs b/mithril-stm/src/protocol/mod.rs index d7a58b7caaf..ee73059d5cb 100644 --- a/mithril-stm/src/protocol/mod.rs +++ b/mithril-stm/src/protocol/mod.rs @@ -7,14 +7,11 @@ mod participant; mod single_signature; pub use aggregate_signature::{ - AggregateSignature, AggregateSignatureType, AggregateVerificationKey, BasicVerifier, Clerk, + AggregateSignature, AggregateSignatureError, AggregateSignatureType, AggregateVerificationKey, + AggregationError, BasicVerifier, Clerk, }; pub(crate) use eligibility_check::is_lottery_won; -pub(crate) use error::blst_error_to_stm_error; -pub use error::{ - AggregateSignatureError, AggregationError, MerkleTreeError, MultiSignatureError, RegisterError, - SignatureError, -}; +pub use error::{RegisterError, SignatureError}; pub use key_registration::{ClosedKeyRegistration, KeyRegistration, RegisteredParty}; pub use parameters::Parameters; pub use participant::{Initializer, Signer, VerificationKey, VerificationKeyProofOfPossession}; diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/error.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/error.rs new file mode 100644 index 00000000000..bed7e621c6f --- /dev/null +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/error.rs @@ -0,0 +1,68 @@ +//! Crate specific errors +use anyhow::anyhow; +use blst::BLST_ERROR; + +use super::{BlsSignature, BlsVerificationKey, BlsVerificationKeyProofOfPossession}; + +use crate::StmResult; + +/// Error types for multi signatures. +#[derive(Debug, thiserror::Error, Eq, PartialEq)] +pub enum BlsSignatureError { + /// Invalid Single signature + #[error("Invalid single signature")] + SignatureInvalid(BlsSignature), + + /// Invalid aggregate signature + #[error("Invalid aggregated signature")] + AggregateSignatureInvalid, + + /// This error occurs when the the serialization of the raw bytes failed + #[error("Invalid bytes")] + SerializationError, + + /// Incorrect proof of possession + #[error("Key with invalid PoP")] + KeyInvalid(Box), + + /// At least one signature in the batch is invalid + #[error("One signature in the batch is invalid")] + BatchInvalid, + + /// Single signature is the infinity + #[error("Single signature is the infinity")] + SignatureInfinity(BlsSignature), + + /// Verification key is the infinity + #[error("Verification key is the infinity")] + VerificationKeyInfinity(Box), +} + +pub fn blst_error_to_stm_error( + e: BLST_ERROR, + sig: Option, + key: Option, +) -> StmResult<()> { + match e { + BLST_ERROR::BLST_SUCCESS => Ok(()), + BLST_ERROR::BLST_PK_IS_INFINITY => { + if let Some(s) = sig { + return Err(anyhow!(BlsSignatureError::SignatureInfinity(s))); + } + if let Some(vk) = key { + return Err(anyhow!(BlsSignatureError::VerificationKeyInfinity( + Box::new(vk) + ))); + } + Err(anyhow!(BlsSignatureError::SerializationError)) + } + BLST_ERROR::BLST_VERIFY_FAIL => { + if let Some(s) = sig { + Err(anyhow!(BlsSignatureError::SignatureInvalid(s))) + } else { + Err(anyhow!(BlsSignatureError::AggregateSignatureInvalid)) + } + } + _ => Err(anyhow!(BlsSignatureError::SerializationError)), + } +} diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/helper.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/helper.rs index 8eeae988526..3e7e52ff280 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/helper.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/helper.rs @@ -9,8 +9,8 @@ pub(crate) mod unsafe_helpers { }; use crate::{ - MultiSignatureError::SerializationError, StmResult, + signature_scheme::bls_multi_signature::error::BlsSignatureError::SerializationError, signature_scheme::{BlsProofOfPossession, BlsVerificationKey}, }; diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/mod.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/mod.rs index fc3c3bc1646..dba959071c1 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/mod.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/mod.rs @@ -1,11 +1,13 @@ //! BLST Multi-signature module +mod error; pub(super) mod helper; mod proof_of_possession; mod signature; mod signing_key; mod verification_key; +pub use error::*; pub use proof_of_possession::*; pub use signature::*; pub use signing_key::*; @@ -94,8 +96,9 @@ mod tests { use rand_chacha::ChaCha20Rng; use rand_core::{RngCore, SeedableRng}; + use super::error::BlsSignatureError; use super::helper::unsafe_helpers::{p1_affine_to_sig, p2_affine_to_vk}; - use crate::{KeyRegistration, MultiSignatureError, RegisterError}; + use crate::{KeyRegistration, RegisterError}; use super::*; @@ -134,8 +137,8 @@ mod tests { assert!( matches!( - error.downcast_ref::(), - Some(MultiSignatureError::SignatureInvalid(_)) + error.downcast_ref::(), + Some(BlsSignatureError::SignatureInvalid(_)) ), "Unexpected error: {error:?}"); } @@ -152,8 +155,8 @@ mod tests { let error = sig_infinity.verify(&msg, &vk).expect_err("Verification should fail"); assert!( matches!( - error.downcast_ref::(), - Some(MultiSignatureError::SignatureInfinity(_)) + error.downcast_ref::(), + Some(BlsSignatureError::SignatureInfinity(_)) ), "Unexpected error: {error:?}"); } @@ -171,8 +174,8 @@ mod tests { let error = vkpop_infinity.verify_proof_of_possession().expect_err("VK pop infinity should fail"); assert!( matches!( - error.downcast_ref::(), - Some(MultiSignatureError::VerificationKeyInfinity(_)) + error.downcast_ref::(), + Some(BlsSignatureError::VerificationKeyInfinity(_)) ), "Unexpected error: {error:?}"); } @@ -296,8 +299,8 @@ mod tests { let error = BlsSignature::batch_verify_aggregates(&batch_msgs, &batch_vk, &batch_sig).expect_err("Batch verify should fail"); assert!( matches!( - error.downcast_ref::(), - Some(MultiSignatureError::BatchInvalid) + error.downcast_ref::(), + Some(BlsSignatureError::BatchInvalid) ), "Unexpected error: {error:?}"); } diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs index 41035e41af1..134d42fb40e 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs @@ -1,10 +1,10 @@ use blst::{blst_p1, min_sig::Signature as BlstSig}; use super::{ - BlsSigningKey, POP, + BlsSignatureError, BlsSigningKey, POP, blst_error_to_stm_error, helper::unsafe_helpers::{compress_p1, scalar_to_pk_in_g1, uncompress_p1}, }; -use crate::{MultiSignatureError, StmResult, blst_error_to_stm_error}; +use crate::StmResult; /// MultiSig proof of possession, which contains two elements from G1. However, /// the two elements have different types: `k1` is represented as a BlstSig @@ -35,7 +35,7 @@ impl BlsProofOfPossession { /// Deserialize a byte string to a `PublicKeyPoP`. pub fn from_bytes(bytes: &[u8]) -> StmResult { let k1 = match BlstSig::from_bytes( - bytes.get(..48).ok_or(MultiSignatureError::SerializationError)?, + bytes.get(..48).ok_or(BlsSignatureError::SerializationError)?, ) { Ok(key) => key, Err(e) => { @@ -44,7 +44,7 @@ impl BlsProofOfPossession { } }; - let k2 = uncompress_p1(bytes.get(48..96).ok_or(MultiSignatureError::SerializationError)?)?; + let k2 = uncompress_p1(bytes.get(48..96).ok_or(BlsSignatureError::SerializationError)?)?; Ok(Self { k1, k2 }) } diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs index 3ad44712dd0..b9f97e7914d 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs @@ -9,10 +9,10 @@ use digest::consts::U16; use std::{cmp::Ordering, iter::Sum}; use super::{ - BlsVerificationKey, + BlsSignatureError, BlsVerificationKey, blst_error_to_stm_error, helper::unsafe_helpers::{p1_affine_to_sig, p2_affine_to_vk, sig_to_p1, vk_from_p2_affine}, }; -use crate::{Index, MultiSignatureError, StmResult, blst_error_to_stm_error}; +use crate::{Index, StmResult}; /// MultiSig signature, which is a wrapper over the `BlstSig` type. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -62,7 +62,7 @@ impl BlsSignature { /// # Error /// Returns an error if the byte string does not represent a point in the curve. pub fn from_bytes(bytes: &[u8]) -> StmResult { - let bytes = bytes.get(..48).ok_or(MultiSignatureError::SerializationError)?; + let bytes = bytes.get(..48).ok_or(BlsSignatureError::SerializationError)?; match BlstSig::sig_validate(bytes, true) { Ok(sig) => Ok(Self(sig)), Err(e) => Err(blst_error_to_stm_error(e, None, None) @@ -95,7 +95,7 @@ impl BlsSignature { sigs: &[BlsSignature], ) -> StmResult<(BlsVerificationKey, BlsSignature)> { if vks.len() != sigs.len() || vks.is_empty() { - return Err(anyhow!(MultiSignatureError::AggregateSignatureInvalid)); + return Err(anyhow!(BlsSignatureError::AggregateSignatureInvalid)); } if vks.len() < 2 { @@ -175,7 +175,7 @@ impl BlsSignature { None, None, ) - .map_err(|_| anyhow!(MultiSignatureError::BatchInvalid)) + .map_err(|_| anyhow!(BlsSignatureError::BatchInvalid)) } } diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs index 6108d9f6374..92705b5231f 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs @@ -1,8 +1,8 @@ use blst::min_sig::SecretKey as BlstSk; use rand_core::{CryptoRng, RngCore}; -use super::BlsSignature; -use crate::{MultiSignatureError, StmResult, blst_error_to_stm_error}; +use super::{BlsSignature, BlsSignatureError, blst_error_to_stm_error}; +use crate::StmResult; /// MultiSig secret key, which is a wrapper over the BlstSk type from the blst /// library. @@ -35,7 +35,7 @@ impl BlsSigningKey { /// # Error /// Fails if the byte string represents a scalar larger than the group order. pub fn from_bytes(bytes: &[u8]) -> StmResult { - let bytes = bytes.get(..32).ok_or(MultiSignatureError::SerializationError)?; + let bytes = bytes.get(..32).ok_or(BlsSignatureError::SerializationError)?; match BlstSk::from_bytes(bytes) { Ok(sk) => Ok(Self(sk)), Err(e) => Err(blst_error_to_stm_error(e, None, None) diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs index 1247115d28f..05f60260915 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs @@ -12,8 +12,11 @@ use blst::{ }; use serde::{Deserialize, Serialize}; -use super::{BlsProofOfPossession, BlsSigningKey, POP, helper::unsafe_helpers::verify_pairing}; -use crate::{MultiSignatureError, StmResult, blst_error_to_stm_error}; +use super::{ + BlsProofOfPossession, BlsSignatureError, BlsSigningKey, POP, blst_error_to_stm_error, + helper::unsafe_helpers::verify_pairing, +}; +use crate::StmResult; /// MultiSig verification key, which is a wrapper over the BlstVk (element in G2) /// from the blst library. @@ -32,7 +35,7 @@ impl BlsVerificationKey { /// This function fails if the bytes do not represent a compressed point of the prime /// order subgroup of the curve Bls12-381. pub fn from_bytes(bytes: &[u8]) -> StmResult { - let bytes = bytes.get(..96).ok_or(MultiSignatureError::SerializationError)?; + let bytes = bytes.get(..96).ok_or(BlsSignatureError::SerializationError)?; match BlstVk::key_validate(bytes) { Ok(vk) => Ok(Self(vk)), Err(e) => Err(blst_error_to_stm_error(e, None, None) @@ -149,7 +152,7 @@ impl BlsVerificationKeyProofOfPossession { ) == BLST_ERROR::BLST_SUCCESS && result) { - return Err(anyhow!(MultiSignatureError::KeyInvalid(Box::new(*self)))); + return Err(anyhow!(BlsSignatureError::KeyInvalid(Box::new(*self)))); } Ok(()) } @@ -187,11 +190,11 @@ impl BlsVerificationKeyProofOfPossession { /// Deserialize a byte string to a `BlsVerificationKeyProofOfPossession`. pub fn from_bytes(bytes: &[u8]) -> StmResult { let mvk = BlsVerificationKey::from_bytes( - bytes.get(..96).ok_or(MultiSignatureError::SerializationError)?, + bytes.get(..96).ok_or(BlsSignatureError::SerializationError)?, )?; let pop = BlsProofOfPossession::from_bytes( - bytes.get(96..).ok_or(MultiSignatureError::SerializationError)?, + bytes.get(96..).ok_or(BlsSignatureError::SerializationError)?, )?; Ok(Self { vk: mvk, pop }) From 82891865fb041b711eb6156654b53594d9defdb8 Mon Sep 17 00:00:00 2001 From: Dam Date: Tue, 9 Dec 2025 14:35:05 +0100 Subject: [PATCH 2/5] replace future_proof_system feature with future_snark --- mithril-stm/Cargo.toml | 1 - .../src/protocol/aggregate_signature/clerk.rs | 6 ++--- .../protocol/aggregate_signature/signature.rs | 24 +++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/mithril-stm/Cargo.toml b/mithril-stm/Cargo.toml index 09a33778454..80c13292e79 100644 --- a/mithril-stm/Cargo.toml +++ b/mithril-stm/Cargo.toml @@ -18,7 +18,6 @@ default = ["rug-backend"] rug-backend = ["rug/default"] num-integer-backend = ["dep:num-bigint", "dep:num-rational", "dep:num-traits"] benchmark-internals = [] # For benchmarking multi_sig -future_proof_system = [] # For activating future proof systems future_snark = [ "dep:ff", "dep:group", diff --git a/mithril-stm/src/protocol/aggregate_signature/clerk.rs b/mithril-stm/src/protocol/aggregate_signature/clerk.rs index c7e2f4371b4..d17d35ca27e 100644 --- a/mithril-stm/src/protocol/aggregate_signature/clerk.rs +++ b/mithril-stm/src/protocol/aggregate_signature/clerk.rs @@ -1,10 +1,10 @@ use anyhow::Context; use blake2::digest::{Digest, FixedOutput}; -#[cfg(feature = "future_proof_system")] +#[cfg(feature = "future_snark")] use anyhow::anyhow; -#[cfg(feature = "future_proof_system")] +#[cfg(feature = "future_snark")] use super::AggregationError; use super::{AggregateSignature, AggregateSignatureType, AggregateVerificationKey}; @@ -89,7 +89,7 @@ impl Clerk { ) })?, )), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignatureType::Future => Err(anyhow!( AggregationError::UnsupportedProofSystem(aggregate_signature_type) )), diff --git a/mithril-stm/src/protocol/aggregate_signature/signature.rs b/mithril-stm/src/protocol/aggregate_signature/signature.rs index f4fe3609cf8..966df3083f0 100644 --- a/mithril-stm/src/protocol/aggregate_signature/signature.rs +++ b/mithril-stm/src/protocol/aggregate_signature/signature.rs @@ -17,7 +17,7 @@ pub enum AggregateSignatureType { #[default] Concatenation, /// Future proof system. Not suitable for production. - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] Future, } @@ -28,7 +28,7 @@ impl AggregateSignatureType { pub fn get_byte_encoding_prefix(&self) -> u8 { match self { AggregateSignatureType::Concatenation => 0, - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignatureType::Future => 255, } } @@ -39,7 +39,7 @@ impl AggregateSignatureType { pub fn from_byte_encoding_prefix(byte: u8) -> Option { match byte { 0 => Some(AggregateSignatureType::Concatenation), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] 255 => Some(AggregateSignatureType::Future), _ => None, } @@ -52,7 +52,7 @@ impl From<&AggregateSignature> fn from(aggr_sig: &AggregateSignature) -> Self { match aggr_sig { AggregateSignature::Concatenation(_) => AggregateSignatureType::Concatenation, - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignature::Future => AggregateSignatureType::Future, } } @@ -64,7 +64,7 @@ impl FromStr for AggregateSignatureType { fn from_str(s: &str) -> Result { match s { "Concatenation" => Ok(AggregateSignatureType::Concatenation), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] "Future" => Ok(AggregateSignatureType::Future), _ => Err(anyhow!("Unknown aggregate signature type: {}", s)), } @@ -75,7 +75,7 @@ impl Display for AggregateSignatureType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { AggregateSignatureType::Concatenation => write!(f, "Concatenation"), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignatureType::Future => write!(f, "Future"), } } @@ -89,7 +89,7 @@ impl Display for AggregateSignatureType { ))] pub enum AggregateSignature { /// A future proof system. - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] Future, /// Concatenation proof system. @@ -112,7 +112,7 @@ impl AggregateSignature { AggregateSignature::Concatenation(concatenation_proof) => { concatenation_proof.verify(msg, avk, parameters) } - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignature::Future => Err(anyhow!( AggregateSignatureError::UnsupportedProofSystem(self.into()) )), @@ -145,7 +145,7 @@ impl AggregateSignature { ConcatenationProof::batch_verify(&concatenation_proofs, msgs, avks, parameters) } - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignatureType::Future => Err(anyhow!( AggregateSignatureError::UnsupportedProofSystem(aggregate_signature_type) )), @@ -164,7 +164,7 @@ impl AggregateSignature { AggregateSignature::Concatenation(concatenation_proof) => { concatenation_proof.to_bytes() } - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignature::Future => vec![], }; aggregate_signature_bytes.append(&mut proof_bytes); @@ -182,7 +182,7 @@ impl AggregateSignature { AggregateSignatureType::Concatenation => Ok(AggregateSignature::Concatenation( ConcatenationProof::from_bytes(proof_bytes)?, )), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignatureType::Future => Ok(AggregateSignature::Future), } } @@ -191,7 +191,7 @@ impl AggregateSignature { pub fn to_concatenation_proof(&self) -> Option<&ConcatenationProof> { match self { AggregateSignature::Concatenation(proof) => Some(proof), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignature::Future => None, } } From 0d8aae9e5bf47e3ff2ec90cef33a40fe468923d7 Mon Sep 17 00:00:00 2001 From: Dam Date: Tue, 9 Dec 2025 14:38:32 +0100 Subject: [PATCH 3/5] finished moving error to submodule and fixed import order and typos --- mithril-stm/Cargo.toml | 2 +- .../merkle_tree/commitment.rs | 3 +- .../membership_commitment/merkle_tree/leaf.rs | 4 +- .../membership_commitment/merkle_tree/path.rs | 3 +- .../membership_commitment/merkle_tree/tree.rs | 3 +- .../aggregate_signature/basic_verifier.rs | 3 +- .../src/protocol/aggregate_signature/clerk.rs | 3 +- .../src/protocol/aggregate_signature/error.rs | 2 +- .../src/protocol/aggregate_signature/mod.rs | 7 +- .../protocol/aggregate_signature/signature.rs | 3 +- mithril-stm/src/protocol/error.rs | 133 +----------------- mithril-stm/src/protocol/mod.rs | 4 +- .../src/protocol/participant/initializer.rs | 3 +- .../src/protocol/single_signature/error.rs | 15 ++ .../src/protocol/single_signature/mod.rs | 2 + .../protocol/single_signature/signature.rs | 6 +- .../signature_registered_party.rs | 5 +- .../bls_multi_signature/error.rs | 6 +- .../proof_of_possession.rs | 3 +- .../bls_multi_signature/signature.rs | 3 +- .../bls_multi_signature/signing_key.rs | 3 +- .../bls_multi_signature/verification_key.rs | 3 +- .../schnorr_signature/signature.rs | 9 +- .../schnorr_signature/signing_key.rs | 8 +- .../schnorr_signature/utils.rs | 7 +- .../schnorr_signature/verification_key.rs | 8 +- 26 files changed, 78 insertions(+), 173 deletions(-) create mode 100644 mithril-stm/src/protocol/single_signature/error.rs diff --git a/mithril-stm/Cargo.toml b/mithril-stm/Cargo.toml index 80c13292e79..bdfd9d7f092 100644 --- a/mithril-stm/Cargo.toml +++ b/mithril-stm/Cargo.toml @@ -72,7 +72,7 @@ required-features = ["benchmark-internals"] [[bench]] name = "schnorr_sig" harness = false -required-features = ["future_snark"] +required-features = ["future_snark", "benchmark-internals"] [[bench]] name = "stm" diff --git a/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs b/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs index d618b21c59d..de029ea61b5 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs @@ -3,9 +3,10 @@ use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; use std::marker::PhantomData; -use super::{MerkleBatchPath, MerklePath, MerkleTreeError, MerkleTreeLeaf, parent, sibling}; use crate::StmResult; +use super::{MerkleBatchPath, MerklePath, MerkleTreeError, MerkleTreeLeaf, parent, sibling}; + /// `MerkleTree` commitment. /// This structure differs from `MerkleTree` in that it does not contain all elements, which are not always necessary. /// Instead, it only contains the root of the tree. diff --git a/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs b/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs index 0bd9aeb8af2..8ebdf658ab8 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs @@ -2,10 +2,10 @@ use std::cmp::Ordering; use serde::{Deserialize, Serialize}; -use super::MerkleTreeError; - use crate::{Stake, StmResult, VerificationKey, signature_scheme::BlsVerificationKey}; +use super::MerkleTreeError; + /// The values that are committed in the Merkle Tree. /// Namely, a verified `VerificationKey` and its corresponding stake. #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize, Hash)] diff --git a/mithril-stm/src/membership_commitment/merkle_tree/path.rs b/mithril-stm/src/membership_commitment/merkle_tree/path.rs index 494e979e3fa..1661beb03a3 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/path.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/path.rs @@ -2,9 +2,10 @@ use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; use std::marker::PhantomData; -use super::MerkleTreeError; use crate::StmResult; +use super::MerkleTreeError; + /// Path of hashes from root to leaf in a Merkle Tree. /// Contains all hashes on the path, and the index of the leaf. /// Used to verify that signatures come from eligible signers. diff --git a/mithril-stm/src/membership_commitment/merkle_tree/tree.rs b/mithril-stm/src/membership_commitment/merkle_tree/tree.rs index 471e384243a..a36716ad3d6 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/tree.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/tree.rs @@ -2,11 +2,12 @@ use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; use std::marker::PhantomData; +use crate::StmResult; + use super::{ MerkleBatchPath, MerklePath, MerkleTreeBatchCommitment, MerkleTreeCommitment, MerkleTreeError, MerkleTreeLeaf, left_child, parent, right_child, sibling, }; -use crate::StmResult; /// Tree of hashes, providing a commitment of data and its ordering. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs b/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs index a1242ea388b..1b757e31f89 100644 --- a/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs +++ b/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs @@ -1,7 +1,6 @@ use anyhow::{Context, anyhow}; use std::collections::{BTreeMap, HashMap, HashSet}; -use super::AggregationError; use crate::{ Index, Parameters, RegisteredParty, SingleSignature, SingleSignatureWithRegisteredParty, Stake, StmResult, @@ -9,6 +8,8 @@ use crate::{ signature_scheme::{BlsSignature, BlsVerificationKey}, }; +use super::AggregationError; + /// Full node verifier including the list of eligible signers and the total stake of the system. pub struct BasicVerifier { /// List of registered parties. diff --git a/mithril-stm/src/protocol/aggregate_signature/clerk.rs b/mithril-stm/src/protocol/aggregate_signature/clerk.rs index d17d35ca27e..8a76709c2b6 100644 --- a/mithril-stm/src/protocol/aggregate_signature/clerk.rs +++ b/mithril-stm/src/protocol/aggregate_signature/clerk.rs @@ -7,12 +7,13 @@ use anyhow::anyhow; #[cfg(feature = "future_snark")] use super::AggregationError; -use super::{AggregateSignature, AggregateSignatureType, AggregateVerificationKey}; use crate::{ ClosedKeyRegistration, Index, Parameters, Signer, SingleSignature, Stake, StmResult, VerificationKey, proof_system::ConcatenationProof, }; +use super::{AggregateSignature, AggregateSignatureType, AggregateVerificationKey}; + /// `Clerk` can verify and aggregate `SingleSignature`s and verify `AggregateSignature`s. /// Clerks can only be generated with the registration closed. /// This avoids that a Merkle Tree is computed before all parties have registered. diff --git a/mithril-stm/src/protocol/aggregate_signature/error.rs b/mithril-stm/src/protocol/aggregate_signature/error.rs index d6d8e7931f8..0888b7ddc2e 100644 --- a/mithril-stm/src/protocol/aggregate_signature/error.rs +++ b/mithril-stm/src/protocol/aggregate_signature/error.rs @@ -18,7 +18,7 @@ pub enum AggregationError { /// Errors which can be output by Mithril aggregate verification. #[derive(Debug, Clone, thiserror::Error)] pub enum AggregateSignatureError { - /// This error occurs when the the serialization of the raw bytes failed + /// This error occurs when the serialization of the raw bytes failed #[error("Invalid bytes")] SerializationError, diff --git a/mithril-stm/src/protocol/aggregate_signature/mod.rs b/mithril-stm/src/protocol/aggregate_signature/mod.rs index 451209b5c93..3a59f190d0e 100644 --- a/mithril-stm/src/protocol/aggregate_signature/mod.rs +++ b/mithril-stm/src/protocol/aggregate_signature/mod.rs @@ -22,15 +22,16 @@ mod tests { use rand_core::{RngCore, SeedableRng}; use std::collections::{HashMap, HashSet}; - use super::{ - AggregateSignature, AggregateSignatureType, AggregationError, BasicVerifier, Clerk, - }; use crate::{ Initializer, KeyRegistration, Parameters, Signer, SingleSignature, SingleSignatureWithRegisteredParty, Stake, StmResult, membership_commitment::MerkleBatchPath, signature_scheme::BlsVerificationKey, }; + use super::{ + AggregateSignature, AggregateSignatureType, AggregationError, BasicVerifier, Clerk, + }; + type Sig = AggregateSignature; type D = Blake2b; diff --git a/mithril-stm/src/protocol/aggregate_signature/signature.rs b/mithril-stm/src/protocol/aggregate_signature/signature.rs index 966df3083f0..6f5ced1b63e 100644 --- a/mithril-stm/src/protocol/aggregate_signature/signature.rs +++ b/mithril-stm/src/protocol/aggregate_signature/signature.rs @@ -4,12 +4,13 @@ use anyhow::anyhow; use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; -use super::{AggregateSignatureError, AggregateVerificationKey}; use crate::{ Parameters, StmError, StmResult, membership_commitment::MerkleBatchPath, proof_system::ConcatenationProof, }; +use super::{AggregateSignatureError, AggregateVerificationKey}; + /// The type of STM aggregate signature. #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum AggregateSignatureType { diff --git a/mithril-stm/src/protocol/error.rs b/mithril-stm/src/protocol/error.rs index 920de4553bb..410498b3bfd 100644 --- a/mithril-stm/src/protocol/error.rs +++ b/mithril-stm/src/protocol/error.rs @@ -1,106 +1,4 @@ -//! Crate specific errors -use anyhow::anyhow; -use blst::BLST_ERROR; - -use crate::{ - AggregateSignatureType, StmResult, - signature_scheme::{BlsSignature, BlsVerificationKey, BlsVerificationKeyProofOfPossession}, -}; - -/// Error types for multi signatures. -// #[derive(Debug, thiserror::Error, Eq, PartialEq)] -// pub enum MultiSignatureError { -// /// Invalid Single signature -// #[error("Invalid single signature")] -// SignatureInvalid(BlsSignature), - -// /// Invalid aggregate signature -// #[error("Invalid aggregated signature")] -// AggregateSignatureInvalid, - -// /// This error occurs when the the serialization of the raw bytes failed -// #[error("Invalid bytes")] -// SerializationError, - -// /// Incorrect proof of possession -// #[error("Key with invalid PoP")] -// KeyInvalid(Box), - -// /// At least one signature in the batch is invalid -// #[error("One signature in the batch is invalid")] -// BatchInvalid, - -// /// Single signature is the infinity -// #[error("Single signature is the infinity")] -// SignatureInfinity(BlsSignature), - -// /// Verification key is the infinity -// #[error("Verification key is the infinity")] -// VerificationKeyInfinity(Box), -// } - -/// Error types related to merkle trees. -// #[derive(Debug, Clone, thiserror::Error)] -// pub enum MerkleTreeError { -// /// Serialization error -// #[error("Serialization of a merkle tree failed")] -// SerializationError, - -// /// Invalid merkle path -// #[error("Path does not verify against root")] -// PathInvalid(Vec), - -// /// Invalid merkle batch path -// #[error("Batch path does not verify against root")] -// BatchPathInvalid(Vec), -// } - -/// Errors which can be output by Mithril single signature verification. -#[derive(Debug, Clone, thiserror::Error)] -pub enum SignatureError { - /// There is an index out of bounds - #[error("Received index, {0}, is higher than what the security parameter allows, {1}.")] - IndexBoundFailed(u64, u64), - - /// The lottery was actually lost for the signature - #[error("Lottery for this epoch was lost.")] - LotteryLost, - - /// This error occurs when the the serialization of the raw bytes failed - #[error("Invalid bytes")] - SerializationError, -} - -// /// Error types for aggregation. -// #[derive(Debug, Clone, thiserror::Error)] -// pub enum AggregationError { -// /// Not enough signatures were collected, got this many instead. -// #[error("Not enough signatures. Got only {0} out of {1}.")] -// NotEnoughSignatures(u64, u64), - -// #[error("Unsupported proof system: {0}")] -// UnsupportedProofSystem(AggregateSignatureType), - -// /// There is a duplicate index -// #[error("Indices are not unique.")] -// IndexNotUnique, -// } - -// /// Errors which can be output by Mithril aggregate verification. -// #[derive(Debug, Clone, thiserror::Error)] -// pub enum AggregateSignatureError { -// /// This error occurs when the the serialization of the raw bytes failed -// #[error("Invalid bytes")] -// SerializationError, - -// /// Batch verification of STM aggregate signatures failed -// #[error("Batch verification of STM aggregate signatures failed")] -// BatchInvalid, - -// /// The proof system used in the aggregate signature is not supported -// #[error("Unsupported proof system: {0}")] -// UnsupportedProofSystem(AggregateSignatureType), -// } +use crate::signature_scheme::{BlsVerificationKey, BlsVerificationKeyProofOfPossession}; /// Errors which can be outputted by key registration. #[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)] @@ -121,32 +19,3 @@ pub enum RegisterError { #[error("Initializer not registered. Cannot participate as a signer.")] UnregisteredInitializer, } - -// pub fn blst_error_to_stm_error( -// e: BLST_ERROR, -// sig: Option, -// key: Option, -// ) -> StmResult<()> { -// match e { -// BLST_ERROR::BLST_SUCCESS => Ok(()), -// BLST_ERROR::BLST_PK_IS_INFINITY => { -// if let Some(s) = sig { -// return Err(anyhow!(MultiSignatureError::SignatureInfinity(s))); -// } -// if let Some(vk) = key { -// return Err(anyhow!(MultiSignatureError::VerificationKeyInfinity( -// Box::new(vk) -// ))); -// } -// Err(anyhow!(MultiSignatureError::SerializationError)) -// } -// BLST_ERROR::BLST_VERIFY_FAIL => { -// if let Some(s) = sig { -// Err(anyhow!(MultiSignatureError::SignatureInvalid(s))) -// } else { -// Err(anyhow!(MultiSignatureError::AggregateSignatureInvalid)) -// } -// } -// _ => Err(anyhow!(MultiSignatureError::SerializationError)), -// } -// } diff --git a/mithril-stm/src/protocol/mod.rs b/mithril-stm/src/protocol/mod.rs index ee73059d5cb..7975dda24a2 100644 --- a/mithril-stm/src/protocol/mod.rs +++ b/mithril-stm/src/protocol/mod.rs @@ -11,11 +11,11 @@ pub use aggregate_signature::{ AggregationError, BasicVerifier, Clerk, }; pub(crate) use eligibility_check::is_lottery_won; -pub use error::{RegisterError, SignatureError}; +pub use error::RegisterError; pub use key_registration::{ClosedKeyRegistration, KeyRegistration, RegisteredParty}; pub use parameters::Parameters; pub use participant::{Initializer, Signer, VerificationKey, VerificationKeyProofOfPossession}; -pub use single_signature::{SingleSignature, SingleSignatureWithRegisteredParty}; +pub use single_signature::{SignatureError, SingleSignature, SingleSignatureWithRegisteredParty}; // Aliases #[deprecated(since = "0.5.0", note = "Use `AggregateSignature` instead")] diff --git a/mithril-stm/src/protocol/participant/initializer.rs b/mithril-stm/src/protocol/participant/initializer.rs index daff6272ae0..f2c16ef7e55 100644 --- a/mithril-stm/src/protocol/participant/initializer.rs +++ b/mithril-stm/src/protocol/participant/initializer.rs @@ -4,12 +4,13 @@ use digest::FixedOutput; use rand_core::{CryptoRng, RngCore}; use serde::{Deserialize, Serialize}; -use super::Signer; use crate::{ ClosedKeyRegistration, Parameters, RegisterError, RegisteredParty, Stake, StmResult, signature_scheme::{BlsSigningKey, BlsVerificationKeyProofOfPossession}, }; +use super::Signer; + /// Wrapper of the MultiSignature Verification key with proof of possession pub type VerificationKeyProofOfPossession = BlsVerificationKeyProofOfPossession; diff --git a/mithril-stm/src/protocol/single_signature/error.rs b/mithril-stm/src/protocol/single_signature/error.rs new file mode 100644 index 00000000000..8cdbad1b1c7 --- /dev/null +++ b/mithril-stm/src/protocol/single_signature/error.rs @@ -0,0 +1,15 @@ +/// Errors which can be output by Mithril single signature verification. +#[derive(Debug, Clone, thiserror::Error)] +pub enum SignatureError { + /// There is an index out of bounds + #[error("Received index, {0}, is higher than what the security parameter allows, {1}.")] + IndexBoundFailed(u64, u64), + + /// The lottery was actually lost for the signature + #[error("Lottery for this epoch was lost.")] + LotteryLost, + + /// This error occurs when the serialization of the raw bytes failed + #[error("Invalid bytes")] + SerializationError, +} diff --git a/mithril-stm/src/protocol/single_signature/mod.rs b/mithril-stm/src/protocol/single_signature/mod.rs index 43b3969c8ee..945d4b5672c 100644 --- a/mithril-stm/src/protocol/single_signature/mod.rs +++ b/mithril-stm/src/protocol/single_signature/mod.rs @@ -1,5 +1,7 @@ +mod error; mod signature; mod signature_registered_party; +pub use error::*; pub use signature::*; pub use signature_registered_party::*; diff --git a/mithril-stm/src/protocol/single_signature/signature.rs b/mithril-stm/src/protocol/single_signature/signature.rs index 57a9620ebc6..f477497ff43 100644 --- a/mithril-stm/src/protocol/single_signature/signature.rs +++ b/mithril-stm/src/protocol/single_signature/signature.rs @@ -8,10 +8,12 @@ use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; use crate::{ - AggregateVerificationKey, Index, Parameters, SignatureError, Stake, StmResult, VerificationKey, - is_lottery_won, signature_scheme::BlsSignature, + AggregateVerificationKey, Index, Parameters, Stake, StmResult, VerificationKey, is_lottery_won, + signature_scheme::BlsSignature, }; +use super::SignatureError; + /// Signature created by a single party who has won the lottery. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SingleSignature { diff --git a/mithril-stm/src/protocol/single_signature/signature_registered_party.rs b/mithril-stm/src/protocol/single_signature/signature_registered_party.rs index a72ee0d97cf..2fbc6846cfe 100644 --- a/mithril-stm/src/protocol/single_signature/signature_registered_party.rs +++ b/mithril-stm/src/protocol/single_signature/signature_registered_party.rs @@ -1,8 +1,9 @@ use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize, Serializer, ser::SerializeTuple}; -use super::SingleSignature; -use crate::{RegisteredParty, SignatureError, StmResult}; +use crate::{RegisteredParty, StmResult}; + +use super::{SignatureError, SingleSignature}; /// Signature with its registered party. #[derive(Debug, Clone, Hash, Deserialize, Eq, PartialEq, Ord, PartialOrd)] diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/error.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/error.rs index bed7e621c6f..7589d4b141d 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/error.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/error.rs @@ -2,10 +2,10 @@ use anyhow::anyhow; use blst::BLST_ERROR; -use super::{BlsSignature, BlsVerificationKey, BlsVerificationKeyProofOfPossession}; - use crate::StmResult; +use super::{BlsSignature, BlsVerificationKey, BlsVerificationKeyProofOfPossession}; + /// Error types for multi signatures. #[derive(Debug, thiserror::Error, Eq, PartialEq)] pub enum BlsSignatureError { @@ -17,7 +17,7 @@ pub enum BlsSignatureError { #[error("Invalid aggregated signature")] AggregateSignatureInvalid, - /// This error occurs when the the serialization of the raw bytes failed + /// This error occurs when the serialization of the raw bytes failed #[error("Invalid bytes")] SerializationError, diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs index 134d42fb40e..c934bf1ee7e 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs @@ -1,10 +1,11 @@ use blst::{blst_p1, min_sig::Signature as BlstSig}; +use crate::StmResult; + use super::{ BlsSignatureError, BlsSigningKey, POP, blst_error_to_stm_error, helper::unsafe_helpers::{compress_p1, scalar_to_pk_in_g1, uncompress_p1}, }; -use crate::StmResult; /// MultiSig proof of possession, which contains two elements from G1. However, /// the two elements have different types: `k1` is represented as a BlstSig diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs index b9f97e7914d..819eede9cb3 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs @@ -8,11 +8,12 @@ use blst::{ use digest::consts::U16; use std::{cmp::Ordering, iter::Sum}; +use crate::{Index, StmResult}; + use super::{ BlsSignatureError, BlsVerificationKey, blst_error_to_stm_error, helper::unsafe_helpers::{p1_affine_to_sig, p2_affine_to_vk, sig_to_p1, vk_from_p2_affine}, }; -use crate::{Index, StmResult}; /// MultiSig signature, which is a wrapper over the `BlstSig` type. #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs index 92705b5231f..607c11c182c 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs @@ -1,9 +1,10 @@ use blst::min_sig::SecretKey as BlstSk; use rand_core::{CryptoRng, RngCore}; -use super::{BlsSignature, BlsSignatureError, blst_error_to_stm_error}; use crate::StmResult; +use super::{BlsSignature, BlsSignatureError, blst_error_to_stm_error}; + /// MultiSig secret key, which is a wrapper over the BlstSk type from the blst /// library. #[derive(Debug, Clone)] diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs index 05f60260915..ebc55386e35 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs @@ -12,11 +12,12 @@ use blst::{ }; use serde::{Deserialize, Serialize}; +use crate::StmResult; + use super::{ BlsProofOfPossession, BlsSignatureError, BlsSigningKey, POP, blst_error_to_stm_error, helper::unsafe_helpers::verify_pairing, }; -use crate::StmResult; /// MultiSig verification key, which is a wrapper over the BlstVk (element in G2) /// from the blst library. diff --git a/mithril-stm/src/signature_scheme/schnorr_signature/signature.rs b/mithril-stm/src/signature_scheme/schnorr_signature/signature.rs index 6ddf3bcfba2..4a16ebe156c 100644 --- a/mithril-stm/src/signature_scheme/schnorr_signature/signature.rs +++ b/mithril-stm/src/signature_scheme/schnorr_signature/signature.rs @@ -6,11 +6,12 @@ use dusk_jubjub::{ use dusk_poseidon::{Domain, Hash}; use group::{Group, GroupEncoding}; +use crate::StmResult; + use super::{ DST_SIGNATURE, SchnorrSignatureError, SchnorrVerificationKey, get_coordinates_several_points, is_on_curve, }; -use crate::StmResult; /// Structure of the Schnorr signature to use with the SNARK /// @@ -153,11 +154,11 @@ impl SchnorrSignature { #[cfg(test)] mod tests { - - use crate::{SchnorrSignature, SchnorrSigningKey, SchnorrVerificationKey}; use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; + use crate::signature_scheme::{SchnorrSignature, SchnorrSigningKey, SchnorrVerificationKey}; + #[test] fn invalid_sig() { let msg = vec![0, 0, 0, 1]; @@ -209,7 +210,7 @@ mod tests { use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; - use crate::{SchnorrSignature, SchnorrSigningKey}; + use crate::signature_scheme::{SchnorrSignature, SchnorrSigningKey}; const GOLDEN_BYTES: &[u8; 96] = &[ 143, 53, 198, 62, 178, 1, 88, 253, 21, 92, 100, 13, 72, 180, 198, 127, 39, 175, 102, diff --git a/mithril-stm/src/signature_scheme/schnorr_signature/signing_key.rs b/mithril-stm/src/signature_scheme/schnorr_signature/signing_key.rs index ef2148f39d1..2bffc1dea70 100644 --- a/mithril-stm/src/signature_scheme/schnorr_signature/signing_key.rs +++ b/mithril-stm/src/signature_scheme/schnorr_signature/signing_key.rs @@ -7,11 +7,12 @@ use dusk_poseidon::{Domain, Hash}; use group::Group; use rand_core::{CryptoRng, RngCore}; +use crate::StmResult; + use super::{ DST_SIGNATURE, SchnorrSignature, SchnorrSignatureError, SchnorrVerificationKey, generate_non_zero_scalar, get_coordinates_several_points, }; -use crate::StmResult; /// Schnorr Signing key, it is essentially a random scalar of the Jubjub scalar field #[derive(Debug, Clone)] @@ -128,10 +129,11 @@ impl SchnorrSigningKey { #[cfg(test)] mod tests { - pub(crate) use super::*; use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; + use super::*; + #[test] fn generate_signing_key() { let mut rng = ChaCha20Rng::from_seed([0u8; 32]); @@ -191,7 +193,7 @@ mod tests { use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; - use crate::SchnorrSigningKey; + use crate::signature_scheme::SchnorrSigningKey; const GOLDEN_BYTES: &[u8; 32] = &[ 126, 191, 239, 197, 88, 151, 248, 254, 187, 143, 86, 35, 29, 62, 90, 13, 196, 71, 234, diff --git a/mithril-stm/src/signature_scheme/schnorr_signature/utils.rs b/mithril-stm/src/signature_scheme/schnorr_signature/utils.rs index 44b53f83181..606b60f1671 100644 --- a/mithril-stm/src/signature_scheme/schnorr_signature/utils.rs +++ b/mithril-stm/src/signature_scheme/schnorr_signature/utils.rs @@ -7,9 +7,10 @@ use ff::Field; use group::Curve; use rand_core::{CryptoRng, RngCore}; -use super::SchnorrSignatureError; use crate::StmResult; +use super::SchnorrSignatureError; + /// Check if the given point is on the curve using its coordinates pub fn is_on_curve(point: JubjubExtended) -> bool { let point_affine_representation = JubjubAffine::from(point); @@ -57,13 +58,13 @@ pub fn generate_non_zero_scalar(rng: &mut R) -> StmResul #[cfg(test)] mod tests { - - use super::*; use dusk_jubjub::{AffinePoint as JubjubAffine, ExtendedPoint as JubjubExtended}; use group::Group; use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; + use super::*; + #[test] fn get_coordinates_from_several_points() { let seed = [0u8; 32]; diff --git a/mithril-stm/src/signature_scheme/schnorr_signature/verification_key.rs b/mithril-stm/src/signature_scheme/schnorr_signature/verification_key.rs index a2b671fd7fc..0e1787f3f96 100644 --- a/mithril-stm/src/signature_scheme/schnorr_signature/verification_key.rs +++ b/mithril-stm/src/signature_scheme/schnorr_signature/verification_key.rs @@ -2,9 +2,10 @@ use anyhow::{Context, anyhow}; use dusk_jubjub::SubgroupPoint as JubjubSubgroup; use group::{Group, GroupEncoding}; -use super::SchnorrSignatureError; use crate::StmResult; +use super::{SchnorrSignatureError, SchnorrSigningKey}; + /// Schnorr verification key, it consists of a point on the Jubjub curve /// vk = g * sk, where g is a generator #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] @@ -38,12 +39,12 @@ impl SchnorrVerificationKey { } } -impl From<&crate::SchnorrSigningKey> for SchnorrVerificationKey { +impl From<&SchnorrSigningKey> for SchnorrVerificationKey { /// Convert a Schnorr secret key into a verification key /// /// This is done by computing `vk = g * sk` where g is the generator /// of the subgroup and sk is the schnorr secret key - fn from(signing_key: &crate::SchnorrSigningKey) -> Self { + fn from(signing_key: &SchnorrSigningKey) -> Self { let generator = JubjubSubgroup::generator(); SchnorrVerificationKey(generator * signing_key.0) @@ -52,7 +53,6 @@ impl From<&crate::SchnorrSigningKey> for SchnorrVerificationKey { #[cfg(test)] mod tests { - use dusk_jubjub::Fq as JubjubBase; use dusk_jubjub::SubgroupPoint as JubjubSubgroup; use ff::Field; From b0c9d5ce3c0aae8e1a5e324787a2416055ac19f2 Mon Sep 17 00:00:00 2001 From: Dam Date: Thu, 11 Dec 2025 12:21:32 +0100 Subject: [PATCH 4/5] Finished fixing import format and bls error exposure --- mithril-stm/Cargo.toml | 2 +- .../src/membership_commitment/merkle_tree/commitment.rs | 3 ++- mithril-stm/src/membership_commitment/merkle_tree/path.rs | 3 ++- mithril-stm/src/membership_commitment/merkle_tree/tree.rs | 3 ++- mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs | 3 ++- mithril-stm/src/protocol/aggregate_signature/error.rs | 2 +- .../src/signature_scheme/bls_multi_signature/signature.rs | 3 ++- .../signature_scheme/bls_multi_signature/verification_key.rs | 3 ++- 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mithril-stm/Cargo.toml b/mithril-stm/Cargo.toml index bdfd9d7f092..4b1647bd0be 100644 --- a/mithril-stm/Cargo.toml +++ b/mithril-stm/Cargo.toml @@ -17,7 +17,7 @@ crate-type = ["lib", "cdylib", "staticlib"] default = ["rug-backend"] rug-backend = ["rug/default"] num-integer-backend = ["dep:num-bigint", "dep:num-rational", "dep:num-traits"] -benchmark-internals = [] # For benchmarking multi_sig +benchmark-internals = [] # For benchmarking future_snark = [ "dep:ff", "dep:group", diff --git a/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs b/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs index de029ea61b5..845f8c2289e 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs @@ -1,7 +1,8 @@ +use std::marker::PhantomData; + use anyhow::{Context, anyhow}; use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; -use std::marker::PhantomData; use crate::StmResult; diff --git a/mithril-stm/src/membership_commitment/merkle_tree/path.rs b/mithril-stm/src/membership_commitment/merkle_tree/path.rs index 1661beb03a3..5d38ef97837 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/path.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/path.rs @@ -1,6 +1,7 @@ +use std::marker::PhantomData; + use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; -use std::marker::PhantomData; use crate::StmResult; diff --git a/mithril-stm/src/membership_commitment/merkle_tree/tree.rs b/mithril-stm/src/membership_commitment/merkle_tree/tree.rs index a36716ad3d6..01c3b3b07f7 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/tree.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/tree.rs @@ -1,6 +1,7 @@ +use std::marker::PhantomData; + use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; -use std::marker::PhantomData; use crate::StmResult; diff --git a/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs b/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs index 1b757e31f89..0b14021123d 100644 --- a/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs +++ b/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs @@ -1,6 +1,7 @@ -use anyhow::{Context, anyhow}; use std::collections::{BTreeMap, HashMap, HashSet}; +use anyhow::{Context, anyhow}; + use crate::{ Index, Parameters, RegisteredParty, SingleSignature, SingleSignatureWithRegisteredParty, Stake, StmResult, diff --git a/mithril-stm/src/protocol/aggregate_signature/error.rs b/mithril-stm/src/protocol/aggregate_signature/error.rs index 0888b7ddc2e..dc7d561f759 100644 --- a/mithril-stm/src/protocol/aggregate_signature/error.rs +++ b/mithril-stm/src/protocol/aggregate_signature/error.rs @@ -1,4 +1,4 @@ -use crate::AggregateSignatureType; +use super::AggregateSignatureType; /// Error types for aggregation. #[derive(Debug, Clone, thiserror::Error)] diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs index 819eede9cb3..2177af094e0 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs @@ -1,3 +1,5 @@ +use std::{cmp::Ordering, iter::Sum}; + use anyhow::{Context, anyhow}; use blake2::{Blake2b, Blake2b512, Digest}; use blst::{ @@ -6,7 +8,6 @@ use blst::{ p1_affines, p2_affines, }; use digest::consts::U16; -use std::{cmp::Ordering, iter::Sum}; use crate::{Index, StmResult}; diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs index ebc55386e35..492be1748f8 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs @@ -1,4 +1,3 @@ -use anyhow::anyhow; use std::{ cmp::Ordering, fmt::{Display, Formatter}, @@ -6,6 +5,8 @@ use std::{ iter::Sum, }; +use anyhow::anyhow; + use blst::{ BLST_ERROR, min_sig::{AggregatePublicKey, PublicKey as BlstVk}, From c0cbd4b023fed1e2e477b93ccdc335bd68c9fc05 Mon Sep 17 00:00:00 2001 From: Dam Date: Fri, 12 Dec 2025 10:12:34 +0100 Subject: [PATCH 5/5] Update version and CHANGELOG --- Cargo.lock | 4 ++-- mithril-common/Cargo.toml | 2 +- mithril-stm/CHANGELOG.md | 6 ++++++ mithril-stm/Cargo.toml | 2 +- .../bls_multi_signature/verification_key.rs | 1 - 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 331f80a7454..f9df08d9396 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4016,7 +4016,7 @@ dependencies = [ [[package]] name = "mithril-common" -version = "0.6.35" +version = "0.6.37" dependencies = [ "anyhow", "async-trait", @@ -4294,7 +4294,7 @@ dependencies = [ [[package]] name = "mithril-stm" -version = "0.6.3" +version = "0.6.4" dependencies = [ "anyhow", "blake2 0.10.6", diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 7c088aedd1a..1c0cfcf0e5c 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-common" -version = "0.6.35" +version = "0.6.37" description = "Common types, interfaces, and utilities for Mithril nodes." authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-stm/CHANGELOG.md b/mithril-stm/CHANGELOG.md index f3aa3bcf4eb..642fc4e5893 100644 --- a/mithril-stm/CHANGELOG.md +++ b/mithril-stm/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.6.4 (12-12-2025) + +### Changed + +- Error types in the Stm library moved to corresponding sub-modules. + ## 0.6.2 (11-27-2025) ### Changed diff --git a/mithril-stm/Cargo.toml b/mithril-stm/Cargo.toml index 4b1647bd0be..a7d22bcb28a 100644 --- a/mithril-stm/Cargo.toml +++ b/mithril-stm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-stm" -version = "0.6.3" +version = "0.6.4" edition = { workspace = true } authors = { workspace = true } homepage = { workspace = true } diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs index 492be1748f8..73ec370f8a5 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs @@ -6,7 +6,6 @@ use std::{ }; use anyhow::anyhow; - use blst::{ BLST_ERROR, min_sig::{AggregatePublicKey, PublicKey as BlstVk},