From 47be3804b464cac2bbeb3f390bd9f3db1f2a4043 Mon Sep 17 00:00:00 2001 From: Simon Rastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Mon, 15 Jun 2026 15:31:46 +0200 Subject: [PATCH 1/9] Renaming ReconstructionLowerBound to ReconstructionThreshold --- crates/node/src/coordinator.rs | 6 ++-- crates/node/src/key_events.rs | 14 +++++----- crates/node/src/providers.rs | 6 ++-- crates/node/src/providers/ckd.rs | 6 ++-- .../node/src/providers/ckd/key_generation.rs | 10 +++---- .../node/src/providers/ckd/key_resharing.rs | 16 +++++------ crates/node/src/providers/ckd/sign.rs | 4 +-- crates/node/src/providers/ecdsa.rs | 8 +++--- .../src/providers/ecdsa/key_generation.rs | 10 +++---- .../node/src/providers/ecdsa/key_resharing.rs | 16 +++++------ crates/node/src/providers/ecdsa/presign.rs | 10 +++---- crates/node/src/providers/ecdsa/sign.rs | 10 +++---- crates/node/src/providers/ecdsa/triple.rs | 16 +++++------ crates/node/src/providers/eddsa.rs | 6 ++-- .../src/providers/eddsa/key_generation.rs | 10 +++---- .../node/src/providers/eddsa/key_resharing.rs | 16 +++++------ crates/node/src/providers/eddsa/sign.rs | 8 +++--- crates/node/src/providers/robust_ecdsa.rs | 12 ++++---- .../node/src/providers/verify_foreign_tx.rs | 6 ++-- .../benches/advanced_dkg.rs | 10 +++---- .../benches/advanced_eddsa_frost_sign_v1.rs | 6 ++-- .../benches/advanced_eddsa_frost_sign_v2.rs | 6 ++-- .../benches/advanced_ot_based_ecdsa.rs | 6 ++-- .../benches/bench_utils.rs | 6 ++-- .../benches/bench_utils/dkg.rs | 4 +-- .../benches/bench_utils/frost_eddsa.rs | 12 ++++---- .../benches/bench_utils/ot_based_ecdsa.rs | 8 +++--- crates/threshold-signatures/benches/ckd.rs | 8 +++--- .../benches/naive_ot_based_ecdsa.rs | 6 ++-- .../benches/simulate_dkg.rs | 6 ++-- .../benches/simulate_ecdsa.rs | 12 ++++---- .../benches/simulate_frost.rs | 10 +++---- crates/threshold-signatures/src/dkg.rs | 28 +++++++++---------- .../threshold-signatures/src/ecdsa/README.md | 4 +-- .../src/ecdsa/ot_based_ecdsa.rs | 4 +-- .../src/ecdsa/ot_based_ecdsa/sign.rs | 4 +-- .../src/ecdsa/ot_based_ecdsa/test.rs | 10 +++---- .../src/ecdsa/ot_based_ecdsa/triples.rs | 4 +-- .../ot_based_ecdsa/triples/generation.rs | 16 +++++------ .../src/ecdsa/ot_based_ecdsa/triples/test.rs | 4 +-- .../src/frost/eddsa/sign.rs | 20 ++++++------- .../src/frost/eddsa/test.rs | 8 +++--- .../threshold-signatures/src/frost/presign.rs | 4 +-- .../src/frost/redjubjub/sign.rs | 12 ++++---- .../src/frost/redjubjub/test.rs | 6 ++-- .../src/frost/sign_utils.rs | 4 +-- crates/threshold-signatures/src/lib.rs | 10 +++---- .../src/test_utils/dkg.rs | 10 +++---- .../src/test_utils/presign.rs | 4 +-- crates/threshold-signatures/src/thresholds.rs | 6 ++-- crates/threshold-signatures/tests/common.rs | 8 +++--- crates/threshold-signatures/tests/eddsa.rs | 6 ++-- docs/design/domain-separation.md | 6 ++-- 53 files changed, 234 insertions(+), 234 deletions(-) diff --git a/crates/node/src/coordinator.rs b/crates/node/src/coordinator.rs index 965836da13..911437adf8 100644 --- a/crates/node/src/coordinator.rs +++ b/crates/node/src/coordinator.rs @@ -38,7 +38,7 @@ use near_time::Clock; use std::collections::HashMap; use std::future::Future; use std::sync::{Arc, Mutex}; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::{confidential_key_derivation, ecdsa, frost::eddsa}; use tokio::select; use tokio::sync::mpsc::unbounded_channel; @@ -332,7 +332,7 @@ where let (network_client, channel_receiver, _handle) = run_network_client(Arc::new(sender), Box::new(receiver)); let threshold: usize = mpc_config.participants.threshold.try_into()?; - let threshold = ReconstructionLowerBound::from(threshold); + let threshold = ReconstructionThreshold::from(threshold); if mpc_config.is_leader_for_key_event() { keygen_leader( network_client, @@ -780,7 +780,7 @@ where let args = Arc::new(ResharingArgs { previous_keyset, existing_keyshares, - new_threshold: ReconstructionLowerBound::from(new_threshold), + new_threshold: ReconstructionThreshold::from(new_threshold), old_participants: current_running_state.participants, }); diff --git a/crates/node/src/key_events.rs b/crates/node/src/key_events.rs index 9cb682b677..d02a09b70d 100644 --- a/crates/node/src/key_events.rs +++ b/crates/node/src/key_events.rs @@ -28,7 +28,7 @@ use near_mpc_crypto_types::{KeyForDomain, Keyset}; use std::sync::Arc; use std::time::Duration; use threshold_signatures::{ - ReconstructionLowerBound, confidential_key_derivation as ckd, frost_ed25519, frost_secp256k1, + ReconstructionThreshold, confidential_key_derivation as ckd, frost_ed25519, frost_secp256k1, }; use tokio::sync::{RwLock, mpsc, watch}; use tokio::time::timeout; @@ -47,7 +47,7 @@ pub async fn keygen_computation_inner( generated_keys: Vec, key_id: KeyEventId, domain: DomainConfig, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> anyhow::Result<()> { anyhow::ensure!(key_id.domain_id == domain.id, "Domain mismatch"); let keyshare_handle = keyshare_storage @@ -124,7 +124,7 @@ async fn keygen_computation( keyshare_storage: Arc>, chain_txn_sender: impl TransactionSender, key_id: KeyEventId, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> anyhow::Result<()> { let key_event = wait_for_contract_catchup(&mut contract_key_event_id, key_id).await; let inner = keygen_computation_inner( @@ -160,7 +160,7 @@ async fn keygen_computation( pub struct ResharingArgs { pub previous_keyset: Keyset, pub existing_keyshares: Option>, - pub new_threshold: ReconstructionLowerBound, + pub new_threshold: ReconstructionThreshold, pub old_participants: ParticipantsConfig, } @@ -416,7 +416,7 @@ pub async fn keygen_leader( keyshare_storage: Arc>, mut key_event_receiver: watch::Receiver, chain_txn_sender: impl TransactionSender, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> anyhow::Result<()> { loop { // Wait for all participants to be connected. Otherwise, computations are most likely going @@ -500,7 +500,7 @@ pub async fn keygen_follower( keyshare_storage: Arc>, key_event_receiver: watch::Receiver, chain_txn_sender: impl TransactionSender + 'static, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> anyhow::Result<()> { let mut tasks = AutoAbortTaskCollection::new(); loop { @@ -900,7 +900,7 @@ mod tests { Arc::new(ResharingArgs { previous_keyset: Keyset::new(EpochId::new(5), vec![]), existing_keyshares: None, - new_threshold: ReconstructionLowerBound::from(3), + new_threshold: ReconstructionThreshold::from(3), old_participants: ParticipantsConfig { threshold: 3, participants: vec![], diff --git a/crates/node/src/providers.rs b/crates/node/src/providers.rs index a0ff31a5e6..3eb654698e 100644 --- a/crates/node/src/providers.rs +++ b/crates/node/src/providers.rs @@ -21,7 +21,7 @@ pub use ecdsa::EcdsaSignatureProvider; pub use ecdsa::EcdsaTaskId; pub use robust_ecdsa::RobustEcdsaSignatureProvider; use std::sync::Arc; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; /// The interface that defines the requirements for a signing schema to be correctly used in the code. pub trait SignatureProvider { @@ -51,7 +51,7 @@ pub trait SignatureProvider { /// /// It drains `channel_receiver` until the required task is found, meaning these clients must not be run in parallel. async fn run_key_generation_client( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, channel: NetworkTaskChannel, ) -> anyhow::Result; @@ -59,7 +59,7 @@ pub trait SignatureProvider { /// Both leaders and followers call this function. /// It drains `channel_receiver` until the required task is found, meaning these clients must not be run in parallel. async fn run_key_resharing_client( - new_threshold: ReconstructionLowerBound, + new_threshold: ReconstructionThreshold, key_share: Option, public_key: Self::PublicKey, old_participants: &ParticipantsConfig, diff --git a/crates/node/src/providers/ckd.rs b/crates/node/src/providers/ckd.rs index 9447f9425c..39394769b4 100644 --- a/crates/node/src/providers/ckd.rs +++ b/crates/node/src/providers/ckd.rs @@ -11,7 +11,7 @@ use threshold_signatures::confidential_key_derivation::{ ElementG1, KeygenOutput, SigningShare, VerifyingKey, }; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use mpc_node_config::ConfigFile; @@ -79,14 +79,14 @@ impl SignatureProvider for CKDProvider { } async fn run_key_generation_client( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, channel: NetworkTaskChannel, ) -> anyhow::Result { Self::run_key_generation_client_internal(threshold, channel).await } async fn run_key_resharing_client( - new_threshold: ReconstructionLowerBound, + new_threshold: ReconstructionThreshold, key_share: Option, public_key: VerifyingKey, old_participants: &ParticipantsConfig, diff --git a/crates/node/src/providers/ckd/key_generation.rs b/crates/node/src/providers/ckd/key_generation.rs index 58bfbaee18..88aa5a3e94 100644 --- a/crates/node/src/providers/ckd/key_generation.rs +++ b/crates/node/src/providers/ckd/key_generation.rs @@ -3,14 +3,14 @@ use crate::network::computation::MpcLeaderCentricComputation; use crate::protocol::run_protocol; use crate::providers::ckd::CKDProvider; use rand::rngs::OsRng; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::confidential_key_derivation::BLS12381SHA256; use threshold_signatures::confidential_key_derivation::KeygenOutput; use threshold_signatures::participants::Participant; impl CKDProvider { pub(super) async fn run_key_generation_client_internal( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, channel: NetworkTaskChannel, ) -> anyhow::Result { let key = KeyGenerationComputation { threshold } @@ -25,7 +25,7 @@ impl CKDProvider { /// Runs the key generation protocol, returning the key generated. /// This protocol is identical for the leader and the followers. pub struct KeyGenerationComputation { - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, } #[async_trait::async_trait] @@ -64,7 +64,7 @@ mod tests { use mpc_primitives::domain::DomainId; use near_mpc_contract_interface::types::{AttemptId, EpochId, KeyEventId}; use std::sync::Arc; - use threshold_signatures::ReconstructionLowerBound; + use threshold_signatures::ReconstructionThreshold; use threshold_signatures::confidential_key_derivation::KeygenOutput; use threshold_signatures::frost_core::Group; use threshold_signatures::participants::Participant; @@ -120,7 +120,7 @@ mod tests { .ok_or_else(|| anyhow::anyhow!("No channel"))? }; let key = KeyGenerationComputation { - threshold: ReconstructionLowerBound::from(3), + threshold: ReconstructionThreshold::from(3), } .perform_leader_centric_computation(channel, std::time::Duration::from_secs(60)) .await?; diff --git a/crates/node/src/providers/ckd/key_resharing.rs b/crates/node/src/providers/ckd/key_resharing.rs index 684c8aa2a8..19d02716d7 100644 --- a/crates/node/src/providers/ckd/key_resharing.rs +++ b/crates/node/src/providers/ckd/key_resharing.rs @@ -5,7 +5,7 @@ use crate::primitives::ParticipantId; use crate::protocol::run_protocol; use crate::providers::ckd::CKDProvider; use rand::rngs::OsRng; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::confidential_key_derivation::KeygenOutput; use threshold_signatures::confidential_key_derivation::SigningShare; use threshold_signatures::confidential_key_derivation::{BLS12381SHA256, VerifyingKey}; @@ -13,7 +13,7 @@ use threshold_signatures::participants::Participant; impl CKDProvider { pub(super) async fn run_key_resharing_client_internal( - new_threshold: ReconstructionLowerBound, + new_threshold: ReconstructionThreshold, my_share: Option, public_key: VerifyingKey, old_participants: &ParticipantsConfig, @@ -23,7 +23,7 @@ impl CKDProvider { let new_keyshare = KeyResharingComputation { threshold: new_threshold, old_participants: old_participants.participants.iter().map(|p| p.id).collect(), - old_threshold: ReconstructionLowerBound::from(old_threshold), + old_threshold: ReconstructionThreshold::from(old_threshold), my_share, public_key, } @@ -49,9 +49,9 @@ impl CKDProvider { /// the old threshold; or /// - the threshold is larger than the number of participants. pub struct KeyResharingComputation { - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, old_participants: Vec, - old_threshold: ReconstructionLowerBound, + old_threshold: ReconstructionThreshold, my_share: Option, public_key: VerifyingKey, } @@ -105,7 +105,7 @@ mod tests { use near_mpc_contract_interface::types::{AttemptId, EpochId, KeyEventId}; use rand::{Rng as _, SeedableRng as _}; use std::sync::Arc; - use threshold_signatures::ReconstructionLowerBound; + use threshold_signatures::ReconstructionThreshold; use threshold_signatures::confidential_key_derivation::BLS12381SHA256; use threshold_signatures::frost_core::Group; use threshold_signatures::participants::Participant; @@ -155,9 +155,9 @@ mod tests { .ok_or_else(|| anyhow::anyhow!("No channel"))? }; let key = KeyResharingComputation { - threshold: ReconstructionLowerBound::from(THRESHOLD), + threshold: ReconstructionThreshold::from(THRESHOLD), old_participants, - old_threshold: ReconstructionLowerBound::from(THRESHOLD), + old_threshold: ReconstructionThreshold::from(THRESHOLD), my_share: keyshare, public_key: pubkey, } diff --git a/crates/node/src/providers/ckd/sign.rs b/crates/node/src/providers/ckd/sign.rs index b17d707e41..74182141e7 100644 --- a/crates/node/src/providers/ckd/sign.rs +++ b/crates/node/src/providers/ckd/sign.rs @@ -6,7 +6,7 @@ use tokio::time::timeout; use near_mpc_contract_interface::types as dtos; use threshold_signatures::{ - ReconstructionLowerBound, + ReconstructionThreshold, confidential_key_derivation::{ AppId, ElementG1, ElementG2, KeygenOutput, PublicVerificationKey, VerifyingKey, ckd_pv, protocol::ckd, @@ -30,7 +30,7 @@ impl CKDProvider { let ckd_request = self.ckd_request_store.get(id).await?; let threshold: usize = self.mpc_config.participants.threshold.try_into()?; - let threshold = ReconstructionLowerBound::from(threshold); + let threshold = ReconstructionThreshold::from(threshold); let running_participants: Vec<_> = self .mpc_config .participants diff --git a/crates/node/src/providers/ecdsa.rs b/crates/node/src/providers/ecdsa.rs index 8abf51f26e..71009c0947 100644 --- a/crates/node/src/providers/ecdsa.rs +++ b/crates/node/src/providers/ecdsa.rs @@ -26,7 +26,7 @@ use mpc_primitives::ReconstructionThreshold; use mpc_primitives::domain::DomainId; use near_time::Clock; use std::sync::Arc; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::KeygenOutput; use threshold_signatures::ecdsa::Signature; use threshold_signatures::frost_secp256k1::VerifyingKey; @@ -193,14 +193,14 @@ impl SignatureProvider for EcdsaSignatureProvider { } async fn run_key_generation_client( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, channel: NetworkTaskChannel, ) -> anyhow::Result { EcdsaSignatureProvider::run_key_generation_client_internal(threshold, channel).await } async fn run_key_resharing_client( - new_threshold: ReconstructionLowerBound, + new_threshold: ReconstructionThreshold, my_share: Option, public_key: VerifyingKey, old_participants: &ParticipantsConfig, @@ -272,7 +272,7 @@ impl SignatureProvider for EcdsaSignatureProvider { // network-wide threshold. let threshold = ReconstructionThreshold::new(self.mpc_config.participants.threshold); let threshold_usize: usize = threshold.inner().try_into()?; - let threshold_bound = ReconstructionLowerBound::from(threshold_usize); + let threshold_bound = ReconstructionThreshold::from(threshold_usize); let triple_store = self.triple_store_for_t(threshold)?; let generate_triples = tracking::spawn( diff --git a/crates/node/src/providers/ecdsa/key_generation.rs b/crates/node/src/providers/ecdsa/key_generation.rs index 55d7b8e44d..4e26044d77 100644 --- a/crates/node/src/providers/ecdsa/key_generation.rs +++ b/crates/node/src/providers/ecdsa/key_generation.rs @@ -3,13 +3,13 @@ use crate::network::computation::MpcLeaderCentricComputation; use crate::protocol::run_protocol; use crate::providers::ecdsa::{EcdsaSignatureProvider, KeygenOutput}; use rand::rngs::OsRng; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::frost_secp256k1::Secp256K1Sha256; use threshold_signatures::participants::Participant; impl EcdsaSignatureProvider { pub(crate) async fn run_key_generation_client_internal( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, channel: NetworkTaskChannel, ) -> anyhow::Result { let key = KeyGenerationComputation { threshold } @@ -24,7 +24,7 @@ impl EcdsaSignatureProvider { /// Runs the key generation protocol, returning the key generated. /// This protocol is identical for the leader and the followers. pub struct KeyGenerationComputation { - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, } #[async_trait::async_trait] @@ -63,7 +63,7 @@ mod tests { use mpc_primitives::domain::DomainId; use near_mpc_contract_interface::types::{AttemptId, EpochId, KeyEventId}; use std::sync::Arc; - use threshold_signatures::ReconstructionLowerBound; + use threshold_signatures::ReconstructionThreshold; use threshold_signatures::test_utils::generate_participants; use tokio::sync::mpsc; @@ -106,7 +106,7 @@ mod tests { .ok_or_else(|| anyhow::anyhow!("No channel"))? }; let key = KeyGenerationComputation { - threshold: ReconstructionLowerBound::from(3), + threshold: ReconstructionThreshold::from(3), } .perform_leader_centric_computation(channel, std::time::Duration::from_secs(60)) .await?; diff --git a/crates/node/src/providers/ecdsa/key_resharing.rs b/crates/node/src/providers/ecdsa/key_resharing.rs index 0e63d0fe2c..72b6c92539 100644 --- a/crates/node/src/providers/ecdsa/key_resharing.rs +++ b/crates/node/src/providers/ecdsa/key_resharing.rs @@ -5,14 +5,14 @@ use crate::primitives::ParticipantId; use crate::protocol::run_protocol; use crate::providers::ecdsa::{EcdsaSignatureProvider, KeygenOutput}; use rand::rngs::OsRng; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::frost_secp256k1::keys::SigningShare; use threshold_signatures::frost_secp256k1::{Secp256K1Sha256, VerifyingKey}; use threshold_signatures::participants::Participant; impl EcdsaSignatureProvider { pub(crate) async fn run_key_resharing_client_internal( - new_threshold: ReconstructionLowerBound, + new_threshold: ReconstructionThreshold, my_share: Option, public_key: VerifyingKey, old_participants: &ParticipantsConfig, @@ -22,7 +22,7 @@ impl EcdsaSignatureProvider { let new_keyshare = KeyResharingComputation { threshold: new_threshold, old_participants: old_participants.participants.iter().map(|p| p.id).collect(), - old_threshold: ReconstructionLowerBound::from(old_threshold), + old_threshold: ReconstructionThreshold::from(old_threshold), my_share, public_key, } @@ -48,9 +48,9 @@ impl EcdsaSignatureProvider { /// the old threshold; or /// - the threshold is larger than the number of participants. pub struct KeyResharingComputation { - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, old_participants: Vec, - old_threshold: ReconstructionLowerBound, + old_threshold: ReconstructionThreshold, my_share: Option, public_key: VerifyingKey, } @@ -103,7 +103,7 @@ mod tests { use near_mpc_contract_interface::types::{AttemptId, EpochId, KeyEventId}; use rand::{Rng as _, SeedableRng as _}; use std::sync::Arc; - use threshold_signatures::ReconstructionLowerBound; + use threshold_signatures::ReconstructionThreshold; use threshold_signatures::frost_secp256k1::Secp256K1Sha256; use threshold_signatures::test_utils::{generate_participants_with_random_ids, run_keygen}; use tokio::sync::mpsc; @@ -150,9 +150,9 @@ mod tests { .ok_or_else(|| anyhow::anyhow!("No channel"))? }; let key = KeyResharingComputation { - threshold: ReconstructionLowerBound::from(THRESHOLD), + threshold: ReconstructionThreshold::from(THRESHOLD), old_participants, - old_threshold: ReconstructionLowerBound::from(THRESHOLD), + old_threshold: ReconstructionThreshold::from(THRESHOLD), my_share: keyshare, public_key: pubkey, } diff --git a/crates/node/src/providers/ecdsa/presign.rs b/crates/node/src/providers/ecdsa/presign.rs index 361f604c04..c5afbe24be 100644 --- a/crates/node/src/providers/ecdsa/presign.rs +++ b/crates/node/src/providers/ecdsa/presign.rs @@ -19,7 +19,7 @@ use serde::{Deserialize, Serialize}; use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::time::Duration; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::ot_based_ecdsa::triples::TripleGenerationOutput; use threshold_signatures::ecdsa::ot_based_ecdsa::{ PresignArguments, PresignOutput, presign::presign, @@ -66,7 +66,7 @@ impl EcdsaSignatureProvider { /// so that needs to be separately handled. pub(super) async fn run_background_presignature_generation( client: Arc, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, config: Arc, triple_store: Arc, domain_id: DomainId, @@ -186,7 +186,7 @@ impl EcdsaSignatureProvider { let threshold = ReconstructionThreshold::new(threshold_usize.try_into()?); let triple_store = self.triple_store_for_t(threshold)?; FollowerPresignComputation { - threshold: ReconstructionLowerBound::from(threshold_usize), + threshold: ReconstructionThreshold::from(threshold_usize), keygen_out: domain_data.keyshare, triple_store, paired_triple_id, @@ -220,7 +220,7 @@ impl HasParticipants for PresignOutputWithParticipants { /// Performs an MPC presignature operation. This is shared for the initiator /// and for passive participants. pub struct PresignComputation { - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, triple0: TripleGenerationOutput, triple1: TripleGenerationOutput, keygen_out: KeygenOutput, @@ -260,7 +260,7 @@ impl MpcLeaderCentricComputation for PresignComputation { /// The difference is: we need to read the triples from the triple store (which may fail), /// and we need to write the presignature to the presignature store before completing. pub struct FollowerPresignComputation { - pub threshold: ReconstructionLowerBound, + pub threshold: ReconstructionThreshold, pub paired_triple_id: UniqueId, pub keygen_out: KeygenOutput, pub triple_store: Arc, diff --git a/crates/node/src/providers/ecdsa/sign.rs b/crates/node/src/providers/ecdsa/sign.rs index c2b5fc0215..562632a9f3 100644 --- a/crates/node/src/providers/ecdsa/sign.rs +++ b/crates/node/src/providers/ecdsa/sign.rs @@ -15,7 +15,7 @@ use near_mpc_contract_interface::types::Tweak; use std::sync::Arc; use std::time::Duration; use threshold_signatures::ParticipantList; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::ot_based_ecdsa::{PresignOutput, RerandomizedPresignOutput}; use threshold_signatures::ecdsa::{RerandomizationArguments, Signature, SignatureOption}; use threshold_signatures::frost_secp256k1::VerifyingKey; @@ -32,7 +32,7 @@ impl EcdsaSignatureProvider { let domain_data = self.domain_data(sign_request.domain)?; let participants = presignature.participants.clone(); let threshold: usize = self.mpc_config.participants.threshold.try_into()?; - let threshold = ReconstructionLowerBound::from(threshold); + let threshold = ReconstructionThreshold::from(threshold); let (signature, public_key) = SignComputation { keygen_out: domain_data.keyshare, @@ -93,7 +93,7 @@ impl EcdsaSignatureProvider { presignature_id.validate_owned_by(channel.sender().get_leader())?; let domain_data = self.domain_data(sign_request.domain)?; let threshold: usize = self.mpc_config.participants.threshold.try_into()?; - let threshold = ReconstructionLowerBound::from(threshold); + let threshold = ReconstructionThreshold::from(threshold); let participants = channel.participants().to_vec(); FollowerSignComputation { @@ -149,7 +149,7 @@ impl EcdsaSignatureProvider { /// The tweak allows key derivation pub struct SignComputation { pub keygen_out: KeygenOutput, - pub threshold: ReconstructionLowerBound, + pub threshold: ReconstructionThreshold, pub presign_out: PresignOutput, pub msg_hash: [u8; 32], pub tweak: Tweak, @@ -218,7 +218,7 @@ impl MpcLeaderCentricComputation<(SignatureOption, VerifyingKey)> for SignComput /// The difference is that the follower needs to look up the presignature, which may fail. pub struct FollowerSignComputation { pub keygen_out: KeygenOutput, - pub threshold: ReconstructionLowerBound, + pub threshold: ReconstructionThreshold, pub presignature_id: UniqueId, pub presignature_store: Arc, pub msg_hash: [u8; 32], diff --git a/crates/node/src/providers/ecdsa/triple.rs b/crates/node/src/providers/ecdsa/triple.rs index b0c43e6228..c75a3e2ff5 100644 --- a/crates/node/src/providers/ecdsa/triple.rs +++ b/crates/node/src/providers/ecdsa/triple.rs @@ -18,7 +18,7 @@ use rand::rngs::OsRng; use std::ops::Deref; use std::sync::Arc; use std::time::Duration; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::ot_based_ecdsa::triples::TripleGenerationOutput; use threshold_signatures::participants::Participant; @@ -74,7 +74,7 @@ impl EcdsaSignatureProvider { mpc_config: Arc, config: Arc, triple_store: Arc, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> ! { let in_flight_generations = InFlightGenerationTracker::new(); let parallelism_limiter = Arc::new(tokio::sync::Semaphore::new(config.concurrency)); @@ -212,7 +212,7 @@ impl EcdsaSignatureProvider { let threshold = ReconstructionThreshold::new(threshold_usize.try_into()?); let triple_store = self.triple_store_for_t(threshold)?; FollowerManyTripleGenerationComputation:: { - threshold: ReconstructionLowerBound::from(threshold_usize), + threshold: ReconstructionThreshold::from(threshold_usize), out_triple_id_start: start, out_triple_store: triple_store, } @@ -240,7 +240,7 @@ impl HasParticipants for PairedTriple { /// Generates many cait-sith triples at once. This can significantly save the /// *number* of network messages. pub struct ManyTripleGenerationComputation { - pub threshold: ReconstructionLowerBound, + pub threshold: ReconstructionThreshold, } #[async_trait::async_trait] @@ -288,7 +288,7 @@ impl MpcLeaderCentricComputation> /// The follower version of the triple generation. The difference is that the follower will only /// complete the computation after successfully persisting the triples to storage. pub struct FollowerManyTripleGenerationComputation { - pub threshold: ReconstructionLowerBound, + pub threshold: ReconstructionThreshold, pub out_triple_store: Arc, pub out_triple_id_start: UniqueId, } @@ -348,7 +348,7 @@ mod tests { use futures::{FutureExt, StreamExt, stream}; use std::collections::HashMap; use std::sync::Arc; - use threshold_signatures::ReconstructionLowerBound; + use threshold_signatures::ReconstructionThreshold; use threshold_signatures::test_utils::generate_participants; use tokio::sync::mpsc; @@ -405,7 +405,7 @@ mod tests { panic!("Unexpected task id"); }; let triples = ManyTripleGenerationComputation:: { - threshold: ReconstructionLowerBound::from(THRESHOLD), + threshold: ReconstructionThreshold::from(THRESHOLD), } .perform_leader_centric_computation( channel, @@ -453,7 +453,7 @@ mod tests { let result = tracking::spawn( &format!("task {:?}", task_id), ManyTripleGenerationComputation:: { - threshold: ReconstructionLowerBound::from(THRESHOLD), + threshold: ReconstructionThreshold::from(THRESHOLD), } .perform_leader_centric_computation( channel, diff --git a/crates/node/src/providers/eddsa.rs b/crates/node/src/providers/eddsa.rs index 3ce938de8a..a4c24d3275 100644 --- a/crates/node/src/providers/eddsa.rs +++ b/crates/node/src/providers/eddsa.rs @@ -21,7 +21,7 @@ use near_mpc_contract_interface::types::Ed25519PublicKey; use near_mpc_contract_interface::types::KeyEventId; use std::collections::HashMap; use std::sync::Arc; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::frost::eddsa::KeygenOutput; use threshold_signatures::frost_ed25519::keys::SigningShare; use threshold_signatures::frost_ed25519::{Signature, VerifyingKey}; @@ -84,14 +84,14 @@ impl SignatureProvider for EddsaSignatureProvider { } async fn run_key_generation_client( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, channel: NetworkTaskChannel, ) -> anyhow::Result { Self::run_key_generation_client_internal(threshold, channel).await } async fn run_key_resharing_client( - new_threshold: ReconstructionLowerBound, + new_threshold: ReconstructionThreshold, key_share: Option, public_key: VerifyingKey, old_participants: &ParticipantsConfig, diff --git a/crates/node/src/providers/eddsa/key_generation.rs b/crates/node/src/providers/eddsa/key_generation.rs index 776081d76e..e4cd856487 100644 --- a/crates/node/src/providers/eddsa/key_generation.rs +++ b/crates/node/src/providers/eddsa/key_generation.rs @@ -3,14 +3,14 @@ use crate::network::computation::MpcLeaderCentricComputation; use crate::protocol::run_protocol; use crate::providers::eddsa::EddsaSignatureProvider; use rand::rngs::OsRng; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::frost::eddsa::KeygenOutput; use threshold_signatures::frost_ed25519::Ed25519Sha512; use threshold_signatures::participants::Participant; impl EddsaSignatureProvider { pub(super) async fn run_key_generation_client_internal( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, channel: NetworkTaskChannel, ) -> anyhow::Result { let key = KeyGenerationComputation { threshold } @@ -25,7 +25,7 @@ impl EddsaSignatureProvider { /// Runs the key generation protocol, returning the key generated. /// This protocol is identical for the leader and the followers. pub struct KeyGenerationComputation { - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, } #[async_trait::async_trait] @@ -64,7 +64,7 @@ mod tests { use mpc_primitives::domain::DomainId; use near_mpc_contract_interface::types::{AttemptId, EpochId, KeyEventId}; use std::sync::Arc; - use threshold_signatures::ReconstructionLowerBound; + use threshold_signatures::ReconstructionThreshold; use threshold_signatures::frost::eddsa::KeygenOutput; use threshold_signatures::test_utils::generate_participants; use tokio::sync::mpsc; @@ -108,7 +108,7 @@ mod tests { .ok_or_else(|| anyhow::anyhow!("No channel"))? }; let key = KeyGenerationComputation { - threshold: ReconstructionLowerBound::from(3), + threshold: ReconstructionThreshold::from(3), } .perform_leader_centric_computation(channel, std::time::Duration::from_secs(60)) .await?; diff --git a/crates/node/src/providers/eddsa/key_resharing.rs b/crates/node/src/providers/eddsa/key_resharing.rs index 4616cc3183..6f40e55559 100644 --- a/crates/node/src/providers/eddsa/key_resharing.rs +++ b/crates/node/src/providers/eddsa/key_resharing.rs @@ -5,7 +5,7 @@ use crate::primitives::ParticipantId; use crate::protocol::run_protocol; use crate::providers::eddsa::EddsaSignatureProvider; use rand::rngs::OsRng; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::frost::eddsa::KeygenOutput; use threshold_signatures::frost_ed25519::keys::SigningShare; use threshold_signatures::frost_ed25519::{Ed25519Sha512, VerifyingKey}; @@ -13,7 +13,7 @@ use threshold_signatures::participants::Participant; impl EddsaSignatureProvider { pub(super) async fn run_key_resharing_client_internal( - new_threshold: ReconstructionLowerBound, + new_threshold: ReconstructionThreshold, my_share: Option, public_key: VerifyingKey, old_participants: &ParticipantsConfig, @@ -23,7 +23,7 @@ impl EddsaSignatureProvider { let new_keyshare = KeyResharingComputation { threshold: new_threshold, old_participants: old_participants.participants.iter().map(|p| p.id).collect(), - old_threshold: ReconstructionLowerBound::from(old_threshold), + old_threshold: ReconstructionThreshold::from(old_threshold), my_share, public_key, } @@ -49,9 +49,9 @@ impl EddsaSignatureProvider { /// the old threshold; or /// - the threshold is larger than the number of participants. pub struct KeyResharingComputation { - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, old_participants: Vec, - old_threshold: ReconstructionLowerBound, + old_threshold: ReconstructionThreshold, my_share: Option, public_key: VerifyingKey, } @@ -105,7 +105,7 @@ mod tests { use near_mpc_contract_interface::types::{AttemptId, EpochId, KeyEventId}; use rand::{Rng as _, SeedableRng as _}; use std::sync::Arc; - use threshold_signatures::ReconstructionLowerBound; + use threshold_signatures::ReconstructionThreshold; use threshold_signatures::frost_ed25519::Ed25519Sha512; use threshold_signatures::test_utils::{generate_participants_with_random_ids, run_keygen}; use tokio::sync::mpsc; @@ -152,9 +152,9 @@ mod tests { .ok_or_else(|| anyhow::anyhow!("No channel"))? }; let key = KeyResharingComputation { - threshold: ReconstructionLowerBound::from(THRESHOLD), + threshold: ReconstructionThreshold::from(THRESHOLD), old_participants, - old_threshold: ReconstructionLowerBound::from(THRESHOLD), + old_threshold: ReconstructionThreshold::from(THRESHOLD), my_share: keyshare, public_key: pubkey, } diff --git a/crates/node/src/providers/eddsa/sign.rs b/crates/node/src/providers/eddsa/sign.rs index c3039599ae..64c08208af 100644 --- a/crates/node/src/providers/eddsa/sign.rs +++ b/crates/node/src/providers/eddsa/sign.rs @@ -8,7 +8,7 @@ use anyhow::Context; use near_mpc_contract_interface::types::Tweak; use rand::rngs::OsRng; use std::time::Duration; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::frost::eddsa::KeygenOutput; use threshold_signatures::frost::eddsa::sign::sign; use threshold_signatures::frost_core::Scalar; @@ -25,7 +25,7 @@ impl EddsaSignatureProvider { let sign_request = self.sign_request_store.get(id).await?; let threshold: usize = self.mpc_config.participants.threshold.try_into()?; - let threshold = ReconstructionLowerBound::from(threshold); + let threshold = ReconstructionThreshold::from(threshold); let running_participants: Vec<_> = self .mpc_config .participants @@ -96,7 +96,7 @@ impl EddsaSignatureProvider { metrics::MPC_NUM_PASSIVE_SIGN_REQUESTS_LOOKUP_SUCCEEDED.inc(); let threshold: usize = self.mpc_config.participants.threshold.try_into()?; - let threshold = ReconstructionLowerBound::from(threshold); + let threshold = ReconstructionThreshold::from(threshold); let Some(keygen_output) = self.keyshares.get(&sign_request.domain) else { anyhow::bail!("No keyshare for domain {:?}", sign_request.domain); @@ -136,7 +136,7 @@ impl EddsaSignatureProvider { /// The tweak allows key derivation pub struct SignComputation { pub keygen_output: KeygenOutput, - pub threshold: ReconstructionLowerBound, + pub threshold: ReconstructionThreshold, pub message: Vec, pub tweak: Tweak, } diff --git a/crates/node/src/providers/robust_ecdsa.rs b/crates/node/src/providers/robust_ecdsa.rs index e1ea0af0fe..338a464fd1 100644 --- a/crates/node/src/providers/robust_ecdsa.rs +++ b/crates/node/src/providers/robust_ecdsa.rs @@ -21,7 +21,7 @@ use mpc_primitives::domain::DomainId; use near_time::Clock; use std::sync::Arc; use threshold_signatures::MaxMalicious; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::KeygenOutput; use threshold_signatures::ecdsa::Signature; use threshold_signatures::frost_secp256k1::VerifyingKey; @@ -144,21 +144,21 @@ impl SignatureProvider for RobustEcdsaSignatureProvider { } async fn run_key_generation_client( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, channel: NetworkTaskChannel, ) -> anyhow::Result { let number_of_participants = channel.participants().len(); let robust_ecdsa_threshold = translate_threshold(threshold.value(), number_of_participants)?; EcdsaSignatureProvider::run_key_generation_client_internal( - ReconstructionLowerBound::try_from(robust_ecdsa_threshold)?, + ReconstructionThreshold::try_from(robust_ecdsa_threshold)?, channel, ) .await } async fn run_key_resharing_client( - new_threshold: ReconstructionLowerBound, + new_threshold: ReconstructionThreshold, my_share: Option, public_key: VerifyingKey, old_participants: &ParticipantsConfig, @@ -176,12 +176,12 @@ impl SignatureProvider for RobustEcdsaSignatureProvider { old_participants.threshold.try_into()?, old_participants.participants.len(), )?; - old_participants_patched.threshold = ReconstructionLowerBound::try_from(old_translated)? + old_participants_patched.threshold = ReconstructionThreshold::try_from(old_translated)? .value() .try_into()?; EcdsaSignatureProvider::run_key_resharing_client_internal( - ReconstructionLowerBound::try_from(new_robust_ecdsa_threshold)?, + ReconstructionThreshold::try_from(new_robust_ecdsa_threshold)?, my_share, public_key, &old_participants_patched, diff --git a/crates/node/src/providers/verify_foreign_tx.rs b/crates/node/src/providers/verify_foreign_tx.rs index 0e8dbef38d..b1857127c8 100644 --- a/crates/node/src/providers/verify_foreign_tx.rs +++ b/crates/node/src/providers/verify_foreign_tx.rs @@ -23,7 +23,7 @@ use mpc_node_config::{ConfigFile, ForeignChainConfig, ForeignChainsConfig}; use near_mpc_contract_interface::types as dtos; use std::sync::Arc; use std::time::Duration; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::{KeygenOutput, Signature}; use threshold_signatures::frost_secp256k1::VerifyingKey; use threshold_signatures::frost_secp256k1::keys::SigningShare; @@ -186,7 +186,7 @@ where } async fn run_key_generation_client( - _threshold: ReconstructionLowerBound, + _threshold: ReconstructionThreshold, _channel: NetworkTaskChannel, ) -> anyhow::Result { anyhow::bail!( @@ -195,7 +195,7 @@ where } async fn run_key_resharing_client( - _new_threshold: ReconstructionLowerBound, + _new_threshold: ReconstructionThreshold, _key_share: Option, _public_key: VerifyingKey, _old_participants: &ParticipantsConfig, diff --git a/crates/threshold-signatures/benches/advanced_dkg.rs b/crates/threshold-signatures/benches/advanced_dkg.rs index 596a19681f..0b50ae76f4 100644 --- a/crates/threshold-signatures/benches/advanced_dkg.rs +++ b/crates/threshold-signatures/benches/advanced_dkg.rs @@ -8,7 +8,7 @@ use crate::bench_utils::{ }; use threshold_signatures::{ - Ciphersuite, Element, KeygenOutput, ReconstructionLowerBound, Scalar, + Ciphersuite, Element, KeygenOutput, ReconstructionThreshold, Scalar, confidential_key_derivation::ciphersuite::BLS12381SHA256, frost_ed25519::Ed25519Sha512, frost_secp256k1::Secp256K1Sha256, @@ -20,8 +20,8 @@ use threshold_signatures::{ }, }; -fn threshold() -> ReconstructionLowerBound { - ReconstructionLowerBound::from(*MAX_MALICIOUS + 1) +fn threshold() -> ReconstructionThreshold { + ReconstructionThreshold::from(*MAX_MALICIOUS + 1) } fn participants_num() -> usize { @@ -82,7 +82,7 @@ struct DkgSetup { } /// Expensive one-time setup: runs the full N-party protocol to capture snapshots -fn setup_dkg_snapshot(threshold: ReconstructionLowerBound) -> DkgSetup +fn setup_dkg_snapshot(threshold: ReconstructionThreshold) -> DkgSetup where Element: Send, Scalar: Send, @@ -112,7 +112,7 @@ where /// Cheap per-sample setup: creates fresh protocol and clones the cached simulator fn prepare_simulated_dkg( setup: &DkgSetup, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> PreparedSimulatedDkg where Element: Send, diff --git a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs index 9a4b2b2be9..a4c462ba76 100644 --- a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs +++ b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs @@ -9,7 +9,7 @@ use crate::bench_utils::{ analyze_received_sizes, ed25519_prepare_sign_v1, }; use threshold_signatures::{ - ReconstructionLowerBound, + ReconstructionThreshold, frost::eddsa::{KeygenOutput, SignatureOption, sign::sign_v1}, participants::Participant, protocol::Protocol, @@ -56,7 +56,7 @@ struct SignSetup { } /// Expensive one-time setup: runs the full N-party protocol to capture snapshots -fn setup_sign_snapshot(threshold: ReconstructionLowerBound) -> SignSetup { +fn setup_sign_snapshot(threshold: ReconstructionThreshold) -> SignSetup { let mut rng = MockCryptoRng::seed_from_u64(41); let preps = ed25519_prepare_sign_v1(threshold, &mut rng); let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) @@ -87,7 +87,7 @@ fn setup_sign_snapshot(threshold: ReconstructionLowerBound) -> SignSetup { /// Cheap per-sample setup: creates fresh sign protocol and clones the cached simulator fn prepare_simulated_sign( setup: &SignSetup, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> PreparedSimulatedSig { let real_protocol = sign_v1( &setup.participants, diff --git a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs index 0645bcaa36..2b4a8df84d 100644 --- a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs +++ b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs @@ -10,7 +10,7 @@ use crate::bench_utils::{ analyze_received_sizes, ed25519_prepare_presign, ed25519_prepare_sign_v2, }; use threshold_signatures::{ - ReconstructionLowerBound, + ReconstructionThreshold, frost::eddsa::{ KeygenOutput, PresignArguments, PresignOutput, SignatureOption, presign, sign::sign_v2, }, @@ -149,7 +149,7 @@ struct SignSetup { } /// Expensive one-time setup for sign: runs the full N-party protocol to capture snapshots -fn setup_sign_snapshot(threshold: ReconstructionLowerBound) -> SignSetup { +fn setup_sign_snapshot(threshold: ReconstructionThreshold) -> SignSetup { let mut rng = MockCryptoRng::seed_from_u64(41); let preps = ed25519_prepare_presign(threshold.value(), &mut rng); let result = run_protocol(preps.protocols).expect("Prepare sign should not fail"); @@ -182,7 +182,7 @@ fn setup_sign_snapshot(threshold: ReconstructionLowerBound) -> SignSetup { /// Cheap per-sample setup: creates fresh sign protocol and clones the cached simulator fn prepare_simulated_sign( setup: &SignSetup, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> PreparedSimulatedSig { let real_protocol = sign_v2( &setup.participants, diff --git a/crates/threshold-signatures/benches/advanced_ot_based_ecdsa.rs b/crates/threshold-signatures/benches/advanced_ot_based_ecdsa.rs index 3393a6203b..8f806f67b5 100644 --- a/crates/threshold-signatures/benches/advanced_ot_based_ecdsa.rs +++ b/crates/threshold-signatures/benches/advanced_ot_based_ecdsa.rs @@ -14,7 +14,7 @@ use crate::bench_utils::{ }; use threshold_signatures::{ - ReconstructionLowerBound, + ReconstructionThreshold, ecdsa::{ KeygenOutput, SignatureOption, ot_based_ecdsa::{ @@ -266,7 +266,7 @@ struct SignSetup { /// Expensive one-time setup for sign: runs the full N-party protocol to capture snapshots fn setup_sign_snapshot( result: &[(Participant, PresignOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, pk: VerifyingKey, ) -> SignSetup { let mut rng = MockCryptoRng::seed_from_u64(40); @@ -297,7 +297,7 @@ fn setup_sign_snapshot( /// Cheap per-sample setup: creates fresh sign protocol and clones the cached simulator fn prepare_simulated_sign( setup: &SignSetup, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> PreparedSimulatedSig { let real_protocol = sign( &setup.participants, diff --git a/crates/threshold-signatures/benches/bench_utils.rs b/crates/threshold-signatures/benches/bench_utils.rs index c188b00a27..b621e26876 100644 --- a/crates/threshold-signatures/benches/bench_utils.rs +++ b/crates/threshold-signatures/benches/bench_utils.rs @@ -24,7 +24,7 @@ use k256::AffinePoint; use std::{env, sync::LazyLock}; use threshold_signatures::{ - ReconstructionLowerBound, + ReconstructionThreshold, ecdsa::{self, Scalar}, participants::Participant, protocol::Protocol, @@ -47,8 +47,8 @@ pub static SAMPLE_SIZE: LazyLock = std::sync::LazyLock::new(|| { .unwrap_or(15) }); -pub static RECONSTRUCTION_LOWER_BOUND: LazyLock = - LazyLock::new(|| ReconstructionLowerBound::from(*MAX_MALICIOUS + 1)); +pub static RECONSTRUCTION_LOWER_BOUND: LazyLock = + LazyLock::new(|| ReconstructionThreshold::from(*MAX_MALICIOUS + 1)); /// This helps defining a generic type for the benchmarks prepared outputs pub struct PreparedOutputs { diff --git a/crates/threshold-signatures/benches/bench_utils/dkg.rs b/crates/threshold-signatures/benches/bench_utils/dkg.rs index c6cf0f903b..c0c8baeeca 100644 --- a/crates/threshold-signatures/benches/bench_utils/dkg.rs +++ b/crates/threshold-signatures/benches/bench_utils/dkg.rs @@ -1,7 +1,7 @@ use rand_core::{CryptoRngCore, SeedableRng}; use threshold_signatures::{ - Ciphersuite, KeygenOutput, ReconstructionLowerBound, keygen, + Ciphersuite, KeygenOutput, ReconstructionThreshold, keygen, participants::Participant, protocol::Protocol, test_utils::{MockCryptoRng, generate_participants_with_random_ids}, @@ -10,7 +10,7 @@ use threshold_signatures::{ /// Used to prepare DKG keygen protocols for benchmarking pub fn prepare_dkg( num_participants: usize, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, rng: &mut R, ) -> PreparedDkgPackage where diff --git a/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs b/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs index f4be1b4e9d..87160a27f7 100644 --- a/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs +++ b/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs @@ -2,7 +2,7 @@ use rand::Rng; use rand_core::{CryptoRngCore, SeedableRng}; use threshold_signatures::{ - ReconstructionLowerBound, + ReconstructionThreshold, confidential_key_derivation::{ self as ckd, ciphersuite::{Field as _, Group as _}, @@ -23,7 +23,7 @@ pub type PresignProtocols = Vec<( pub fn ed25519_build_presign_protocols( participants: &[Participant], key_packages: &[(Participant, eddsa::KeygenOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, rng: &mut R, ) -> PresignProtocols { let mut protocols = Vec::with_capacity(participants.len()); @@ -52,7 +52,7 @@ pub fn ed25519_prepare_presign( ) -> FrostEd25519PreparedPresig { let participants = generate_participants_with_random_ids(num_participants, rng); let key_packages = run_keygen(&participants, *MAX_MALICIOUS + 1, rng); - let threshold = ReconstructionLowerBound::from(*MAX_MALICIOUS + 1); + let threshold = ReconstructionThreshold::from(*MAX_MALICIOUS + 1); let protocols = ed25519_build_presign_protocols(&participants, &key_packages, threshold, rng); FrostEd25519PreparedPresig { protocols, @@ -63,7 +63,7 @@ pub fn ed25519_prepare_presign( /// Used to prepare ed25519 signatures for benchmarking pub fn ed25519_prepare_sign_v1( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, rng: &mut R, ) -> FrostEd25519SigV1 { let num_participants = threshold.value(); @@ -107,7 +107,7 @@ pub fn ed25519_prepare_sign_v1( pub fn ed25519_prepare_sign_v2( result: &[(Participant, eddsa::PresignOutput)], key_packages: Vec<(Participant, eddsa::KeygenOutput)>, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, rng: &mut R, ) -> FrostEd25519SigV2 { let num_participants = threshold.value(); @@ -172,7 +172,7 @@ pub struct FrostEd25519SigV2 { } pub fn prepare_ckd( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, rng: &mut R, ) -> PreparedCkdPackage { let num_participants = threshold.value(); diff --git a/crates/threshold-signatures/benches/bench_utils/ot_based_ecdsa.rs b/crates/threshold-signatures/benches/bench_utils/ot_based_ecdsa.rs index 41b88a0a95..f698b1d1e8 100644 --- a/crates/threshold-signatures/benches/bench_utils/ot_based_ecdsa.rs +++ b/crates/threshold-signatures/benches/bench_utils/ot_based_ecdsa.rs @@ -2,7 +2,7 @@ use rand::Rng; use rand_core::{CryptoRngCore, SeedableRng}; use threshold_signatures::{ - ReconstructionLowerBound, + ReconstructionThreshold, ecdsa::{ self, ot_based_ecdsa::{ @@ -23,7 +23,7 @@ use super::{PreparedPresig, PreparedSig}; /// Used to prepare ot based ecdsa triples for benchmarking pub fn ot_ecdsa_prepare_triples( participant_num: usize, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, rng: &mut R, ) -> OTECDSAPreparedTriples { let mut protocols: Vec<(_, Box>)> = @@ -45,7 +45,7 @@ pub fn ot_ecdsa_prepare_triples /// Used to prepare ot based ecdsa presignatures for benchmarking pub fn ot_ecdsa_prepare_presign( two_triples: &[(Participant, Vec<(TripleShare, TriplePub)>)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, rng: &mut R, ) -> OTECDSAPreparedPresig { let mut two_triples = two_triples.to_owned(); @@ -93,7 +93,7 @@ pub fn ot_ecdsa_prepare_presign /// Used to prepare ot based ecdsa signatures for benchmarking pub fn ot_ecdsa_prepare_sign( result: &[(Participant, ot_based_ecdsa::PresignOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, pk: frost_secp256k1::VerifyingKey, rng: &mut R, ) -> OTECDSAPreparedSig { diff --git a/crates/threshold-signatures/benches/ckd.rs b/crates/threshold-signatures/benches/ckd.rs index 8a61d98c7b..2e0d72c080 100644 --- a/crates/threshold-signatures/benches/ckd.rs +++ b/crates/threshold-signatures/benches/ckd.rs @@ -8,7 +8,7 @@ use crate::bench_utils::{ MAX_MALICIOUS, PreparedOutputs, SAMPLE_SIZE, analyze_received_sizes, prepare_ckd, }; use threshold_signatures::{ - ReconstructionLowerBound, + ReconstructionThreshold, confidential_key_derivation::{ AppId, CKDOutputOption, ElementG1, KeygenOutput, protocol::ckd as ckd_protocol, }, @@ -21,8 +21,8 @@ use threshold_signatures::{ type PreparedSimulatedCkd = PreparedOutputs; -fn threshold() -> ReconstructionLowerBound { - ReconstructionLowerBound::from(*MAX_MALICIOUS + 1) +fn threshold() -> ReconstructionThreshold { + ReconstructionThreshold::from(*MAX_MALICIOUS + 1) } /// Benches the ckd protocol @@ -62,7 +62,7 @@ struct CkdSetup { } /// Expensive one-time setup: runs the full N-party protocol to capture snapshots -fn setup_ckd_snapshot(threshold: ReconstructionLowerBound) -> CkdSetup { +fn setup_ckd_snapshot(threshold: ReconstructionThreshold) -> CkdSetup { let mut rng = MockCryptoRng::seed_from_u64(41); let preps = prepare_ckd(threshold, &mut rng); let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) diff --git a/crates/threshold-signatures/benches/naive_ot_based_ecdsa.rs b/crates/threshold-signatures/benches/naive_ot_based_ecdsa.rs index e8735b2d16..71d3dc5787 100644 --- a/crates/threshold-signatures/benches/naive_ot_based_ecdsa.rs +++ b/crates/threshold-signatures/benches/naive_ot_based_ecdsa.rs @@ -8,12 +8,12 @@ use crate::bench_utils::{ }; use rand_core::SeedableRng; use threshold_signatures::{ - ReconstructionLowerBound, + ReconstructionThreshold, test_utils::{MockCryptoRng, run_protocol}, }; -fn threshold() -> ReconstructionLowerBound { - ReconstructionLowerBound::from(*MAX_MALICIOUS + 1) +fn threshold() -> ReconstructionThreshold { + ReconstructionThreshold::from(*MAX_MALICIOUS + 1) } fn participants_num() -> usize { diff --git a/crates/threshold-signatures/benches/simulate_dkg.rs b/crates/threshold-signatures/benches/simulate_dkg.rs index 33bf3aabec..1b7c29fa9a 100644 --- a/crates/threshold-signatures/benches/simulate_dkg.rs +++ b/crates/threshold-signatures/benches/simulate_dkg.rs @@ -6,7 +6,7 @@ mod bench_utils; use bench_utils::prepare_dkg; use threshold_signatures::{ - Ciphersuite, Element, ReconstructionLowerBound, Scalar, + Ciphersuite, Element, ReconstructionThreshold, Scalar, confidential_key_derivation::ciphersuite::BLS12381SHA256, frost_ed25519::Ed25519Sha512, frost_secp256k1::Secp256K1Sha256, @@ -15,7 +15,7 @@ use threshold_signatures::{ fn main() { let config = BenchConfig::from_env(); - let threshold = ReconstructionLowerBound::from(config.threshold); + let threshold = ReconstructionThreshold::from(config.threshold); let n = config.num_participants; println!("Protocol simulation: DKG"); @@ -50,7 +50,7 @@ fn main() { fn run_dkg( n: usize, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, config: &BenchConfig, ) -> SimulationMetrics where diff --git a/crates/threshold-signatures/benches/simulate_ecdsa.rs b/crates/threshold-signatures/benches/simulate_ecdsa.rs index 14b3599754..01c7971a15 100644 --- a/crates/threshold-signatures/benches/simulate_ecdsa.rs +++ b/crates/threshold-signatures/benches/simulate_ecdsa.rs @@ -7,7 +7,7 @@ mod bench_utils; use bench_utils::split_even_odd; use threshold_signatures::{ - MaxMalicious, ReconstructionLowerBound, + MaxMalicious, ReconstructionThreshold, ecdsa::{ self, ot_based_ecdsa::{self, triples::generate_triple_many}, @@ -30,7 +30,7 @@ type TriplesResult = Vec<(Participant, Vec)>; fn main() { let config = BenchConfig::from_env(); - let threshold = ReconstructionLowerBound::from(config.threshold); + let threshold = ReconstructionThreshold::from(config.threshold); let max_malicious = MaxMalicious::from(config.threshold - 1); println!("Protocol simulation: ECDSA (Cait-Sith vs DamgardEtAl)"); @@ -86,7 +86,7 @@ fn main() { fn bench_cait_sith( participants: &[Participant], key_packages: &[(Participant, ecdsa::KeygenOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, coordinator: Participant, pk: frost_secp256k1::VerifyingKey, config: &BenchConfig, @@ -196,7 +196,7 @@ fn bench_damgard( fn ot_run_triples( participants: &[Participant], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, latency: &LatencyModel, rng: &mut MockCryptoRng, ) -> (TriplesResult, SimulationMetrics) { @@ -215,7 +215,7 @@ fn ot_run_presign( participants: &[Participant], two_triples: &[(Participant, Vec)], key_packages: &[(Participant, ecdsa::KeygenOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, latency: &LatencyModel, ) -> ( Vec<(Participant, ot_based_ecdsa::PresignOutput)>, @@ -251,7 +251,7 @@ fn ot_run_presign( fn ot_run_sign( participants: &[Participant], presign_outputs: &[(Participant, ot_based_ecdsa::PresignOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, coordinator: Participant, pk: frost_secp256k1::VerifyingKey, latency: &LatencyModel, diff --git a/crates/threshold-signatures/benches/simulate_frost.rs b/crates/threshold-signatures/benches/simulate_frost.rs index 85739151cf..65d00e2802 100644 --- a/crates/threshold-signatures/benches/simulate_frost.rs +++ b/crates/threshold-signatures/benches/simulate_frost.rs @@ -7,7 +7,7 @@ mod bench_utils; use bench_utils::ed25519_build_presign_protocols; use threshold_signatures::{ - ReconstructionLowerBound, + ReconstructionThreshold, frost::eddsa, participants::Participant, protocol::Protocol, @@ -19,7 +19,7 @@ use threshold_signatures::{ fn main() { let config = BenchConfig::from_env(); - let threshold = ReconstructionLowerBound::from(config.threshold); + let threshold = ReconstructionThreshold::from(config.threshold); println!("Protocol simulation: EdDSA FROST signing"); println!( @@ -121,7 +121,7 @@ fn main() { fn run_presign( participants: &[Participant], key_packages: &[(Participant, eddsa::KeygenOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, latency: &LatencyModel, rng: &mut MockCryptoRng, ) -> (Vec<(Participant, eddsa::PresignOutput)>, SimulationMetrics) { @@ -134,7 +134,7 @@ fn run_presign( fn run_sign_v1( participants: &[Participant], key_packages: &[(Participant, eddsa::KeygenOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, coordinator: Participant, message: &[u8], latency: &LatencyModel, @@ -167,7 +167,7 @@ fn run_sign_v2( participants: &[Participant], key_packages: &[(Participant, eddsa::KeygenOutput)], presign_outputs: &[(Participant, eddsa::PresignOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, coordinator: Participant, message: &[u8], latency: &LatencyModel, diff --git a/crates/threshold-signatures/src/dkg.rs b/crates/threshold-signatures/src/dkg.rs index bc28c5501e..ab2e10b58c 100644 --- a/crates/threshold-signatures/src/dkg.rs +++ b/crates/threshold-signatures/src/dkg.rs @@ -9,7 +9,7 @@ use crate::participants::{Participant, ParticipantList, ParticipantMap}; use crate::protocol::{ echo_broadcast::do_broadcast, helpers::recv_from_others, internal::SharedChannel, }; -use crate::{KeygenOutput, ReconstructionLowerBound}; +use crate::{KeygenOutput, ReconstructionThreshold}; use frost_core::keys::{ CoefficientCommitment, SecretShare, SigningShare, VerifiableSecretSharingCommitment, @@ -174,7 +174,7 @@ fn internal_verify_proof_of_knowledge( fn verify_proof_of_knowledge( session_id: &HashOutput, domain_separator: &mut DomainSeparator, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, participant: Participant, old_participants: Option, commitment: &VerifiableSecretSharingCommitment, @@ -241,7 +241,7 @@ fn verify_commitment_hash( /// i.e. when the new participant sent a polynomial with a non-existant constant term /// such a participant would do so as the identity is not serializable fn insert_identity_if_missing( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, commitment_i: &VerifiableSecretSharingCommitment, ) -> VerifiableSecretSharingCommitment { // in case the participant was new and it sent a polynomial of length @@ -345,7 +345,7 @@ async fn do_keyshare( mut chan: SharedChannel, participants: ParticipantList, me: Participant, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, secret: Scalar, old_reshare_package: Option<(VerifyingKey, ParticipantList)>, rng: &mut impl CryptoRngCore, @@ -543,7 +543,7 @@ pub async fn do_keygen( chan: SharedChannel, participants: ParticipantList, me: Participant, - threshold: impl Into, + threshold: impl Into, mut rng: impl CryptoRngCore, ) -> Result, ProtocolError> { let threshold = threshold.into(); @@ -560,7 +560,7 @@ pub async fn do_keygen( pub fn assert_key_invariants( participants: &[Participant], me: Participant, - threshold: impl Into, + threshold: impl Into, ) -> Result { let threshold = usize::from(threshold.into()); // need enough participants @@ -603,7 +603,7 @@ pub async fn do_reshare( chan: SharedChannel, participants: ParticipantList, me: Participant, - threshold: impl Into, + threshold: impl Into, old_signing_key: Option>, old_public_key: VerifyingKey, old_participants: ParticipantList, @@ -640,9 +640,9 @@ pub async fn do_reshare( pub fn assert_reshare_keys_invariants( participants: &[Participant], me: Participant, - threshold: impl Into, + threshold: impl Into, old_signing_key: Option>, - old_threshold: impl Into, + old_threshold: impl Into, old_participants: &[Participant], ) -> Result<(ParticipantList, ParticipantList), InitializationError> { let threshold = usize::from(threshold.into()); @@ -687,7 +687,7 @@ pub mod test { generate_participants, run_and_assert_buffer_entries, run_keygen, run_refresh, run_reshare, }; use crate::{DKG_MAX_INCOMING_BUFFER_ENTRIES, keygen, reshare}; - use crate::{KeygenOutput, ReconstructionLowerBound}; + use crate::{KeygenOutput, ReconstructionThreshold}; use frost_core::{Field, Group}; use rand_core::{CryptoRngCore, SeedableRng}; use rstest::rstest; @@ -724,7 +724,7 @@ pub mod test { pub fn test_keygen( participants: &[Participant], - threshold: impl Into + Copy + Send + 'static, + threshold: impl Into + Copy + Send + 'static, rng: &mut R, ) -> Vec<(Participant, KeygenOutput)> where @@ -766,7 +766,7 @@ pub mod test { pub fn test_refresh( participants: &[Participant], - threshold: impl Into + Copy + Send + 'static, + threshold: impl Into + Copy + Send + 'static, rng: &mut R, ) -> Vec<(Participant, KeygenOutput)> where @@ -786,8 +786,8 @@ pub mod test { pub fn test_reshare( participants: &[Participant], - threshold0: impl Into + Copy + Send + 'static, - threshold1: impl Into + Copy + Send + 'static, + threshold0: impl Into + Copy + Send + 'static, + threshold1: impl Into + Copy + Send + 'static, rng: &mut R, ) -> Vec<(Participant, KeygenOutput)> where diff --git a/crates/threshold-signatures/src/ecdsa/README.md b/crates/threshold-signatures/src/ecdsa/README.md index b6314667b1..61df6bd60b 100644 --- a/crates/threshold-signatures/src/ecdsa/README.md +++ b/crates/threshold-signatures/src/ecdsa/README.md @@ -15,7 +15,7 @@ Both schemes share common types defined in this module: ### OT-based ECDSA (`ot_based_ecdsa/`) -Originally imported from the [Cait-Sith](https://github.com/cronokirby/cait-sith) library. Uses an **offline phase with two protocols** (triple generation + presigning) to enable efficient one-round online signing. Requires `N >= t` participants where `t = ReconstructionLowerBound`. +Originally imported from the [Cait-Sith](https://github.com/cronokirby/cait-sith) library. Uses an **offline phase with two protocols** (triple generation + presigning) to enable efficient one-round online signing. Requires `N >= t` participants where `t = ReconstructionThreshold`. See [`ot_based_ecdsa/README.md`](ot_based_ecdsa/README.md) for details. @@ -33,7 +33,7 @@ See [`robust_ecdsa/README.md`](robust_ecdsa/README.md) for details. | **Offline rounds** | 11+ | 3 | | **Sign rounds** | 1 | 1 | | **Triple requirement** | 2 triples per presignature | None | -| **Threshold parameter** | `ReconstructionLowerBound` | `MaxMalicious` | +| **Threshold parameter** | `ReconstructionThreshold` | `MaxMalicious` | | **Scaling** | Less efficient with many participants | Better efficiency and bandwidth | See the [benchmark analysis](../../docs/benches/results.md) for detailed performance comparisons. diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa.rs index 7b735368b3..7ba4bf38a3 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa.rs @@ -7,7 +7,7 @@ mod test; use crate::errors::ProtocolError; use crate::{ - ReconstructionLowerBound, + ReconstructionThreshold, ecdsa::{ AffinePoint, KeygenOutput, RerandomizationArguments, Scalar, ot_based_ecdsa::triples::{TriplePub, TripleShare}, @@ -28,7 +28,7 @@ pub struct PresignArguments { /// This is of type `KeygenOutput` from Frost implementation pub keygen_out: KeygenOutput, /// The desired threshold for the presignature, which must match the original threshold - pub threshold: ReconstructionLowerBound, + pub threshold: ReconstructionThreshold, } /// The output of the presigning protocol. diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs index 5f0267ecb8..76c17af785 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs @@ -2,7 +2,7 @@ use elliptic_curve::scalar::IsHigh; use subtle::ConditionallySelectable; use super::RerandomizedPresignOutput; -use crate::ReconstructionLowerBound; +use crate::ReconstructionThreshold; use crate::errors::{InitializationError, ProtocolError}; use crate::participants::{Participant, ParticipantList}; use crate::{ @@ -35,7 +35,7 @@ pub fn sign( msg_hash: Scalar, ) -> Result + use, InitializationError> where - T: Into, + T: Into, { let threshold = usize::from(threshold.into()); if participants.len() < 2 { diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/test.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/test.rs index 0437c50897..f770ea3fdb 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/test.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/test.rs @@ -9,7 +9,7 @@ use crate::test_utils::{ check_one_coordinator_output, generate_participants, generate_participants_with_random_ids, run_keygen, run_protocol, run_refresh, run_reshare, run_sign, }; -use crate::{Participant, ReconstructionLowerBound, protocol::Protocol}; +use crate::{Participant, ReconstructionThreshold, protocol::Protocol}; use crate::crypto::hash::test::scalar_hash_secp256k1; use crate::ecdsa::{ @@ -25,7 +25,7 @@ use std::error::Error; /// This signing does not rerandomize the presignatures and tests only the core protocol pub fn run_sign_without_rerandomization( participants_presign: &[(Participant, PresignOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, public_key: Element, msg: &[u8], rng: &mut impl CryptoRngCore, @@ -78,7 +78,7 @@ pub fn run_sign_without_rerandomization( /// rerandomizing the presignatures pub fn run_sign_with_rerandomization( participants_presign: &[(Participant, PresignOutput)], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, public_key: Element, msg: &[u8], rng: &mut impl CryptoRngCore, @@ -153,7 +153,7 @@ pub fn run_presign( shares1: Vec, pub0: &TriplePub, pub1: &TriplePub, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> Vec<(Participant, PresignOutput)> { assert!(participants.len() == shares0.len()); assert!(participants.len() == shares1.len()); @@ -461,7 +461,7 @@ fn test_robustness_with_rerandomization() { fn test_robustness(run_sign: F, rng: &mut R) where - F: Fn(&[(Participant, PresignOutput)], ReconstructionLowerBound, Element, &[u8], &mut R) -> T, + F: Fn(&[(Participant, PresignOutput)], ReconstructionThreshold, Element, &[u8], &mut R) -> T, { let participants_count = 7; let mut participants = generate_participants_with_random_ids(participants_count, rng); diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples.rs index c44c22170b..3c8ec6defe 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples.rs @@ -43,7 +43,7 @@ use serde::{Deserialize, Serialize}; use zeroize::ZeroizeOnDrop; use crate::{ - ReconstructionLowerBound, + ReconstructionThreshold, ecdsa::{AffinePoint, Scalar}, participants::Participant, }; @@ -61,7 +61,7 @@ pub struct TriplePub { /// The participants in generating this triple. pub participants: Vec, /// The threshold which will be able to reconstruct it. - pub threshold: ReconstructionLowerBound, + pub threshold: ReconstructionThreshold, } /// Represents a share of a triple. diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs index c30d59ed24..57c2c1f99c 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use serde_with::serde_as; use crate::participants::{Participant, ParticipantList, ParticipantMap}; -use crate::thresholds::ReconstructionLowerBound; +use crate::thresholds::ReconstructionThreshold; use crate::{ crypto::{ commitment::{Commitment, commit}, @@ -32,7 +32,7 @@ use super::{TriplePub, TripleShare, multiplication::multiplication_many}; /// LABEL, NAME, Participants, threshold fn create_transcript( participants: &ParticipantList, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> Result { let mut transcript = Transcript::new(NEAR_TRIPLE_GENERATION_LABEL); @@ -75,7 +75,7 @@ async fn do_generation( comms: Comms, participants: ParticipantList, me: Participant, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, rng: impl CryptoRngCore, ) -> Result { let mut triple = do_generation_many::<1>(comms, participants, me, threshold, rng).await?; @@ -127,7 +127,7 @@ async fn do_generation_many( comms: Comms, participants: ParticipantList, me: Participant, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, mut rng: impl CryptoRngCore, ) -> Result { if N == 0 { @@ -709,8 +709,8 @@ async fn do_generation_many( /// provided to this function. fn validate_triple_inputs( participants: &[Participant], - threshold: impl Into, -) -> Result<(ParticipantList, ReconstructionLowerBound), InitializationError> { + threshold: impl Into, +) -> Result<(ParticipantList, ReconstructionThreshold), InitializationError> { let threshold = threshold.into(); let threshold_value = threshold.value(); if participants.len() < 2 { @@ -787,7 +787,7 @@ pub fn generate_triple( rng: R, ) -> Result + use, InitializationError> where - T: Into, + T: Into, R: CryptoRngCore + Send + 'static, { let (participants, threshold) = validate_triple_inputs(participants, threshold)?; @@ -807,7 +807,7 @@ pub fn generate_triple_many( rng: R, ) -> Result + use, InitializationError> where - T: Into, + T: Into, R: CryptoRngCore + Send + 'static, { let (participants, threshold) = validate_triple_inputs(participants, threshold)?; diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs index 393bf2ab0c..88cd9ba2f5 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs @@ -7,7 +7,7 @@ use super::{ }; use crate::{ - ReconstructionLowerBound, + ReconstructionThreshold, ecdsa::{Field, Polynomial, ProjectivePoint, Secp256K1ScalarField}, test_utils::MockCryptoRng, }; @@ -25,7 +25,7 @@ use crate::test_utils::run_two_party_protocol; pub fn deal( rng: &mut impl CryptoRngCore, participants: &[Participant], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> Result<(TriplePub, Vec), ProtocolError> { let a = Secp256K1ScalarField::random(&mut *rng); let b = Secp256K1ScalarField::random(&mut *rng); diff --git a/crates/threshold-signatures/src/frost/eddsa/sign.rs b/crates/threshold-signatures/src/frost/eddsa/sign.rs index a5d3b9897d..9206e5bc72 100644 --- a/crates/threshold-signatures/src/frost/eddsa/sign.rs +++ b/crates/threshold-signatures/src/frost/eddsa/sign.rs @@ -2,7 +2,7 @@ //! into `cait-sith::Protocol` representation. use super::{KeygenOutput, PresignOutput, SignatureOption}; use crate::{ - Participant, ParticipantList, ReconstructionLowerBound, + Participant, ParticipantList, ReconstructionThreshold, errors::{InitializationError, ProtocolError}, frost::assert_sign_inputs, protocol::{ @@ -56,7 +56,7 @@ pub fn sign_v1( rng: R, ) -> Result + use, InitializationError> where - T: Into, + T: Into, R: CryptoRngCore + Send + 'static, { let threshold = threshold.into(); @@ -87,7 +87,7 @@ pub fn sign_v2( message: Vec, ) -> Result + use, InitializationError> where - T: Into + Copy, + T: Into + Copy, { let participants = assert_sign_inputs(participants, threshold, me, coordinator)?; @@ -118,7 +118,7 @@ where async fn do_sign_coordinator_v1( mut chan: SharedChannel, participants: ParticipantList, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, keygen_output: KeygenOutput, message: Vec, @@ -205,7 +205,7 @@ async fn do_sign_coordinator_v1( async fn do_sign_coordinator_v2( mut chan: SharedChannel, participants: ParticipantList, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, keygen_output: KeygenOutput, presignature: &PresignOutput, @@ -271,7 +271,7 @@ async fn do_sign_coordinator_v2( /// For reference, see how RFC 8032 handles "pre-hashing". async fn do_sign_participant_v1( mut chan: SharedChannel, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, coordinator: Participant, keygen_output: KeygenOutput, @@ -351,7 +351,7 @@ async fn do_sign_participant_v1( /// For reference, see how RFC 8032 handles "pre-hashing". fn do_sign_participant_v2( mut chan: SharedChannel, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, coordinator: Participant, keygen_output: &KeygenOutput, @@ -393,7 +393,7 @@ fn do_sign_participant_v2( /// A function that takes a signing share and a keygenOutput /// and construct a public key package used for frost signing fn construct_key_package( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, signing_share: SigningShare, verifying_key: &VerifyingKey, @@ -416,7 +416,7 @@ fn construct_key_package( async fn fut_wrapper_v1( chan: SharedChannel, participants: ParticipantList, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, coordinator: Participant, keygen_output: KeygenOutput, @@ -452,7 +452,7 @@ async fn fut_wrapper_v1( async fn fut_wrapper_v2( chan: SharedChannel, participants: ParticipantList, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, coordinator: Participant, keygen_output: KeygenOutput, diff --git a/crates/threshold-signatures/src/frost/eddsa/test.rs b/crates/threshold-signatures/src/frost/eddsa/test.rs index f64ddaaad7..6203df3ad3 100644 --- a/crates/threshold-signatures/src/frost/eddsa/test.rs +++ b/crates/threshold-signatures/src/frost/eddsa/test.rs @@ -1,5 +1,5 @@ use crate::{ - Participant, ReconstructionLowerBound, + Participant, ReconstructionThreshold, crypto::hash::HashOutput, frost::eddsa::{ KeygenOutput, PresignOutput, SignatureOption, @@ -21,7 +21,7 @@ pub fn run_sign_v1( participants: &[(Participant, KeygenOutput)], actual_signers: usize, coordinator: Participant, - threshold: impl Into + Copy + 'static, + threshold: impl Into + Copy + 'static, msg_hash: HashOutput, rng: &mut impl CryptoRngCore, ) -> Result, Box> { @@ -59,7 +59,7 @@ pub fn run_sign_v1( pub fn run_presign( participants: &[(Participant, KeygenOutput)], - threshold: impl Into + Copy, + threshold: impl Into + Copy, actual_signers: usize, rng: impl CryptoRngCore + Send + Clone + 'static, ) -> Result, Box> { @@ -70,7 +70,7 @@ pub fn run_sign_v2( participants: &[(Participant, KeygenOutput)], actual_signers: usize, coordinator: Participant, - threshold: impl Into + Copy + 'static, + threshold: impl Into + Copy + 'static, msg_hash: HashOutput, rng: impl CryptoRngCore + Send + Clone + 'static, ) -> Result, Box> { diff --git a/crates/threshold-signatures/src/frost/presign.rs b/crates/threshold-signatures/src/frost/presign.rs index 1760745c52..d14c70e423 100644 --- a/crates/threshold-signatures/src/frost/presign.rs +++ b/crates/threshold-signatures/src/frost/presign.rs @@ -9,7 +9,7 @@ use std::collections::BTreeMap; use zeroize::ZeroizeOnDrop; use crate::{ - Ciphersuite, ReconstructionLowerBound, + Ciphersuite, ReconstructionThreshold, errors::{InitializationError, ProtocolError}, participants::{Participant, ParticipantList}, protocol::{ @@ -24,7 +24,7 @@ pub struct PresignArguments { /// The output of key generation, i.e. our share of the secret key. pub private_share: SigningShare, /// The threshold for the scheme - pub threshold: ReconstructionLowerBound, + pub threshold: ReconstructionThreshold, } /// The output of the presigning protocol. diff --git a/crates/threshold-signatures/src/frost/redjubjub/sign.rs b/crates/threshold-signatures/src/frost/redjubjub/sign.rs index 806eca4784..5823248684 100644 --- a/crates/threshold-signatures/src/frost/redjubjub/sign.rs +++ b/crates/threshold-signatures/src/frost/redjubjub/sign.rs @@ -1,7 +1,7 @@ //! This module and the frost one are supposed to have the same helper function use super::{KeygenOutput, PresignOutput, SignatureOption}; use crate::{ - ReconstructionLowerBound, + ReconstructionThreshold, crypto::random::Randomness, errors::{InitializationError, ProtocolError}, frost::assert_sign_inputs, @@ -60,7 +60,7 @@ pub fn sign( randomizer_seed: Option, ) -> Result + use, InitializationError> where - T: Into, + T: Into, { let threshold = threshold.into(); let participants = assert_sign_inputs(participants, threshold, me, coordinator)?; @@ -85,7 +85,7 @@ where async fn fut_wrapper( chan: SharedChannel, participants: ParticipantList, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, coordinator: Participant, keygen_output: KeygenOutput, @@ -146,7 +146,7 @@ async fn fut_wrapper( async fn do_sign_coordinator( mut chan: SharedChannel, participants: ParticipantList, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, keygen_output: KeygenOutput, presignature: &PresignOutput, @@ -220,7 +220,7 @@ async fn do_sign_coordinator( /// For reference, see how RFC 8032 handles "pre-hashing". async fn do_sign_participant( mut chan: SharedChannel, - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, coordinator: Participant, keygen_output: KeygenOutput, @@ -267,7 +267,7 @@ async fn do_sign_participant( /// A function that takes a signing share and a keygenOutput /// and construct a public key package used for frost signing fn construct_key_package( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, me: Participant, keygen_output: &KeygenOutput, ) -> Result { diff --git a/crates/threshold-signatures/src/frost/redjubjub/test.rs b/crates/threshold-signatures/src/frost/redjubjub/test.rs index fef5b25859..a904b53a03 100644 --- a/crates/threshold-signatures/src/frost/redjubjub/test.rs +++ b/crates/threshold-signatures/src/frost/redjubjub/test.rs @@ -1,5 +1,5 @@ use crate::{ - Participant, ReconstructionLowerBound, + Participant, ReconstructionThreshold, crypto::{ hash::{HashOutput, hash}, random::Randomness, @@ -24,7 +24,7 @@ type C = JubjubBlake2b512; pub fn run_presign( participants: &[(Participant, KeygenOutput)], - threshold: impl Into + Copy, + threshold: impl Into + Copy, actual_signers: usize, rng: impl CryptoRngCore + Send + Clone + 'static, ) -> Result, Box> { @@ -37,7 +37,7 @@ pub fn run_sign_with_presign( participants: &[(Participant, KeygenOutput)], actual_signers: usize, coordinator: Participant, - threshold: impl Into + Copy + 'static, + threshold: impl Into + Copy + 'static, msg_hash: HashOutput, ) -> Result, Box> { let mut rng = MockCryptoRng::seed_from_u64(644_221); diff --git a/crates/threshold-signatures/src/frost/sign_utils.rs b/crates/threshold-signatures/src/frost/sign_utils.rs index 21d646e971..a21e4dd4b1 100644 --- a/crates/threshold-signatures/src/frost/sign_utils.rs +++ b/crates/threshold-signatures/src/frost/sign_utils.rs @@ -1,5 +1,5 @@ use crate::{ - ReconstructionLowerBound, + ReconstructionThreshold, errors::InitializationError, participants::{Participant, ParticipantList}, }; @@ -7,7 +7,7 @@ use crate::{ /// Verifies that the sign inputs are valid pub fn assert_sign_inputs( participants: &[Participant], - threshold: impl Into, + threshold: impl Into, me: Participant, coordinator: Participant, ) -> Result { diff --git a/crates/threshold-signatures/src/lib.rs b/crates/threshold-signatures/src/lib.rs index 95c75dfee6..0834b1d6b5 100644 --- a/crates/threshold-signatures/src/lib.rs +++ b/crates/threshold-signatures/src/lib.rs @@ -36,7 +36,7 @@ use crate::errors::InitializationError; use crate::participants::Participant; use crate::protocol::Protocol; use crate::protocol::internal::{Comms, make_protocol}; -pub use crate::thresholds::{MaxMalicious, ReconstructionLowerBound}; +pub use crate::thresholds::{MaxMalicious, ReconstructionThreshold}; use rand_core::CryptoRngCore; use std::marker::Send; @@ -101,7 +101,7 @@ pub fn keygen( ) -> Result> + use, InitializationError> where C: Ciphersuite, - T: Into + Send + Copy + 'static, + T: Into + Send + Copy + 'static, R: CryptoRngCore + Send + 'static, { let comms = Comms::with_buffer_capacity(DKG_MAX_INCOMING_BUFFER_ENTRIES); @@ -124,8 +124,8 @@ pub fn reshare( ) -> Result> + use, InitializationError> where C: Ciphersuite, - OT: Into + Send + 'static, - NT: Into + Copy + Send + 'static, + OT: Into + Send + 'static, + NT: Into + Copy + Send + 'static, R: CryptoRngCore + Send + 'static, { let comms = Comms::with_buffer_capacity(DKG_MAX_INCOMING_BUFFER_ENTRIES); @@ -162,7 +162,7 @@ pub fn refresh( ) -> Result> + use, InitializationError> where C: Ciphersuite, - T: Into + Copy + Send + 'static, + T: Into + Copy + Send + 'static, R: CryptoRngCore + Send + 'static, { if old_signing_key.is_none() { diff --git a/crates/threshold-signatures/src/test_utils/dkg.rs b/crates/threshold-signatures/src/test_utils/dkg.rs index ec48505822..60d60482b2 100644 --- a/crates/threshold-signatures/src/test_utils/dkg.rs +++ b/crates/threshold-signatures/src/test_utils/dkg.rs @@ -10,7 +10,7 @@ use crate::participants::Participant; #[cfg(test)] use crate::test_utils::participants::generate_participants_with_random_ids; use crate::test_utils::{GenOutput, GenProtocol, run_protocol}; -use crate::thresholds::ReconstructionLowerBound; +use crate::thresholds::ReconstructionThreshold; use crate::{Ciphersuite, KeygenOutput, VerifyingKey, keygen, refresh, reshare}; // +++++++++++++++++ DKG Functions +++++++++++++++++ // @@ -22,7 +22,7 @@ type DKGGenProtocol = GenProtocol>; /// If the protocol succeeds, returns a sorted vector based on participants id pub fn run_keygen( participants: &[Participant], - threshold: impl Into + Copy + Send + 'static, + threshold: impl Into + Copy + Send + 'static, rng: &mut R, ) -> GenOutput { let mut protocols: DKGGenProtocol = Vec::with_capacity(participants.len()); @@ -41,7 +41,7 @@ pub fn run_keygen( participants: &[Participant], keys: &[(Participant, KeygenOutput)], - threshold: impl Into + Copy + Send + 'static, + threshold: impl Into + Copy + Send + 'static, rng: &mut R, ) -> GenOutput { let mut protocols: DKGGenProtocol = Vec::with_capacity(participants.len()); @@ -69,8 +69,8 @@ pub fn run_reshare, keys: &[(Participant, KeygenOutput)], - old_threshold: impl Into + Copy + Send + 'static, - new_threshold: impl Into + Copy + Send + 'static, + old_threshold: impl Into + Copy + Send + 'static, + new_threshold: impl Into + Copy + Send + 'static, new_participants: &[Participant], rng: &mut R, ) -> GenOutput { diff --git a/crates/threshold-signatures/src/test_utils/presign.rs b/crates/threshold-signatures/src/test_utils/presign.rs index ba4c6f3d4e..777966d651 100644 --- a/crates/threshold-signatures/src/test_utils/presign.rs +++ b/crates/threshold-signatures/src/test_utils/presign.rs @@ -7,7 +7,7 @@ use crate::ecdsa::{RerandomizationArguments, Tweak}; use crate::frost; use crate::test_utils::{GenProtocol, run_protocol}; use crate::{ - Ciphersuite, Participant, ParticipantList, ReconstructionLowerBound, Scalar, VerifyingKey, + Ciphersuite, Participant, ParticipantList, ReconstructionThreshold, Scalar, VerifyingKey, }; fn random_32_bytes(rng: &mut impl CryptoRngCore) -> [u8; 32] { @@ -50,7 +50,7 @@ pub fn ecdsa_generate_rerandpresig_args( type BoxErr = Box; pub fn frost_run_presignature( participants: &[(Participant, crate::KeygenOutput)], - threshold: impl Into + Copy, + threshold: impl Into + Copy, actual_signers: usize, mut rng: impl CryptoRngCore + Send + Clone + 'static, ) -> Result)>, BoxErr> diff --git a/crates/threshold-signatures/src/thresholds.rs b/crates/threshold-signatures/src/thresholds.rs index 621267f123..dd56f36dfc 100644 --- a/crates/threshold-signatures/src/thresholds.rs +++ b/crates/threshold-signatures/src/thresholds.rs @@ -10,7 +10,7 @@ pub struct MaxMalicious(usize); #[derive( Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, From, Into, )] -pub struct ReconstructionLowerBound(usize); +pub struct ReconstructionThreshold(usize); // ----- MaxMalicious conversions ----- impl MaxMalicious { @@ -19,14 +19,14 @@ impl MaxMalicious { } } -impl ReconstructionLowerBound { +impl ReconstructionThreshold { pub fn value(self) -> usize { self.0 } } /// Lower bound to reconstruct the secret is `MaxMalicious` + 1. -impl TryFrom for ReconstructionLowerBound { +impl TryFrom for ReconstructionThreshold { type Error = ThresholdError; fn try_from(m: MaxMalicious) -> Result { diff --git a/crates/threshold-signatures/tests/common.rs b/crates/threshold-signatures/tests/common.rs index 2f144ef4b3..c9e8537981 100644 --- a/crates/threshold-signatures/tests/common.rs +++ b/crates/threshold-signatures/tests/common.rs @@ -10,7 +10,7 @@ use rand::seq::SliceRandom as _; use rand_core::OsRng; use threshold_signatures::{ - self, Ciphersuite, Element, KeygenOutput, ReconstructionLowerBound, Scalar, + self, Ciphersuite, Element, KeygenOutput, ReconstructionThreshold, Scalar, errors::ProtocolError, frost_core::VerifyingKey, keygen, @@ -82,7 +82,7 @@ pub fn run_protocol( #[allow(clippy::missing_panics_doc)] pub fn run_keygen( participants: &[Participant], - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, ) -> HashMap> where Element: std::marker::Send, @@ -105,8 +105,8 @@ pub fn run_reshare( participants: &[Participant], pub_key: &VerifyingKey, keys: &[(Participant, KeygenOutput)], - old_threshold: ReconstructionLowerBound, - new_threshold: ReconstructionLowerBound, + old_threshold: ReconstructionThreshold, + new_threshold: ReconstructionThreshold, new_participants: &[Participant], ) -> HashMap> where diff --git a/crates/threshold-signatures/tests/eddsa.rs b/crates/threshold-signatures/tests/eddsa.rs index 2885de54da..b600053690 100644 --- a/crates/threshold-signatures/tests/eddsa.rs +++ b/crates/threshold-signatures/tests/eddsa.rs @@ -9,7 +9,7 @@ use common::{ use rand_core::OsRng; use threshold_signatures::{ - self, ReconstructionLowerBound, + self, ReconstructionThreshold, frost::eddsa::{ Ed25519Sha512, PresignOutput, SignatureOption, sign::{sign_v1, sign_v2}, @@ -22,7 +22,7 @@ type C = Ed25519Sha512; type KeygenOutput = threshold_signatures::KeygenOutput; fn run_sign_v1( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, participants: &[(Participant, KeygenOutput)], coordinator: Participant, msg_hash: &[u8], @@ -49,7 +49,7 @@ fn run_sign_v1( } fn run_sign_v2( - threshold: ReconstructionLowerBound, + threshold: ReconstructionThreshold, participants: &[(Participant, KeygenOutput)], coordinator: Participant, presig: &[(Participant, PresignOutput)], diff --git a/docs/design/domain-separation.md b/docs/design/domain-separation.md index 60adcb5700..5b4e850fc4 100644 --- a/docs/design/domain-separation.md +++ b/docs/design/domain-separation.md @@ -87,7 +87,7 @@ The node (`crates/node/`) imports types from **both** the internal contract crat ``` Contract ThresholdParameters.threshold (Threshold(u64)) → Coordinator extracts: threshold: usize = mpc_config.participants.threshold.try_into()? - → Converts to: ReconstructionLowerBound::from(threshold) + → Converts to: ReconstructionThreshold::from(threshold) → For CaitSith/FROST: passed directly to keygen/sign → For DamgardEtAl: translate_threshold() → MaxMalicious::from((n_signers - 1) / 2) ``` @@ -901,7 +901,7 @@ During resharing, each domain's key must be reshared with its own `Reconstructio ```rust // Current (hack): let threshold: usize = mpc_config.participants.threshold.try_into()?; -let threshold = ReconstructionLowerBound::from(threshold); +let threshold = ReconstructionThreshold::from(threshold); // Proposed (clean): let dk = distributed_key_registry.get(distributed_key_id); @@ -911,7 +911,7 @@ let threshold = match dk.protocol { let max_malicious = MaxMalicious::from(dk.reconstruction_threshold.inner() - 1); // Use MaxMalicious directly, no translation needed } - _ => ReconstructionLowerBound::from(dk.reconstruction_threshold.inner()), + _ => ReconstructionThreshold::from(dk.reconstruction_threshold.inner()), }; ``` From 4e496c37c1dec30bb09c1c0e5abfae1597957e1c Mon Sep 17 00:00:00 2001 From: Simon Rastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Mon, 15 Jun 2026 16:07:49 +0200 Subject: [PATCH 2/9] Fixing conflicting names with alias --- crates/node/src/coordinator.rs | 6 +++--- crates/node/src/key_events.rs | 3 ++- crates/node/src/providers/ecdsa.rs | 8 ++++---- crates/node/src/providers/ecdsa/presign.rs | 10 +++++----- crates/node/src/providers/ecdsa/triple.rs | 16 ++++++++-------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/crates/node/src/coordinator.rs b/crates/node/src/coordinator.rs index 911437adf8..d5ff81ebca 100644 --- a/crates/node/src/coordinator.rs +++ b/crates/node/src/coordinator.rs @@ -38,7 +38,7 @@ use near_time::Clock; use std::collections::HashMap; use std::future::Future; use std::sync::{Arc, Mutex}; -use threshold_signatures::ReconstructionThreshold; +use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; use threshold_signatures::{confidential_key_derivation, ecdsa, frost::eddsa}; use tokio::select; use tokio::sync::mpsc::unbounded_channel; @@ -332,7 +332,7 @@ where let (network_client, channel_receiver, _handle) = run_network_client(Arc::new(sender), Box::new(receiver)); let threshold: usize = mpc_config.participants.threshold.try_into()?; - let threshold = ReconstructionThreshold::from(threshold); + let threshold = TSReconstructionThreshold::from(threshold); if mpc_config.is_leader_for_key_event() { keygen_leader( network_client, @@ -780,7 +780,7 @@ where let args = Arc::new(ResharingArgs { previous_keyset, existing_keyshares, - new_threshold: ReconstructionThreshold::from(new_threshold), + new_threshold: TSReconstructionThreshold::from(new_threshold), old_participants: current_running_state.participants, }); diff --git a/crates/node/src/key_events.rs b/crates/node/src/key_events.rs index d02a09b70d..b9d1d9cc6a 100644 --- a/crates/node/src/key_events.rs +++ b/crates/node/src/key_events.rs @@ -731,6 +731,7 @@ mod tests { }; use std::collections::BTreeSet; use std::sync::atomic::{AtomicUsize, Ordering}; + use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; #[rstest::rstest] #[tokio::test(start_paused = true)] @@ -900,7 +901,7 @@ mod tests { Arc::new(ResharingArgs { previous_keyset: Keyset::new(EpochId::new(5), vec![]), existing_keyshares: None, - new_threshold: ReconstructionThreshold::from(3), + new_threshold: TSReconstructionThreshold::from(3), old_participants: ParticipantsConfig { threshold: 3, participants: vec![], diff --git a/crates/node/src/providers/ecdsa.rs b/crates/node/src/providers/ecdsa.rs index 71009c0947..2f749a49b0 100644 --- a/crates/node/src/providers/ecdsa.rs +++ b/crates/node/src/providers/ecdsa.rs @@ -26,7 +26,7 @@ use mpc_primitives::ReconstructionThreshold; use mpc_primitives::domain::DomainId; use near_time::Clock; use std::sync::Arc; -use threshold_signatures::ReconstructionThreshold; +use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; use threshold_signatures::ecdsa::KeygenOutput; use threshold_signatures::ecdsa::Signature; use threshold_signatures::frost_secp256k1::VerifyingKey; @@ -193,14 +193,14 @@ impl SignatureProvider for EcdsaSignatureProvider { } async fn run_key_generation_client( - threshold: ReconstructionThreshold, + threshold: TSReconstructionThreshold, channel: NetworkTaskChannel, ) -> anyhow::Result { EcdsaSignatureProvider::run_key_generation_client_internal(threshold, channel).await } async fn run_key_resharing_client( - new_threshold: ReconstructionThreshold, + new_threshold: TSReconstructionThreshold, my_share: Option, public_key: VerifyingKey, old_participants: &ParticipantsConfig, @@ -272,7 +272,7 @@ impl SignatureProvider for EcdsaSignatureProvider { // network-wide threshold. let threshold = ReconstructionThreshold::new(self.mpc_config.participants.threshold); let threshold_usize: usize = threshold.inner().try_into()?; - let threshold_bound = ReconstructionThreshold::from(threshold_usize); + let threshold_bound = TSReconstructionThreshold::from(threshold_usize); let triple_store = self.triple_store_for_t(threshold)?; let generate_triples = tracking::spawn( diff --git a/crates/node/src/providers/ecdsa/presign.rs b/crates/node/src/providers/ecdsa/presign.rs index c5afbe24be..6c8bf85fb6 100644 --- a/crates/node/src/providers/ecdsa/presign.rs +++ b/crates/node/src/providers/ecdsa/presign.rs @@ -19,7 +19,7 @@ use serde::{Deserialize, Serialize}; use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::time::Duration; -use threshold_signatures::ReconstructionThreshold; +use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; use threshold_signatures::ecdsa::ot_based_ecdsa::triples::TripleGenerationOutput; use threshold_signatures::ecdsa::ot_based_ecdsa::{ PresignArguments, PresignOutput, presign::presign, @@ -66,7 +66,7 @@ impl EcdsaSignatureProvider { /// so that needs to be separately handled. pub(super) async fn run_background_presignature_generation( client: Arc, - threshold: ReconstructionThreshold, + threshold: TSReconstructionThreshold, config: Arc, triple_store: Arc, domain_id: DomainId, @@ -186,7 +186,7 @@ impl EcdsaSignatureProvider { let threshold = ReconstructionThreshold::new(threshold_usize.try_into()?); let triple_store = self.triple_store_for_t(threshold)?; FollowerPresignComputation { - threshold: ReconstructionThreshold::from(threshold_usize), + threshold: TSReconstructionThreshold::from(threshold_usize), keygen_out: domain_data.keyshare, triple_store, paired_triple_id, @@ -220,7 +220,7 @@ impl HasParticipants for PresignOutputWithParticipants { /// Performs an MPC presignature operation. This is shared for the initiator /// and for passive participants. pub struct PresignComputation { - threshold: ReconstructionThreshold, + threshold: TSReconstructionThreshold, triple0: TripleGenerationOutput, triple1: TripleGenerationOutput, keygen_out: KeygenOutput, @@ -260,7 +260,7 @@ impl MpcLeaderCentricComputation for PresignComputation { /// The difference is: we need to read the triples from the triple store (which may fail), /// and we need to write the presignature to the presignature store before completing. pub struct FollowerPresignComputation { - pub threshold: ReconstructionThreshold, + pub threshold: TSReconstructionThreshold, pub paired_triple_id: UniqueId, pub keygen_out: KeygenOutput, pub triple_store: Arc, diff --git a/crates/node/src/providers/ecdsa/triple.rs b/crates/node/src/providers/ecdsa/triple.rs index c75a3e2ff5..d810d24a87 100644 --- a/crates/node/src/providers/ecdsa/triple.rs +++ b/crates/node/src/providers/ecdsa/triple.rs @@ -18,7 +18,7 @@ use rand::rngs::OsRng; use std::ops::Deref; use std::sync::Arc; use std::time::Duration; -use threshold_signatures::ReconstructionThreshold; +use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; use threshold_signatures::ecdsa::ot_based_ecdsa::triples::TripleGenerationOutput; use threshold_signatures::participants::Participant; @@ -74,7 +74,7 @@ impl EcdsaSignatureProvider { mpc_config: Arc, config: Arc, triple_store: Arc, - threshold: ReconstructionThreshold, + threshold: TSReconstructionThreshold, ) -> ! { let in_flight_generations = InFlightGenerationTracker::new(); let parallelism_limiter = Arc::new(tokio::sync::Semaphore::new(config.concurrency)); @@ -212,7 +212,7 @@ impl EcdsaSignatureProvider { let threshold = ReconstructionThreshold::new(threshold_usize.try_into()?); let triple_store = self.triple_store_for_t(threshold)?; FollowerManyTripleGenerationComputation:: { - threshold: ReconstructionThreshold::from(threshold_usize), + threshold: TSReconstructionThreshold::from(threshold_usize), out_triple_id_start: start, out_triple_store: triple_store, } @@ -240,7 +240,7 @@ impl HasParticipants for PairedTriple { /// Generates many cait-sith triples at once. This can significantly save the /// *number* of network messages. pub struct ManyTripleGenerationComputation { - pub threshold: ReconstructionThreshold, + pub threshold: TSReconstructionThreshold, } #[async_trait::async_trait] @@ -288,7 +288,7 @@ impl MpcLeaderCentricComputation> /// The follower version of the triple generation. The difference is that the follower will only /// complete the computation after successfully persisting the triples to storage. pub struct FollowerManyTripleGenerationComputation { - pub threshold: ReconstructionThreshold, + pub threshold: TSReconstructionThreshold, pub out_triple_store: Arc, pub out_triple_id_start: UniqueId, } @@ -348,7 +348,7 @@ mod tests { use futures::{FutureExt, StreamExt, stream}; use std::collections::HashMap; use std::sync::Arc; - use threshold_signatures::ReconstructionThreshold; + use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; use threshold_signatures::test_utils::generate_participants; use tokio::sync::mpsc; @@ -405,7 +405,7 @@ mod tests { panic!("Unexpected task id"); }; let triples = ManyTripleGenerationComputation:: { - threshold: ReconstructionThreshold::from(THRESHOLD), + threshold: TSReconstructionThreshold::from(THRESHOLD), } .perform_leader_centric_computation( channel, @@ -453,7 +453,7 @@ mod tests { let result = tracking::spawn( &format!("task {:?}", task_id), ManyTripleGenerationComputation:: { - threshold: ReconstructionThreshold::from(THRESHOLD), + threshold: TSReconstructionThreshold::from(THRESHOLD), } .perform_leader_centric_computation( channel, From 4b53ead797797c05cbc72352cafa224ae979c149 Mon Sep 17 00:00:00 2001 From: Simon Rastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Tue, 16 Jun 2026 19:10:47 +0200 Subject: [PATCH 3/9] merging with main --- crates/node/src/assets/cleanup.rs | 3 +- crates/node/src/assets/test_utils.rs | 3 +- crates/node/src/coordinator.rs | 8 ++-- crates/node/src/providers/ckd/sign.rs | 2 +- crates/node/src/providers/ecdsa.rs | 9 ++--- crates/node/src/providers/ecdsa/presign.rs | 11 +++--- crates/node/src/providers/ecdsa/triple.rs | 18 ++++----- crates/node/src/providers/eddsa/sign.rs | 2 +- crates/node/src/providers/robust_ecdsa.rs | 9 ++--- .../benches/advanced_eddsa_frost_sign_v1.rs | 2 +- .../benches/advanced_eddsa_frost_sign_v2.rs | 6 +-- .../benches/bench_utils/frost_eddsa.rs | 6 +-- crates/threshold-signatures/benches/ckd.rs | 2 +- crates/threshold-signatures/src/dkg.rs | 12 +++--- .../src/ecdsa/ot_based_ecdsa/presign.rs | 4 +- .../src/ecdsa/ot_based_ecdsa/sign.rs | 2 +- .../ot_based_ecdsa/triples/generation.rs | 19 ++++------ .../src/ecdsa/ot_based_ecdsa/triples/test.rs | 2 +- .../src/frost/eddsa/sign.rs | 2 +- .../threshold-signatures/src/frost/presign.rs | 4 +- .../src/frost/redjubjub/sign.rs | 2 +- .../src/frost/sign_utils.rs | 4 +- crates/threshold-signatures/src/thresholds.rs | 38 ++++++++++++++++--- 23 files changed, 94 insertions(+), 76 deletions(-) diff --git a/crates/node/src/assets/cleanup.rs b/crates/node/src/assets/cleanup.rs index 31e7b26a9c..76fc8ad466 100644 --- a/crates/node/src/assets/cleanup.rs +++ b/crates/node/src/assets/cleanup.rs @@ -4,9 +4,10 @@ use crate::db::{DBCol, EPOCH_ID_KEY, SecretDB}; use crate::primitives; use crate::providers::ecdsa::presign::PresignOutputWithParticipants; use crate::providers::ecdsa::triple::PairedTriple; -use mpc_primitives::{EpochId, ReconstructionThreshold, domain::DomainId}; +use mpc_primitives::{EpochId, domain::DomainId}; use serde::{self, Deserialize, Serialize}; use std::sync::Arc; +use threshold_signatures::ReconstructionThreshold; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct EpochData { diff --git a/crates/node/src/assets/test_utils.rs b/crates/node/src/assets/test_utils.rs index 2e63aee8f3..ae16f2b0b9 100644 --- a/crates/node/src/assets/test_utils.rs +++ b/crates/node/src/assets/test_utils.rs @@ -14,13 +14,14 @@ use ed25519_dalek::{SigningKey, VerifyingKey}; use k256::ProjectivePoint; use mpc_contract::primitives::test_utils::gen_participants; use mpc_contract::primitives::thresholds::{Threshold, ThresholdParameters}; -use mpc_primitives::{EpochId, ReconstructionThreshold, domain::DomainId}; +use mpc_primitives::{EpochId, domain::DomainId}; use near_time::FakeClock; use rand::RngCore; use rand::rngs::OsRng; use serde::Serialize; use serde::de::DeserializeOwned; use std::sync::{Arc, Mutex}; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::Polynomial; use threshold_signatures::ecdsa::ot_based_ecdsa::PresignOutput; use threshold_signatures::ecdsa::ot_based_ecdsa::triples::{ diff --git a/crates/node/src/coordinator.rs b/crates/node/src/coordinator.rs index d5ff81ebca..5c4ab1f002 100644 --- a/crates/node/src/coordinator.rs +++ b/crates/node/src/coordinator.rs @@ -32,13 +32,13 @@ use crate::web::DebugRequest; use futures::FutureExt; use futures::future::BoxFuture; use mpc_node_config::ConfigFile; +use mpc_primitives::EpochId; use mpc_primitives::domain::{Curve, DomainId, Protocol}; -use mpc_primitives::{EpochId, ReconstructionThreshold}; use near_time::Clock; use std::collections::HashMap; use std::future::Future; use std::sync::{Arc, Mutex}; -use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::{confidential_key_derivation, ecdsa, frost::eddsa}; use tokio::select; use tokio::sync::mpsc::unbounded_channel; @@ -332,7 +332,7 @@ where let (network_client, channel_receiver, _handle) = run_network_client(Arc::new(sender), Box::new(receiver)); let threshold: usize = mpc_config.participants.threshold.try_into()?; - let threshold = TSReconstructionThreshold::from(threshold); + let threshold = ReconstructionThreshold::from(threshold); if mpc_config.is_leader_for_key_event() { keygen_leader( network_client, @@ -780,7 +780,7 @@ where let args = Arc::new(ResharingArgs { previous_keyset, existing_keyshares, - new_threshold: TSReconstructionThreshold::from(new_threshold), + new_threshold: ReconstructionThreshold::from(new_threshold), old_participants: current_running_state.participants, }); diff --git a/crates/node/src/providers/ckd/sign.rs b/crates/node/src/providers/ckd/sign.rs index 74182141e7..c2a4960d74 100644 --- a/crates/node/src/providers/ckd/sign.rs +++ b/crates/node/src/providers/ckd/sign.rs @@ -42,7 +42,7 @@ impl CKDProvider { let participants = self .client .select_random_active_participants_including_me( - threshold.value(), + threshold.as_usize(), &running_participants, ) .context("Could not choose active participants for a ckd")?; diff --git a/crates/node/src/providers/ecdsa.rs b/crates/node/src/providers/ecdsa.rs index 2f749a49b0..0ff50f07c4 100644 --- a/crates/node/src/providers/ecdsa.rs +++ b/crates/node/src/providers/ecdsa.rs @@ -22,11 +22,10 @@ use mpc_node_config::ConfigFile; use crate::types::SignatureId; use borsh::{BorshDeserialize, BorshSerialize}; -use mpc_primitives::ReconstructionThreshold; use mpc_primitives::domain::DomainId; use near_time::Clock; use std::sync::Arc; -use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::KeygenOutput; use threshold_signatures::ecdsa::Signature; use threshold_signatures::frost_secp256k1::VerifyingKey; @@ -193,14 +192,14 @@ impl SignatureProvider for EcdsaSignatureProvider { } async fn run_key_generation_client( - threshold: TSReconstructionThreshold, + threshold: ReconstructionThreshold, channel: NetworkTaskChannel, ) -> anyhow::Result { EcdsaSignatureProvider::run_key_generation_client_internal(threshold, channel).await } async fn run_key_resharing_client( - new_threshold: TSReconstructionThreshold, + new_threshold: ReconstructionThreshold, my_share: Option, public_key: VerifyingKey, old_participants: &ParticipantsConfig, @@ -272,7 +271,7 @@ impl SignatureProvider for EcdsaSignatureProvider { // network-wide threshold. let threshold = ReconstructionThreshold::new(self.mpc_config.participants.threshold); let threshold_usize: usize = threshold.inner().try_into()?; - let threshold_bound = TSReconstructionThreshold::from(threshold_usize); + let threshold_bound = ReconstructionThreshold::from(threshold_usize); let triple_store = self.triple_store_for_t(threshold)?; let generate_triples = tracking::spawn( diff --git a/crates/node/src/providers/ecdsa/presign.rs b/crates/node/src/providers/ecdsa/presign.rs index 6c8bf85fb6..a24969dab4 100644 --- a/crates/node/src/providers/ecdsa/presign.rs +++ b/crates/node/src/providers/ecdsa/presign.rs @@ -12,14 +12,13 @@ use crate::providers::ecdsa::{EcdsaSignatureProvider, EcdsaTaskId, KeygenOutput, use crate::tracking::AutoAbortTaskCollection; use crate::{metrics, tracking}; use mpc_node_config::PresignatureConfig; -use mpc_primitives::ReconstructionThreshold; use mpc_primitives::domain::DomainId; use near_time::Clock; use serde::{Deserialize, Serialize}; use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::time::Duration; -use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::ot_based_ecdsa::triples::TripleGenerationOutput; use threshold_signatures::ecdsa::ot_based_ecdsa::{ PresignArguments, PresignOutput, presign::presign, @@ -66,7 +65,7 @@ impl EcdsaSignatureProvider { /// so that needs to be separately handled. pub(super) async fn run_background_presignature_generation( client: Arc, - threshold: TSReconstructionThreshold, + threshold: ReconstructionThreshold, config: Arc, triple_store: Arc, domain_id: DomainId, @@ -186,7 +185,7 @@ impl EcdsaSignatureProvider { let threshold = ReconstructionThreshold::new(threshold_usize.try_into()?); let triple_store = self.triple_store_for_t(threshold)?; FollowerPresignComputation { - threshold: TSReconstructionThreshold::from(threshold_usize), + threshold: ReconstructionThreshold::from(threshold_usize), keygen_out: domain_data.keyshare, triple_store, paired_triple_id, @@ -220,7 +219,7 @@ impl HasParticipants for PresignOutputWithParticipants { /// Performs an MPC presignature operation. This is shared for the initiator /// and for passive participants. pub struct PresignComputation { - threshold: TSReconstructionThreshold, + threshold: ReconstructionThreshold, triple0: TripleGenerationOutput, triple1: TripleGenerationOutput, keygen_out: KeygenOutput, @@ -260,7 +259,7 @@ impl MpcLeaderCentricComputation for PresignComputation { /// The difference is: we need to read the triples from the triple store (which may fail), /// and we need to write the presignature to the presignature store before completing. pub struct FollowerPresignComputation { - pub threshold: TSReconstructionThreshold, + pub threshold: ReconstructionThreshold, pub paired_triple_id: UniqueId, pub keygen_out: KeygenOutput, pub triple_store: Arc, diff --git a/crates/node/src/providers/ecdsa/triple.rs b/crates/node/src/providers/ecdsa/triple.rs index d810d24a87..0ba0ef0dc5 100644 --- a/crates/node/src/providers/ecdsa/triple.rs +++ b/crates/node/src/providers/ecdsa/triple.rs @@ -12,13 +12,12 @@ use crate::providers::HasParticipants; use crate::providers::ecdsa::{EcdsaSignatureProvider, EcdsaTaskId}; use crate::tracking::AutoAbortTaskCollection; use mpc_node_config::TripleConfig; -use mpc_primitives::ReconstructionThreshold; use near_time::Clock; use rand::rngs::OsRng; use std::ops::Deref; use std::sync::Arc; use std::time::Duration; -use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::ot_based_ecdsa::triples::TripleGenerationOutput; use threshold_signatures::participants::Participant; @@ -74,7 +73,7 @@ impl EcdsaSignatureProvider { mpc_config: Arc, config: Arc, triple_store: Arc, - threshold: TSReconstructionThreshold, + threshold: ReconstructionThreshold, ) -> ! { let in_flight_generations = InFlightGenerationTracker::new(); let parallelism_limiter = Arc::new(tokio::sync::Semaphore::new(config.concurrency)); @@ -107,7 +106,7 @@ impl EcdsaSignatureProvider { < config.concurrency * 2 * SUPPORTED_TRIPLE_GENERATION_BATCH_SIZE { let participants = match client.select_random_active_participants_including_me( - threshold.value(), + threshold.as_usize(), &running_participants, ) { Ok(participants) => participants, @@ -212,7 +211,7 @@ impl EcdsaSignatureProvider { let threshold = ReconstructionThreshold::new(threshold_usize.try_into()?); let triple_store = self.triple_store_for_t(threshold)?; FollowerManyTripleGenerationComputation:: { - threshold: TSReconstructionThreshold::from(threshold_usize), + threshold: ReconstructionThreshold::from(threshold_usize), out_triple_id_start: start, out_triple_store: triple_store, } @@ -240,7 +239,7 @@ impl HasParticipants for PairedTriple { /// Generates many cait-sith triples at once. This can significantly save the /// *number* of network messages. pub struct ManyTripleGenerationComputation { - pub threshold: TSReconstructionThreshold, + pub threshold: ReconstructionThreshold, } #[async_trait::async_trait] @@ -288,7 +287,7 @@ impl MpcLeaderCentricComputation> /// The follower version of the triple generation. The difference is that the follower will only /// complete the computation after successfully persisting the triples to storage. pub struct FollowerManyTripleGenerationComputation { - pub threshold: TSReconstructionThreshold, + pub threshold: ReconstructionThreshold, pub out_triple_store: Arc, pub out_triple_id_start: UniqueId, } @@ -348,7 +347,6 @@ mod tests { use futures::{FutureExt, StreamExt, stream}; use std::collections::HashMap; use std::sync::Arc; - use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; use threshold_signatures::test_utils::generate_participants; use tokio::sync::mpsc; @@ -405,7 +403,7 @@ mod tests { panic!("Unexpected task id"); }; let triples = ManyTripleGenerationComputation:: { - threshold: TSReconstructionThreshold::from(THRESHOLD), + threshold: ReconstructionThreshold::from(THRESHOLD), } .perform_leader_centric_computation( channel, @@ -453,7 +451,7 @@ mod tests { let result = tracking::spawn( &format!("task {:?}", task_id), ManyTripleGenerationComputation:: { - threshold: TSReconstructionThreshold::from(THRESHOLD), + threshold: ReconstructionThreshold::from(THRESHOLD), } .perform_leader_centric_computation( channel, diff --git a/crates/node/src/providers/eddsa/sign.rs b/crates/node/src/providers/eddsa/sign.rs index 64c08208af..ae749d7a42 100644 --- a/crates/node/src/providers/eddsa/sign.rs +++ b/crates/node/src/providers/eddsa/sign.rs @@ -37,7 +37,7 @@ impl EddsaSignatureProvider { let participants = self .client .select_random_active_participants_including_me( - threshold.value(), + threshold.as_usize(), &running_participants, ) .context("Can't choose active participants for a eddsa signature")?; diff --git a/crates/node/src/providers/robust_ecdsa.rs b/crates/node/src/providers/robust_ecdsa.rs index 338a464fd1..5d772f3b90 100644 --- a/crates/node/src/providers/robust_ecdsa.rs +++ b/crates/node/src/providers/robust_ecdsa.rs @@ -149,7 +149,7 @@ impl SignatureProvider for RobustEcdsaSignatureProvider { ) -> anyhow::Result { let number_of_participants = channel.participants().len(); let robust_ecdsa_threshold = - translate_threshold(threshold.value(), number_of_participants)?; + translate_threshold(threshold.as_usize(), number_of_participants)?; EcdsaSignatureProvider::run_key_generation_client_internal( ReconstructionThreshold::try_from(robust_ecdsa_threshold)?, channel, @@ -166,7 +166,7 @@ impl SignatureProvider for RobustEcdsaSignatureProvider { ) -> anyhow::Result { let number_of_participants = channel.participants().len(); let new_robust_ecdsa_threshold = - translate_threshold(new_threshold.value(), number_of_participants)?; + translate_threshold(new_threshold.as_usize(), number_of_participants)?; // This is a bad hack, but cannot think of a better way to solve it, as the struct // comes directly from generic implementations, so probably this is the best place @@ -176,9 +176,8 @@ impl SignatureProvider for RobustEcdsaSignatureProvider { old_participants.threshold.try_into()?, old_participants.participants.len(), )?; - old_participants_patched.threshold = ReconstructionThreshold::try_from(old_translated)? - .value() - .try_into()?; + old_participants_patched.threshold = + ReconstructionThreshold::try_from(old_translated)?.inner(); EcdsaSignatureProvider::run_key_resharing_client_internal( ReconstructionThreshold::try_from(new_robust_ecdsa_threshold)?, diff --git a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs index a4c462ba76..4168d65d96 100644 --- a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs +++ b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs @@ -22,7 +22,7 @@ type PreparedSimulatedSig = PreparedOutputs; /// Benches the signing protocol fn bench_sign(c: &mut Criterion) { - let num = RECONSTRUCTION_LOWER_BOUND.value(); + let num = RECONSTRUCTION_LOWER_BOUND.as_usize(); let max_malicious = *MAX_MALICIOUS; let setup = setup_sign_snapshot(*RECONSTRUCTION_LOWER_BOUND); diff --git a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs index 2b4a8df84d..01b9a0f6de 100644 --- a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs +++ b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs @@ -27,7 +27,7 @@ type PreparedSimulatedSig = PreparedOutputs; /// Benches the presigning protocol fn bench_presign(c: &mut Criterion) { - let num = RECONSTRUCTION_LOWER_BOUND.value(); + let num = RECONSTRUCTION_LOWER_BOUND.as_usize(); let max_malicious = *MAX_MALICIOUS; let setup = setup_presign_snapshot(num); @@ -50,7 +50,7 @@ fn bench_presign(c: &mut Criterion) { /// Benches the signing protocol fn bench_sign(c: &mut Criterion) { - let num = RECONSTRUCTION_LOWER_BOUND.value(); + let num = RECONSTRUCTION_LOWER_BOUND.as_usize(); let max_malicious = *MAX_MALICIOUS; let setup = setup_sign_snapshot(*RECONSTRUCTION_LOWER_BOUND); @@ -151,7 +151,7 @@ struct SignSetup { /// Expensive one-time setup for sign: runs the full N-party protocol to capture snapshots fn setup_sign_snapshot(threshold: ReconstructionThreshold) -> SignSetup { let mut rng = MockCryptoRng::seed_from_u64(41); - let preps = ed25519_prepare_presign(threshold.value(), &mut rng); + let preps = ed25519_prepare_presign(threshold.as_usize(), &mut rng); let result = run_protocol(preps.protocols).expect("Prepare sign should not fail"); let preps = ed25519_prepare_sign_v2(&result, preps.key_packages, threshold, &mut rng); let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) diff --git a/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs b/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs index 87160a27f7..b9ffa43707 100644 --- a/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs +++ b/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs @@ -66,7 +66,7 @@ pub fn ed25519_prepare_sign_v1( threshold: ReconstructionThreshold, rng: &mut R, ) -> FrostEd25519SigV1 { - let num_participants = threshold.value(); + let num_participants = threshold.as_usize(); let participants = generate_participants_with_random_ids(num_participants, rng); let key_packages = run_keygen(&participants, *MAX_MALICIOUS + 1, rng); @@ -110,7 +110,7 @@ pub fn ed25519_prepare_sign_v2( threshold: ReconstructionThreshold, rng: &mut R, ) -> FrostEd25519SigV2 { - let num_participants = threshold.value(); + let num_participants = threshold.as_usize(); // collect all participants let participants: Vec<_> = result.iter().map(|(participant, _)| *participant).collect(); @@ -175,7 +175,7 @@ pub fn prepare_ckd( threshold: ReconstructionThreshold, rng: &mut R, ) -> PreparedCkdPackage { - let num_participants = threshold.value(); + let num_participants = threshold.as_usize(); // collect all participants let participants = generate_participants_with_random_ids(num_participants, rng); let key_packages = run_keygen(&participants, *MAX_MALICIOUS + 1, rng); diff --git a/crates/threshold-signatures/benches/ckd.rs b/crates/threshold-signatures/benches/ckd.rs index 2e0d72c080..cc4c3602fc 100644 --- a/crates/threshold-signatures/benches/ckd.rs +++ b/crates/threshold-signatures/benches/ckd.rs @@ -27,7 +27,7 @@ fn threshold() -> ReconstructionThreshold { /// Benches the ckd protocol fn bench_ckd(c: &mut Criterion) { - let num = threshold().value(); + let num = threshold().as_usize(); let max_malicious = *MAX_MALICIOUS; let setup = setup_ckd_snapshot(threshold()); diff --git a/crates/threshold-signatures/src/dkg.rs b/crates/threshold-signatures/src/dkg.rs index ab2e10b58c..ab4b292a17 100644 --- a/crates/threshold-signatures/src/dkg.rs +++ b/crates/threshold-signatures/src/dkg.rs @@ -180,7 +180,7 @@ fn verify_proof_of_knowledge( commitment: &VerifiableSecretSharingCommitment, proof_of_knowledge: Option<&Signature>, ) -> Result<(), ProtocolError> { - let threshold = threshold.value(); + let threshold = threshold.as_usize(); match proof_of_knowledge { // if participant did not send anything but he is actually an old participant None => { @@ -248,7 +248,7 @@ fn insert_identity_if_missing( // threshold -1 (because the zero term is not serializable) let mut commitment_i = commitment_i.clone(); let mut coefficients_i = commitment_i.coefficients().to_vec(); - if coefficients_i.len() == threshold.value() - 1 { + if coefficients_i.len() == threshold.as_usize() - 1 { let identity = CoefficientCommitment::new(::identity()); coefficients_i.insert(0, identity); commitment_i = VerifiableSecretSharingCommitment::new(coefficients_i); @@ -373,7 +373,7 @@ async fn do_keyshare( // Step 2.3 // the degree of the polynomial is threshold - 1 let degree = threshold - .value() + .as_usize() .checked_sub(1) .ok_or(ProtocolError::IntegerOverflow)?; let secret_coefficients = Polynomial::::generate_polynomial(Some(secret), degree, rng)?; @@ -562,7 +562,7 @@ pub fn assert_key_invariants( me: Participant, threshold: impl Into, ) -> Result { - let threshold = usize::from(threshold.into()); + let threshold = threshold.into().as_usize(); // need enough participants if participants.len() < 2 { return Err(InitializationError::NotEnoughParticipants { @@ -645,8 +645,8 @@ pub fn assert_reshare_keys_invariants( old_threshold: impl Into, old_participants: &[Participant], ) -> Result<(ParticipantList, ParticipantList), InitializationError> { - let threshold = usize::from(threshold.into()); - let old_threshold = usize::from(old_threshold.into()); + let threshold = threshold.into(); + let old_threshold = old_threshold.into().as_usize(); let participants = assert_key_invariants(participants, me, threshold)?; diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/presign.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/presign.rs index 5ff172fda5..aa19962aab 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/presign.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/presign.rs @@ -31,9 +31,9 @@ pub fn presign( }); } // Spec 1.1 - if args.threshold.value() > participants.len() { + if args.threshold.as_usize() > participants.len() { return Err(InitializationError::ThresholdTooLarge { - threshold: args.threshold.value(), + threshold: args.threshold.as_usize(), max: participants.len(), }); } diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs index 76c17af785..5f1a6d9215 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs @@ -37,7 +37,7 @@ pub fn sign( where T: Into, { - let threshold = usize::from(threshold.into()); + let threshold = threshold.into().as_usize(); if participants.len() < 2 { return Err(InitializationError::NotEnoughParticipants { participants: participants.len(), diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs index 57c2c1f99c..f80b07d49b 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs @@ -41,12 +41,7 @@ fn create_transcript( let enc = rmp_serde::encode::to_vec(participants).map_err(|_| ProtocolError::ErrorEncoding)?; transcript.message(b"participants", &enc); // To allow interop between platforms where usize is different - transcript.message( - b"threshold", - &u64::try_from(threshold.value()) - .expect("threshold should always fit in u64") - .to_be_bytes(), - ); + transcript.message(b"threshold", &threshold.inner().to_be_bytes()); Ok(transcript) } @@ -149,11 +144,11 @@ async fn do_generation_many( let mut big_l_i_v = vec![]; let degree1 = threshold - .value() + .as_usize() .checked_sub(1) .ok_or(ProtocolError::IntegerOverflow)?; let degree2 = threshold - .value() + .as_usize() .checked_sub(2) .ok_or(ProtocolError::IntegerOverflow)?; @@ -372,10 +367,10 @@ async fn do_generation_many( big_f_v.iter_mut(), big_l_v.iter_mut(), )) { - if their_big_e.degree() != threshold.value() - 1 - || their_big_f.degree() != threshold.value() - 1 + if their_big_e.degree() != threshold.as_usize() - 1 + || their_big_f.degree() != threshold.as_usize() - 1 // degree is threshold - 2 because the constant element identity is not serializable - || their_big_l.degree() != threshold.value() - 2 + || their_big_l.degree() != threshold.as_usize() - 2 { return Err(ProtocolError::AssertionFailed(format!( "polynomial from {from:?} has the wrong length" @@ -712,7 +707,7 @@ fn validate_triple_inputs( threshold: impl Into, ) -> Result<(ParticipantList, ReconstructionThreshold), InitializationError> { let threshold = threshold.into(); - let threshold_value = threshold.value(); + let threshold_value = threshold.as_usize(); if participants.len() < 2 { return Err(InitializationError::NotEnoughParticipants { participants: participants.len(), diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs index 88cd9ba2f5..13ff07e466 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs @@ -31,7 +31,7 @@ pub fn deal( let b = Secp256K1ScalarField::random(&mut *rng); let c = a * b; - let degree = threshold.value().checked_sub(1).unwrap(); + let degree = threshold.as_usize().checked_sub(1).unwrap(); let f_a = Polynomial::generate_polynomial(Some(a), degree, rng)?; let f_b = Polynomial::generate_polynomial(Some(b), degree, rng)?; let f_c = Polynomial::generate_polynomial(Some(c), degree, rng)?; diff --git a/crates/threshold-signatures/src/frost/eddsa/sign.rs b/crates/threshold-signatures/src/frost/eddsa/sign.rs index 9206e5bc72..6b1a6d56d1 100644 --- a/crates/threshold-signatures/src/frost/eddsa/sign.rs +++ b/crates/threshold-signatures/src/frost/eddsa/sign.rs @@ -406,7 +406,7 @@ fn construct_key_package( signing_share, verifying_share, *verifying_key, - u16::try_from(threshold.value()).map_err(|_| { + u16::try_from(threshold.inner()).map_err(|_| { ProtocolError::Other("threshold cannot be converted to u16".to_string()) })?, )) diff --git a/crates/threshold-signatures/src/frost/presign.rs b/crates/threshold-signatures/src/frost/presign.rs index d14c70e423..a94b885797 100644 --- a/crates/threshold-signatures/src/frost/presign.rs +++ b/crates/threshold-signatures/src/frost/presign.rs @@ -72,9 +72,9 @@ where } // validate threshold - if args.threshold.value() > participants.len() { + if args.threshold.as_usize() > participants.len() { return Err(InitializationError::ThresholdTooLarge { - threshold: args.threshold.into(), + threshold: args.threshold.as_usize(), max: participants.len(), }); } diff --git a/crates/threshold-signatures/src/frost/redjubjub/sign.rs b/crates/threshold-signatures/src/frost/redjubjub/sign.rs index 5823248684..7a29c2cbd7 100644 --- a/crates/threshold-signatures/src/frost/redjubjub/sign.rs +++ b/crates/threshold-signatures/src/frost/redjubjub/sign.rs @@ -280,7 +280,7 @@ fn construct_key_package( signing_share, verifying_share, verifying_key, - u16::try_from(threshold.value()).map_err(|_| { + u16::try_from(threshold.inner()).map_err(|_| { ProtocolError::Other("threshold cannot be converted to u16".to_string()) })?, ); diff --git a/crates/threshold-signatures/src/frost/sign_utils.rs b/crates/threshold-signatures/src/frost/sign_utils.rs index a21e4dd4b1..fe0608eec0 100644 --- a/crates/threshold-signatures/src/frost/sign_utils.rs +++ b/crates/threshold-signatures/src/frost/sign_utils.rs @@ -30,9 +30,9 @@ pub fn assert_sign_inputs( } // validate threshold - if threshold.value() > participants.len() { + if threshold.as_usize() > participants.len() { return Err(InitializationError::ThresholdTooLarge { - threshold: threshold.value(), + threshold: threshold.as_usize(), max: participants.len(), }); } diff --git a/crates/threshold-signatures/src/thresholds.rs b/crates/threshold-signatures/src/thresholds.rs index dd56f36dfc..19ab2b14a1 100644 --- a/crates/threshold-signatures/src/thresholds.rs +++ b/crates/threshold-signatures/src/thresholds.rs @@ -7,10 +7,8 @@ use thiserror::Error; )] pub struct MaxMalicious(usize); -#[derive( - Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, From, Into, -)] -pub struct ReconstructionThreshold(usize); +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +pub struct ReconstructionThreshold(u64); // ----- MaxMalicious conversions ----- impl MaxMalicious { @@ -20,9 +18,35 @@ impl MaxMalicious { } impl ReconstructionThreshold { - pub fn value(self) -> usize { + pub const fn new(value: u64) -> Self { + Self(value) + } + + pub fn inner(self) -> u64 { self.0 } + + /// The threshold as a `usize`, for indexing and sizing collections in the + /// protocol code. Lossless on all supported (>= 32-bit) targets. + /// + /// # Panics + /// + /// Panics only if the threshold exceeds `usize::MAX` — impossible on + /// supported targets, where a participant count always fits in `usize`. + pub fn as_usize(self) -> usize { + usize::try_from(self.0).expect("reconstruction threshold fits in usize") + } +} + +/// Construct from a `usize` participant count. `usize` → `u64` is lossless on +/// all supported targets. Provided (instead of `derive_more::From`) so that +/// untyped integer literals like `ReconstructionThreshold::from(3)` infer cleanly +/// and the crypto crate keeps its `usize`-based construction ergonomics; the node +/// constructs the `u64`-backed value via [`ReconstructionThreshold::new`]. +impl From for ReconstructionThreshold { + fn from(value: usize) -> Self { + Self(value as u64) + } } /// Lower bound to reconstruct the secret is `MaxMalicious` + 1. @@ -30,7 +54,9 @@ impl TryFrom for ReconstructionThreshold { type Error = ThresholdError; fn try_from(m: MaxMalicious) -> Result { - m.0.checked_add(1) + u64::try_from(m.0) + .ok() + .and_then(|v| v.checked_add(1)) .map(Self) .ok_or(ThresholdError::IntegerOverflow) } From d1d856cd9ca294bb9973c66c5e708f603497a3e8 Mon Sep 17 00:00:00 2001 From: SimonRastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Tue, 16 Jun 2026 20:02:53 +0200 Subject: [PATCH 4/9] fixing post-merge --- crates/node/src/tests/protocol_yielding.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/node/src/tests/protocol_yielding.rs b/crates/node/src/tests/protocol_yielding.rs index 908d4684c4..21d35bcd78 100644 --- a/crates/node/src/tests/protocol_yielding.rs +++ b/crates/node/src/tests/protocol_yielding.rs @@ -28,7 +28,7 @@ use anyhow::Context; use rand::SeedableRng as _; use std::sync::Arc; use std::time::{Duration, Instant}; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::ot_based_ecdsa::triples::generate_triple_many; use threshold_signatures::participants::Participant; use threshold_signatures::test_utils::{MockCryptoRng, generate_participants}; @@ -139,7 +139,7 @@ async fn run_triple_gen_client( let protocol = generate_triple_many::( &cs_participants, my_id.into(), - ReconstructionLowerBound::from(THRESHOLD), + ReconstructionThreshold::from(THRESHOLD), rng, )?; let triples = run_protocol("canary triple gen", &mut channel, protocol).await?; From f169d807faa4debbc017a76891ebc943377924f6 Mon Sep 17 00:00:00 2001 From: SimonRastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Tue, 16 Jun 2026 20:13:56 +0200 Subject: [PATCH 5/9] Adding extra renaming post merge --- crates/threshold-signatures/src/frost/sign_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/threshold-signatures/src/frost/sign_utils.rs b/crates/threshold-signatures/src/frost/sign_utils.rs index d0bb3dfdea..94cbe558f2 100644 --- a/crates/threshold-signatures/src/frost/sign_utils.rs +++ b/crates/threshold-signatures/src/frost/sign_utils.rs @@ -42,7 +42,7 @@ pub fn assert_participant_inputs( /// Verifies that the sign inputs are valid pub fn assert_sign_inputs( participants: &[Participant], - threshold: impl Into, + threshold: impl Into, me: Participant, coordinator: Participant, ) -> Result { From ed8865bb1b426b840bf002b0ff16dac0ce5a8271 Mon Sep 17 00:00:00 2001 From: Simon Rastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Tue, 16 Jun 2026 20:24:01 +0200 Subject: [PATCH 6/9] Adding unit tests, replacing as_usize with try_as_usize and fix redundant double-construction at the node boundary --- crates/node/src/providers/ckd/sign.rs | 2 +- crates/node/src/providers/ecdsa.rs | 6 +- crates/node/src/providers/ecdsa/presign.rs | 5 +- crates/node/src/providers/ecdsa/triple.rs | 12 ++- crates/node/src/providers/eddsa/sign.rs | 2 +- crates/node/src/providers/robust_ecdsa.rs | 4 +- .../benches/advanced_eddsa_frost_sign_v1.rs | 4 +- .../benches/advanced_eddsa_frost_sign_v2.rs | 15 +++- .../benches/bench_utils/frost_eddsa.rs | 12 ++- crates/threshold-signatures/benches/ckd.rs | 4 +- crates/threshold-signatures/src/dkg.rs | 18 ++--- .../src/ecdsa/ot_based_ecdsa/presign.rs | 5 +- .../src/ecdsa/ot_based_ecdsa/sign.rs | 2 +- .../ot_based_ecdsa/triples/generation.rs | 13 +-- .../src/ecdsa/ot_based_ecdsa/triples/test.rs | 2 +- crates/threshold-signatures/src/errors.rs | 13 +++ .../threshold-signatures/src/frost/presign.rs | 5 +- .../src/frost/sign_utils.rs | 5 +- crates/threshold-signatures/src/thresholds.rs | 81 +++++++++++++++++-- 19 files changed, 157 insertions(+), 53 deletions(-) diff --git a/crates/node/src/providers/ckd/sign.rs b/crates/node/src/providers/ckd/sign.rs index c2a4960d74..c7c83f537d 100644 --- a/crates/node/src/providers/ckd/sign.rs +++ b/crates/node/src/providers/ckd/sign.rs @@ -42,7 +42,7 @@ impl CKDProvider { let participants = self .client .select_random_active_participants_including_me( - threshold.as_usize(), + threshold.try_as_usize()?, &running_participants, ) .context("Could not choose active participants for a ckd")?; diff --git a/crates/node/src/providers/ecdsa.rs b/crates/node/src/providers/ecdsa.rs index 0ff50f07c4..35bc6ded20 100644 --- a/crates/node/src/providers/ecdsa.rs +++ b/crates/node/src/providers/ecdsa.rs @@ -270,8 +270,6 @@ impl SignatureProvider for EcdsaSignatureProvider { // and source `t` from `domain.reconstruction_threshold` rather than the // network-wide threshold. let threshold = ReconstructionThreshold::new(self.mpc_config.participants.threshold); - let threshold_usize: usize = threshold.inner().try_into()?; - let threshold_bound = ReconstructionThreshold::from(threshold_usize); let triple_store = self.triple_store_for_t(threshold)?; let generate_triples = tracking::spawn( @@ -281,7 +279,7 @@ impl SignatureProvider for EcdsaSignatureProvider { self.mpc_config.clone(), self.config.triple.clone().into(), triple_store.clone(), - threshold_bound, + threshold, ), ); @@ -293,7 +291,7 @@ impl SignatureProvider for EcdsaSignatureProvider { &format!("generate presignatures for domain {}", domain_id.0), Self::run_background_presignature_generation( self.client.clone(), - threshold_bound, + threshold, self.config.presignature.clone().into(), triple_store.clone(), *domain_id, diff --git a/crates/node/src/providers/ecdsa/presign.rs b/crates/node/src/providers/ecdsa/presign.rs index a24969dab4..913aee545f 100644 --- a/crates/node/src/providers/ecdsa/presign.rs +++ b/crates/node/src/providers/ecdsa/presign.rs @@ -181,11 +181,10 @@ impl EcdsaSignatureProvider { // Triple store to consume from is keyed by the presign's `t`, which // equals the number of presign participants (same as triple // participants — the leader pairs them). - let threshold_usize: usize = channel.participants().len(); - let threshold = ReconstructionThreshold::new(threshold_usize.try_into()?); + let threshold = ReconstructionThreshold::from(channel.participants().len()); let triple_store = self.triple_store_for_t(threshold)?; FollowerPresignComputation { - threshold: ReconstructionThreshold::from(threshold_usize), + threshold, keygen_out: domain_data.keyshare, triple_store, paired_triple_id, diff --git a/crates/node/src/providers/ecdsa/triple.rs b/crates/node/src/providers/ecdsa/triple.rs index 0ba0ef0dc5..6015f6194e 100644 --- a/crates/node/src/providers/ecdsa/triple.rs +++ b/crates/node/src/providers/ecdsa/triple.rs @@ -78,6 +78,11 @@ impl EcdsaSignatureProvider { let in_flight_generations = InFlightGenerationTracker::new(); let parallelism_limiter = Arc::new(tokio::sync::Semaphore::new(config.concurrency)); let mut tasks = AutoAbortTaskCollection::new(); + // Converted once: loop-invariant, and this `-> !` loop has no error + // channel. Unreachable on supported targets (count fits in `usize`). + let threshold_usize = threshold + .try_as_usize() + .expect("reconstruction threshold fits in usize"); let running_participants: Vec<_> = mpc_config .participants .participants @@ -106,7 +111,7 @@ impl EcdsaSignatureProvider { < config.concurrency * 2 * SUPPORTED_TRIPLE_GENERATION_BATCH_SIZE { let participants = match client.select_random_active_participants_including_me( - threshold.as_usize(), + threshold_usize, &running_participants, ) { Ok(participants) => participants, @@ -207,11 +212,10 @@ impl EcdsaSignatureProvider { // Cait-sith triple generation runs with exactly `t` participants, so we // can derive the store's `t` from the channel's participant list // without a wire-format change to `EcdsaTaskId::ManyTriples`. - let threshold_usize: usize = channel.participants().len(); - let threshold = ReconstructionThreshold::new(threshold_usize.try_into()?); + let threshold = ReconstructionThreshold::from(channel.participants().len()); let triple_store = self.triple_store_for_t(threshold)?; FollowerManyTripleGenerationComputation:: { - threshold: ReconstructionThreshold::from(threshold_usize), + threshold, out_triple_id_start: start, out_triple_store: triple_store, } diff --git a/crates/node/src/providers/eddsa/sign.rs b/crates/node/src/providers/eddsa/sign.rs index ae749d7a42..2eda2835a1 100644 --- a/crates/node/src/providers/eddsa/sign.rs +++ b/crates/node/src/providers/eddsa/sign.rs @@ -37,7 +37,7 @@ impl EddsaSignatureProvider { let participants = self .client .select_random_active_participants_including_me( - threshold.as_usize(), + threshold.try_as_usize()?, &running_participants, ) .context("Can't choose active participants for a eddsa signature")?; diff --git a/crates/node/src/providers/robust_ecdsa.rs b/crates/node/src/providers/robust_ecdsa.rs index 5d772f3b90..8162985f60 100644 --- a/crates/node/src/providers/robust_ecdsa.rs +++ b/crates/node/src/providers/robust_ecdsa.rs @@ -149,7 +149,7 @@ impl SignatureProvider for RobustEcdsaSignatureProvider { ) -> anyhow::Result { let number_of_participants = channel.participants().len(); let robust_ecdsa_threshold = - translate_threshold(threshold.as_usize(), number_of_participants)?; + translate_threshold(threshold.try_as_usize()?, number_of_participants)?; EcdsaSignatureProvider::run_key_generation_client_internal( ReconstructionThreshold::try_from(robust_ecdsa_threshold)?, channel, @@ -166,7 +166,7 @@ impl SignatureProvider for RobustEcdsaSignatureProvider { ) -> anyhow::Result { let number_of_participants = channel.participants().len(); let new_robust_ecdsa_threshold = - translate_threshold(new_threshold.as_usize(), number_of_participants)?; + translate_threshold(new_threshold.try_as_usize()?, number_of_participants)?; // This is a bad hack, but cannot think of a better way to solve it, as the struct // comes directly from generic implementations, so probably this is the best place diff --git a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs index 4168d65d96..a748145b3f 100644 --- a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs +++ b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v1.rs @@ -22,7 +22,9 @@ type PreparedSimulatedSig = PreparedOutputs; /// Benches the signing protocol fn bench_sign(c: &mut Criterion) { - let num = RECONSTRUCTION_LOWER_BOUND.as_usize(); + let num = RECONSTRUCTION_LOWER_BOUND + .try_as_usize() + .expect("reconstruction threshold fits in usize"); let max_malicious = *MAX_MALICIOUS; let setup = setup_sign_snapshot(*RECONSTRUCTION_LOWER_BOUND); diff --git a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs index 01b9a0f6de..363f916185 100644 --- a/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs +++ b/crates/threshold-signatures/benches/advanced_eddsa_frost_sign_v2.rs @@ -27,7 +27,9 @@ type PreparedSimulatedSig = PreparedOutputs; /// Benches the presigning protocol fn bench_presign(c: &mut Criterion) { - let num = RECONSTRUCTION_LOWER_BOUND.as_usize(); + let num = RECONSTRUCTION_LOWER_BOUND + .try_as_usize() + .expect("reconstruction threshold fits in usize"); let max_malicious = *MAX_MALICIOUS; let setup = setup_presign_snapshot(num); @@ -50,7 +52,9 @@ fn bench_presign(c: &mut Criterion) { /// Benches the signing protocol fn bench_sign(c: &mut Criterion) { - let num = RECONSTRUCTION_LOWER_BOUND.as_usize(); + let num = RECONSTRUCTION_LOWER_BOUND + .try_as_usize() + .expect("reconstruction threshold fits in usize"); let max_malicious = *MAX_MALICIOUS; let setup = setup_sign_snapshot(*RECONSTRUCTION_LOWER_BOUND); @@ -151,7 +155,12 @@ struct SignSetup { /// Expensive one-time setup for sign: runs the full N-party protocol to capture snapshots fn setup_sign_snapshot(threshold: ReconstructionThreshold) -> SignSetup { let mut rng = MockCryptoRng::seed_from_u64(41); - let preps = ed25519_prepare_presign(threshold.as_usize(), &mut rng); + let preps = ed25519_prepare_presign( + threshold + .try_as_usize() + .expect("reconstruction threshold fits in usize"), + &mut rng, + ); let result = run_protocol(preps.protocols).expect("Prepare sign should not fail"); let preps = ed25519_prepare_sign_v2(&result, preps.key_packages, threshold, &mut rng); let (_, protocol_snapshot) = run_protocol_and_take_snapshots(preps.protocols) diff --git a/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs b/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs index b9ffa43707..97f149fb6a 100644 --- a/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs +++ b/crates/threshold-signatures/benches/bench_utils/frost_eddsa.rs @@ -66,7 +66,9 @@ pub fn ed25519_prepare_sign_v1( threshold: ReconstructionThreshold, rng: &mut R, ) -> FrostEd25519SigV1 { - let num_participants = threshold.as_usize(); + let num_participants = threshold + .try_as_usize() + .expect("reconstruction threshold fits in usize"); let participants = generate_participants_with_random_ids(num_participants, rng); let key_packages = run_keygen(&participants, *MAX_MALICIOUS + 1, rng); @@ -110,7 +112,9 @@ pub fn ed25519_prepare_sign_v2( threshold: ReconstructionThreshold, rng: &mut R, ) -> FrostEd25519SigV2 { - let num_participants = threshold.as_usize(); + let num_participants = threshold + .try_as_usize() + .expect("reconstruction threshold fits in usize"); // collect all participants let participants: Vec<_> = result.iter().map(|(participant, _)| *participant).collect(); @@ -175,7 +179,9 @@ pub fn prepare_ckd( threshold: ReconstructionThreshold, rng: &mut R, ) -> PreparedCkdPackage { - let num_participants = threshold.as_usize(); + let num_participants = threshold + .try_as_usize() + .expect("reconstruction threshold fits in usize"); // collect all participants let participants = generate_participants_with_random_ids(num_participants, rng); let key_packages = run_keygen(&participants, *MAX_MALICIOUS + 1, rng); diff --git a/crates/threshold-signatures/benches/ckd.rs b/crates/threshold-signatures/benches/ckd.rs index cc4c3602fc..d8e91b0973 100644 --- a/crates/threshold-signatures/benches/ckd.rs +++ b/crates/threshold-signatures/benches/ckd.rs @@ -27,7 +27,9 @@ fn threshold() -> ReconstructionThreshold { /// Benches the ckd protocol fn bench_ckd(c: &mut Criterion) { - let num = threshold().as_usize(); + let num = threshold() + .try_as_usize() + .expect("reconstruction threshold fits in usize"); let max_malicious = *MAX_MALICIOUS; let setup = setup_ckd_snapshot(threshold()); diff --git a/crates/threshold-signatures/src/dkg.rs b/crates/threshold-signatures/src/dkg.rs index ab4b292a17..0229c25c7f 100644 --- a/crates/threshold-signatures/src/dkg.rs +++ b/crates/threshold-signatures/src/dkg.rs @@ -180,7 +180,7 @@ fn verify_proof_of_knowledge( commitment: &VerifiableSecretSharingCommitment, proof_of_knowledge: Option<&Signature>, ) -> Result<(), ProtocolError> { - let threshold = threshold.as_usize(); + let threshold = threshold.try_as_usize()?; match proof_of_knowledge { // if participant did not send anything but he is actually an old participant None => { @@ -243,17 +243,17 @@ fn verify_commitment_hash( fn insert_identity_if_missing( threshold: ReconstructionThreshold, commitment_i: &VerifiableSecretSharingCommitment, -) -> VerifiableSecretSharingCommitment { +) -> Result, ProtocolError> { // in case the participant was new and it sent a polynomial of length // threshold -1 (because the zero term is not serializable) let mut commitment_i = commitment_i.clone(); let mut coefficients_i = commitment_i.coefficients().to_vec(); - if coefficients_i.len() == threshold.as_usize() - 1 { + if coefficients_i.len() == threshold.try_as_usize()? - 1 { let identity = CoefficientCommitment::new(::identity()); coefficients_i.insert(0, identity); commitment_i = VerifiableSecretSharingCommitment::new(coefficients_i); } - commitment_i + Ok(commitment_i) } // creates a signing share structure using my identifier, the received @@ -373,7 +373,7 @@ async fn do_keyshare( // Step 2.3 // the degree of the polynomial is threshold - 1 let degree = threshold - .as_usize() + .try_as_usize()? .checked_sub(1) .ok_or(ProtocolError::IntegerOverflow)?; let secret_coefficients = Polynomial::::generate_polynomial(Some(secret), degree, rng)?; @@ -429,7 +429,7 @@ async fn do_keyshare( // Start Round 3 // add my commitment to the map with the proper commitment sizes = threshold - let my_full_commitment = insert_identity_if_missing(threshold, &commitment); + let my_full_commitment = insert_identity_if_missing(threshold, &commitment)?; all_full_commitments.put(me, my_full_commitment); // Broadcast the commitment and the proof of knowledge @@ -472,7 +472,7 @@ async fn do_keyshare( // in case the participant was new and it sent a polynomial of length // threshold -1 (because the zero term is not serializable) - let full_commitment_i = insert_identity_if_missing(threshold, commitment_i); + let full_commitment_i = insert_identity_if_missing(threshold, commitment_i)?; // add received full commitment all_full_commitments.put(p, full_commitment_i); @@ -562,7 +562,7 @@ pub fn assert_key_invariants( me: Participant, threshold: impl Into, ) -> Result { - let threshold = threshold.into().as_usize(); + let threshold = threshold.into().try_as_usize()?; // need enough participants if participants.len() < 2 { return Err(InitializationError::NotEnoughParticipants { @@ -646,7 +646,7 @@ pub fn assert_reshare_keys_invariants( old_participants: &[Participant], ) -> Result<(ParticipantList, ParticipantList), InitializationError> { let threshold = threshold.into(); - let old_threshold = old_threshold.into().as_usize(); + let old_threshold = old_threshold.into().try_as_usize()?; let participants = assert_key_invariants(participants, me, threshold)?; diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/presign.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/presign.rs index aa19962aab..b4f49e90a2 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/presign.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/presign.rs @@ -31,9 +31,10 @@ pub fn presign( }); } // Spec 1.1 - if args.threshold.as_usize() > participants.len() { + let threshold = args.threshold.try_as_usize()?; + if threshold > participants.len() { return Err(InitializationError::ThresholdTooLarge { - threshold: args.threshold.as_usize(), + threshold, max: participants.len(), }); } diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs index 5f1a6d9215..44f3b20a9a 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/sign.rs @@ -37,7 +37,7 @@ pub fn sign( where T: Into, { - let threshold = threshold.into().as_usize(); + let threshold = threshold.into().try_as_usize()?; if participants.len() < 2 { return Err(InitializationError::NotEnoughParticipants { participants: participants.len(), diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs index f80b07d49b..8d7279c7c9 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/generation.rs @@ -144,11 +144,11 @@ async fn do_generation_many( let mut big_l_i_v = vec![]; let degree1 = threshold - .as_usize() + .try_as_usize()? .checked_sub(1) .ok_or(ProtocolError::IntegerOverflow)?; let degree2 = threshold - .as_usize() + .try_as_usize()? .checked_sub(2) .ok_or(ProtocolError::IntegerOverflow)?; @@ -367,10 +367,11 @@ async fn do_generation_many( big_f_v.iter_mut(), big_l_v.iter_mut(), )) { - if their_big_e.degree() != threshold.as_usize() - 1 - || their_big_f.degree() != threshold.as_usize() - 1 + let threshold_value = threshold.try_as_usize()?; + if their_big_e.degree() != threshold_value - 1 + || their_big_f.degree() != threshold_value - 1 // degree is threshold - 2 because the constant element identity is not serializable - || their_big_l.degree() != threshold.as_usize() - 2 + || their_big_l.degree() != threshold_value - 2 { return Err(ProtocolError::AssertionFailed(format!( "polynomial from {from:?} has the wrong length" @@ -707,7 +708,7 @@ fn validate_triple_inputs( threshold: impl Into, ) -> Result<(ParticipantList, ReconstructionThreshold), InitializationError> { let threshold = threshold.into(); - let threshold_value = threshold.as_usize(); + let threshold_value = threshold.try_as_usize()?; if participants.len() < 2 { return Err(InitializationError::NotEnoughParticipants { participants: participants.len(), diff --git a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs index 13ff07e466..5d89171beb 100644 --- a/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs +++ b/crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/test.rs @@ -31,7 +31,7 @@ pub fn deal( let b = Secp256K1ScalarField::random(&mut *rng); let c = a * b; - let degree = threshold.as_usize().checked_sub(1).unwrap(); + let degree = threshold.try_as_usize()?.checked_sub(1).unwrap(); let f_a = Polynomial::generate_polynomial(Some(a), degree, rng)?; let f_b = Polynomial::generate_polynomial(Some(b), degree, rng)?; let f_c = Polynomial::generate_polynomial(Some(c), degree, rng)?; diff --git a/crates/threshold-signatures/src/errors.rs b/crates/threshold-signatures/src/errors.rs index 61aecf6acf..acacc6ce5c 100644 --- a/crates/threshold-signatures/src/errors.rs +++ b/crates/threshold-signatures/src/errors.rs @@ -1,4 +1,5 @@ use crate::participants::Participant; +use crate::thresholds::ThresholdError; use std::error; use thiserror::Error; @@ -165,3 +166,15 @@ pub enum InitializationError { #[error("participant has an invalid index")] InvalidParticipantIndex, } + +impl From for ProtocolError { + fn from(_: ThresholdError) -> Self { + Self::IntegerOverflow + } +} + +impl From for InitializationError { + fn from(value: ThresholdError) -> Self { + Self::BadParameters(value.to_string()) + } +} diff --git a/crates/threshold-signatures/src/frost/presign.rs b/crates/threshold-signatures/src/frost/presign.rs index a94b885797..c0474d7672 100644 --- a/crates/threshold-signatures/src/frost/presign.rs +++ b/crates/threshold-signatures/src/frost/presign.rs @@ -72,9 +72,10 @@ where } // validate threshold - if args.threshold.as_usize() > participants.len() { + let threshold = args.threshold.try_as_usize()?; + if threshold > participants.len() { return Err(InitializationError::ThresholdTooLarge { - threshold: args.threshold.as_usize(), + threshold, max: participants.len(), }); } diff --git a/crates/threshold-signatures/src/frost/sign_utils.rs b/crates/threshold-signatures/src/frost/sign_utils.rs index fe0608eec0..d132163216 100644 --- a/crates/threshold-signatures/src/frost/sign_utils.rs +++ b/crates/threshold-signatures/src/frost/sign_utils.rs @@ -30,9 +30,10 @@ pub fn assert_sign_inputs( } // validate threshold - if threshold.as_usize() > participants.len() { + let threshold = threshold.try_as_usize()?; + if threshold > participants.len() { return Err(InitializationError::ThresholdTooLarge { - threshold: threshold.as_usize(), + threshold, max: participants.len(), }); } diff --git a/crates/threshold-signatures/src/thresholds.rs b/crates/threshold-signatures/src/thresholds.rs index 19ab2b14a1..9db498128e 100644 --- a/crates/threshold-signatures/src/thresholds.rs +++ b/crates/threshold-signatures/src/thresholds.rs @@ -26,15 +26,14 @@ impl ReconstructionThreshold { self.0 } - /// The threshold as a `usize`, for indexing and sizing collections in the - /// protocol code. Lossless on all supported (>= 32-bit) targets. + /// The threshold as a `usize`, for indexing and sizing collections. /// - /// # Panics + /// # Errors /// - /// Panics only if the threshold exceeds `usize::MAX` — impossible on - /// supported targets, where a participant count always fits in `usize`. - pub fn as_usize(self) -> usize { - usize::try_from(self.0).expect("reconstruction threshold fits in usize") + /// [`ThresholdError::IntegerOverflow`] if the threshold exceeds `usize::MAX` + /// — unreachable on supported (>= 32-bit) targets. + pub fn try_as_usize(self) -> Result { + usize::try_from(self.0).map_err(|_| ThresholdError::IntegerOverflow) } } @@ -67,3 +66,71 @@ pub enum ThresholdError { #[error("integer overflow")] IntegerOverflow, } + +#[cfg(test)] +#[allow(non_snake_case)] +mod tests { + use super::*; + + #[test] + fn reconstruction_threshold__should_round_trip_through_new_and_inner() { + // Given + let threshold = ReconstructionThreshold::new(3); + + // When + let inner = threshold.inner(); + + // Then + assert_eq!(inner, 3); + assert_eq!(ReconstructionThreshold::new(inner), threshold); + } + + #[test] + fn reconstruction_threshold__should_round_trip_through_from_usize_and_try_as_usize() { + // Given + let threshold = ReconstructionThreshold::from(5usize); + + // When + let as_usize = threshold.try_as_usize(); + + // Then + assert_eq!(as_usize, Ok(5usize)); + assert_eq!(ReconstructionThreshold::from(as_usize.unwrap()), threshold); + } + + #[test] + fn try_as_usize__should_return_ok_for_representable_value() { + // Given + let threshold = ReconstructionThreshold::new(7); + + // When + let result = threshold.try_as_usize(); + + // Then + assert_eq!(result, Ok(7usize)); + } + + #[test] + fn try_from_max_malicious__should_be_max_malicious_plus_one() { + // Given + let max_malicious = MaxMalicious::from(4usize); + + // When + let threshold = ReconstructionThreshold::try_from(max_malicious); + + // Then + assert_eq!(threshold, Ok(ReconstructionThreshold::new(5))); + } + + #[test] + fn try_from_max_malicious__should_overflow_when_at_usize_max() { + // Given + let max_malicious = MaxMalicious::from(usize::MAX); + + // When + let result = ReconstructionThreshold::try_from(max_malicious); + + // Then + assert_eq!(result, Err(ThresholdError::IntegerOverflow)); + } +} From c29e61784bc0d655597b83c06adae3c42532a6d5 Mon Sep 17 00:00:00 2001 From: Simon Rastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Tue, 16 Jun 2026 20:40:58 +0200 Subject: [PATCH 7/9] Fixing errors --- crates/node/src/tests/protocol_yielding.rs | 4 ++-- crates/threshold-signatures/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/node/src/tests/protocol_yielding.rs b/crates/node/src/tests/protocol_yielding.rs index 908d4684c4..21d35bcd78 100644 --- a/crates/node/src/tests/protocol_yielding.rs +++ b/crates/node/src/tests/protocol_yielding.rs @@ -28,7 +28,7 @@ use anyhow::Context; use rand::SeedableRng as _; use std::sync::Arc; use std::time::{Duration, Instant}; -use threshold_signatures::ReconstructionLowerBound; +use threshold_signatures::ReconstructionThreshold; use threshold_signatures::ecdsa::ot_based_ecdsa::triples::generate_triple_many; use threshold_signatures::participants::Participant; use threshold_signatures::test_utils::{MockCryptoRng, generate_participants}; @@ -139,7 +139,7 @@ async fn run_triple_gen_client( let protocol = generate_triple_many::( &cs_participants, my_id.into(), - ReconstructionLowerBound::from(THRESHOLD), + ReconstructionThreshold::from(THRESHOLD), rng, )?; let triples = run_protocol("canary triple gen", &mut channel, protocol).await?; diff --git a/crates/threshold-signatures/src/lib.rs b/crates/threshold-signatures/src/lib.rs index 0834b1d6b5..0bbf6114d9 100644 --- a/crates/threshold-signatures/src/lib.rs +++ b/crates/threshold-signatures/src/lib.rs @@ -36,7 +36,7 @@ use crate::errors::InitializationError; use crate::participants::Participant; use crate::protocol::Protocol; use crate::protocol::internal::{Comms, make_protocol}; -pub use crate::thresholds::{MaxMalicious, ReconstructionThreshold}; +pub use crate::thresholds::{MaxMalicious, ReconstructionThreshold, ThresholdError}; use rand_core::CryptoRngCore; use std::marker::Send; From be03538f17aabed39f2fe8d81eda500246321bf3 Mon Sep 17 00:00:00 2001 From: Simon Rastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Tue, 16 Jun 2026 22:18:27 +0200 Subject: [PATCH 8/9] Had missed some conflict --- crates/threshold-signatures/src/lib.rs | 4 ---- crates/threshold-signatures/src/thresholds.rs | 11 ----------- 2 files changed, 15 deletions(-) diff --git a/crates/threshold-signatures/src/lib.rs b/crates/threshold-signatures/src/lib.rs index 3c96d774c6..0bbf6114d9 100644 --- a/crates/threshold-signatures/src/lib.rs +++ b/crates/threshold-signatures/src/lib.rs @@ -36,11 +36,7 @@ use crate::errors::InitializationError; use crate::participants::Participant; use crate::protocol::Protocol; use crate::protocol::internal::{Comms, make_protocol}; -<<<<<<< HEAD pub use crate::thresholds::{MaxMalicious, ReconstructionThreshold, ThresholdError}; -======= -pub use crate::thresholds::{MaxMalicious, ReconstructionThreshold}; ->>>>>>> main use rand_core::CryptoRngCore; use std::marker::Send; diff --git a/crates/threshold-signatures/src/thresholds.rs b/crates/threshold-signatures/src/thresholds.rs index 450d35017f..9db498128e 100644 --- a/crates/threshold-signatures/src/thresholds.rs +++ b/crates/threshold-signatures/src/thresholds.rs @@ -7,15 +7,8 @@ use thiserror::Error; )] pub struct MaxMalicious(usize); -<<<<<<< HEAD #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] pub struct ReconstructionThreshold(u64); -======= -#[derive( - Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, From, Into, -)] -pub struct ReconstructionThreshold(usize); ->>>>>>> main // ----- MaxMalicious conversions ----- impl MaxMalicious { @@ -25,15 +18,11 @@ impl MaxMalicious { } impl ReconstructionThreshold { -<<<<<<< HEAD pub const fn new(value: u64) -> Self { Self(value) } pub fn inner(self) -> u64 { -======= - pub fn value(self) -> usize { ->>>>>>> main self.0 } From dc55e9d78e9c2807766252dcfd93c34a49cae3ba Mon Sep 17 00:00:00 2001 From: Simon Rastikian <43679791+SimonRastikian@users.noreply.github.com> Date: Wed, 17 Jun 2026 09:32:16 +0200 Subject: [PATCH 9/9] Single name of threshold in node tests --- crates/node/src/key_events.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/node/src/key_events.rs b/crates/node/src/key_events.rs index b9d1d9cc6a..3c468068e5 100644 --- a/crates/node/src/key_events.rs +++ b/crates/node/src/key_events.rs @@ -727,11 +727,11 @@ mod tests { use mpc_primitives::domain::DomainId; use mpc_primitives::{AttemptId, EpochId, KeyEventId}; use near_mpc_contract_interface::types::{ - DomainConfig, DomainPurpose, Protocol, ReconstructionThreshold, + DomainConfig, DomainPurpose, Protocol, }; use std::collections::BTreeSet; use std::sync::atomic::{AtomicUsize, Ordering}; - use threshold_signatures::ReconstructionThreshold as TSReconstructionThreshold; + use threshold_signatures::ReconstructionThreshold; #[rstest::rstest] #[tokio::test(start_paused = true)] @@ -888,7 +888,7 @@ mod tests { domain: DomainConfig { id: key_event_id.domain_id, protocol: Protocol::CaitSith, - reconstruction_threshold: ReconstructionThreshold::new(2), + reconstruction_threshold: dtos::ReconstructionThreshold::new(2), purpose: DomainPurpose::Sign, }, started, @@ -901,7 +901,7 @@ mod tests { Arc::new(ResharingArgs { previous_keyset: Keyset::new(EpochId::new(5), vec![]), existing_keyshares: None, - new_threshold: TSReconstructionThreshold::from(3), + new_threshold: ReconstructionThreshold::from(3), old_participants: ParticipantsConfig { threshold: 3, participants: vec![],