Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
edf21ec
Adding test_utils as common.rs
SimonRastikian Nov 11, 2025
ac58781
adding common in dkg
SimonRastikian Nov 11, 2025
f8966a2
Pushing function ecdsa_generate_rerandpresig_args to common.rs
SimonRastikian Nov 11, 2025
d35d317
Isolating MockCryptoRnG
SimonRastikian Nov 11, 2025
11db1da
Adding the run protocol file
SimonRastikian Nov 11, 2025
5bcd605
Separating DKG
SimonRastikian Nov 11, 2025
47f4fed
test_utils/sign.rs
SimonRastikian Nov 11, 2025
fab6283
Presign for robust ECDSA
SimonRastikian Nov 11, 2025
a685499
integrating ecdsa rerandomized args in more test cases
SimonRastikian Nov 11, 2025
63c02be
Switching function calls to test_utils/participants.rs
SimonRastikian Nov 11, 2025
4bee396
cargo fmt and clippy
SimonRastikian Nov 11, 2025
f7a34c0
Snapshotting all
SimonRastikian Nov 11, 2025
3720e8f
Cargo fmt
SimonRastikian Nov 11, 2025
e3d3e15
Handling comments
SimonRastikian Nov 20, 2025
09ad1ef
patch
SimonRastikian Nov 20, 2025
56654e3
cargo fmt
SimonRastikian Nov 20, 2025
05af30a
Merge branch 'simon/test_utils_folder' into simon/snapshots
SimonRastikian Nov 20, 2025
0433f71
Deleting useless tests
SimonRastikian Nov 20, 2025
fbecd8c
Moving the line
SimonRastikian Nov 20, 2025
344b0b1
renamping mpc_interface to test_generators
SimonRastikian Nov 20, 2025
d15c9e1
cargo fmt
SimonRastikian Nov 20, 2025
10cad9a
cargo fmt
SimonRastikian Nov 20, 2025
5190b81
Merge branch 'simon/test_utils_folder' into simon/snapshots
SimonRastikian Nov 20, 2025
c1127b9
clippy
SimonRastikian Nov 20, 2025
948ab62
Solving conflict
SimonRastikian Nov 20, 2025
0ea5e3e
deriving default
SimonRastikian Nov 21, 2025
9fbb034
Create rngs
SimonRastikian Nov 21, 2025
a2ddf02
cargo fmt
SimonRastikian Nov 21, 2025
8c45ad0
no deadcode
SimonRastikian Nov 21, 2025
da21da3
cargo fmt
SimonRastikian Nov 21, 2025
3ad84b2
Eq, PartialEq derived
SimonRastikian Nov 21, 2025
8a7b1e4
fmt and mistake
SimonRastikian 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
18 changes: 13 additions & 5 deletions benches/naive_ot_based_ecdsa.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
mod utils;

use criterion::{criterion_group, Criterion};
use frost_secp256k1::{Secp256K1Sha256, VerifyingKey};
use rand::Rng;
use rand_core::OsRng;
use utils::ecdsa_generate_rerandpresig_args;

