diff --git a/Cargo.lock b/Cargo.lock index c121c8a3..c0c27a8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8483,6 +8483,7 @@ dependencies = [ "ciphersuite", "const-hex", "dalek-ff-group", + "dkg-pedpop", "dockertest", "env_logger", "ethereum-serai", @@ -8667,7 +8668,7 @@ version = "0.1.0" dependencies = [ "borsh", "ciphersuite", - "dkg", + "dkg-musig", "parity-scale-codec", "scale-info", "serai-primitives", diff --git a/processor/Cargo.toml b/processor/Cargo.toml index e881a85e..b68d8a89 100644 --- a/processor/Cargo.toml +++ b/processor/Cargo.toml @@ -37,6 +37,7 @@ serde_json = { version = "1", default-features = false, features = ["std"] } ciphersuite = { path = "../crypto/ciphersuite", default-features = false, features = ["std", "ristretto"] } transcript = { package = "flexible-transcript", path = "../crypto/transcript", default-features = false, features = ["std"] } +dkg-pedpop = { path = "../crypto/dkg/pedpop", default-features = false } frost = { package = "modular-frost", path = "../crypto/frost", default-features = false, features = ["ristretto"] } frost-schnorrkel = { path = "../crypto/schnorrkel", default-features = false } diff --git a/processor/src/key_gen.rs b/processor/src/key_gen.rs index 297db194..894fec78 100644 --- a/processor/src/key_gen.rs +++ b/processor/src/key_gen.rs @@ -7,11 +7,10 @@ use rand_chacha::ChaCha20Rng; use transcript::{Transcript, RecommendedTranscript}; use ciphersuite::group::GroupEncoding; +use dkg_pedpop::*; use frost::{ curve::{Ciphersuite, Ristretto}, - dkg::{ - DkgError, Participant, ThresholdParams, ThresholdCore, ThresholdKeys, encryption::*, pedpop::*, - }, + dkg::{DkgError, Participant, ThresholdParams, ThresholdCore, ThresholdKeys}, }; use log::info; diff --git a/substrate/validator-sets/primitives/Cargo.toml b/substrate/validator-sets/primitives/Cargo.toml index 844e6134..41883059 100644 --- a/substrate/validator-sets/primitives/Cargo.toml +++ b/substrate/validator-sets/primitives/Cargo.toml @@ -19,7 +19,7 @@ workspace = true zeroize = { version = "^1.5", features = ["derive"], optional = true } ciphersuite = { path = "../../../crypto/ciphersuite", version = "0.4", default-features = false, features = ["alloc", "ristretto"] } -dkg = { path = "../../../crypto/dkg", version = "0.5", default-features = false } +dkg-musig = { path = "../../../crypto/dkg/musig", default-features = false } borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"], optional = true } serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true } @@ -33,7 +33,7 @@ sp-std = { git = "https://github.com/serai-dex/substrate", default-features = fa serai-primitives = { path = "../../primitives", default-features = false } [features] -std = ["zeroize", "ciphersuite/std", "dkg/std", "borsh?/std", "serde?/std", "scale/std", "scale-info/std", "sp-core/std", "sp-std/std", "serai-primitives/std"] +std = ["zeroize", "ciphersuite/std", "dkg-musig/std", "borsh?/std", "serde?/std", "scale/std", "scale-info/std", "sp-core/std", "sp-std/std", "serai-primitives/std"] borsh = ["dep:borsh", "serai-primitives/borsh"] serde = ["dep:serde", "serai-primitives/serde"] default = ["std"] diff --git a/substrate/validator-sets/primitives/src/lib.rs b/substrate/validator-sets/primitives/src/lib.rs index 9944d485..581491f0 100644 --- a/substrate/validator-sets/primitives/src/lib.rs +++ b/substrate/validator-sets/primitives/src/lib.rs @@ -107,8 +107,13 @@ impl Zeroize for KeyPair { } /// The MuSig context for a validator set. -pub fn musig_context(set: ValidatorSet) -> Vec { - [b"ValidatorSets-musig_key".as_ref(), &set.encode()].concat() +pub fn musig_context(set: ValidatorSet) -> [u8; 32] { + let mut context = [0; 32]; + const DST: &[u8] = b"ValidatorSets-musig_key"; + context[.. DST.len()].copy_from_slice(DST); + let set = set.encode(); + context[DST.len() .. (DST.len() + set.len())].copy_from_slice(set.len()); + context } /// The MuSig public key for a validator set. @@ -122,7 +127,7 @@ pub fn musig_key(set: ValidatorSet, set_keys: &[Public]) -> Public { .expect("invalid participant"), ); } - Public(dkg::musig::musig_key::(&musig_context(set), &keys).unwrap().to_bytes()) + Public(dkg_musig::musig_key_vartime::(musig_context(set), &keys).unwrap().to_bytes()) } /// The message for the set_keys signature. diff --git a/tests/coordinator/Cargo.toml b/tests/coordinator/Cargo.toml index 89b168c0..edc3c112 100644 --- a/tests/coordinator/Cargo.toml +++ b/tests/coordinator/Cargo.toml @@ -26,7 +26,7 @@ rand_core = { version = "0.6", default-features = false } blake2 = "0.10" ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["ristretto", "secp256k1"] } schnorrkel = "0.11" -dkg = { path = "../../crypto/dkg", default-features = false, features = ["tests"] } +dkg = { path = "../../crypto/dkg", default-features = false } messages = { package = "serai-processor-messages", path = "../../processor/messages" } diff --git a/tests/processor/Cargo.toml b/tests/processor/Cargo.toml index 395bcad8..9da9a347 100644 --- a/tests/processor/Cargo.toml +++ b/tests/processor/Cargo.toml @@ -24,7 +24,7 @@ rand_core = { version = "0.6", default-features = false, features = ["getrandom" curve25519-dalek = "4" ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["secp256k1", "ristretto"] } -dkg = { path = "../../crypto/dkg", default-features = false, features = ["tests"] } +dkg = { path = "../../crypto/dkg", default-features = false } bitcoin-serai = { path = "../../networks/bitcoin" } diff --git a/tests/processor/src/tests/batch.rs b/tests/processor/src/tests/batch.rs index 4a34500e..fb6803c8 100644 --- a/tests/processor/src/tests/batch.rs +++ b/tests/processor/src/tests/batch.rs @@ -3,7 +3,7 @@ use std::{ time::{SystemTime, Duration}, }; -use dkg::{Participant, tests::clone_without}; +use dkg::Participant; use messages::{coordinator::*, SubstrateContext}; diff --git a/tests/processor/src/tests/key_gen.rs b/tests/processor/src/tests/key_gen.rs index ec616b51..abaddfcf 100644 --- a/tests/processor/src/tests/key_gen.rs +++ b/tests/processor/src/tests/key_gen.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, time::SystemTime}; -use dkg::{Participant, ThresholdParams, tests::clone_without}; +use dkg::{Participant, ThresholdParams}; use serai_client::{ primitives::{BlockHash, PublicKey, EXTERNAL_NETWORKS}, diff --git a/tests/processor/src/tests/mod.rs b/tests/processor/src/tests/mod.rs index 0347a3dd..42cfef69 100644 --- a/tests/processor/src/tests/mod.rs +++ b/tests/processor/src/tests/mod.rs @@ -15,6 +15,15 @@ mod send; pub(crate) const COORDINATORS: usize = 4; pub(crate) const THRESHOLD: usize = ((COORDINATORS * 2) / 3) + 1; +fn clone_without( + map: &HashMap, + without: &K, +) -> HashMap { + let mut res = map.clone(); + res.remove(without).unwrap(); + res +} + fn new_test( network: ExternalNetworkId, ) -> (Vec<(Handles, ::F)>, DockerTest) { diff --git a/tests/processor/src/tests/send.rs b/tests/processor/src/tests/send.rs index e50edc3f..1e5f55ce 100644 --- a/tests/processor/src/tests/send.rs +++ b/tests/processor/src/tests/send.rs @@ -3,7 +3,7 @@ use std::{ time::{SystemTime, Duration}, }; -use dkg::{Participant, tests::clone_without}; +use dkg::Participant; use messages::{sign::SignId, SubstrateContext};