Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
414e5f4
Added file structure for Schnorr signature module.
damrobi Nov 3, 2025
88e68a5
Added to/from bytes for SchnorrSignature and started adding tests.
damrobi Nov 4, 2025
ab69338
Moved test out of proptest.
damrobi Nov 4, 2025
92128de
Added more test and helper function to convert msg to base field.
damrobi Nov 4, 2025
fb67ed4
applied clippy.
damrobi Nov 4, 2025
63781df
Cargo.lock change.
damrobi Nov 5, 2025
cbfe509
Update msg to base field conversion.
damrobi Nov 5, 2025
4555a3f
Add to and from bytes for SchnorrSignature.
damrobi Nov 5, 2025
7827393
Removed prototype implementation of schnorr signature and started new…
damrobi Nov 6, 2025
aae4b05
Added generate function for Schnorr signature.
damrobi Nov 6, 2025
f190460
Added conversion from sk to vk for use in signature.
damrobi Nov 6, 2025
09f84ee
Added helper function for converting a message to jubjub base field.
damrobi Nov 6, 2025
6fd5f71
Added sign function for SchnorrSigningKey and necessary helper functi…
damrobi Nov 6, 2025
0f6796e
Added test function for get_coordinates and fix the sign function.
damrobi Nov 6, 2025
e8af769
Added verification function and tests to signature.
damrobi Nov 6, 2025
0450883
Removed unused dependency.
damrobi Nov 6, 2025
56fa186
Added DST to signature and removed unwraps.
damrobi Nov 7, 2025
bf7d58e
Added conversion function for scalar from BLS12 to Jubjub.
damrobi Nov 7, 2025
12b66f9
Added wip to and from bytes for Schnorr signing key.
damrobi Nov 7, 2025
8408d98
Added comments and derive for main structs.
damrobi Nov 7, 2025
452bed3
Added eval_dense_mapping function to signature.
damrobi Nov 7, 2025
bb72c9a
Took comment into account and started to add signature comment descri…
damrobi Nov 10, 2025
634ed74
Added description for Schnorr sign and verify.
damrobi Nov 11, 2025
6f48d60
Added to and from bytes for verification key and signature.
damrobi Nov 11, 2025
041fcd2
Changing the variables name and the dependency depending on the futur…
damrobi Nov 12, 2025
d0f2be0
Added utils module for utility functions.
damrobi Nov 12, 2025
d81a663
Small modifications based on JP feedback.
damrobi Nov 12, 2025
4e646a2
Modifications according to reviews.
damrobi Nov 13, 2025
ac6ca3d
Finished changing variables name.
damrobi Nov 13, 2025
09f6c4c
Added crates for jubjub and poseidon to try to replace midnight while…
damrobi Nov 14, 2025
8bf9e12
Change to dusk jubjub dependency.
damrobi Nov 14, 2025
0b12f01
Modify last variable names and removed evaluate_dense_mapping functio…
damrobi Nov 18, 2025
b47dfad
fmt and clippy.
damrobi Nov 18, 2025
8d782a3
Correction on variable names and started adding bench for schnorr_sig…
damrobi Nov 19, 2025
3b3a158
Changed bench values.
damrobi Nov 19, 2025
635b241
Added new schnorr error and better error handling for schnorr signatu…
damrobi Nov 20, 2025
67c12e2
modified comments for public functions.
damrobi Nov 20, 2025
a6e0aaf
Modified from_bytes for schnorr signature.
damrobi Nov 20, 2025
f0a0632
Changed utility function to get coordinates.
damrobi Nov 20, 2025
1c0a563
Added verification key error and check.
damrobi Nov 21, 2025
b5f647f
added error checks and test for new errors.
damrobi Nov 21, 2025
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
156 changes: 154 additions & 2 deletions Cargo.lock

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

17 changes: 17 additions & 0 deletions mithril-stm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ rug-backend = ["rug/default"]
num-integer-backend = ["num-bigint", "num-rational", "num-traits"]
benchmark-internals = [] # For benchmarking multi_sig
future_proof_system = [] # For activating future proof systems
future_snark = [
"ff",
"group",
"num-traits",
"dusk-poseidon",
"dusk-jubjub",
] # For activating snark features

