mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 04:09:23 +00:00
Fix misc compilation errors
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -8050,6 +8050,7 @@ dependencies = [
|
||||
"bitcoin",
|
||||
"blake2",
|
||||
"ciphersuite",
|
||||
"dkg-musig",
|
||||
"dockertest",
|
||||
"frame-system",
|
||||
"frost-schnorrkel",
|
||||
@@ -8109,6 +8110,7 @@ dependencies = [
|
||||
"blake2",
|
||||
"borsh",
|
||||
"ciphersuite",
|
||||
"dkg-musig",
|
||||
"env_logger",
|
||||
"flexible-transcript",
|
||||
"frost-schnorrkel",
|
||||
@@ -8480,6 +8482,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"bitcoin-serai",
|
||||
"blake2",
|
||||
"borsh",
|
||||
"ciphersuite",
|
||||
"const-hex",
|
||||
|
||||
@@ -27,6 +27,7 @@ blake2 = { version = "0.10", default-features = false, features = ["std"] }
|
||||
transcript = { package = "flexible-transcript", path = "../crypto/transcript", default-features = false, features = ["std", "recommended"] }
|
||||
ciphersuite = { path = "../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||
schnorr = { package = "schnorr-signatures", path = "../crypto/schnorr", default-features = false, features = ["std"] }
|
||||
dkg-musig = { path = "../crypto/dkg/musig", default-features = false, features = ["std"] }
|
||||
frost = { package = "modular-frost", path = "../crypto/frost" }
|
||||
frost-schnorrkel = { path = "../crypto/schnorrkel" }
|
||||
|
||||
|
||||
@@ -361,8 +361,8 @@ async fn dkg_test() {
|
||||
assert!(signature.verify(
|
||||
&*serai_client::validator_sets::primitives::set_keys_message(&set, &[], &key_pair),
|
||||
&serai_client::Public(
|
||||
frost::dkg::musig::musig_key::<Ristretto>(
|
||||
&serai_client::validator_sets::primitives::musig_context(set.into()),
|
||||
dkg_musig::musig_key_vartime::<Ristretto>(
|
||||
serai_client::validator_sets::primitives::musig_context(set.into()),
|
||||
&self.spec.validators().into_iter().map(|(validator, _)| validator).collect::<Vec<_>>()
|
||||
)
|
||||
.unwrap()
|
||||
|
||||
@@ -67,12 +67,8 @@ use ciphersuite::{
|
||||
group::{ff::PrimeField, GroupEncoding},
|
||||
Ciphersuite, Ristretto,
|
||||
};
|
||||
use frost::{
|
||||
FrostError,
|
||||
dkg::{Participant, musig::musig},
|
||||
ThresholdKeys,
|
||||
sign::*,
|
||||
};
|
||||
use dkg_musig::musig;
|
||||
use frost::{FrostError, dkg::Participant, ThresholdKeys, sign::*};
|
||||
use frost_schnorrkel::Schnorrkel;
|
||||
|
||||
use scale::Encode;
|
||||
@@ -119,7 +115,7 @@ impl<T: DbTxn, C: Encode> SigningProtocol<'_, T, C> {
|
||||
|
||||
let algorithm = Schnorrkel::new(b"substrate");
|
||||
let keys: ThresholdKeys<Ristretto> =
|
||||
musig(&musig_context(self.spec.set().into()), self.key, participants)
|
||||
musig(musig_context(self.spec.set().into()), self.key.clone(), participants)
|
||||
.expect("signing for a set we aren't in/validator present multiple times")
|
||||
.into();
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ pub fn key_gen() -> (HashMap<Participant, ThresholdKeys<Secp256k1>>, PublicKey)
|
||||
group_key += ProjectivePoint::GENERATOR;
|
||||
}
|
||||
for keys in keys.values_mut() {
|
||||
*keys = keys.offset(offset);
|
||||
*keys = keys.clone().offset(offset);
|
||||
}
|
||||
let public_key = PublicKey::new(group_key).unwrap();
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ borsh = { version = "1", default-features = false, features = ["std", "derive",
|
||||
serde_json = { version = "1", default-features = false, features = ["std"] }
|
||||
|
||||
# Cryptography
|
||||
blake2 = { version = "0.10", 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"] }
|
||||
|
||||
@@ -10,7 +10,7 @@ use ciphersuite::group::GroupEncoding;
|
||||
use dkg_pedpop::*;
|
||||
use frost::{
|
||||
curve::{Ciphersuite, Ristretto},
|
||||
dkg::{DkgError, Participant, ThresholdParams, ThresholdCore, ThresholdKeys},
|
||||
dkg::{Participant, ThresholdParams, ThresholdKeys},
|
||||
};
|
||||
|
||||
use log::info;
|
||||
@@ -54,8 +54,8 @@ impl GeneratedKeysDb {
|
||||
let mut substrate_keys = vec![];
|
||||
let mut network_keys = vec![];
|
||||
while !keys_ref.is_empty() {
|
||||
substrate_keys.push(ThresholdKeys::new(ThresholdCore::read(&mut keys_ref).unwrap()));
|
||||
let mut these_network_keys = ThresholdKeys::new(ThresholdCore::read(&mut keys_ref).unwrap());
|
||||
substrate_keys.push(ThresholdKeys::read(&mut keys_ref).unwrap());
|
||||
let mut these_network_keys = ThresholdKeys::read(&mut keys_ref).unwrap();
|
||||
N::tweak_keys(&mut these_network_keys);
|
||||
network_keys.push(these_network_keys);
|
||||
}
|
||||
@@ -65,7 +65,7 @@ impl GeneratedKeysDb {
|
||||
fn save_keys<N: Network>(
|
||||
txn: &mut impl DbTxn,
|
||||
id: &KeyGenId,
|
||||
substrate_keys: &[ThresholdCore<Ristretto>],
|
||||
substrate_keys: &[ThresholdKeys<Ristretto>],
|
||||
network_keys: &[ThresholdKeys<N::Curve>],
|
||||
) {
|
||||
let mut keys = Zeroizing::new(vec![]);
|
||||
@@ -181,8 +181,9 @@ impl<N: Network, D: Db> KeyGen<N, D> {
|
||||
) -> ProcessorMessage {
|
||||
const SUBSTRATE_KEY_CONTEXT: &str = "substrate";
|
||||
const NETWORK_KEY_CONTEXT: &str = "network";
|
||||
let context = |id: &KeyGenId, key| {
|
||||
let context = |id: &KeyGenId, key| -> [u8; 32] {
|
||||
// TODO2: Also embed the chain ID/genesis block
|
||||
<blake2::Blake2s256 as blake2::digest::Digest>::digest(
|
||||
format!(
|
||||
"Serai Key Gen. Session: {:?}, Network: {:?}, Attempt: {}, Key: {}",
|
||||
id.session,
|
||||
@@ -190,6 +191,9 @@ impl<N: Network, D: Db> KeyGen<N, D> {
|
||||
id.attempt,
|
||||
key,
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
.into()
|
||||
};
|
||||
|
||||
let rng = |label, id: KeyGenId| {
|
||||
@@ -246,19 +250,10 @@ impl<N: Network, D: Db> KeyGen<N, D> {
|
||||
match machine.generate_secret_shares(rng, commitments) {
|
||||
Ok(res) => Ok(res),
|
||||
Err(e) => match e {
|
||||
DkgError::ZeroParameter(_, _) |
|
||||
DkgError::InvalidThreshold(_, _) |
|
||||
DkgError::InvalidParticipant(_, _) |
|
||||
DkgError::InvalidSigningSet |
|
||||
DkgError::InvalidShare { .. } => unreachable!("{e:?}"),
|
||||
DkgError::InvalidParticipantQuantity(_, _) |
|
||||
DkgError::DuplicatedParticipant(_) |
|
||||
DkgError::MissingParticipant(_) => {
|
||||
panic!("coordinator sent invalid DKG commitments: {e:?}")
|
||||
}
|
||||
DkgError::InvalidCommitments(i) => {
|
||||
PedPoPError::InvalidCommitments(i) => {
|
||||
Err(ProcessorMessage::InvalidCommitments { id, faulty: i })?
|
||||
}
|
||||
_ => panic!("unknown error: {e:?}"),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -396,7 +391,7 @@ impl<N: Network, D: Db> KeyGen<N, D> {
|
||||
m: usize,
|
||||
machine: KeyMachine<C>,
|
||||
shares_ref: &mut HashMap<Participant, &[u8]>,
|
||||
) -> Result<ThresholdCore<C>, ProcessorMessage> {
|
||||
) -> Result<ThresholdKeys<C>, ProcessorMessage> {
|
||||
let params = ThresholdParams::new(
|
||||
params.t(),
|
||||
params.n(),
|
||||
@@ -421,17 +416,7 @@ impl<N: Network, D: Db> KeyGen<N, D> {
|
||||
(match machine.calculate_share(rng, shares) {
|
||||
Ok(res) => res,
|
||||
Err(e) => match e {
|
||||
DkgError::ZeroParameter(_, _) |
|
||||
DkgError::InvalidThreshold(_, _) |
|
||||
DkgError::InvalidParticipant(_, _) |
|
||||
DkgError::InvalidSigningSet |
|
||||
DkgError::InvalidCommitments(_) => unreachable!("{e:?}"),
|
||||
DkgError::InvalidParticipantQuantity(_, _) |
|
||||
DkgError::DuplicatedParticipant(_) |
|
||||
DkgError::MissingParticipant(_) => {
|
||||
panic!("coordinator sent invalid DKG shares: {e:?}")
|
||||
}
|
||||
DkgError::InvalidShare { participant, blame } => {
|
||||
PedPoPError::InvalidShare { participant, blame } => {
|
||||
Err(ProcessorMessage::InvalidShare {
|
||||
id,
|
||||
accuser: params.i(),
|
||||
@@ -439,6 +424,7 @@ impl<N: Network, D: Db> KeyGen<N, D> {
|
||||
blame: Some(blame.map(|blame| blame.serialize())).flatten(),
|
||||
})?
|
||||
}
|
||||
_ => panic!("unknown error: {e:?}"),
|
||||
},
|
||||
})
|
||||
.complete(),
|
||||
@@ -468,7 +454,7 @@ impl<N: Network, D: Db> KeyGen<N, D> {
|
||||
Ok(keys) => keys,
|
||||
Err(msg) => return msg,
|
||||
};
|
||||
let these_network_keys =
|
||||
let mut these_network_keys =
|
||||
match handle_machine(&mut rng, id, params, m, machines.1, &mut shares_ref) {
|
||||
Ok(keys) => keys,
|
||||
Err(msg) => return msg,
|
||||
@@ -487,7 +473,6 @@ impl<N: Network, D: Db> KeyGen<N, D> {
|
||||
}
|
||||
}
|
||||
|
||||
let mut these_network_keys = ThresholdKeys::new(these_network_keys);
|
||||
N::tweak_keys(&mut these_network_keys);
|
||||
|
||||
substrate_keys.push(these_substrate_keys);
|
||||
@@ -556,7 +541,6 @@ impl<N: Network, D: Db> KeyGen<N, D> {
|
||||
blame.clone().and_then(|blame| EncryptionKeyProof::read(&mut blame.as_slice()).ok());
|
||||
|
||||
let substrate_blame = AdditionalBlameMachine::new(
|
||||
&mut rand_core::OsRng,
|
||||
context(&id, SUBSTRATE_KEY_CONTEXT),
|
||||
params.n(),
|
||||
substrate_commitment_msgs,
|
||||
@@ -564,7 +548,6 @@ impl<N: Network, D: Db> KeyGen<N, D> {
|
||||
.unwrap()
|
||||
.blame(accuser, accused, substrate_share, substrate_blame);
|
||||
let network_blame = AdditionalBlameMachine::new(
|
||||
&mut rand_core::OsRng,
|
||||
context(&id, NETWORK_KEY_CONTEXT),
|
||||
params.n(),
|
||||
network_commitment_msgs,
|
||||
|
||||
@@ -648,7 +648,7 @@ impl Network for Bitcoin {
|
||||
const MAX_OUTPUTS: usize = MAX_OUTPUTS;
|
||||
|
||||
fn tweak_keys(keys: &mut ThresholdKeys<Self::Curve>) {
|
||||
*keys = tweak_keys(keys);
|
||||
*keys = tweak_keys(keys.clone());
|
||||
// Also create a scanner to assert these keys, and all expected paths, are usable
|
||||
scanner(keys.group_key());
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ impl<D: Db> Network for Ethereum<D> {
|
||||
|
||||
fn tweak_keys(keys: &mut ThresholdKeys<Self::Curve>) {
|
||||
while PublicKey::new(keys.group_key()).is_none() {
|
||||
*keys = keys.offset(<Secp256k1 as Ciphersuite>::F::ONE);
|
||||
*keys = keys.clone().offset(<Secp256k1 as Ciphersuite>::F::ONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -666,7 +666,7 @@ impl Network for Monero {
|
||||
keys: ThresholdKeys<Self::Curve>,
|
||||
transaction: SignableTransaction,
|
||||
) -> Result<Self::TransactionMachine, NetworkError> {
|
||||
match transaction.0.clone().multisig(&keys) {
|
||||
match transaction.0.clone().multisig(keys) {
|
||||
Ok(machine) => Ok(machine),
|
||||
Err(e) => panic!("failed to create a multisig machine for TX: {e}"),
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use ciphersuite::group::GroupEncoding;
|
||||
use frost::{
|
||||
curve::Ristretto,
|
||||
Participant,
|
||||
dkg::tests::{key_gen, clone_without},
|
||||
tests::{key_gen, clone_without},
|
||||
};
|
||||
|
||||
use sp_application_crypto::{RuntimePublic, sr25519::Public};
|
||||
|
||||
@@ -6,7 +6,7 @@ use ciphersuite::group::GroupEncoding;
|
||||
use frost::{
|
||||
curve::Ristretto,
|
||||
Participant,
|
||||
dkg::tests::{key_gen, clone_without},
|
||||
tests::{key_gen, clone_without},
|
||||
};
|
||||
|
||||
use sp_application_crypto::{RuntimePublic, sr25519::Public};
|
||||
|
||||
@@ -6,7 +6,7 @@ use rand_core::{RngCore, OsRng};
|
||||
use ciphersuite::group::GroupEncoding;
|
||||
use frost::{
|
||||
Participant, ThresholdKeys,
|
||||
dkg::tests::{key_gen, clone_without},
|
||||
tests::{key_gen, clone_without},
|
||||
};
|
||||
|
||||
use serai_db::{DbTxn, Db, MemDb};
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::collections::HashMap;
|
||||
use rand_core::OsRng;
|
||||
|
||||
use ciphersuite::group::GroupEncoding;
|
||||
use frost::{Participant, dkg::tests::key_gen};
|
||||
use frost::{Participant, tests::key_gen};
|
||||
|
||||
use tokio::time::timeout;
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ hex = "0.4"
|
||||
blake2 = "0.10"
|
||||
|
||||
ciphersuite = { path = "../../crypto/ciphersuite", features = ["ristretto"] }
|
||||
dkg-musig = { path = "../../crypto/dkg/musig" }
|
||||
frost = { package = "modular-frost", path = "../../crypto/frost", features = ["tests"] }
|
||||
schnorrkel = { path = "../../crypto/schnorrkel", package = "frost-schnorrkel" }
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use rand_core::{RngCore, OsRng};
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
use ciphersuite::{Ciphersuite, Ristretto};
|
||||
use frost::dkg::musig::musig;
|
||||
use dkg_musig::musig;
|
||||
use schnorrkel::Schnorrkel;
|
||||
|
||||
use sp_core::{sr25519::Signature, Pair as PairTrait};
|
||||
@@ -99,7 +99,7 @@ async fn set_values(serai: &Serai, values: &Values) {
|
||||
|
||||
assert_eq!(Ristretto::generator() * secret_key, public_key);
|
||||
let threshold_keys =
|
||||
musig::<Ristretto>(&musig_context(set), &Zeroizing::new(secret_key), &[public_key]).unwrap();
|
||||
musig::<Ristretto>(musig_context(set), Zeroizing::new(secret_key), &[public_key]).unwrap();
|
||||
|
||||
let sig = frost::tests::sign_without_caching(
|
||||
&mut OsRng,
|
||||
|
||||
@@ -10,7 +10,7 @@ use sp_core::{
|
||||
};
|
||||
|
||||
use ciphersuite::{Ciphersuite, Ristretto};
|
||||
use frost::dkg::musig::musig;
|
||||
use dkg_musig::musig;
|
||||
use schnorrkel::Schnorrkel;
|
||||
|
||||
use serai_client::{
|
||||
@@ -46,8 +46,7 @@ pub async fn set_keys(
|
||||
assert_eq!(Ristretto::generator() * secret_key, pub_keys[i]);
|
||||
|
||||
threshold_keys.push(
|
||||
musig::<Ristretto>(&musig_context(set.into()), &Zeroizing::new(secret_key), &pub_keys)
|
||||
.unwrap(),
|
||||
musig::<Ristretto>(musig_context(set.into()), Zeroizing::new(secret_key), &pub_keys).unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ pub fn musig_context(set: ValidatorSet) -> [u8; 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[DST.len() .. (DST.len() + set.len())].copy_from_slice(&set);
|
||||
context
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use ciphersuite::{Ciphersuite, Ristretto};
|
||||
|
||||
use dockertest::DockerTest;
|
||||
|
||||
Reference in New Issue
Block a user