use threshold_signatures::{
ecdsa::{
Expand All @@ -18,10 +15,21 @@ use threshold_signatures::{
},
participants::Participant,
protocol::Protocol,
test_utils::{generate_participants_with_random_ids, run_keygen, run_protocol},
test_utils::{
ecdsa_generate_rerandpresig_args, generate_participants_with_random_ids, run_keygen,
run_protocol,
},
};

use utils::MAX_MALICIOUS;
use std::{env, sync::LazyLock};

// fix malicious number of participants
pub static MAX_MALICIOUS: LazyLock<usize> = std::sync::LazyLock::new(|| {
env::var("MAX_MALICIOUS")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(6)
});

fn threshold() -> usize {
*crate::MAX_MALICIOUS + 1
Expand Down
17 changes: 13 additions & 4 deletions benches/naive_robust_ecdsa.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod utils;
use criterion::{criterion_group, Criterion};
use frost_secp256k1::{Secp256K1Sha256, VerifyingKey};
use rand::Rng;
use rand_core::OsRng;
use utils::ecdsa_generate_rerandpresig_args;

use threshold_signatures::{
ecdsa::{
Expand All @@ -15,10 +13,21 @@ use threshold_signatures::{
},
participants::Participant,
protocol::Protocol,
test_utils::{generate_participants_with_random_ids, run_keygen, run_protocol},
test_utils::{
ecdsa_generate_rerandpresig_args, generate_participants_with_random_ids, run_keygen,
run_protocol,
},
};

use utils::MAX_MALICIOUS;
use std::{env, sync::LazyLock};

// fix malicious number of participants
pub static MAX_MALICIOUS: LazyLock<usize> = std::sync::LazyLock::new(|| {
env::var("MAX_MALICIOUS")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(6)
});

fn participants_num() -> usize {
2 * *crate::MAX_MALICIOUS + 1
Expand Down
47 changes: 0 additions & 47 deletions benches/utils/mod.rs

This file was deleted.

16 changes: 5 additions & 11 deletions src/confidential_key_derivation/ciphersuite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,16 @@ impl FromOkm for ScalarWrapper {
mod tests {
use blstrs::Scalar;
use digest::generic_array::GenericArray;
use elliptic_curve::hash2curve::FromOkm;
use elliptic_curve::Field;
use elliptic_curve::Group;
use rand::Rng;
use rand::RngCore;
use elliptic_curve::{hash2curve::FromOkm, Field, Group};
use rand::{Rng, RngCore};
use rand_core::OsRng;

use crate::confidential_key_derivation::ciphersuite::verify_signature;
use crate::confidential_key_derivation::ciphersuite::ScalarWrapper;
use crate::confidential_key_derivation::VerifyingKey;
use crate::{
confidential_key_derivation::{
ciphersuite::{hash_to_curve, BLS12381SHA256},
ElementG2,
ciphersuite::{hash_to_curve, verify_signature, ScalarWrapper, BLS12381SHA256},
ElementG2, VerifyingKey,
},
test_utils::check_common_traits_for_type,
test_utils::mpc_interface::check_common_traits_for_type,
};

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/confidential_key_derivation/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn compute_signature_share(
mod test {
use super::*;
use crate::confidential_key_derivation::ciphersuite::hash_to_curve;
use crate::test_utils::{one_coordinator_output, run_protocol, GenProtocol};
use crate::test_utils::{check_one_coordinator_output, run_protocol, GenProtocol};
use rand::Rng;

#[test]
Expand Down Expand Up @@ -240,7 +240,7 @@ mod test {
let result = run_protocol(protocols).unwrap();

// test one single some for the coordinator
let ckd = one_coordinator_output(result, coordinator).unwrap();
let ckd = check_one_coordinator_output(result, coordinator).unwrap();

// compute msk . H(app_id)
let confidential_key = ckd.unmask(app_sk);
Expand Down
5 changes: 3 additions & 2 deletions src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,9 @@ pub mod test {
use super::domain_separate_hash;
use crate::crypto::ciphersuite::Ciphersuite;
use crate::participants::{Participant, ParticipantList};
use crate::test_utils::generate_participants;
use crate::test_utils::{assert_public_key_invariant, run_keygen, run_refresh, run_reshare};
use crate::test_utils::{
assert_public_key_invariant, generate_participants, run_keygen, run_refresh, run_reshare,
};
use frost_core::{Field, Group};

#[test]
Expand Down
28 changes: 11 additions & 17 deletions src/ecdsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,17 @@ mod test {
},
participants::ParticipantList,
test_utils::{
generate_participants, generate_participants_with_random_ids, random_32_bytes,
MockCryptoRng,
ecdsa_generate_rerandpresig_args, generate_participants,
generate_participants_with_random_ids, MockCryptoRng,
},
};

use elliptic_curve::ops::{Invert, LinearCombination, Reduce};

use frost_core::{
keys::SigningShare, Ciphersuite, SigningKey as FrostSigningKey,
VerifyingKey as FrostVerifyingKey,
};
use frost_core::{keys::SigningShare, Ciphersuite, SigningKey as FrostSigningKey};

use k256::{
ecdsa::{signature::Verifier, SigningKey, VerifyingKey},
ecdsa::{signature::Verifier, SigningKey},
ProjectivePoint, Secp256k1,
};
use rand_core::{CryptoRngCore, OsRng, RngCore};
Expand All @@ -217,7 +214,7 @@ mod test {
hasher.update(msg);

let sk = SigningKey::random(&mut OsRng);
let pk = VerifyingKey::from(&sk);
let pk = ecdsa::VerifyingKey::from(&sk);
let (sig, _) = sk.sign_digest_recoverable(hasher.clone()).unwrap();
assert!(pk.verify(msg, &sig).is_ok());

Expand Down Expand Up @@ -250,7 +247,7 @@ mod test {

let keygen_output = KeygenOutput {
private_share: SigningShare::<C>::new(Scalar::ONE),
public_key: FrostVerifyingKey::<C>::from(signing_key),
public_key: frost_core::VerifyingKey::<C>::from(signing_key),
};

// When
Expand All @@ -269,19 +266,16 @@ mod test {
rng: &mut impl CryptoRngCore,
num_participants: usize,
) -> (RerandomizationArguments, Scalar) {
let sk = SigningKey::random(&mut OsRng);
let pk = *VerifyingKey::from(sk).as_affine();
let tweak = Tweak::new(frost_core::random_nonzero::<Secp256K1Sha256, _>(&mut OsRng));
let (_, big_r) = <C>::generate_nonce(&mut OsRng);
let (_, pk) = <C>::generate_nonce(&mut OsRng);
let pk = frost_core::VerifyingKey::new(pk);
let big_r = big_r.to_affine();

let msg_hash = random_32_bytes(rng);
let entropy = random_32_bytes(rng);
// Generate unique ten ParticipantId values
let participants = generate_participants_with_random_ids(num_participants, rng);
let participants = ParticipantList::new(&participants).unwrap();
// Generate Rerandomization arguments
let (args, _) = ecdsa_generate_rerandpresig_args(rng, &participants, pk, big_r);

let args = RerandomizationArguments::new(pk, tweak, msg_hash, big_r, participants, entropy);
let delta = args.derive_randomness().unwrap();
(args, delta)
}
Expand Down Expand Up @@ -315,7 +309,7 @@ mod test {
let mut rng = OsRng;
let (mut args, delta) = compute_random_outputs(&mut rng, num_participants);
// different msg_hash
args.msg_hash = random_32_bytes(&mut rng);
args.msg_hash = [0; 32];
let delta_prime = args.derive_randomness().unwrap();
assert_ne!(delta, delta_prime);
}
Expand Down
3 changes: 2 additions & 1 deletion src/ecdsa/ot_based_ecdsa/presign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ async fn do_presign(
#[cfg(test)]
mod test {
use super::*;
use crate::test_utils::{run_protocol, GenProtocol};
use crate::{
ecdsa::{ot_based_ecdsa::triples::test::deal, KeygenOutput, Polynomial, ProjectivePoint},
test_utils::{generate_participants, run_protocol, GenProtocol},
test_utils::generate_participants,
};
use frost_secp256k1::{
keys::{PublicKeyPackage, SigningShare},
Expand Down
30 changes: 13 additions & 17 deletions src/ecdsa/ot_based_ecdsa/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@ use super::{
presign::presign,
sign::sign,
triples::{generate_triple_many, test::deal, TriplePub, TripleShare},
PresignArguments, PresignOutput,
PresignArguments, PresignOutput, RerandomizedPresignOutput,
};
use crate::participants::Participant;
use crate::protocol::Protocol;
use crate::test_utils::{
assert_public_key_invariant, generate_participants, generate_participants_with_random_ids,
one_coordinator_output, run_keygen, run_protocol, run_refresh, run_reshare, run_sign,
assert_public_key_invariant, check_one_coordinator_output, generate_participants,
generate_participants_with_random_ids, run_keygen, run_protocol, run_refresh, run_reshare,
run_sign, GenOutput, GenProtocol,
};
use crate::{
crypto::hash::test::scalar_hash_secp256k1, ecdsa::ot_based_ecdsa::RerandomizedPresignOutput,
};
use crate::{
ecdsa::{
Element, ParticipantList, RerandomizationArguments, Secp256K1Sha256, Signature,
SignatureOption, Tweak,
},
test_utils::{GenOutput, GenProtocol},

use crate::crypto::hash::test::scalar_hash_secp256k1;
use crate::ecdsa::{
Element, ParticipantList, RerandomizationArguments, Secp256K1Sha256, Signature,
SignatureOption, Tweak,
};

use rand::rngs::OsRng;
use rand::Rng;
use rand::{rngs::OsRng, Rng};
use rand_core::RngCore;
use std::error::Error;

Expand Down Expand Up @@ -62,7 +58,7 @@ pub fn run_sign_without_rerandomization(
)
.unwrap();
// test one single some for the coordinator
let signature = one_coordinator_output(result, coordinator).unwrap();
let signature = check_one_coordinator_output(result, coordinator).unwrap();
(coordinator, signature)
}

Expand Down Expand Up @@ -111,7 +107,7 @@ pub fn run_sign_with_rerandomization(
let coordinator = participants_presign[index].0;

// run sign instanciation with the necessary arguments
let result = crate::test_utils::run_sign::<Secp256K1Sha256, _, _, _>(
let result = run_sign::<Secp256K1Sha256, _, _, _>(
rerand_participants_presign,
coordinator,
derived_pk,
Expand All @@ -124,7 +120,7 @@ pub fn run_sign_with_rerandomization(
)?;

// test one single some for the coordinator
let signature = one_coordinator_output(result, coordinator)?;
let signature = check_one_coordinator_output(result, coordinator)?;
Ok((tweak, coordinator, signature))
}

Expand Down
3 changes: 1 addition & 2 deletions src/ecdsa/ot_based_ecdsa/triples/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,7 @@ mod test {

use crate::{
ecdsa::{ot_based_ecdsa::triples::generate_triple, ProjectivePoint},
participants::Participant,
participants::ParticipantList,
participants::{Participant, ParticipantList},
protocol::Protocol,
test_utils::{generate_participants, run_protocol},
};
Expand Down
14 changes: 3 additions & 11 deletions src/ecdsa/robust_ecdsa/presign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,11 @@ impl Shares {
#[cfg(test)]
mod test {
use super::*;
use rand_core::OsRng;

use crate::ecdsa::KeygenOutput;
use crate::test_utils::{generate_participants, run_protocol, GenProtocol};
use frost_secp256k1::keys::PublicKeyPackage;
use frost_secp256k1::VerifyingKey;

use k256::ProjectivePoint;
use std::collections::BTreeMap;
use rand_core::OsRng;

#[test]
fn test_presign() {
Expand All @@ -380,10 +376,9 @@ mod test {
// simulating the key packages for each participant
let private_share = f.eval_at_participant(*p).unwrap();
let verifying_key = VerifyingKey::new(big_x);
let public_key_package = PublicKeyPackage::new(BTreeMap::new(), verifying_key);
let keygen_out = KeygenOutput {
private_share: SigningShare::new(private_share.0),
public_key: *public_key_package.verifying_key(),
public_key: verifying_key,
};

let protocol = presign(
Expand All @@ -403,9 +398,6 @@ mod test {

assert!(result.len() == 5);
// testing that big_r is the same accross participants
assert_eq!(result[0].1.big_r, result[1].1.big_r);
assert_eq!(result[1].1.big_r, result[2].1.big_r);
assert_eq!(result[2].1.big_r, result[3].1.big_r);
assert_eq!(result[3].1.big_r, result[4].1.big_r);
assert!(result.windows(2).all(|w| w[0].1.big_r == w[1].1.big_r));
}
}
3 changes: 0 additions & 3 deletions src/ecdsa/robust_ecdsa/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,6 @@ mod test {

#[test]
fn test_sign_fails_if_s_is_zero() {
use crate::ecdsa::{ProjectivePoint, Secp256K1ScalarField};
use crate::test_utils::generate_participants;

let participants = generate_participants(2);

// presignatures with s_me = 0 for each participant
Expand Down
Loading