Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
10 changes: 5 additions & 5 deletions mithril-common/src/protocol/multi_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl MultiSigner {

#[cfg(test)]
mod test {
use mithril_stm::MultiSignatureError;
use mithril_stm::BlsSignatureError;

use crate::{
crypto_helper::ProtocolAggregationError,
Expand Down Expand Up @@ -195,8 +195,8 @@ mod test {
"Verify single signature should fail if the signer isn't in the registered parties",
);

match error.downcast_ref::<MultiSignatureError>() {
Some(MultiSignatureError::SignatureInvalid(_)) => (),
match error.downcast_ref::<BlsSignatureError>() {
Some(BlsSignatureError::SignatureInvalid(_)) => (),
_ => panic!("Expected an SignatureInvalid error, got: {error:?}"),
}
}
Expand All @@ -221,8 +221,8 @@ mod test {
.verify_single_signature(&ProtocolMessage::default(), &single_signature)
.expect_err("Verify single signature should fail");

match error.downcast_ref::<MultiSignatureError>() {
Some(MultiSignatureError::SignatureInvalid(_)) => (),
match error.downcast_ref::<BlsSignatureError>() {
Some(BlsSignatureError::SignatureInvalid(_)) => (),
_ => panic!("Expected an SignatureInvalid error, got: {error:?}"),
}
}
Expand Down
6 changes: 6 additions & 0 deletions mithril-stm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions mithril-stm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
Expand All @@ -17,8 +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
future_proof_system = [] # For activating future proof systems
benchmark-internals = [] # For benchmarking
future_snark = [
"dep:ff",
"dep:group",
Expand Down Expand Up @@ -73,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"
Expand Down
1 change: 1 addition & 0 deletions mithril-stm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::marker::PhantomData;

use anyhow::{Context, anyhow};
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 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.
Expand Down
15 changes: 15 additions & 0 deletions mithril-stm/src/membership_commitment/merkle_tree/error.rs
Original file line number Diff line number Diff line change
@@ -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<u8>),

/// Invalid merkle batch path
#[error("Batch path does not verify against root")]
BatchPathInvalid(Vec<u8>),
}
6 changes: 3 additions & 3 deletions mithril-stm/src/membership_commitment/merkle_tree/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::cmp::Ordering;

use serde::{Deserialize, Serialize};

use crate::{
MerkleTreeError, Stake, StmResult, VerificationKey, signature_scheme::BlsVerificationKey,
};
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.
Expand Down
2 changes: 2 additions & 0 deletions mithril-stm/src/membership_commitment/merkle_tree/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
7 changes: 5 additions & 2 deletions mithril-stm/src/membership_commitment/merkle_tree/path.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use std::marker::PhantomData;

use blake2::digest::{Digest, FixedOutput};
use serde::{Deserialize, Serialize};
use std::marker::PhantomData;

use crate::{MerkleTreeError, StmResult};
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.
Expand Down
10 changes: 6 additions & 4 deletions mithril-stm/src/membership_commitment/merkle_tree/tree.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::marker::PhantomData;

use blake2::digest::{Digest, FixedOutput};
use serde::{Deserialize, Serialize};
use std::marker::PhantomData;

use crate::StmResult;

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};

/// Tree of hashes, providing a commitment of data and its ordering.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use anyhow::{Context, anyhow};
use std::collections::{BTreeMap, HashMap, HashSet};

use anyhow::{Context, anyhow};

use crate::{
AggregationError, Index, Parameters, RegisteredParty, SingleSignature,
SingleSignatureWithRegisteredParty, Stake, StmResult,
Index, Parameters, RegisteredParty, SingleSignature, SingleSignatureWithRegisteredParty, Stake,
StmResult,
membership_commitment::MerkleTreeLeaf,
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.
Expand Down
11 changes: 6 additions & 5 deletions mithril-stm/src/protocol/aggregate_signature/clerk.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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")]
use crate::AggregationError;
#[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.
Expand Down Expand Up @@ -89,7 +90,7 @@ impl<D: Digest + Clone + FixedOutput + Send + Sync> Clerk<D> {
)
})?,
)),
#[cfg(feature = "future_proof_system")]
#[cfg(feature = "future_snark")]
AggregateSignatureType::Future => Err(anyhow!(
AggregationError::UnsupportedProofSystem(aggregate_signature_type)
)),
Expand Down
32 changes: 32 additions & 0 deletions mithril-stm/src/protocol/aggregate_signature/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use super::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 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),
}
9 changes: 7 additions & 2 deletions mithril-stm/src/protocol/aggregate_signature/mod.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -20,13 +22,16 @@ mod tests {
use rand_core::{RngCore, SeedableRng};
use std::collections::{HashMap, HashSet};

use super::{AggregateSignature, AggregateSignatureType, BasicVerifier, Clerk};
use crate::{
AggregationError, Initializer, KeyRegistration, Parameters, Signer, SingleSignature,
Initializer, KeyRegistration, Parameters, Signer, SingleSignature,
SingleSignatureWithRegisteredParty, Stake, StmResult,
membership_commitment::MerkleBatchPath, signature_scheme::BlsVerificationKey,
};

use super::{
AggregateSignature, AggregateSignatureType, AggregationError, BasicVerifier, Clerk,
};

type Sig = AggregateSignature<D>;
type D = Blake2b<U32>;

Expand Down
Loading
Loading