Skip to content
Open
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
18 changes: 17 additions & 1 deletion crates/threshold-signatures/src/frost/eddsa/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::{
sign::{sign_v1, sign_v2},
KeygenOutput, PresignOutput, SignatureOption,
},
test_utils::{generate_participants, run_protocol, GenProtocol, MockCryptoRng},
test_utils::{
assert_frost_presignatures_well_formed, generate_participants, run_protocol, GenProtocol,
MockCryptoRng,
},
Participant, ReconstructionLowerBound,
};

Expand Down Expand Up @@ -113,6 +116,19 @@ pub fn run_sign_v2(
Ok(run_protocol(protocols)?)
}

#[test]
fn check_presignatures_terms() {
let mut rng = MockCryptoRng::seed_from_u64(42);
let participants = generate_participants(5);
let threshold = 4;
let actual_signers = 4;

let keys = crate::dkg::test::test_keygen::<C, _>(&participants, threshold, &mut rng);
let presignatures = run_presign(&keys, threshold, actual_signers, rng).unwrap();

assert_frost_presignatures_well_formed(&presignatures);
}

#[test]
#[allow(non_snake_case)]
fn keygen_output__should_be_serializable() {
Expand Down
25 changes: 5 additions & 20 deletions crates/threshold-signatures/src/frost/redjubjub/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::{
};

use crate::test_utils::{
assert_public_key_invariant, build_frost_key_packages_with_dealer, generate_participants,
assert_frost_presignatures_well_formed, assert_public_key_invariant,
build_frost_key_packages_with_dealer, generate_participants,
generate_participants_with_random_ids, one_coordinator_output, run_keygen, run_protocol,
run_refresh, run_reshare, GenProtocol, MockCryptoRng,
};
Expand Down Expand Up @@ -297,17 +298,10 @@ fn check_presignatures_terms() {
let actual_signers = 10;

let key_packages = build_frost_key_packages_with_dealer(max_signers, threshold, &mut rng);
// add the presignatures here
let presignatures =
run_presign(&key_packages, threshold as usize, actual_signers, rng).unwrap();

for (i, (p1, presig1)) in presignatures.iter().enumerate() {
for (p2, presig2) in presignatures.iter().skip(i + 1) {
assert_ne!(p1, p2);
assert_ne!(presig1.nonces, presig2.nonces);
assert_eq!(presig1.commitments_map, presig2.commitments_map);
}
}
assert_frost_presignatures_well_formed(&presignatures);
}

#[test]
Expand All @@ -319,17 +313,8 @@ fn check_presignatures_terms_with_less_active_participants() {
let actual_signers = 8;

let key_packages = build_frost_key_packages_with_dealer(max_signers, threshold, &mut rng);
// add the presignatures here
let presignatures =
run_presign(&key_packages, threshold as usize, actual_signers, rng).unwrap();
for i in 0..presignatures.len() {
for j in (i + 1)..presignatures.len() {
let (p1, presig1) = &presignatures[i];
let (p2, presig2) = &presignatures[j];

assert_ne!(p1, p2);
assert_ne!(presig1.nonces, presig2.nonces);
assert_eq!(presig1.commitments_map, presig2.commitments_map);
}
}

assert_frost_presignatures_well_formed(&presignatures);
}
5 changes: 4 additions & 1 deletion crates/threshold-signatures/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ pub use ckd::generate_ckd_app_package;
pub use dkg::{assert_public_key_invariant, run_keygen, run_refresh, run_reshare};
pub use participant_simulation::Simulator;
pub use participants::{generate_participants, generate_participants_with_random_ids};
pub use presign::{ecdsa_generate_rerandpresig_args, frost_run_presignature};
pub use presign::{
assert_frost_presignatures_well_formed, ecdsa_generate_rerandpresig_args,
frost_run_presignature,
};
pub use protocol::{
assert_buffer_capacity, build_buffer_test, expected_buffer_by_role,
run_and_assert_buffer_entries,
Expand Down
30 changes: 29 additions & 1 deletion crates/threshold-signatures/src/test_utils/presign.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use frost_core::{Field, Group};
use frost_core::round1::{SigningCommitments, SigningNonces};
use frost_core::{Field, Group, Identifier};
use frost_secp256k1::Secp256K1Sha256;
use k256::AffinePoint;
use rand_core::CryptoRngCore;
use std::collections::BTreeMap;
use std::error::Error;
use std::fmt::Debug;

use crate::ecdsa::{RerandomizationArguments, Tweak};
use crate::frost;
Expand Down Expand Up @@ -78,3 +81,28 @@ where

Ok(run_protocol(protocols)?)
}

/// Asserts that a batch of FROST presignatures from a single run is well-formed.
///
/// Every participant identifier is unique, every participant's secret nonces
/// are distinct, and every participant observes the same commitments map.
pub fn assert_frost_presignatures_well_formed<C>(
presignatures: &[(Participant, frost::PresignOutput<C>)],
) where
C: Ciphersuite + Send + 'static,
SigningNonces<C>: PartialEq + Debug,
BTreeMap<Identifier<C>, SigningCommitments<C>>: PartialEq + Debug,
{
assert!(
presignatures.len() >= 2,
"expected at least 2 presignatures to compare; got {}",
presignatures.len()
);
for (i, (p1, presig1)) in presignatures.iter().enumerate() {
for (p2, presig2) in presignatures.iter().skip(i + 1) {
assert_ne!(p1, p2);
assert_ne!(presig1.nonces, presig2.nonces);
assert_eq!(presig1.commitments_map, presig2.commitments_map);
}
}
}
174 changes: 0 additions & 174 deletions crates/threshold-signatures/tests/ckd.rs

This file was deleted.

Loading
Loading