[dependencies]
anyhow = { workspace = true }
blake2 = "0.10.6"
# Enforce blst portable feature for runtime detection of Intel ADX instruction set.
blst = { version = "0.3.16", features = ["portable"] }
digest = { workspace = true }
dusk-jubjub = { version = "0.15.1", optional = true }
dusk-poseidon = { version = "0.41.0", optional = true }
ff = { version = "0.13.1", optional = true }
group = { version = "0.13.0", optional = true }
num-traits = { version = "0.2.19", optional = true }
rand_core = { workspace = true }
rayon = { workspace = true }
serde = { workspace = true }
Expand Down Expand Up @@ -58,6 +70,11 @@ name = "multi_sig"
harness = false
required-features = ["benchmark-internals"]

[[bench]]
name = "schnorr_sig"
harness = false
required-features = ["future_snark"]

[[bench]]
name = "stm"
harness = false
Expand Down
41 changes: 41 additions & 0 deletions mithril-stm/benches/schnorr_sig.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use mithril_stm::{SchnorrSigningKey, SchnorrVerificationKey};
use rand_chacha::ChaCha20Rng;
use rand_core::{RngCore, SeedableRng};

fn sign_and_verify(c: &mut Criterion, nr_sigs: usize) {
let mut group = c.benchmark_group("Schnorr".to_string());
let mut rng = ChaCha20Rng::from_seed([0u8; 32]);
let mut rng_sig = ChaCha20Rng::from_seed([1u8; 32]);

let mut msg = [0u8; 32];
rng.fill_bytes(&mut msg);
let mut mvks = Vec::new();
let mut sigs = Vec::new();
for _ in 0..nr_sigs {
let sk = SchnorrSigningKey::generate(&mut rng);
let vk = SchnorrVerificationKey::from(&sk);
let sig = sk.sign(&msg, &mut rng_sig).unwrap();
sigs.push(sig);
mvks.push(vk);
}

group.bench_function(BenchmarkId::new("Individual verif", nr_sigs), |b| {
b.iter(|| {
for (vk, sig) in mvks.iter().zip(sigs.iter()) {
assert!(sig.verify(&msg, vk).is_ok());
}
})
});
}

fn schnorr_benches(c: &mut Criterion) {
sign_and_verify(c, 856);
}

criterion_group!(name = benches;
config = Criterion::default().nresamples(1000);
targets =
schnorr_benches
);
criterion_main!(benches);
19 changes: 19 additions & 0 deletions mithril-stm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::aggregate_signature::AggregateSignatureType;
use crate::bls_multi_signature::{
BlsSignature, BlsVerificationKey, BlsVerificationKeyProofOfPossession,
};
#[cfg(feature = "future_snark")]
use crate::{SchnorrSignature, SchnorrVerificationKey};

/// Error types for multi signatures.
#[derive(Debug, thiserror::Error, Eq, PartialEq)]
Expand Down Expand Up @@ -40,6 +42,23 @@ pub enum MultiSignatureError {
VerificationKeyInfinity(Box<BlsVerificationKey>),
}

/// Error types for Schnorr signatures.
#[cfg(feature = "future_snark")]
#[derive(Debug, thiserror::Error, Eq, PartialEq)]
pub enum SchnorrSignatureError {
/// Invalid Single signature
#[error("Invalid Schnorr single signature")]
SignatureInvalid(Box<SchnorrSignature>),

/// Invalid Verification key
#[error("Invalid Schnorr Verification key")]
VerificationKeyInvalid(Box<SchnorrVerificationKey>),

/// This error occurs when the the serialization of the raw bytes failed
#[error("Invalid bytes")]
SerializationError,
}

/// Error types related to merkle trees.
#[derive(Debug, Clone, thiserror::Error)]
pub enum MerkleTreeError {
Expand Down
5 changes: 5 additions & 0 deletions mithril-stm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ mod key_registration;
mod merkle_tree;
mod parameters;
mod participant;
#[cfg(feature = "future_snark")]
mod schnorr_signature;
mod single_signature;

pub use aggregate_signature::{
Expand All @@ -138,6 +140,9 @@ pub use bls_multi_signature::{
BlsVerificationKeyProofOfPossession,
};

#[cfg(feature = "future_snark")]
pub use schnorr_signature::{SchnorrSignature, SchnorrSigningKey, SchnorrVerificationKey};

/// The quantity of stake held by a party, represented as a `u64`.
pub type Stake = u64;

Expand Down
Loading