mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Fix clippy, update old dependencies
This commit is contained in:
499
Cargo.lock
generated
499
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -205,6 +205,9 @@ matches = { path = "patches/matches" }
|
|||||||
option-ext = { path = "patches/option-ext" }
|
option-ext = { path = "patches/option-ext" }
|
||||||
directories-next = { path = "patches/directories-next" }
|
directories-next = { path = "patches/directories-next" }
|
||||||
|
|
||||||
|
# Patch to include `FromUniformBytes<64>` over Scalar
|
||||||
|
k256 = { git = "https://github.com/kayabaNerve/elliptic-curves", rev = "fc92333e222b7f0cbe268d2ca92ed572f71f3e1d" }
|
||||||
|
|
||||||
[workspace.lints.clippy]
|
[workspace.lints.clippy]
|
||||||
unwrap_or_default = "allow"
|
unwrap_or_default = "allow"
|
||||||
map_unwrap_or = "allow"
|
map_unwrap_or = "allow"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ workspace = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
parity-db = { version = "0.4", default-features = false, optional = true }
|
parity-db = { version = "0.4", default-features = false, optional = true }
|
||||||
rocksdb = { version = "0.23", default-features = false, features = ["zstd"], optional = true }
|
rocksdb = { version = "0.24", default-features = false, features = ["zstd"], optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
parity-db = ["dep:parity-db"]
|
parity-db = ["dep:parity-db"]
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ transcript = { package = "flexible-transcript", path = "../crypto/transcript", d
|
|||||||
dalek-ff-group = { path = "../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
dalek-ff-group = { path = "../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
||||||
ciphersuite = { path = "../crypto/ciphersuite", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
schnorr = { package = "schnorr-signatures", path = "../crypto/schnorr", default-features = false, features = ["std", "aggregate"] }
|
schnorr = { package = "schnorr-signatures", path = "../crypto/schnorr", default-features = false, features = ["std", "aggregate"] }
|
||||||
dkg-musig = { path = "../crypto/dkg/musig", default-features = false, features = ["std"] }
|
dkg = { package = "dkg-musig", path = "../crypto/dkg/musig", default-features = false, features = ["std"] }
|
||||||
frost = { package = "modular-frost", path = "../crypto/frost" }
|
frost = { package = "modular-frost", path = "../crypto/frost" }
|
||||||
frost-schnorrkel = { path = "../crypto/schnorrkel" }
|
frost-schnorrkel = { path = "../crypto/schnorrkel" }
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ impl<D: Db> ContinuallyRan for CosignIntendTask<D> {
|
|||||||
|
|
||||||
// Tell each set of their expectation to cosign this block
|
// Tell each set of their expectation to cosign this block
|
||||||
for set in global_session_info.sets {
|
for set in global_session_info.sets {
|
||||||
log::debug!("{:?} will be cosigning block #{block_number}", set);
|
log::debug!("{set:?} will be cosigning block #{block_number}");
|
||||||
IntendedCosigns::send(
|
IntendedCosigns::send(
|
||||||
&mut txn,
|
&mut txn,
|
||||||
set,
|
set,
|
||||||
|
|||||||
@@ -3,13 +3,11 @@ use std::{boxed::Box, collections::HashMap};
|
|||||||
|
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
use rand_core::OsRng;
|
use rand_core::OsRng;
|
||||||
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
|
use ciphersuite::{group::GroupEncoding, Ciphersuite};
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
|
use dkg::{Participant, musig};
|
||||||
use frost_schnorrkel::{
|
use frost_schnorrkel::{
|
||||||
frost::{
|
frost::{FrostError, sign::*},
|
||||||
dkg::{Participant, musig::musig},
|
|
||||||
FrostError,
|
|
||||||
sign::*,
|
|
||||||
},
|
|
||||||
Schnorrkel,
|
Schnorrkel,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -155,16 +153,15 @@ impl<CD: DbTrait, TD: DbTrait> ConfirmDkgTask<CD, TD> {
|
|||||||
db: &mut CD,
|
db: &mut CD,
|
||||||
set: ExternalValidatorSet,
|
set: ExternalValidatorSet,
|
||||||
attempt: u32,
|
attempt: u32,
|
||||||
key: &Zeroizing<<Ristretto as Ciphersuite>::F>,
|
key: Zeroizing<<Ristretto as Ciphersuite>::F>,
|
||||||
signer: &mut Option<Signer>,
|
signer: &mut Option<Signer>,
|
||||||
) {
|
) {
|
||||||
// Perform the preprocess
|
// Perform the preprocess
|
||||||
|
let public_key = Ristretto::generator() * key.deref();
|
||||||
let (machine, preprocess) = AlgorithmMachine::new(
|
let (machine, preprocess) = AlgorithmMachine::new(
|
||||||
schnorrkel(),
|
schnorrkel(),
|
||||||
// We use a 1-of-1 Musig here as we don't know who will actually be in this Musig yet
|
// We use a 1-of-1 Musig here as we don't know who will actually be in this Musig yet
|
||||||
musig(&musig_context(set.into()), key, &[Ristretto::generator() * key.deref()])
|
musig(musig_context(set.into()), key, &[public_key]).unwrap(),
|
||||||
.unwrap()
|
|
||||||
.into(),
|
|
||||||
)
|
)
|
||||||
.preprocess(&mut OsRng);
|
.preprocess(&mut OsRng);
|
||||||
// We take the preprocess so we can use it in a distinct machine with the actual Musig
|
// We take the preprocess so we can use it in a distinct machine with the actual Musig
|
||||||
@@ -199,7 +196,7 @@ impl<CD: DbTrait, TD: DbTrait> ContinuallyRan for ConfirmDkgTask<CD, TD> {
|
|||||||
// If we were sent a key to set, create the signer for it
|
// If we were sent a key to set, create the signer for it
|
||||||
if self.signer.is_none() && KeysToConfirm::get(&self.db, self.set.set).is_some() {
|
if self.signer.is_none() && KeysToConfirm::get(&self.db, self.set.set).is_some() {
|
||||||
// Create and publish the initial preprocess
|
// Create and publish the initial preprocess
|
||||||
Self::preprocess(&mut self.db, self.set.set, 0, &self.key, &mut self.signer);
|
Self::preprocess(&mut self.db, self.set.set, 0, self.key.clone(), &mut self.signer);
|
||||||
|
|
||||||
made_progress = true;
|
made_progress = true;
|
||||||
}
|
}
|
||||||
@@ -219,7 +216,13 @@ impl<CD: DbTrait, TD: DbTrait> ContinuallyRan for ConfirmDkgTask<CD, TD> {
|
|||||||
id: messages::sign::SignId { attempt, .. },
|
id: messages::sign::SignId { attempt, .. },
|
||||||
} => {
|
} => {
|
||||||
// Create and publish the preprocess for the specified attempt
|
// Create and publish the preprocess for the specified attempt
|
||||||
Self::preprocess(&mut self.db, self.set.set, attempt, &self.key, &mut self.signer);
|
Self::preprocess(
|
||||||
|
&mut self.db,
|
||||||
|
self.set.set,
|
||||||
|
attempt,
|
||||||
|
self.key.clone(),
|
||||||
|
&mut self.signer,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
messages::sign::CoordinatorMessage::Preprocesses {
|
messages::sign::CoordinatorMessage::Preprocesses {
|
||||||
id: messages::sign::SignId { attempt, .. },
|
id: messages::sign::SignId { attempt, .. },
|
||||||
@@ -258,9 +261,9 @@ impl<CD: DbTrait, TD: DbTrait> ContinuallyRan for ConfirmDkgTask<CD, TD> {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let keys = musig(&musig_context(self.set.set.into()), &self.key, &musig_public_keys)
|
let keys =
|
||||||
.unwrap()
|
musig(musig_context(self.set.set.into()), self.key.clone(), &musig_public_keys)
|
||||||
.into();
|
.unwrap();
|
||||||
|
|
||||||
// Rebuild the machine
|
// Rebuild the machine
|
||||||
let (machine, preprocess_from_cache) =
|
let (machine, preprocess_from_cache) =
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ use rand_core::{RngCore, OsRng};
|
|||||||
|
|
||||||
use dalek_ff_group::Ristretto;
|
use dalek_ff_group::Ristretto;
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{
|
group::{ff::PrimeField, GroupEncoding},
|
||||||
ff::{Field, PrimeField},
|
|
||||||
GroupEncoding,
|
|
||||||
},
|
|
||||||
Ciphersuite,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Ristretto};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ use std::sync::Arc;
|
|||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
use rand_core::OsRng;
|
use rand_core::OsRng;
|
||||||
use blake2::{digest::typenum::U32, Digest, Blake2s};
|
use blake2::{digest::typenum::U32, Digest, Blake2s};
|
||||||
use ciphersuite::{Ciphersuite, Ristretto};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
@@ -67,9 +68,7 @@ async fn provide_transaction<TD: DbTrait, P: P2p>(
|
|||||||
// advancing
|
// advancing
|
||||||
Err(ProvidedError::LocalMismatchesOnChain) => loop {
|
Err(ProvidedError::LocalMismatchesOnChain) => loop {
|
||||||
log::error!(
|
log::error!(
|
||||||
"Tributary {:?} was supposed to provide {:?} but peers disagree, halting Tributary",
|
"Tributary {set:?} was supposed to provide {tx:?} but peers disagree, halting Tributary",
|
||||||
set,
|
|
||||||
tx,
|
|
||||||
);
|
);
|
||||||
// Print this every five minutes as this does need to be handled
|
// Print this every five minutes as this does need to be handled
|
||||||
tokio::time::sleep(Duration::from_secs(5 * 60)).await;
|
tokio::time::sleep(Duration::from_secs(5 * 60)).await;
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ rand_chacha = { version = "0.3", default-features = false, features = ["std"] }
|
|||||||
blake2 = { version = "0.10", default-features = false, features = ["std"] }
|
blake2 = { version = "0.10", default-features = false, features = ["std"] }
|
||||||
transcript = { package = "flexible-transcript", path = "../../crypto/transcript", version = "0.3", default-features = false, features = ["std", "recommended"] }
|
transcript = { package = "flexible-transcript", path = "../../crypto/transcript", version = "0.3", default-features = false, features = ["std", "recommended"] }
|
||||||
|
|
||||||
ciphersuite = { package = "ciphersuite", path = "../../crypto/ciphersuite", version = "0.4", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", version = "0.4", default-features = false, features = ["std"] }
|
||||||
|
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
||||||
schnorr = { package = "schnorr-signatures", path = "../../crypto/schnorr", version = "0.5", default-features = false, features = ["std", "aggregate"] }
|
schnorr = { package = "schnorr-signatures", path = "../../crypto/schnorr", version = "0.5", default-features = false, features = ["std", "aggregate"] }
|
||||||
|
|
||||||
hex = { version = "0.4", default-features = false, features = ["std"] }
|
hex = { version = "0.4", default-features = false, features = ["std"] }
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ use std::{sync::Arc, io};
|
|||||||
|
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Ristretto};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
|
|
||||||
use scale::Decode;
|
use scale::Decode;
|
||||||
use futures_channel::mpsc::UnboundedReceiver;
|
use futures_channel::mpsc::UnboundedReceiver;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use rand_chacha::ChaCha12Rng;
|
|||||||
|
|
||||||
use transcript::{Transcript, RecommendedTranscript};
|
use transcript::{Transcript, RecommendedTranscript};
|
||||||
|
|
||||||
use dalek_ff_group::Ristretto;
|
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{
|
group::{
|
||||||
GroupEncoding,
|
GroupEncoding,
|
||||||
@@ -17,6 +16,7 @@ use ciphersuite::{
|
|||||||
},
|
},
|
||||||
Ciphersuite,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
use schnorr::{
|
use schnorr::{
|
||||||
SchnorrSignature,
|
SchnorrSignature,
|
||||||
aggregate::{SchnorrAggregator, SchnorrAggregate},
|
aggregate::{SchnorrAggregator, SchnorrAggregate},
|
||||||
@@ -164,7 +164,6 @@ impl SignatureScheme for Validators {
|
|||||||
type AggregateSignature = Vec<u8>;
|
type AggregateSignature = Vec<u8>;
|
||||||
type Signer = Arc<Signer>;
|
type Signer = Arc<Signer>;
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
fn verify(&self, validator: Self::ValidatorId, msg: &[u8], sig: &Self::Signature) -> bool {
|
fn verify(&self, validator: Self::ValidatorId, msg: &[u8], sig: &Self::Signature) -> bool {
|
||||||
if !self.weights.contains_key(&validator) {
|
if !self.weights.contains_key(&validator) {
|
||||||
return false;
|
return false;
|
||||||
@@ -197,7 +196,6 @@ impl SignatureScheme for Validators {
|
|||||||
aggregate.serialize()
|
aggregate.serialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
fn verify_aggregate(
|
fn verify_aggregate(
|
||||||
&self,
|
&self,
|
||||||
signers: &[Self::ValidatorId],
|
signers: &[Self::ValidatorId],
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ use blake2::{Digest, Blake2b512};
|
|||||||
|
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{Group, GroupEncoding},
|
group::{Group, GroupEncoding},
|
||||||
Ciphersuite, Ristretto,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
use schnorr::SchnorrSignature;
|
use schnorr::SchnorrSignature;
|
||||||
|
|
||||||
use crate::{TRANSACTION_SIZE_LIMIT, ReadWrite};
|
use crate::{TRANSACTION_SIZE_LIMIT, ReadWrite};
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ impl<S: SignatureScheme> SignatureScheme for Arc<S> {
|
|||||||
self.as_ref().aggregate(validators, msg, sigs)
|
self.as_ref().aggregate(validators, msg, sigs)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
fn verify_aggregate(
|
fn verify_aggregate(
|
||||||
&self,
|
&self,
|
||||||
signers: &[Self::ValidatorId],
|
signers: &[Self::ValidatorId],
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ impl SignatureScheme for TestSignatureScheme {
|
|||||||
type AggregateSignature = Vec<[u8; 32]>;
|
type AggregateSignature = Vec<[u8; 32]>;
|
||||||
type Signer = TestSigner;
|
type Signer = TestSigner;
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
fn verify(&self, validator: u16, msg: &[u8], sig: &[u8; 32]) -> bool {
|
fn verify(&self, validator: u16, msg: &[u8], sig: &[u8; 32]) -> bool {
|
||||||
(sig[.. 2] == validator.to_le_bytes()) && (sig[2 ..] == [msg, &[0; 30]].concat()[.. 30])
|
(sig[.. 2] == validator.to_le_bytes()) && (sig[2 ..] == [msg, &[0; 30]].concat()[.. 30])
|
||||||
}
|
}
|
||||||
@@ -60,7 +59,6 @@ impl SignatureScheme for TestSignatureScheme {
|
|||||||
sigs.to_vec()
|
sigs.to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
fn verify_aggregate(
|
fn verify_aggregate(
|
||||||
&self,
|
&self,
|
||||||
signers: &[TestValidatorId],
|
signers: &[TestValidatorId],
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ borsh = { version = "1", default-features = false, features = ["std", "derive",
|
|||||||
|
|
||||||
blake2 = { version = "0.10", default-features = false, features = ["std"] }
|
blake2 = { version = "0.10", default-features = false, features = ["std"] }
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
|
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
||||||
dkg = { path = "../../crypto/dkg", default-features = false, features = ["std"] }
|
dkg = { path = "../../crypto/dkg", default-features = false, features = ["std"] }
|
||||||
schnorr = { package = "schnorr-signatures", path = "../../crypto/schnorr", default-features = false, features = ["std"] }
|
schnorr = { package = "schnorr-signatures", path = "../../crypto/schnorr", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ impl<TD: Db, TDT: DbTxn, P: P2p> ScanBlock<'_, TD, TDT, P> {
|
|||||||
let signer = signer(signed);
|
let signer = signer(signed);
|
||||||
|
|
||||||
// Check the participant voted to be removed actually exists
|
// Check the participant voted to be removed actually exists
|
||||||
if !self.validators.iter().any(|validator| *validator == participant) {
|
if !self.validators.contains(&participant) {
|
||||||
TributaryDb::fatal_slash(
|
TributaryDb::fatal_slash(
|
||||||
self.tributary_txn,
|
self.tributary_txn,
|
||||||
self.set.set,
|
self.set.set,
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ use zeroize::Zeroizing;
|
|||||||
use rand_core::{RngCore, CryptoRng};
|
use rand_core::{RngCore, CryptoRng};
|
||||||
|
|
||||||
use blake2::{digest::typenum::U32, Digest, Blake2b};
|
use blake2::{digest::typenum::U32, Digest, Blake2b};
|
||||||
use dalek_ff_group::Ristretto;
|
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{Group, GroupEncoding},
|
group::{ff::Field, Group, GroupEncoding},
|
||||||
Ciphersuite,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
use schnorr::SchnorrSignature;
|
use schnorr::SchnorrSignature;
|
||||||
|
|
||||||
use scale::Encode;
|
use scale::Encode;
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ use elliptic_curve::{
|
|||||||
|
|
||||||
use ciphersuite::{group::ff::PrimeField, Ciphersuite};
|
use ciphersuite::{group::ff::PrimeField, Ciphersuite};
|
||||||
|
|
||||||
|
pub use k256;
|
||||||
|
pub use p256;
|
||||||
|
|
||||||
macro_rules! kp_curve {
|
macro_rules! kp_curve {
|
||||||
(
|
(
|
||||||
$feature: literal,
|
$feature: literal,
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ impl<C: Curves> Generators<C> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
|
||||||
/// Secp256k1, and an elliptic curve defined over its scalar field (secq256k1).
|
/// Secp256k1, and an elliptic curve defined over its scalar field (secq256k1).
|
||||||
#[cfg(feature = "secp256k1")]
|
#[cfg(feature = "secp256k1")]
|
||||||
pub struct Secp256k1;
|
pub struct Secp256k1;
|
||||||
@@ -86,7 +85,6 @@ impl Curves for Secp256k1 {
|
|||||||
type EmbeddedCurve = secq256k1::Secq256k1;
|
type EmbeddedCurve = secq256k1::Secq256k1;
|
||||||
type EmbeddedCurveParameters = secq256k1::Secq256k1;
|
type EmbeddedCurveParameters = secq256k1::Secq256k1;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/// Ed25519, and an elliptic curve defined over its scalar field (embedwards25519).
|
/// Ed25519, and an elliptic curve defined over its scalar field (embedwards25519).
|
||||||
#[cfg(feature = "ed25519")]
|
#[cfg(feature = "ed25519")]
|
||||||
|
|||||||
@@ -47,12 +47,12 @@ mod tests;
|
|||||||
/// `Participation` is meant to be broadcast to all other participants over an authenticated,
|
/// `Participation` is meant to be broadcast to all other participants over an authenticated,
|
||||||
/// reliable broadcast channel.
|
/// reliable broadcast channel.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
pub struct Participation<C: Ciphersuite> {
|
pub struct Participation<C: Curves> {
|
||||||
proof: Vec<u8>,
|
proof: Vec<u8>,
|
||||||
encrypted_secret_shares: HashMap<Participant, C::F>,
|
encrypted_secret_shares: HashMap<Participant, <C::ToweringCurve as Ciphersuite>::F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: Ciphersuite> Participation<C> {
|
impl<C: Curves> Participation<C> {
|
||||||
pub fn read<R: Read>(reader: &mut R, n: u16) -> io::Result<Self> {
|
pub fn read<R: Read>(reader: &mut R, n: u16) -> io::Result<Self> {
|
||||||
// Ban <32-bit platforms, allowing us to assume `u32` -> `usize` works
|
// Ban <32-bit platforms, allowing us to assume `u32` -> `usize` works
|
||||||
const _NO_16_BIT_PLATFORMS: [(); (usize::BITS - u32::BITS) as usize] = [(); _];
|
const _NO_16_BIT_PLATFORMS: [(); (usize::BITS - u32::BITS) as usize] = [(); _];
|
||||||
@@ -79,7 +79,7 @@ impl<C: Ciphersuite> Participation<C> {
|
|||||||
|
|
||||||
let mut encrypted_secret_shares = HashMap::with_capacity(usize::from(n));
|
let mut encrypted_secret_shares = HashMap::with_capacity(usize::from(n));
|
||||||
for i in Participant::iter().take(usize::from(n)) {
|
for i in Participant::iter().take(usize::from(n)) {
|
||||||
encrypted_secret_shares.insert(i, C::read_F(reader)?);
|
encrypted_secret_shares.insert(i, <C::ToweringCurve as Ciphersuite>::read_F(reader)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self { proof, encrypted_secret_shares })
|
Ok(Self { proof, encrypted_secret_shares })
|
||||||
@@ -190,7 +190,7 @@ impl<C: Curves> Dkg<C> {
|
|||||||
t: u16,
|
t: u16,
|
||||||
evrf_public_keys: &[<C::EmbeddedCurve as Ciphersuite>::G],
|
evrf_public_keys: &[<C::EmbeddedCurve as Ciphersuite>::G],
|
||||||
evrf_private_key: &Zeroizing<<C::EmbeddedCurve as Ciphersuite>::F>,
|
evrf_private_key: &Zeroizing<<C::EmbeddedCurve as Ciphersuite>::F>,
|
||||||
) -> Result<Participation<C::ToweringCurve>, Error> {
|
) -> Result<Participation<C>, Error> {
|
||||||
let Ok(n) = u16::try_from(evrf_public_keys.len()) else {
|
let Ok(n) = u16::try_from(evrf_public_keys.len()) else {
|
||||||
Err(Error::TooManyParticipants { provided: evrf_public_keys.len() })?
|
Err(Error::TooManyParticipants { provided: evrf_public_keys.len() })?
|
||||||
};
|
};
|
||||||
@@ -311,7 +311,7 @@ impl<C: Curves> Dkg<C> {
|
|||||||
context: [u8; 32],
|
context: [u8; 32],
|
||||||
t: u16,
|
t: u16,
|
||||||
evrf_public_keys: &[<C::EmbeddedCurve as Ciphersuite>::G],
|
evrf_public_keys: &[<C::EmbeddedCurve as Ciphersuite>::G],
|
||||||
participations: &HashMap<Participant, Participation<C::ToweringCurve>>,
|
participations: &HashMap<Participant, Participation<C>>,
|
||||||
) -> Result<VerifyResult<C>, Error> {
|
) -> Result<VerifyResult<C>, Error> {
|
||||||
let Ok(n) = u16::try_from(evrf_public_keys.len()) else {
|
let Ok(n) = u16::try_from(evrf_public_keys.len()) else {
|
||||||
Err(Error::TooManyParticipants { provided: evrf_public_keys.len() })?
|
Err(Error::TooManyParticipants { provided: evrf_public_keys.len() })?
|
||||||
|
|||||||
@@ -210,7 +210,6 @@ impl<C: Curve, T: Sync + Clone + Debug + Transcript, H: Hram<C>> Algorithm<C> fo
|
|||||||
SchnorrSignature::<C>::sign(params.secret_share(), nonces.swap_remove(0), c).s
|
SchnorrSignature::<C>::sign(params.secret_share(), nonces.swap_remove(0), c).s
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
fn verify(&self, group_key: C::G, nonces: &[Vec<C::G>], sum: C::F) -> Option<Self::Signature> {
|
fn verify(&self, group_key: C::G, nonces: &[Vec<C::G>], sum: C::F) -> Option<Self::Signature> {
|
||||||
let sig = SchnorrSignature { R: nonces[0][0], s: sum };
|
let sig = SchnorrSignature { R: nonces[0][0], s: sum };
|
||||||
Some(sig).filter(|sig| sig.verify(group_key, self.c.unwrap()))
|
Some(sig).filter(|sig| sig.verify(group_key, self.c.unwrap()))
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ impl<C: Curve> Algorithm<C> for MultiNonce<C> {
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
fn verify(&self, _: C::G, nonces: &[Vec<C::G>], sum: C::F) -> Option<Self::Signature> {
|
fn verify(&self, _: C::G, nonces: &[Vec<C::G>], sum: C::F) -> Option<Self::Signature> {
|
||||||
verify_nonces::<C>(nonces);
|
verify_nonces::<C>(nonces);
|
||||||
assert_eq!(&self.nonces.clone().unwrap(), nonces);
|
assert_eq!(&self.nonces.clone().unwrap(), nonces);
|
||||||
|
|||||||
@@ -128,7 +128,6 @@ impl Algorithm<Ristretto> for Schnorrkel {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
fn verify(
|
fn verify(
|
||||||
&self,
|
&self,
|
||||||
group_key: RistrettoPoint,
|
group_key: RistrettoPoint,
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ unknown-git = "deny"
|
|||||||
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
|
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
|
||||||
allow-git = [
|
allow-git = [
|
||||||
"https://github.com/rust-lang-nursery/lazy-static.rs",
|
"https://github.com/rust-lang-nursery/lazy-static.rs",
|
||||||
|
"https://github.com/kayabaNerve/elliptic-curves",
|
||||||
"https://github.com/kayabaNerve/pasta_curves",
|
"https://github.com/kayabaNerve/pasta_curves",
|
||||||
"https://github.com/kayabaNerve/monero-oxide",
|
"https://github.com/kayabaNerve/monero-oxide",
|
||||||
"https://github.com/serai-dex/substrate-bip39",
|
"https://github.com/serai-dex/substrate-bip39",
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ pub(crate) fn ack_message(from: Service, to: Service, id: u64, sig: SchnorrSigna
|
|||||||
// It's the second if we acknowledge messages before saving them as acknowledged
|
// It's the second if we acknowledge messages before saving them as acknowledged
|
||||||
// TODO: Check only a proper message is being acked
|
// TODO: Check only a proper message is being acked
|
||||||
|
|
||||||
log::info!("Acknowledging From: {:?} To: {:?} ID: {}", from, to, id);
|
log::info!("Acknowledging From: {from:?} To: {to:?} ID: {id}");
|
||||||
|
|
||||||
QUEUES.read().unwrap()[&(from, to)].write().unwrap().ack_message(id)
|
QUEUES.read().unwrap()[&(from, to)].write().unwrap().ack_message(id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ mod frost_crypto {
|
|||||||
self.0.sign_share(params, nonce_sums, nonces, msg)
|
self.0.sign_share(params, nonce_sums, nonces, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
fn verify(
|
fn verify(
|
||||||
&self,
|
&self,
|
||||||
group_key: ProjectivePoint,
|
group_key: ProjectivePoint,
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ tower = "0.5"
|
|||||||
serde_json = { version = "1", default-features = false }
|
serde_json = { version = "1", default-features = false }
|
||||||
simple-request = { path = "../../../common/request", version = "0.1", default-features = false }
|
simple-request = { path = "../../../common/request", version = "0.1", default-features = false }
|
||||||
|
|
||||||
alloy-json-rpc = { version = "0.14", default-features = false }
|
alloy-json-rpc = { version = "1", default-features = false }
|
||||||
alloy-transport = { version = "0.14", default-features = false }
|
alloy-transport = { version = "1", default-features = false }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["tls"]
|
default = ["tls"]
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ k256 = { version = "^0.13.1", default-features = false, features = ["ecdsa"] }
|
|||||||
alloy-core = { version = "1", default-features = false }
|
alloy-core = { version = "1", default-features = false }
|
||||||
alloy-sol-types = { version = "1", default-features = false }
|
alloy-sol-types = { version = "1", default-features = false }
|
||||||
|
|
||||||
alloy-simple-request-transport = { path = "../../../networks/ethereum/alloy-simple-request-transport", default-features = false }
|
alloy-simple-request-transport = { path = "../alloy-simple-request-transport", default-features = false }
|
||||||
alloy-rpc-types-eth = { version = "0.14", default-features = false }
|
alloy-rpc-types-eth = { version = "1", default-features = false }
|
||||||
alloy-rpc-client = { version = "0.14", default-features = false }
|
alloy-rpc-client = { version = "1", default-features = false }
|
||||||
alloy-provider = { version = "0.14", default-features = false }
|
alloy-provider = { version = "1", default-features = false }
|
||||||
|
|
||||||
alloy-node-bindings = { version = "0.14", default-features = false }
|
alloy-node-bindings = { version = "1", default-features = false }
|
||||||
|
|
||||||
tokio = { version = "1", default-features = false, features = ["macros"] }
|
tokio = { version = "1", default-features = false, features = ["macros"] }
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
pub use ciphersuite::*;
|
pub use ciphersuite::*;
|
||||||
#[cfg(feature = "ed25519")]
|
#[cfg(feature = "ed25519")]
|
||||||
use dalek_ff_group::Ed25519;
|
pub use dalek_ff_group::Ed25519;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ all-features = true
|
|||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocksdb = { version = "0.23", default-features = false, features = ["bindgen-runtime"] }
|
rocksdb = { version = "0.24", default-features = false, features = ["bindgen-runtime"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
jemalloc = [] # Dropped as this causes a compilation failure on windows
|
jemalloc = [] # Dropped as this causes a compilation failure on windows
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ use zeroize::{Zeroize, Zeroizing};
|
|||||||
|
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{ff::PrimeField, GroupEncoding},
|
group::{ff::PrimeField, GroupEncoding},
|
||||||
Ciphersuite, Ristretto,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
use dkg::evrf::EvrfCurve;
|
use dkg::{Curves, Ristretto};
|
||||||
|
|
||||||
use serai_client::validator_sets::primitives::Session;
|
use serai_client::validator_sets::primitives::Session;
|
||||||
|
|
||||||
@@ -100,8 +100,8 @@ fn key_gen<K: KeyGenParams>() -> KeyGen<K> {
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
KeyGen::new(
|
KeyGen::new(
|
||||||
read_key_from_env::<<Ristretto as EvrfCurve>::EmbeddedCurve>("SUBSTRATE_EVRF_KEY"),
|
read_key_from_env::<<Ristretto as Curves>::EmbeddedCurve>("SUBSTRATE_EVRF_KEY"),
|
||||||
read_key_from_env::<<K::ExternalNetworkCiphersuite as EvrfCurve>::EmbeddedCurve>(
|
read_key_from_env::<<K::ExternalNetworkCiphersuite as Curves>::EmbeddedCurve>(
|
||||||
"NETWORK_EVRF_KEY",
|
"NETWORK_EVRF_KEY",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -170,11 +170,13 @@ impl Hooks for () {
|
|||||||
pub async fn main_loop<
|
pub async fn main_loop<
|
||||||
H: Hooks,
|
H: Hooks,
|
||||||
S: ScannerFeed,
|
S: ScannerFeed,
|
||||||
K: KeyGenParams<ExternalNetworkCiphersuite: Ciphersuite<G = KeyFor<S>>>,
|
K: KeyGenParams<ExternalNetworkCiphersuite: Curves<ToweringCurve: Ciphersuite<G = KeyFor<S>>>>,
|
||||||
Sch: Clone
|
Sch: Clone
|
||||||
+ Scheduler<
|
+ Scheduler<
|
||||||
S,
|
S,
|
||||||
SignableTransaction: SignableTransaction<Ciphersuite = K::ExternalNetworkCiphersuite>,
|
SignableTransaction: SignableTransaction<
|
||||||
|
Ciphersuite = <K::ExternalNetworkCiphersuite as Curves>::ToweringCurve,
|
||||||
|
>,
|
||||||
>,
|
>,
|
||||||
>(
|
>(
|
||||||
mut db: Db,
|
mut db: Db,
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ scale = { package = "parity-scale-codec", version = "3", default-features = fals
|
|||||||
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
|
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
|
||||||
|
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
|
ciphersuite-kp256 = { path = "../../crypto/ciphersuite/kp256", default-features = false, features = ["std"] }
|
||||||
dkg = { package = "dkg-evrf", path = "../../crypto/dkg/evrf", default-features = false, features = ["std", "secp256k1"] }
|
dkg = { package = "dkg-evrf", path = "../../crypto/dkg/evrf", default-features = false, features = ["std", "secp256k1"] }
|
||||||
frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false }
|
frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use ciphersuite::{group::GroupEncoding, Ciphersuite, Secp256k1};
|
use ciphersuite::{group::GroupEncoding, Ciphersuite};
|
||||||
use frost::ThresholdKeys;
|
use dkg::{ThresholdKeys, Curves, Secp256k1};
|
||||||
|
|
||||||
use crate::{primitives::x_coord_to_even_point, scan::scanner};
|
use crate::{primitives::x_coord_to_even_point, scan::scanner};
|
||||||
|
|
||||||
@@ -9,20 +9,26 @@ impl key_gen::KeyGenParams for KeyGenParams {
|
|||||||
|
|
||||||
type ExternalNetworkCiphersuite = Secp256k1;
|
type ExternalNetworkCiphersuite = Secp256k1;
|
||||||
|
|
||||||
fn tweak_keys(keys: &mut ThresholdKeys<Self::ExternalNetworkCiphersuite>) {
|
fn tweak_keys(
|
||||||
*keys = bitcoin_serai::wallet::tweak_keys(keys);
|
keys: &mut ThresholdKeys<<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve>,
|
||||||
|
) {
|
||||||
|
*keys = bitcoin_serai::wallet::tweak_keys(keys.clone());
|
||||||
// Also create a scanner to assert these keys, and all expected paths, are usable
|
// Also create a scanner to assert these keys, and all expected paths, are usable
|
||||||
scanner(keys.group_key());
|
scanner(keys.group_key());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_key(key: <Self::ExternalNetworkCiphersuite as Ciphersuite>::G) -> Vec<u8> {
|
fn encode_key(
|
||||||
|
key: <<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::G,
|
||||||
|
) -> Vec<u8> {
|
||||||
let key = key.to_bytes();
|
let key = key.to_bytes();
|
||||||
let key: &[u8] = key.as_ref();
|
let key: &[u8] = key.as_ref();
|
||||||
// Skip the parity encoding as we know this key is even
|
// Skip the parity encoding as we know this key is even
|
||||||
key[1 ..].to_vec()
|
key[1 ..].to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode_key(key: &[u8]) -> Option<<Self::ExternalNetworkCiphersuite as Ciphersuite>::G> {
|
fn decode_key(
|
||||||
|
key: &[u8],
|
||||||
|
) -> Option<<<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::G> {
|
||||||
x_coord_to_even_point(key)
|
x_coord_to_even_point(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Secp256k1};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use ciphersuite_kp256::Secp256k1;
|
||||||
|
|
||||||
use bitcoin_serai::bitcoin::block::{Header, Block as BBlock};
|
use bitcoin_serai::bitcoin::block::{Header, Block as BBlock};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use ciphersuite::{Ciphersuite, Secp256k1};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use ciphersuite_kp256::Secp256k1;
|
||||||
|
|
||||||
use bitcoin_serai::bitcoin::key::{Parity, XOnlyPublicKey};
|
use bitcoin_serai::bitcoin::key::{Parity, XOnlyPublicKey};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Secp256k1};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use ciphersuite_kp256::Secp256k1;
|
||||||
|
|
||||||
use bitcoin_serai::{
|
use bitcoin_serai::{
|
||||||
bitcoin::{
|
bitcoin::{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::io;
|
|||||||
|
|
||||||
use rand_core::{RngCore, CryptoRng};
|
use rand_core::{RngCore, CryptoRng};
|
||||||
|
|
||||||
use ciphersuite::Secp256k1;
|
use ciphersuite_kp256::Secp256k1;
|
||||||
use frost::{dkg::ThresholdKeys, sign::PreprocessMachine};
|
use frost::{dkg::ThresholdKeys, sign::PreprocessMachine};
|
||||||
|
|
||||||
use bitcoin_serai::{
|
use bitcoin_serai::{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::{sync::LazyLock, collections::HashMap};
|
use std::{sync::LazyLock, collections::HashMap};
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Secp256k1};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use ciphersuite_kp256::Secp256k1;
|
||||||
|
|
||||||
use bitcoin_serai::{
|
use bitcoin_serai::{
|
||||||
bitcoin::{
|
bitcoin::{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use core::future::Future;
|
use core::future::Future;
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Secp256k1};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use ciphersuite_kp256::Secp256k1;
|
||||||
|
|
||||||
use bitcoin_serai::{
|
use bitcoin_serai::{
|
||||||
bitcoin::ScriptBuf,
|
bitcoin::ScriptBuf,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ scale = { package = "parity-scale-codec", version = "3", default-features = fals
|
|||||||
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
|
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
|
||||||
|
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
|
ciphersuite-kp256 = { path = "../../crypto/ciphersuite/kp256", default-features = false, features = ["std"] }
|
||||||
dkg = { package = "dkg-evrf", path = "../../crypto/dkg/evrf", default-features = false, features = ["std", "secp256k1"] }
|
dkg = { package = "dkg-evrf", path = "../../crypto/dkg/evrf", default-features = false, features = ["std", "secp256k1"] }
|
||||||
frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false, features = ["secp256k1"] }
|
frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false, features = ["secp256k1"] }
|
||||||
|
|
||||||
@@ -34,11 +35,11 @@ k256 = { version = "^0.13.1", default-features = false, features = ["std"] }
|
|||||||
alloy-core = { version = "1", default-features = false }
|
alloy-core = { version = "1", default-features = false }
|
||||||
alloy-rlp = { version = "0.3", default-features = false }
|
alloy-rlp = { version = "0.3", default-features = false }
|
||||||
|
|
||||||
alloy-rpc-types-eth = { version = "0.14", default-features = false }
|
alloy-rpc-types-eth = { version = "1", default-features = false }
|
||||||
alloy-transport = { version = "0.14", default-features = false }
|
alloy-transport = { version = "1", default-features = false }
|
||||||
alloy-simple-request-transport = { path = "../../networks/ethereum/alloy-simple-request-transport", default-features = false }
|
alloy-simple-request-transport = { path = "../../networks/ethereum/alloy-simple-request-transport", default-features = false }
|
||||||
alloy-rpc-client = { version = "0.14", default-features = false }
|
alloy-rpc-client = { version = "1", default-features = false }
|
||||||
alloy-provider = { version = "0.14", default-features = false }
|
alloy-provider = { version = "1", default-features = false }
|
||||||
|
|
||||||
serai-client = { path = "../../substrate/client", default-features = false, features = ["ethereum"] }
|
serai-client = { path = "../../substrate/client", default-features = false, features = ["ethereum"] }
|
||||||
|
|
||||||
|
|||||||
@@ -1,164 +0,0 @@
|
|||||||
TODO
|
|
||||||
|
|
||||||
async fn publish_completion(
|
|
||||||
&self,
|
|
||||||
completion: &<Self::Eventuality as EventualityTrait>::Completion,
|
|
||||||
) -> Result<(), NetworkError> {
|
|
||||||
// Publish this to the dedicated TX server for a solver to actually publish
|
|
||||||
#[cfg(not(test))]
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Publish this using a dummy account we fund with magic RPC commands
|
|
||||||
#[cfg(test)]
|
|
||||||
{
|
|
||||||
let router = self.router().await;
|
|
||||||
let router = router.as_ref().unwrap();
|
|
||||||
|
|
||||||
let mut tx = match completion.command() {
|
|
||||||
RouterCommand::UpdateSeraiKey { key, .. } => {
|
|
||||||
router.update_serai_key(key, completion.signature())
|
|
||||||
}
|
|
||||||
RouterCommand::Execute { outs, .. } => router.execute(
|
|
||||||
&outs.iter().cloned().map(Into::into).collect::<Vec<_>>(),
|
|
||||||
completion.signature(),
|
|
||||||
),
|
|
||||||
};
|
|
||||||
tx.gas_limit = 1_000_000u64.into();
|
|
||||||
tx.gas_price = 1_000_000_000u64.into();
|
|
||||||
let tx = ethereum_serai::crypto::deterministically_sign(tx);
|
|
||||||
|
|
||||||
if self.provider.get_transaction_by_hash(*tx.hash()).await.unwrap().is_none() {
|
|
||||||
self
|
|
||||||
.provider
|
|
||||||
.raw_request::<_, ()>(
|
|
||||||
"anvil_setBalance".into(),
|
|
||||||
[
|
|
||||||
tx.recover_signer().unwrap().to_string(),
|
|
||||||
(U256::from(tx.tx().gas_limit) * U256::from(tx.tx().gas_price)).to_string(),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (tx, sig, _) = tx.into_parts();
|
|
||||||
let mut bytes = vec![];
|
|
||||||
tx.encode_with_signature_fields(&sig, &mut bytes);
|
|
||||||
let pending_tx = self.provider.send_raw_transaction(&bytes).await.unwrap();
|
|
||||||
self.mine_block().await;
|
|
||||||
assert!(pending_tx.get_receipt().await.unwrap().status());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
async fn get_transaction_by_eventuality(
|
|
||||||
&self,
|
|
||||||
block: usize,
|
|
||||||
eventuality: &Self::Eventuality,
|
|
||||||
) -> Self::Transaction {
|
|
||||||
// We mine 96 blocks to ensure the 32 blocks relevant are finalized
|
|
||||||
// Back-check the prior two epochs in response to this
|
|
||||||
// TODO: Review why this is sub(3) and not sub(2)
|
|
||||||
for block in block.saturating_sub(3) ..= block {
|
|
||||||
match eventuality.1 {
|
|
||||||
RouterCommand::UpdateSeraiKey { nonce, .. } | RouterCommand::Execute { nonce, .. } => {
|
|
||||||
let router = self.router().await;
|
|
||||||
let router = router.as_ref().unwrap();
|
|
||||||
|
|
||||||
let block = u64::try_from(block).unwrap();
|
|
||||||
let filter = router
|
|
||||||
.key_updated_filter()
|
|
||||||
.from_block(block * 32)
|
|
||||||
.to_block(((block + 1) * 32) - 1)
|
|
||||||
.topic1(nonce);
|
|
||||||
let logs = self.provider.get_logs(&filter).await.unwrap();
|
|
||||||
if let Some(log) = logs.first() {
|
|
||||||
return self
|
|
||||||
.provider
|
|
||||||
.get_transaction_by_hash(log.clone().transaction_hash.unwrap())
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
};
|
|
||||||
|
|
||||||
let filter = router
|
|
||||||
.executed_filter()
|
|
||||||
.from_block(block * 32)
|
|
||||||
.to_block(((block + 1) * 32) - 1)
|
|
||||||
.topic1(nonce);
|
|
||||||
let logs = self.provider.get_logs(&filter).await.unwrap();
|
|
||||||
if logs.is_empty() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return self
|
|
||||||
.provider
|
|
||||||
.get_transaction_by_hash(logs[0].transaction_hash.unwrap())
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panic!("couldn't find completion in any three of checked blocks");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
async fn mine_block(&self) {
|
|
||||||
self.provider.raw_request::<_, ()>("anvil_mine".into(), [96]).await.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
async fn test_send(&self, send_to: Self::Address) -> Self::Block {
|
|
||||||
use rand_core::OsRng;
|
|
||||||
use ciphersuite::group::ff::Field;
|
|
||||||
use ethereum_serai::alloy::sol_types::SolCall;
|
|
||||||
|
|
||||||
let key = <Secp256k1 as Ciphersuite>::F::random(&mut OsRng);
|
|
||||||
let address = ethereum_serai::crypto::address(&(Secp256k1::generator() * key));
|
|
||||||
|
|
||||||
// Set a 1.1 ETH balance
|
|
||||||
self
|
|
||||||
.provider
|
|
||||||
.raw_request::<_, ()>(
|
|
||||||
"anvil_setBalance".into(),
|
|
||||||
[Address(address).to_string(), "1100000000000000000".into()],
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let value = U256::from_str_radix("1000000000000000000", 10).unwrap();
|
|
||||||
let tx = ethereum_serai::alloy::consensus::TxLegacy {
|
|
||||||
chain_id: None,
|
|
||||||
nonce: 0,
|
|
||||||
gas_price: 1_000_000_000u128,
|
|
||||||
gas_limit: 200_000u128,
|
|
||||||
to: ethereum_serai::alloy::primitives::TxKind::Call(send_to.0.into()),
|
|
||||||
// 1 ETH
|
|
||||||
value,
|
|
||||||
input: ethereum_serai::router::abi::inInstructionCall::new((
|
|
||||||
[0; 20].into(),
|
|
||||||
value,
|
|
||||||
vec![].into(),
|
|
||||||
))
|
|
||||||
.abi_encode()
|
|
||||||
.into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
use ethereum_serai::alloy::{primitives::Signature, consensus::SignableTransaction};
|
|
||||||
let sig = k256::ecdsa::SigningKey::from(k256::elliptic_curve::NonZeroScalar::new(key).unwrap())
|
|
||||||
.sign_prehash_recoverable(tx.signature_hash().as_ref())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut bytes = vec![];
|
|
||||||
tx.encode_with_signature_fields(&Signature::from(sig), &mut bytes);
|
|
||||||
let pending_tx = self.provider.send_raw_transaction(&bytes).await.ok().unwrap();
|
|
||||||
|
|
||||||
// Mine an epoch containing this TX
|
|
||||||
self.mine_block().await;
|
|
||||||
assert!(pending_tx.get_receipt().await.unwrap().status());
|
|
||||||
// Yield the freshly mined block
|
|
||||||
self.get_block(self.get_latest_block_number().await.unwrap()).await.unwrap()
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
// TODO
|
|
||||||
|
|
||||||
use rand_core::OsRng;
|
|
||||||
|
|
||||||
use group::ff::{Field, PrimeField};
|
|
||||||
use k256::{
|
|
||||||
ecdsa::{
|
|
||||||
self, hazmat::SignPrimitive, signature::hazmat::PrehashVerifier, SigningKey, VerifyingKey,
|
|
||||||
},
|
|
||||||
Scalar, ProjectivePoint,
|
|
||||||
};
|
|
||||||
|
|
||||||
use frost::{
|
|
||||||
curve::{Ciphersuite, Secp256k1},
|
|
||||||
algorithm::{Hram, IetfSchnorr},
|
|
||||||
tests::{algorithm_machines, sign},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{crypto::*, tests::key_gen};
|
|
||||||
|
|
||||||
// Run the sign test with the EthereumHram
|
|
||||||
#[test]
|
|
||||||
fn test_signing() {
|
|
||||||
let (keys, _) = key_gen();
|
|
||||||
|
|
||||||
const MESSAGE: &[u8] = b"Hello, World!";
|
|
||||||
|
|
||||||
let algo = IetfSchnorr::<Secp256k1, EthereumHram>::ietf();
|
|
||||||
let _sig =
|
|
||||||
sign(&mut OsRng, &algo, keys.clone(), algorithm_machines(&mut OsRng, &algo, &keys), MESSAGE);
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
// TODO
|
|
||||||
|
|
||||||
use std::{sync::Arc, collections::HashMap};
|
|
||||||
|
|
||||||
use rand_core::OsRng;
|
|
||||||
|
|
||||||
use k256::{Scalar, ProjectivePoint};
|
|
||||||
use frost::{curve::Secp256k1, Participant, ThresholdKeys, tests::key_gen as frost_key_gen};
|
|
||||||
|
|
||||||
use alloy_core::{
|
|
||||||
primitives::{Address, U256, Bytes, Signature, TxKind},
|
|
||||||
hex::FromHex,
|
|
||||||
};
|
|
||||||
use alloy_consensus::{SignableTransaction, TxLegacy};
|
|
||||||
|
|
||||||
use alloy_rpc_types_eth::TransactionReceipt;
|
|
||||||
use alloy_simple_request_transport::SimpleRequest;
|
|
||||||
use alloy_provider::{Provider, RootProvider};
|
|
||||||
|
|
||||||
use crate::crypto::{address, deterministically_sign, PublicKey};
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod crypto;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
use contracts::tests as abi;
|
|
||||||
#[cfg(test)]
|
|
||||||
mod router;
|
|
||||||
|
|
||||||
pub fn key_gen() -> (HashMap<Participant, ThresholdKeys<Secp256k1>>, PublicKey) {
|
|
||||||
let mut keys = frost_key_gen::<_, Secp256k1>(&mut OsRng);
|
|
||||||
let mut group_key = keys[&Participant::new(1).unwrap()].group_key();
|
|
||||||
|
|
||||||
let mut offset = Scalar::ZERO;
|
|
||||||
while PublicKey::new(group_key).is_none() {
|
|
||||||
offset += Scalar::ONE;
|
|
||||||
group_key += ProjectivePoint::GENERATOR;
|
|
||||||
}
|
|
||||||
for keys in keys.values_mut() {
|
|
||||||
*keys = keys.offset(offset);
|
|
||||||
}
|
|
||||||
let public_key = PublicKey::new(group_key).unwrap();
|
|
||||||
|
|
||||||
(keys, public_key)
|
|
||||||
}
|
|
||||||
@@ -22,11 +22,11 @@ alloy-core = { version = "1", default-features = false }
|
|||||||
alloy-sol-types = { version = "1", default-features = false }
|
alloy-sol-types = { version = "1", default-features = false }
|
||||||
alloy-sol-macro = { version = "1", default-features = false }
|
alloy-sol-macro = { version = "1", default-features = false }
|
||||||
|
|
||||||
alloy-consensus = { version = "0.14", default-features = false }
|
alloy-consensus = { version = "1", default-features = false }
|
||||||
|
|
||||||
alloy-rpc-types-eth = { version = "0.14", default-features = false }
|
alloy-rpc-types-eth = { version = "1", default-features = false }
|
||||||
alloy-transport = { version = "0.14", default-features = false }
|
alloy-transport = { version = "1", default-features = false }
|
||||||
alloy-provider = { version = "0.14", default-features = false }
|
alloy-provider = { version = "1", default-features = false }
|
||||||
|
|
||||||
ethereum-primitives = { package = "serai-processor-ethereum-primitives", path = "../primitives", default-features = false }
|
ethereum-primitives = { package = "serai-processor-ethereum-primitives", path = "../primitives", default-features = false }
|
||||||
|
|
||||||
@@ -35,9 +35,9 @@ build-solidity-contracts = { path = "../../../networks/ethereum/build-contracts"
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
alloy-simple-request-transport = { path = "../../../networks/ethereum/alloy-simple-request-transport", default-features = false }
|
alloy-simple-request-transport = { path = "../../../networks/ethereum/alloy-simple-request-transport", default-features = false }
|
||||||
alloy-rpc-client = { version = "0.14", default-features = false }
|
alloy-rpc-client = { version = "1", default-features = false }
|
||||||
alloy-node-bindings = { version = "0.14", default-features = false }
|
alloy-node-bindings = { version = "1", default-features = false }
|
||||||
|
|
||||||
tokio = { version = "1.0", default-features = false, features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "macros"] }
|
||||||
|
|
||||||
ethereum-test-primitives = { package = "serai-ethereum-test-primitives", path = "../test-primitives" }
|
ethereum-test-primitives = { package = "serai-ethereum-test-primitives", path = "../test-primitives" }
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ alloy-core = { version = "1", default-features = false }
|
|||||||
alloy-sol-types = { version = "1", default-features = false }
|
alloy-sol-types = { version = "1", default-features = false }
|
||||||
alloy-sol-macro = { version = "1", default-features = false }
|
alloy-sol-macro = { version = "1", default-features = false }
|
||||||
|
|
||||||
alloy-rpc-types-eth = { version = "0.14", default-features = false }
|
alloy-rpc-types-eth = { version = "1", default-features = false }
|
||||||
alloy-transport = { version = "0.14", default-features = false }
|
alloy-transport = { version = "1", default-features = false }
|
||||||
alloy-provider = { version = "0.14", default-features = false }
|
alloy-provider = { version = "1", default-features = false }
|
||||||
|
|
||||||
ethereum-primitives = { package = "serai-processor-ethereum-primitives", path = "../primitives", default-features = false }
|
ethereum-primitives = { package = "serai-processor-ethereum-primitives", path = "../primitives", default-features = false }
|
||||||
|
|
||||||
|
|||||||
@@ -23,4 +23,4 @@ group = { version = "0.13", default-features = false }
|
|||||||
k256 = { version = "^0.13.1", default-features = false, features = ["std", "arithmetic"] }
|
k256 = { version = "^0.13.1", default-features = false, features = ["std", "arithmetic"] }
|
||||||
|
|
||||||
alloy-primitives = { version = "1", default-features = false }
|
alloy-primitives = { version = "1", default-features = false }
|
||||||
alloy-consensus = { version = "0.14", default-features = false, features = ["k256"] }
|
alloy-consensus = { version = "1", default-features = false, features = ["k256"] }
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ alloy-core = { version = "1", default-features = false }
|
|||||||
alloy-sol-types = { version = "1", default-features = false }
|
alloy-sol-types = { version = "1", default-features = false }
|
||||||
alloy-sol-macro = { version = "1", default-features = false }
|
alloy-sol-macro = { version = "1", default-features = false }
|
||||||
|
|
||||||
alloy-consensus = { version = "0.14", default-features = false }
|
alloy-consensus = { version = "1", default-features = false }
|
||||||
|
|
||||||
alloy-rpc-types-eth = { version = "0.14", default-features = false }
|
alloy-rpc-types-eth = { version = "1", default-features = false }
|
||||||
alloy-transport = { version = "0.14", default-features = false }
|
alloy-transport = { version = "1", default-features = false }
|
||||||
alloy-provider = { version = "0.14", default-features = false }
|
alloy-provider = { version = "1", default-features = false }
|
||||||
|
|
||||||
revm = { version = "22", default-features = false, features = ["std"] }
|
revm = { version = "29", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
ethereum-schnorr = { package = "ethereum-schnorr-contract", path = "../../../networks/ethereum/schnorr", default-features = false }
|
ethereum-schnorr = { package = "ethereum-schnorr-contract", path = "../../../networks/ethereum/schnorr", default-features = false }
|
||||||
|
|
||||||
@@ -61,10 +61,10 @@ rand_core = { version = "0.6", default-features = false, features = ["std"] }
|
|||||||
k256 = { version = "0.13", default-features = false, features = ["std"] }
|
k256 = { version = "0.13", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
alloy-simple-request-transport = { path = "../../../networks/ethereum/alloy-simple-request-transport", default-features = false }
|
alloy-simple-request-transport = { path = "../../../networks/ethereum/alloy-simple-request-transport", default-features = false }
|
||||||
alloy-provider = { version = "0.14", default-features = false, features = ["debug-api", "trace-api"] }
|
alloy-provider = { version = "1", default-features = false, features = ["debug-api", "trace-api"] }
|
||||||
alloy-rpc-client = { version = "0.14", default-features = false }
|
alloy-rpc-client = { version = "1", default-features = false }
|
||||||
alloy-node-bindings = { version = "0.14", default-features = false }
|
alloy-node-bindings = { version = "1", default-features = false }
|
||||||
|
|
||||||
tokio = { version = "1.0", default-features = false, features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "macros"] }
|
||||||
|
|
||||||
ethereum-test-primitives = { package = "serai-ethereum-test-primitives", path = "../test-primitives" }
|
ethereum-test-primitives = { package = "serai-ethereum-test-primitives", path = "../test-primitives" }
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ use revm::{
|
|||||||
},
|
},
|
||||||
context::{
|
context::{
|
||||||
result::{EVMError, InvalidTransaction, ExecutionResult},
|
result::{EVMError, InvalidTransaction, ExecutionResult},
|
||||||
evm::{EvmData, Evm},
|
|
||||||
context::Context,
|
context::Context,
|
||||||
|
evm::Evm,
|
||||||
*,
|
*,
|
||||||
},
|
},
|
||||||
inspector::{Inspector, InspectorHandler},
|
inspector::{Inspector, InspectorHandler},
|
||||||
@@ -124,6 +124,7 @@ pub(crate) type GasEstimator = Evm<
|
|||||||
WorstCaseCallInspector,
|
WorstCaseCallInspector,
|
||||||
EthInstructions<EthInterpreter, RevmContext>,
|
EthInstructions<EthInterpreter, RevmContext>,
|
||||||
EthPrecompiles,
|
EthPrecompiles,
|
||||||
|
EthFrame,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
impl Router {
|
impl Router {
|
||||||
@@ -218,26 +219,24 @@ impl Router {
|
|||||||
db
|
db
|
||||||
};
|
};
|
||||||
|
|
||||||
Evm {
|
Evm::new_with_inspector(
|
||||||
data: EvmData {
|
RevmContext::new(db, SPEC_ID)
|
||||||
ctx: RevmContext::new(db, SPEC_ID)
|
.modify_cfg_chained(|cfg| {
|
||||||
.modify_cfg_chained(|cfg| {
|
cfg.chain_id = CHAIN_ID.try_into().unwrap();
|
||||||
cfg.chain_id = CHAIN_ID.try_into().unwrap();
|
})
|
||||||
})
|
.modify_tx_chained(|tx: &mut TxEnv| {
|
||||||
.modify_tx_chained(|tx: &mut TxEnv| {
|
tx.gas_limit = u64::MAX;
|
||||||
tx.gas_limit = u64::MAX;
|
tx.kind = self.address.into();
|
||||||
tx.kind = self.address.into();
|
}),
|
||||||
}),
|
WorstCaseCallInspector {
|
||||||
inspector: WorstCaseCallInspector {
|
erc20,
|
||||||
erc20,
|
call_depth: 0,
|
||||||
call_depth: 0,
|
unused_gas: 0,
|
||||||
unused_gas: 0,
|
override_immediate_call_return_value: false,
|
||||||
override_immediate_call_return_value: false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
instruction: EthInstructions::default(),
|
EthInstructions::default(),
|
||||||
precompiles: precompiles(),
|
precompiles(),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The worst-case gas cost for a legacy transaction which executes this batch.
|
/// The worst-case gas cost for a legacy transaction which executes this batch.
|
||||||
@@ -262,7 +261,7 @@ impl Router {
|
|||||||
let fee = if fee_per_gas == U256::ZERO { U256::ZERO } else { U256::ONE };
|
let fee = if fee_per_gas == U256::ZERO { U256::ZERO } else { U256::ONE };
|
||||||
|
|
||||||
// Set a balance of the amount sent out to ensure we don't error on that premise
|
// Set a balance of the amount sent out to ensure we don't error on that premise
|
||||||
gas_estimator.data.ctx.modify_db(|db| {
|
gas_estimator.ctx.modify_db(|db| {
|
||||||
let account = db.load_account(self.address).unwrap();
|
let account = db.load_account(self.address).unwrap();
|
||||||
account.info.balance = fee + outs.0.iter().map(|out| out.amount).sum::<U256>();
|
account.info.balance = fee + outs.0.iter().map(|out| out.amount).sum::<U256>();
|
||||||
});
|
});
|
||||||
@@ -290,7 +289,7 @@ impl Router {
|
|||||||
consistent use of nonce #1 shows storage read/writes aren't being persisted. They're solely
|
consistent use of nonce #1 shows storage read/writes aren't being persisted. They're solely
|
||||||
returned upon execution in a `state` field we ignore.
|
returned upon execution in a `state` field we ignore.
|
||||||
*/
|
*/
|
||||||
gas_estimator.data.ctx.modify_tx(|tx| {
|
gas_estimator.ctx.modify_tx(|tx| {
|
||||||
tx.caller = Address::from({
|
tx.caller = Address::from({
|
||||||
/*
|
/*
|
||||||
We assume the transaction sender is not the destination of any `OutInstruction`, making
|
We assume the transaction sender is not the destination of any `OutInstruction`, making
|
||||||
@@ -317,21 +316,17 @@ impl Router {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Execute the transaction
|
// Execute the transaction
|
||||||
let mut gas = match MainnetHandler::<
|
let mut gas =
|
||||||
_,
|
match MainnetHandler::<_, EVMError<Infallible, InvalidTransaction>, EthFrame<_>>::default()
|
||||||
EVMError<Infallible, InvalidTransaction>,
|
.inspect_run(&mut gas_estimator)
|
||||||
EthFrame<_, _, _>,
|
.unwrap()
|
||||||
>::default()
|
{
|
||||||
.inspect_run(&mut gas_estimator)
|
ExecutionResult::Success { gas_used, gas_refunded, .. } => {
|
||||||
.unwrap()
|
assert_eq!(gas_refunded, 0);
|
||||||
.result
|
gas_used
|
||||||
{
|
}
|
||||||
ExecutionResult::Success { gas_used, gas_refunded, .. } => {
|
res => panic!("estimated execute transaction failed: {res:?}"),
|
||||||
assert_eq!(gas_refunded, 0);
|
};
|
||||||
gas_used
|
|
||||||
}
|
|
||||||
res => panic!("estimated execute transaction failed: {res:?}"),
|
|
||||||
};
|
|
||||||
gas += gas_estimator.into_inspector().unused_gas;
|
gas += gas_estimator.into_inspector().unused_gas;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use ciphersuite::{Ciphersuite, Secp256k1};
|
use ciphersuite::Ciphersuite;
|
||||||
use dkg::ThresholdKeys;
|
use dkg::{ThresholdKeys, Curves, Secp256k1};
|
||||||
|
|
||||||
use ethereum_schnorr::PublicKey;
|
use ethereum_schnorr::PublicKey;
|
||||||
|
|
||||||
@@ -9,17 +9,23 @@ impl key_gen::KeyGenParams for KeyGenParams {
|
|||||||
|
|
||||||
type ExternalNetworkCiphersuite = Secp256k1;
|
type ExternalNetworkCiphersuite = Secp256k1;
|
||||||
|
|
||||||
fn tweak_keys(keys: &mut ThresholdKeys<Self::ExternalNetworkCiphersuite>) {
|
fn tweak_keys(
|
||||||
|
keys: &mut ThresholdKeys<<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve>,
|
||||||
|
) {
|
||||||
while PublicKey::new(keys.group_key()).is_none() {
|
while PublicKey::new(keys.group_key()).is_none() {
|
||||||
*keys = keys.offset(<Secp256k1 as Ciphersuite>::F::ONE);
|
*keys = keys.clone().offset(<<Secp256k1 as Curves>::ToweringCurve as Ciphersuite>::F::ONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_key(key: <Self::ExternalNetworkCiphersuite as Ciphersuite>::G) -> Vec<u8> {
|
fn encode_key(
|
||||||
|
key: <<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::G,
|
||||||
|
) -> Vec<u8> {
|
||||||
PublicKey::new(key).unwrap().eth_repr().to_vec()
|
PublicKey::new(key).unwrap().eth_repr().to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode_key(key: &[u8]) -> Option<<Self::ExternalNetworkCiphersuite as Ciphersuite>::G> {
|
fn decode_key(
|
||||||
|
key: &[u8],
|
||||||
|
) -> Option<<<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::G> {
|
||||||
PublicKey::from_eth_repr(key.try_into().ok()?).map(|key| key.point())
|
PublicKey::from_eth_repr(key.try_into().ok()?).map(|key| key.point())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Secp256k1};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use ciphersuite_kp256::Secp256k1;
|
||||||
|
|
||||||
use serai_client::networks::ethereum::Address;
|
use serai_client::networks::ethereum::Address;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ use std::{io, collections::HashMap};
|
|||||||
|
|
||||||
use rand_core::{RngCore, CryptoRng};
|
use rand_core::{RngCore, CryptoRng};
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Secp256k1};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use ciphersuite_kp256::Secp256k1;
|
||||||
use frost::{
|
use frost::{
|
||||||
dkg::{Participant, ThresholdKeys},
|
dkg::{Participant, ThresholdKeys},
|
||||||
FrostError,
|
FrostError,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use ciphersuite::{group::GroupEncoding, Ciphersuite, Secp256k1};
|
use ciphersuite::{group::GroupEncoding, Ciphersuite};
|
||||||
|
use ciphersuite_kp256::Secp256k1;
|
||||||
|
|
||||||
use alloy_core::primitives::U256;
|
use alloy_core::primitives::U256;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use ciphersuite::Secp256k1;
|
use ciphersuite_kp256::Secp256k1;
|
||||||
use frost::dkg::ThresholdKeys;
|
use frost::dkg::ThresholdKeys;
|
||||||
|
|
||||||
use alloy_core::primitives::{U256, Address as EthereumAddress};
|
use alloy_core::primitives::{U256, Address as EthereumAddress};
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ workspace = true
|
|||||||
k256 = { version = "0.13", default-features = false, features = ["std"] }
|
k256 = { version = "0.13", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
alloy-core = { version = "1", default-features = false }
|
alloy-core = { version = "1", default-features = false }
|
||||||
alloy-consensus = { version = "0.14", default-features = false, features = ["std"] }
|
alloy-consensus = { version = "1", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
alloy-rpc-types-eth = { version = "0.14", default-features = false }
|
alloy-rpc-types-eth = { version = "1", default-features = false }
|
||||||
alloy-provider = { version = "0.14", default-features = false }
|
alloy-provider = { version = "1", default-features = false }
|
||||||
|
|
||||||
ethereum-primitives = { package = "serai-processor-ethereum-primitives", path = "../primitives", default-features = false }
|
ethereum-primitives = { package = "serai-processor-ethereum-primitives", path = "../primitives", default-features = false }
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ rand_chacha = { version = "0.3", default-features = false, features = ["std"] }
|
|||||||
# Cryptography
|
# Cryptography
|
||||||
blake2 = { version = "0.10", default-features = false, features = ["std"] }
|
blake2 = { version = "0.10", default-features = false, features = ["std"] }
|
||||||
transcript = { package = "flexible-transcript", path = "../../crypto/transcript", default-features = false, features = ["std"] }
|
transcript = { package = "flexible-transcript", path = "../../crypto/transcript", default-features = false, features = ["std"] }
|
||||||
ec-divisors = { git = "https://github.com/kayabaNerve/monero-oxide", rev = "54da48f27a05fa8656014942919da1dfbab4d8e3", default-features = false }
|
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
|
||||||
dkg = { package = "dkg-evrf", path = "../../crypto/dkg/evrf", default-features = false, features = ["std", "ristretto"] }
|
dkg = { package = "dkg-evrf", path = "../../crypto/dkg/evrf", default-features = false, features = ["std", "ristretto"] }
|
||||||
|
|
||||||
# Substrate
|
# Substrate
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
|
use ciphersuite::{group::GroupEncoding, Ciphersuite};
|
||||||
use dkg::{Participant, ThresholdCore, ThresholdKeys, evrf::EvrfCurve};
|
use dkg::*;
|
||||||
|
|
||||||
use serai_validator_sets_primitives::Session;
|
use serai_validator_sets_primitives::Session;
|
||||||
|
|
||||||
@@ -17,9 +17,9 @@ pub(crate) struct Params<P: KeyGenParams> {
|
|||||||
pub(crate) t: u16,
|
pub(crate) t: u16,
|
||||||
pub(crate) n: u16,
|
pub(crate) n: u16,
|
||||||
pub(crate) substrate_evrf_public_keys:
|
pub(crate) substrate_evrf_public_keys:
|
||||||
Vec<<<Ristretto as EvrfCurve>::EmbeddedCurve as Ciphersuite>::G>,
|
Vec<<<Ristretto as Curves>::EmbeddedCurve as Ciphersuite>::G>,
|
||||||
pub(crate) network_evrf_public_keys:
|
pub(crate) network_evrf_public_keys:
|
||||||
Vec<<<P::ExternalNetworkCiphersuite as EvrfCurve>::EmbeddedCurve as Ciphersuite>::G>,
|
Vec<<<P::ExternalNetworkCiphersuite as Curves>::EmbeddedCurve as Ciphersuite>::G>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(BorshSerialize, BorshDeserialize)]
|
#[derive(BorshSerialize, BorshDeserialize)]
|
||||||
@@ -85,7 +85,7 @@ impl<P: KeyGenParams> KeyGenDb<P> {
|
|||||||
.substrate_evrf_public_keys
|
.substrate_evrf_public_keys
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|key| {
|
.map(|key| {
|
||||||
<<Ristretto as EvrfCurve>::EmbeddedCurve as Ciphersuite>::read_G(&mut key.as_slice())
|
<<Ristretto as Curves>::EmbeddedCurve as Ciphersuite>::read_G(&mut key.as_slice())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -93,7 +93,7 @@ impl<P: KeyGenParams> KeyGenDb<P> {
|
|||||||
.network_evrf_public_keys
|
.network_evrf_public_keys
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|key| {
|
.map(|key| {
|
||||||
<<P::ExternalNetworkCiphersuite as EvrfCurve>::EmbeddedCurve as Ciphersuite>::read_G::<
|
<<P::ExternalNetworkCiphersuite as Curves>::EmbeddedCurve as Ciphersuite>::read_G::<
|
||||||
&[u8],
|
&[u8],
|
||||||
>(&mut key.as_ref())
|
>(&mut key.as_ref())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -117,8 +117,8 @@ impl<P: KeyGenParams> KeyGenDb<P> {
|
|||||||
pub(crate) fn set_key_shares(
|
pub(crate) fn set_key_shares(
|
||||||
txn: &mut impl DbTxn,
|
txn: &mut impl DbTxn,
|
||||||
session: Session,
|
session: Session,
|
||||||
substrate_keys: &[ThresholdKeys<Ristretto>],
|
substrate_keys: &[ThresholdKeys<<Ristretto as Curves>::ToweringCurve>],
|
||||||
network_keys: &[ThresholdKeys<P::ExternalNetworkCiphersuite>],
|
network_keys: &[ThresholdKeys<<P::ExternalNetworkCiphersuite as Curves>::ToweringCurve>],
|
||||||
) {
|
) {
|
||||||
assert_eq!(substrate_keys.len(), network_keys.len());
|
assert_eq!(substrate_keys.len(), network_keys.len());
|
||||||
|
|
||||||
@@ -134,16 +134,18 @@ impl<P: KeyGenParams> KeyGenDb<P> {
|
|||||||
pub(crate) fn key_shares(
|
pub(crate) fn key_shares(
|
||||||
getter: &impl Get,
|
getter: &impl Get,
|
||||||
session: Session,
|
session: Session,
|
||||||
) -> Option<(Vec<ThresholdKeys<Ristretto>>, Vec<ThresholdKeys<P::ExternalNetworkCiphersuite>>)>
|
) -> Option<(
|
||||||
{
|
Vec<ThresholdKeys<<Ristretto as Curves>::ToweringCurve>>,
|
||||||
|
Vec<ThresholdKeys<<P::ExternalNetworkCiphersuite as Curves>::ToweringCurve>>,
|
||||||
|
)> {
|
||||||
let keys = _db::KeyShares::get(getter, &session)?;
|
let keys = _db::KeyShares::get(getter, &session)?;
|
||||||
let mut keys: &[u8] = keys.as_ref();
|
let mut keys: &[u8] = keys.as_ref();
|
||||||
|
|
||||||
let mut substrate_keys = vec![];
|
let mut substrate_keys = vec![];
|
||||||
let mut network_keys = vec![];
|
let mut network_keys = vec![];
|
||||||
while !keys.is_empty() {
|
while !keys.is_empty() {
|
||||||
substrate_keys.push(ThresholdKeys::new(ThresholdCore::read(&mut keys).unwrap()));
|
substrate_keys.push(ThresholdKeys::read(&mut keys).unwrap());
|
||||||
let mut these_network_keys = ThresholdKeys::new(ThresholdCore::read(&mut keys).unwrap());
|
let mut these_network_keys = ThresholdKeys::read(&mut keys).unwrap();
|
||||||
P::tweak_keys(&mut these_network_keys);
|
P::tweak_keys(&mut these_network_keys);
|
||||||
network_keys.push(these_network_keys);
|
network_keys.push(these_network_keys);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::{
|
|||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
};
|
};
|
||||||
|
|
||||||
use dkg::evrf::*;
|
use dkg::*;
|
||||||
|
|
||||||
use serai_validator_sets_primitives::MAX_KEY_SHARES_PER_SET;
|
use serai_validator_sets_primitives::MAX_KEY_SHARES_PER_SET;
|
||||||
|
|
||||||
@@ -21,14 +21,14 @@ use serai_validator_sets_primitives::MAX_KEY_SHARES_PER_SET;
|
|||||||
static GENERATORS: LazyLock<Mutex<HashMap<TypeId, &'static (dyn Send + Sync + Any)>>> =
|
static GENERATORS: LazyLock<Mutex<HashMap<TypeId, &'static (dyn Send + Sync + Any)>>> =
|
||||||
LazyLock::new(|| Mutex::new(HashMap::new()));
|
LazyLock::new(|| Mutex::new(HashMap::new()));
|
||||||
|
|
||||||
pub(crate) fn generators<C: EvrfCurve>() -> &'static EvrfGenerators<C> {
|
pub(crate) fn generators<C: 'static + Curves>() -> &'static Generators<C> {
|
||||||
GENERATORS
|
GENERATORS
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.entry(TypeId::of::<C>())
|
.entry(TypeId::of::<C>())
|
||||||
.or_insert_with(|| {
|
.or_insert_with(|| {
|
||||||
// If we haven't prior needed generators for this Ciphersuite, generate new ones
|
// If we haven't prior needed generators for this Ciphersuite, generate new ones
|
||||||
Box::leak(Box::new(EvrfGenerators::<C>::new(
|
Box::leak(Box::new(Generators::<C>::new(
|
||||||
(MAX_KEY_SHARES_PER_SET * 2 / 3) + 1,
|
(MAX_KEY_SHARES_PER_SET * 2 / 3) + 1,
|
||||||
MAX_KEY_SHARES_PER_SET,
|
MAX_KEY_SHARES_PER_SET,
|
||||||
)))
|
)))
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ use blake2::{Digest, Blake2s256};
|
|||||||
use transcript::{Transcript, RecommendedTranscript};
|
use transcript::{Transcript, RecommendedTranscript};
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{Group, GroupEncoding},
|
group::{Group, GroupEncoding},
|
||||||
Ciphersuite, Ristretto,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
use dkg::{Participant, ThresholdKeys, evrf::*};
|
use dkg::*;
|
||||||
|
|
||||||
use serai_validator_sets_primitives::Session;
|
use serai_validator_sets_primitives::Session;
|
||||||
use messages::key_gen::*;
|
use messages::key_gen::*;
|
||||||
@@ -34,33 +34,36 @@ pub trait KeyGenParams {
|
|||||||
const ID: &'static str;
|
const ID: &'static str;
|
||||||
|
|
||||||
/// The curve used for the external network.
|
/// The curve used for the external network.
|
||||||
type ExternalNetworkCiphersuite: EvrfCurve<
|
type ExternalNetworkCiphersuite: 'static + Curves;
|
||||||
EmbeddedCurve: Ciphersuite<
|
|
||||||
G: ec_divisors::DivisorCurve<
|
|
||||||
FieldElement = <Self::ExternalNetworkCiphersuite as Ciphersuite>::F,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
>;
|
|
||||||
|
|
||||||
/// Tweaks keys as necessary/beneficial.
|
/// Tweaks keys as necessary/beneficial.
|
||||||
///
|
///
|
||||||
/// A default implementation which doesn't perform any tweaking is provided.
|
/// A default implementation which doesn't perform any tweaking is provided.
|
||||||
fn tweak_keys(keys: &mut ThresholdKeys<Self::ExternalNetworkCiphersuite>) {
|
fn tweak_keys(
|
||||||
|
keys: &mut ThresholdKeys<<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve>,
|
||||||
|
) {
|
||||||
let _ = keys;
|
let _ = keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encode keys as optimal.
|
/// Encode keys as optimal.
|
||||||
///
|
///
|
||||||
/// A default implementation is provided which calls the traditional `to_bytes`.
|
/// A default implementation is provided which calls the traditional `to_bytes`.
|
||||||
fn encode_key(key: <Self::ExternalNetworkCiphersuite as Ciphersuite>::G) -> Vec<u8> {
|
fn encode_key(
|
||||||
|
key: <<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::G,
|
||||||
|
) -> Vec<u8> {
|
||||||
key.to_bytes().as_ref().to_vec()
|
key.to_bytes().as_ref().to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decode keys from their optimal encoding.
|
/// Decode keys from their optimal encoding.
|
||||||
///
|
///
|
||||||
/// A default implementation is provided which calls the traditional `from_bytes`.
|
/// A default implementation is provided which calls the traditional `from_bytes`.
|
||||||
fn decode_key(mut key: &[u8]) -> Option<<Self::ExternalNetworkCiphersuite as Ciphersuite>::G> {
|
fn decode_key(
|
||||||
let res = <Self::ExternalNetworkCiphersuite as Ciphersuite>::read_G(&mut key).ok()?;
|
mut key: &[u8],
|
||||||
|
) -> Option<<<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::G> {
|
||||||
|
let res = <<Self::ExternalNetworkCiphersuite as Curves>::ToweringCurve as Ciphersuite>::read_G(
|
||||||
|
&mut key,
|
||||||
|
)
|
||||||
|
.ok()?;
|
||||||
if !key.is_empty() {
|
if !key.is_empty() {
|
||||||
None?;
|
None?;
|
||||||
}
|
}
|
||||||
@@ -96,10 +99,10 @@ pub trait KeyGenParams {
|
|||||||
|
|
||||||
Returns the coerced keys and faulty participants.
|
Returns the coerced keys and faulty participants.
|
||||||
*/
|
*/
|
||||||
fn coerce_keys<C: EvrfCurve>(
|
fn coerce_keys<C: 'static + Curves>(
|
||||||
key_bytes: &[impl AsRef<[u8]>],
|
key_bytes: &[impl AsRef<[u8]>],
|
||||||
) -> (Vec<<C::EmbeddedCurve as Ciphersuite>::G>, Vec<Participant>) {
|
) -> (Vec<<C::EmbeddedCurve as Ciphersuite>::G>, Vec<Participant>) {
|
||||||
fn evrf_key<C: EvrfCurve>(key: &[u8]) -> Option<<C::EmbeddedCurve as Ciphersuite>::G> {
|
fn evrf_key<C: 'static + Curves>(key: &[u8]) -> Option<<C::EmbeddedCurve as Ciphersuite>::G> {
|
||||||
let mut repr = <<C::EmbeddedCurve as Ciphersuite>::G as GroupEncoding>::Repr::default();
|
let mut repr = <<C::EmbeddedCurve as Ciphersuite>::G as GroupEncoding>::Repr::default();
|
||||||
if repr.as_ref().len() != key.len() {
|
if repr.as_ref().len() != key.len() {
|
||||||
None?;
|
None?;
|
||||||
@@ -146,21 +149,18 @@ fn coerce_keys<C: EvrfCurve>(
|
|||||||
/// An instance of the Serai key generation protocol.
|
/// An instance of the Serai key generation protocol.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct KeyGen<P: KeyGenParams> {
|
pub struct KeyGen<P: KeyGenParams> {
|
||||||
substrate_evrf_private_key:
|
substrate_evrf_private_key: Zeroizing<<<Ristretto as Curves>::EmbeddedCurve as Ciphersuite>::F>,
|
||||||
Zeroizing<<<Ristretto as EvrfCurve>::EmbeddedCurve as Ciphersuite>::F>,
|
|
||||||
network_evrf_private_key:
|
network_evrf_private_key:
|
||||||
Zeroizing<<<P::ExternalNetworkCiphersuite as EvrfCurve>::EmbeddedCurve as Ciphersuite>::F>,
|
Zeroizing<<<P::ExternalNetworkCiphersuite as Curves>::EmbeddedCurve as Ciphersuite>::F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: KeyGenParams> KeyGen<P> {
|
impl<P: KeyGenParams> KeyGen<P> {
|
||||||
/// Create a new key generation instance.
|
/// Create a new key generation instance.
|
||||||
#[allow(clippy::new_ret_no_self)]
|
#[allow(clippy::new_ret_no_self)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
substrate_evrf_private_key: Zeroizing<
|
substrate_evrf_private_key: Zeroizing<<<Ristretto as Curves>::EmbeddedCurve as Ciphersuite>::F>,
|
||||||
<<Ristretto as EvrfCurve>::EmbeddedCurve as Ciphersuite>::F,
|
|
||||||
>,
|
|
||||||
network_evrf_private_key: Zeroizing<
|
network_evrf_private_key: Zeroizing<
|
||||||
<<P::ExternalNetworkCiphersuite as EvrfCurve>::EmbeddedCurve as Ciphersuite>::F,
|
<<P::ExternalNetworkCiphersuite as Curves>::EmbeddedCurve as Ciphersuite>::F,
|
||||||
>,
|
>,
|
||||||
) -> KeyGen<P> {
|
) -> KeyGen<P> {
|
||||||
KeyGen { substrate_evrf_private_key, network_evrf_private_key }
|
KeyGen { substrate_evrf_private_key, network_evrf_private_key }
|
||||||
@@ -171,8 +171,10 @@ impl<P: KeyGenParams> KeyGen<P> {
|
|||||||
pub fn key_shares(
|
pub fn key_shares(
|
||||||
getter: &impl Get,
|
getter: &impl Get,
|
||||||
session: Session,
|
session: Session,
|
||||||
) -> Option<(Vec<ThresholdKeys<Ristretto>>, Vec<ThresholdKeys<P::ExternalNetworkCiphersuite>>)>
|
) -> Option<(
|
||||||
{
|
Vec<ThresholdKeys<<Ristretto as Curves>::ToweringCurve>>,
|
||||||
|
Vec<ThresholdKeys<<P::ExternalNetworkCiphersuite as Curves>::ToweringCurve>>,
|
||||||
|
)> {
|
||||||
// This is safe, despite not having a txn, since it's a static value
|
// This is safe, despite not having a txn, since it's a static value
|
||||||
// It doesn't change over time/in relation to other operations
|
// It doesn't change over time/in relation to other operations
|
||||||
// It is solely set or unset
|
// It is solely set or unset
|
||||||
@@ -209,14 +211,14 @@ impl<P: KeyGenParams> KeyGen<P> {
|
|||||||
faulty.extend(additional_faulty);
|
faulty.extend(additional_faulty);
|
||||||
|
|
||||||
// Participate for both Substrate and the network
|
// Participate for both Substrate and the network
|
||||||
fn participate<C: EvrfCurve>(
|
fn participate<C: 'static + Curves>(
|
||||||
context: [u8; 32],
|
context: [u8; 32],
|
||||||
threshold: u16,
|
threshold: u16,
|
||||||
evrf_public_keys: &[<C::EmbeddedCurve as Ciphersuite>::G],
|
evrf_public_keys: &[<C::EmbeddedCurve as Ciphersuite>::G],
|
||||||
evrf_private_key: &Zeroizing<<C::EmbeddedCurve as Ciphersuite>::F>,
|
evrf_private_key: &Zeroizing<<C::EmbeddedCurve as Ciphersuite>::F>,
|
||||||
output: &mut impl io::Write,
|
output: &mut impl io::Write,
|
||||||
) {
|
) {
|
||||||
let participation = EvrfDkg::<C>::participate(
|
let participation = Dkg::<C>::participate(
|
||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
generators(),
|
generators(),
|
||||||
context,
|
context,
|
||||||
@@ -270,7 +272,7 @@ impl<P: KeyGenParams> KeyGen<P> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CoordinatorMessage::Participation { session, participant, participation } => {
|
CoordinatorMessage::Participation { session, participant, participation } => {
|
||||||
log::debug!("received participation from {:?} for {:?}", participant, session);
|
log::debug!("received participation from {participant:?} for {session:?}");
|
||||||
|
|
||||||
let Params { t: threshold, n, substrate_evrf_public_keys, network_evrf_public_keys } =
|
let Params { t: threshold, n, substrate_evrf_public_keys, network_evrf_public_keys } =
|
||||||
KeyGenDb::<P>::params(txn, session).unwrap();
|
KeyGenDb::<P>::params(txn, session).unwrap();
|
||||||
@@ -305,9 +307,9 @@ impl<P: KeyGenParams> KeyGen<P> {
|
|||||||
// participations and continue. We solely have to verify them, as to identify malicious
|
// participations and continue. We solely have to verify them, as to identify malicious
|
||||||
// participants and prevent DoSs, before returning
|
// participants and prevent DoSs, before returning
|
||||||
if Self::key_shares(txn, session).is_some() {
|
if Self::key_shares(txn, session).is_some() {
|
||||||
log::debug!("already finished generating a key for {:?}", session);
|
log::debug!("already finished generating a key for {session:?}");
|
||||||
|
|
||||||
match EvrfDkg::<Ristretto>::verify(
|
match Dkg::<Ristretto>::verify(
|
||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
generators(),
|
generators(),
|
||||||
context::<P>(session, SUBSTRATE_KEY_CONTEXT),
|
context::<P>(session, SUBSTRATE_KEY_CONTEXT),
|
||||||
@@ -324,7 +326,7 @@ impl<P: KeyGenParams> KeyGen<P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match EvrfDkg::<P::ExternalNetworkCiphersuite>::verify(
|
match Dkg::<P::ExternalNetworkCiphersuite>::verify(
|
||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
generators(),
|
generators(),
|
||||||
context::<P>(session, NETWORK_KEY_CONTEXT),
|
context::<P>(session, NETWORK_KEY_CONTEXT),
|
||||||
@@ -404,7 +406,7 @@ impl<P: KeyGenParams> KeyGen<P> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we now have the threshold participating, verify their `Participation`s
|
// If we now have the threshold participating, verify their `Participation`s
|
||||||
fn verify_dkg<P: KeyGenParams, C: EvrfCurve>(
|
fn verify_dkg<P: KeyGenParams, C: 'static + Curves>(
|
||||||
txn: &mut impl DbTxn,
|
txn: &mut impl DbTxn,
|
||||||
session: Session,
|
session: Session,
|
||||||
true_if_substrate_false_if_network: bool,
|
true_if_substrate_false_if_network: bool,
|
||||||
@@ -412,7 +414,7 @@ impl<P: KeyGenParams> KeyGen<P> {
|
|||||||
evrf_public_keys: &[<C::EmbeddedCurve as Ciphersuite>::G],
|
evrf_public_keys: &[<C::EmbeddedCurve as Ciphersuite>::G],
|
||||||
substrate_participations: &mut HashMap<Participant, Vec<u8>>,
|
substrate_participations: &mut HashMap<Participant, Vec<u8>>,
|
||||||
network_participations: &mut HashMap<Participant, Vec<u8>>,
|
network_participations: &mut HashMap<Participant, Vec<u8>>,
|
||||||
) -> Result<EvrfDkg<C>, Vec<ProcessorMessage>> {
|
) -> Result<Dkg<C>, Vec<ProcessorMessage>> {
|
||||||
// Parse the `Participation`s
|
// Parse the `Participation`s
|
||||||
let participations = (if true_if_substrate_false_if_network {
|
let participations = (if true_if_substrate_false_if_network {
|
||||||
&*substrate_participations
|
&*substrate_participations
|
||||||
@@ -433,7 +435,7 @@ impl<P: KeyGenParams> KeyGen<P> {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Actually call verify on the DKG
|
// Actually call verify on the DKG
|
||||||
match EvrfDkg::<C>::verify(
|
match Dkg::<C>::verify(
|
||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
generators(),
|
generators(),
|
||||||
context::<P>(
|
context::<P>(
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ zeroize = { version = "1", default-features = false, features = ["std"] }
|
|||||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std"] }
|
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std"] }
|
||||||
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
|
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
|
||||||
|
|
||||||
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
|
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
||||||
dkg = { package = "dkg-evrf", path = "../../crypto/dkg/evrf", default-features = false, features = ["std", "ed25519"] }
|
dkg = { package = "dkg-evrf", path = "../../crypto/dkg/evrf", default-features = false, features = ["std", "ed25519"] }
|
||||||
frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false }
|
frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false }
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use ciphersuite::Ed25519;
|
use dkg::Ed25519;
|
||||||
|
|
||||||
pub(crate) struct KeyGenParams;
|
pub(crate) struct KeyGenParams;
|
||||||
impl key_gen::KeyGenParams for KeyGenParams {
|
impl key_gen::KeyGenParams for KeyGenParams {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Ed25519};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use dalek_ff_group::Ed25519;
|
||||||
|
|
||||||
use monero_wallet::{
|
use monero_wallet::{
|
||||||
block::Block as MBlock, rpc::ScannableBlock as MScannableBlock, ScanError, GuaranteedScanner,
|
block::Block as MBlock, rpc::ScannableBlock as MScannableBlock, ScanError, GuaranteedScanner,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Ed25519};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use dalek_ff_group::Ed25519;
|
||||||
|
|
||||||
use monero_wallet::{address::SubaddressIndex, ViewPairError, GuaranteedViewPair};
|
use monero_wallet::{address::SubaddressIndex, ViewPairError, GuaranteedViewPair};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use ciphersuite::{group::Group, Ciphersuite, Ed25519};
|
use ciphersuite::{group::Group, Ciphersuite};
|
||||||
|
use dalek_ff_group::Ed25519;
|
||||||
|
|
||||||
use monero_wallet::WalletOutput;
|
use monero_wallet::WalletOutput;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::io;
|
|||||||
|
|
||||||
use rand_core::{RngCore, CryptoRng};
|
use rand_core::{RngCore, CryptoRng};
|
||||||
|
|
||||||
use ciphersuite::Ed25519;
|
use dalek_ff_group::Ed25519;
|
||||||
use frost::{dkg::ThresholdKeys, sign::PreprocessMachine};
|
use frost::{dkg::ThresholdKeys, sign::PreprocessMachine};
|
||||||
|
|
||||||
use monero_wallet::{
|
use monero_wallet::{
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ use zeroize::Zeroizing;
|
|||||||
use rand_core::SeedableRng;
|
use rand_core::SeedableRng;
|
||||||
use rand_chacha::ChaCha20Rng;
|
use rand_chacha::ChaCha20Rng;
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Ed25519};
|
use ciphersuite::Ciphersuite;
|
||||||
|
use dalek_ff_group::Ed25519;
|
||||||
|
|
||||||
use monero_wallet::rpc::{FeeRate, RpcError};
|
use monero_wallet::rpc::{FeeRate, RpcError};
|
||||||
|
|
||||||
@@ -200,6 +201,9 @@ impl TransactionPlanner<Rpc, ()> for Planner {
|
|||||||
Err(SendError::TooLargeTransaction) => {
|
Err(SendError::TooLargeTransaction) => {
|
||||||
panic!("too large transaction despite MAX_INPUTS/MAX_OUTPUTS")
|
panic!("too large transaction despite MAX_INPUTS/MAX_OUTPUTS")
|
||||||
}
|
}
|
||||||
|
Err(SendError::AmountsUnrepresentable { .. }) => {
|
||||||
|
panic!("monero-wallet AmountsUnrepresentable")
|
||||||
|
}
|
||||||
Err(
|
Err(
|
||||||
SendError::WrongPrivateKey |
|
SendError::WrongPrivateKey |
|
||||||
SendError::MaliciousSerialization |
|
SendError::MaliciousSerialization |
|
||||||
@@ -255,6 +259,9 @@ impl TransactionPlanner<Rpc, ()> for Planner {
|
|||||||
Err(SendError::TooLargeTransaction) => {
|
Err(SendError::TooLargeTransaction) => {
|
||||||
panic!("too large transaction despite MAX_INPUTS/MAX_OUTPUTS")
|
panic!("too large transaction despite MAX_INPUTS/MAX_OUTPUTS")
|
||||||
}
|
}
|
||||||
|
Err(SendError::AmountsUnrepresentable { .. }) => {
|
||||||
|
panic!("monero-wallet AmountsUnrepresentable")
|
||||||
|
}
|
||||||
Err(
|
Err(
|
||||||
SendError::WrongPrivateKey |
|
SendError::WrongPrivateKey |
|
||||||
SendError::MaliciousSerialization |
|
SendError::MaliciousSerialization |
|
||||||
|
|||||||
@@ -70,12 +70,13 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for IndexTask<D, S> {
|
|||||||
Err(e) => Err(format!("couldn't fetch the latest finalized block number: {e:?}"))?,
|
Err(e) => Err(format!("couldn't fetch the latest finalized block number: {e:?}"))?,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[allow(clippy::uninlined_format_args)]
|
||||||
if latest_finalized < our_latest_finalized {
|
if latest_finalized < our_latest_finalized {
|
||||||
// Explicitly log this as an error as returned ephemeral errors are logged with debug
|
// Explicitly log this as an error as returned ephemeral errors are logged with debug
|
||||||
// This doesn't panic as the node should sync along our indexed chain, and if it doesn't,
|
// This doesn't panic as the node should sync along our indexed chain, and if it doesn't,
|
||||||
// we'll panic at that point in time
|
// we'll panic at that point in time
|
||||||
log::error!(
|
log::error!(
|
||||||
"node is out of sync, latest finalized {} is behind our indexed {}",
|
"node is out of sync, latest finalized ({}) is behind our indexed ({})",
|
||||||
latest_finalized,
|
latest_finalized,
|
||||||
our_latest_finalized
|
our_latest_finalized
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ zeroize = { version = "1", default-features = false, features = ["std"] }
|
|||||||
|
|
||||||
blake2 = { version = "0.10", default-features = false, features = ["std"] }
|
blake2 = { version = "0.10", default-features = false, features = ["std"] }
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
|
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
||||||
frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false }
|
frost = { package = "modular-frost", path = "../../crypto/frost", default-features = false }
|
||||||
frost-schnorrkel = { path = "../../crypto/schnorrkel", default-features = false }
|
frost-schnorrkel = { path = "../../crypto/schnorrkel", default-features = false }
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ use core::future::Future;
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use blake2::{digest::typenum::U32, Digest, Blake2b};
|
use blake2::{digest::typenum::U32, Digest, Blake2b};
|
||||||
use ciphersuite::{group::GroupEncoding, Ristretto};
|
use ciphersuite::group::GroupEncoding;
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
use frost::dkg::ThresholdKeys;
|
use frost::dkg::ThresholdKeys;
|
||||||
|
|
||||||
use scale::Encode;
|
use scale::Encode;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use core::future::Future;
|
use core::future::Future;
|
||||||
|
|
||||||
use ciphersuite::Ristretto;
|
use dalek_ff_group::Ristretto;
|
||||||
use frost::dkg::ThresholdKeys;
|
use frost::dkg::ThresholdKeys;
|
||||||
|
|
||||||
use scale::Encode;
|
use scale::Encode;
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
|
use ciphersuite::{group::GroupEncoding, Ciphersuite};
|
||||||
use frost::dkg::{ThresholdCore, ThresholdKeys};
|
use dalek_ff_group::Ristretto;
|
||||||
|
use frost::dkg::ThresholdKeys;
|
||||||
|
|
||||||
use serai_primitives::Signature;
|
use serai_primitives::Signature;
|
||||||
use serai_validator_sets_primitives::{Session, SlashReport};
|
use serai_validator_sets_primitives::{Session, SlashReport};
|
||||||
@@ -262,11 +263,8 @@ impl<
|
|||||||
let mut substrate_keys = vec![];
|
let mut substrate_keys = vec![];
|
||||||
let mut external_keys = vec![];
|
let mut external_keys = vec![];
|
||||||
while !buf.is_empty() {
|
while !buf.is_empty() {
|
||||||
substrate_keys
|
substrate_keys.push(ThresholdKeys::<Ristretto>::read(&mut buf).unwrap());
|
||||||
.push(ThresholdKeys::from(ThresholdCore::<Ristretto>::read(&mut buf).unwrap()));
|
external_keys.push(ThresholdKeys::<CiphersuiteFor<S, Sch>>::read(&mut buf).unwrap());
|
||||||
external_keys.push(ThresholdKeys::from(
|
|
||||||
ThresholdCore::<CiphersuiteFor<S, Sch>>::read(&mut buf).unwrap(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.insert(
|
tasks.insert(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use core::{marker::PhantomData, future::Future};
|
use core::{marker::PhantomData, future::Future};
|
||||||
|
|
||||||
use ciphersuite::Ristretto;
|
use dalek_ff_group::Ristretto;
|
||||||
use frost::dkg::ThresholdKeys;
|
use frost::dkg::ThresholdKeys;
|
||||||
|
|
||||||
use serai_primitives::Signature;
|
use serai_primitives::Signature;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::{
|
|||||||
|
|
||||||
use rand_core::{RngCore, CryptoRng};
|
use rand_core::{RngCore, CryptoRng};
|
||||||
|
|
||||||
use ciphersuite::Ristretto;
|
use dalek_ff_group::Ristretto;
|
||||||
use frost::{
|
use frost::{
|
||||||
dkg::{Participant, ThresholdKeys},
|
dkg::{Participant, ThresholdKeys},
|
||||||
FrostError,
|
FrostError,
|
||||||
|
|||||||
@@ -51,8 +51,9 @@ hex = "0.4"
|
|||||||
|
|
||||||
blake2 = "0.10"
|
blake2 = "0.10"
|
||||||
|
|
||||||
dalek-ff-group = { path = "../../crypto/dalek-ff-group" }
|
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite" }
|
ciphersuite = { path = "../../crypto/ciphersuite" }
|
||||||
|
dalek-ff-group = { path = "../../crypto/dalek-ff-group" }
|
||||||
|
ciphersuite-kp256 = { path = "../../crypto/ciphersuite/kp256" }
|
||||||
dkg-musig = { path = "../../crypto/dkg/musig" }
|
dkg-musig = { path = "../../crypto/dkg/musig" }
|
||||||
frost = { package = "modular-frost", path = "../../crypto/frost", features = ["tests"] }
|
frost = { package = "modular-frost", path = "../../crypto/frost", features = ["tests"] }
|
||||||
schnorrkel = { path = "../../crypto/schnorrkel", package = "frost-schnorrkel" }
|
schnorrkel = { path = "../../crypto/schnorrkel", package = "frost-schnorrkel" }
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
use core::{str::FromStr, fmt};
|
use core::{str::FromStr, fmt};
|
||||||
|
|
||||||
use scale::{Encode, Decode};
|
|
||||||
|
|
||||||
use dalek_ff_group::Ed25519;
|
use dalek_ff_group::Ed25519;
|
||||||
use ciphersuite::Ciphersuite;
|
use ciphersuite::Ciphersuite;
|
||||||
|
|
||||||
|
|||||||
@@ -301,13 +301,13 @@ impl Serai {
|
|||||||
///
|
///
|
||||||
/// The binding occurs at time of call. This does not track the latest finalized block and update
|
/// The binding occurs at time of call. This does not track the latest finalized block and update
|
||||||
/// itself.
|
/// itself.
|
||||||
pub async fn as_of_latest_finalized_block(&self) -> Result<TemporalSerai, SeraiError> {
|
pub async fn as_of_latest_finalized_block(&self) -> Result<TemporalSerai<'_>, SeraiError> {
|
||||||
let latest = self.latest_finalized_block_hash().await?;
|
let latest = self.latest_finalized_block_hash().await?;
|
||||||
Ok(TemporalSerai { serai: self, block: latest, events: RwLock::new(None) })
|
Ok(TemporalSerai { serai: self, block: latest, events: RwLock::new(None) })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a TemporalSerai able to retrieve state as of the specified block.
|
/// Returns a TemporalSerai able to retrieve state as of the specified block.
|
||||||
pub fn as_of(&self, block: [u8; 32]) -> TemporalSerai {
|
pub fn as_of(&self, block: [u8; 32]) -> TemporalSerai<'_> {
|
||||||
TemporalSerai { serai: self, block, events: RwLock::new(None) }
|
TemporalSerai { serai: self, block, events: RwLock::new(None) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,11 +424,11 @@ impl TemporalSerai<'_> {
|
|||||||
SeraiValidatorSets(self)
|
SeraiValidatorSets(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn genesis_liquidity(&self) -> SeraiGenesisLiquidity {
|
pub fn genesis_liquidity(&self) -> SeraiGenesisLiquidity<'_> {
|
||||||
SeraiGenesisLiquidity(self)
|
SeraiGenesisLiquidity(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn liquidity_tokens(&self) -> SeraiLiquidityTokens {
|
pub fn liquidity_tokens(&self) -> SeraiLiquidityTokens<'_> {
|
||||||
SeraiLiquidityTokens(self)
|
SeraiLiquidityTokens(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ async fn set_values(serai: &Serai, values: &Values) {
|
|||||||
frost::tests::algorithm_machines(
|
frost::tests::algorithm_machines(
|
||||||
&mut OsRng,
|
&mut OsRng,
|
||||||
&Schnorrkel::new(b"substrate"),
|
&Schnorrkel::new(b"substrate"),
|
||||||
&HashMap::from([(threshold_keys.params().i(), threshold_keys.into())]),
|
&HashMap::from([(threshold_keys.params().i(), threshold_keys)]),
|
||||||
),
|
),
|
||||||
&oraclize_values_message(&set, values),
|
&oraclize_values_message(&set, values),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ pub async fn set_keys(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut musig_keys = HashMap::new();
|
let mut musig_keys = HashMap::new();
|
||||||
for tk in threshold_keys {
|
for threshold_keys in threshold_keys {
|
||||||
musig_keys.insert(tk.params().i(), tk.into());
|
musig_keys.insert(threshold_keys.params().i(), threshold_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sig = frost::tests::sign_without_caching(
|
let sig = frost::tests::sign_without_caching(
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ use zeroize::Zeroizing;
|
|||||||
|
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{ff::Field, GroupEncoding},
|
group::{ff::Field, GroupEncoding},
|
||||||
Ciphersuite, Ed25519, Secp256k1,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
|
use dalek_ff_group::Ed25519;
|
||||||
|
use ciphersuite_kp256::Secp256k1;
|
||||||
|
|
||||||
use sp_core::{
|
use sp_core::{
|
||||||
Pair as PairTrait,
|
Pair as PairTrait,
|
||||||
@@ -67,7 +69,7 @@ async fn test_external_address(serai: Serai) {
|
|||||||
set_network_keys::<Secp256k1>(
|
set_network_keys::<Secp256k1>(
|
||||||
&serai,
|
&serai,
|
||||||
ExternalValidatorSet { session: Session(0), network },
|
ExternalValidatorSet { session: Session(0), network },
|
||||||
&[pair.clone()],
|
core::slice::from_ref(&pair),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|||||||
@@ -1298,7 +1298,7 @@ fn cannot_block_pool_creation() {
|
|||||||
));
|
));
|
||||||
// Then, the attacker creates 14 tokens and sends one of each to the pool account
|
// Then, the attacker creates 14 tokens and sends one of each to the pool account
|
||||||
// skip the coin1 and coin2 coins.
|
// skip the coin1 and coin2 coins.
|
||||||
for coin in coins().into_iter().filter(|c| (*c != coin1 && *c != coin2)) {
|
for coin in coins().into_iter().filter(|c| (*c != coin1) && (*c != coin2)) {
|
||||||
assert_ok!(CoinsPallet::<Test>::mint(attacker, Balance { coin, amount: Amount(1000) }));
|
assert_ok!(CoinsPallet::<Test>::mint(attacker, Balance { coin, amount: Amount(1000) }));
|
||||||
assert_ok!(CoinsPallet::<Test>::transfer_internal(
|
assert_ok!(CoinsPallet::<Test>::transfer_internal(
|
||||||
attacker,
|
attacker,
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ log = "0.4"
|
|||||||
schnorrkel = "0.11"
|
schnorrkel = "0.11"
|
||||||
|
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite" }
|
ciphersuite = { path = "../../crypto/ciphersuite" }
|
||||||
|
ciphersuite-kp256 = { path = "../../crypto/ciphersuite/kp256" }
|
||||||
|
dalek-ff-group = { path = "../../crypto/dalek-ff-group" }
|
||||||
embedwards25519 = { path = "../../crypto/evrf/embedwards25519" }
|
embedwards25519 = { path = "../../crypto/evrf/embedwards25519" }
|
||||||
secq256k1 = { path = "../../crypto/evrf/secq256k1" }
|
secq256k1 = { path = "../../crypto/evrf/secq256k1" }
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::result_large_err)]
|
||||||
|
|
||||||
mod keystore;
|
mod keystore;
|
||||||
|
|
||||||
mod chain_spec;
|
mod chain_spec;
|
||||||
|
|||||||
@@ -50,8 +50,10 @@ where
|
|||||||
{
|
{
|
||||||
use substrate_frame_rpc_system::{System, SystemApiServer};
|
use substrate_frame_rpc_system::{System, SystemApiServer};
|
||||||
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
|
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
|
||||||
use ciphersuite::{Ciphersuite, Ed25519, Secp256k1};
|
use ciphersuite::Ciphersuite;
|
||||||
use bitcoin_serai::{bitcoin, crypto::x_only};
|
use ciphersuite_kp256::{k256::elliptic_curve::point::AffineCoordinates, Secp256k1};
|
||||||
|
use dalek_ff_group::Ed25519;
|
||||||
|
use bitcoin_serai::bitcoin;
|
||||||
|
|
||||||
let mut module = RpcModule::new(());
|
let mut module = RpcModule::new(());
|
||||||
let FullDeps { id, client, pool, deny_unsafe, authority_discovery } = deps;
|
let FullDeps { id, client, pool, deny_unsafe, authority_discovery } = deps;
|
||||||
@@ -128,7 +130,11 @@ where
|
|||||||
.map_err(|_| Error::Custom("invalid key stored in db".to_string()))?;
|
.map_err(|_| Error::Custom("invalid key stored in db".to_string()))?;
|
||||||
|
|
||||||
let addr = bitcoin::Address::p2tr_tweaked(
|
let addr = bitcoin::Address::p2tr_tweaked(
|
||||||
bitcoin::key::TweakedPublicKey::dangerous_assume_tweaked(x_only(&key)),
|
bitcoin::key::TweakedPublicKey::dangerous_assume_tweaked(
|
||||||
|
bitcoin::key::XOnlyPublicKey::from_slice(key.to_affine().x().as_slice()).map_err(
|
||||||
|
|_| Error::Custom("x-coordinate for Bitcoin key was invalid".to_string()),
|
||||||
|
)?,
|
||||||
|
),
|
||||||
bitcoin::address::KnownHrp::Mainnet,
|
bitcoin::address::KnownHrp::Mainnet,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ pallet-timestamp = { git = "https://github.com/serai-dex/substrate", default-fea
|
|||||||
|
|
||||||
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||||
|
|
||||||
ciphersuite = { path = "../../../crypto/ciphersuite", features = ["std"] }
|
ciphersuite = { path = "../../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
|
dalek-ff-group = { path = "../../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
||||||
|
dkg-musig = { path = "../../../crypto/dkg/musig", default-features = false, features = ["std"] }
|
||||||
frost = { package = "modular-frost", path = "../../../crypto/frost", features = ["tests"] }
|
frost = { package = "modular-frost", path = "../../../crypto/frost", features = ["tests"] }
|
||||||
schnorrkel = { path = "../../../crypto/schnorrkel", package = "frost-schnorrkel" }
|
schnorrkel = { path = "../../../crypto/schnorrkel", package = "frost-schnorrkel" }
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ use crate::{mock::*, primitives::*};
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use ciphersuite::{Ciphersuite, Ristretto};
|
use ciphersuite::Ciphersuite;
|
||||||
use frost::dkg::musig::musig;
|
use dalek_ff_group::Ristretto;
|
||||||
|
use dkg_musig::musig;
|
||||||
use schnorrkel::Schnorrkel;
|
use schnorrkel::Schnorrkel;
|
||||||
|
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
@@ -87,14 +88,14 @@ fn set_keys_signature(set: &ExternalValidatorSet, key_pair: &KeyPair, pairs: &[P
|
|||||||
assert_eq!(Ristretto::generator() * secret_key, pub_keys[i]);
|
assert_eq!(Ristretto::generator() * secret_key, pub_keys[i]);
|
||||||
|
|
||||||
threshold_keys.push(
|
threshold_keys.push(
|
||||||
musig::<Ristretto>(&musig_context((*set).into()), &Zeroizing::new(secret_key), &pub_keys)
|
musig::<Ristretto>(musig_context((*set).into()), Zeroizing::new(secret_key), &pub_keys)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut musig_keys = HashMap::new();
|
let mut musig_keys = HashMap::new();
|
||||||
for tk in threshold_keys {
|
for threshold_keys in threshold_keys {
|
||||||
musig_keys.insert(tk.params().i(), tk.into());
|
musig_keys.insert(threshold_keys.params().i(), threshold_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sig = frost::tests::sign_without_caching(
|
let sig = frost::tests::sign_without_caching(
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ rand_core = { version = "0.6", default-features = false }
|
|||||||
blake2 = "0.10"
|
blake2 = "0.10"
|
||||||
|
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
|
ciphersuite-kp256 = { path = "../../crypto/ciphersuite/kp256", default-features = false, features = ["std"] }
|
||||||
|
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
||||||
embedwards25519 = { path = "../../crypto/evrf/embedwards25519" }
|
embedwards25519 = { path = "../../crypto/evrf/embedwards25519" }
|
||||||
secq256k1 = { path = "../../crypto/evrf/secq256k1" }
|
secq256k1 = { path = "../../crypto/evrf/secq256k1" }
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ use zeroize::Zeroizing;
|
|||||||
|
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{ff::PrimeField, GroupEncoding},
|
group::{ff::PrimeField, GroupEncoding},
|
||||||
Ciphersuite, Ristretto,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
use embedwards25519::Embedwards25519;
|
use embedwards25519::Embedwards25519;
|
||||||
use secq256k1::Secq256k1;
|
use secq256k1::Secq256k1;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ use blake2::{
|
|||||||
digest::{consts::U32, Digest},
|
digest::{consts::U32, Digest},
|
||||||
Blake2b,
|
Blake2b,
|
||||||
};
|
};
|
||||||
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto, Secp256k1};
|
use ciphersuite::{group::GroupEncoding, Ciphersuite}
|
||||||
|
use ciphersuite_kp256::Secp256k1;
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
use dkg::Participant;
|
use dkg::Participant;
|
||||||
|
|
||||||
use scale::Encode;
|
use scale::Encode;
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ use rand_core::OsRng;
|
|||||||
|
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{ff::Field, GroupEncoding},
|
group::{ff::Field, GroupEncoding},
|
||||||
Ciphersuite, Ristretto, Secp256k1,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
|
use ciphersuite_kp256::Secq256k1;
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
use dkg::Participant;
|
use dkg::Participant;
|
||||||
|
|
||||||
use serai_client::{
|
use serai_client::{
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ zeroize = { version = "1", default-features = false }
|
|||||||
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
|
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
|
||||||
|
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
|
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
serai-primitives = { path = "../../substrate/primitives" }
|
serai-primitives = { path = "../../substrate/primitives" }
|
||||||
serai-message-queue = { path = "../../message-queue" }
|
serai-message-queue = { path = "../../message-queue" }
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ use rand_core::OsRng;
|
|||||||
|
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{ff::Field, GroupEncoding},
|
group::{ff::Field, GroupEncoding},
|
||||||
Ciphersuite, Ristretto,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
|
use dalek_ff_group::Ristretto;
|
||||||
|
|
||||||
use serai_primitives::{ExternalNetworkId, EXTERNAL_NETWORKS};
|
use serai_primitives::{ExternalNetworkId, EXTERNAL_NETWORKS};
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ rand_core = { version = "0.6", default-features = false, features = ["getrandom"
|
|||||||
|
|
||||||
curve25519-dalek = "4"
|
curve25519-dalek = "4"
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["std"] }
|
||||||
dkg = { path = "../../crypto/dkg", default-features = false, features = ["std"] }
|
ciphersuite-kp256 = { path = "../../crypto/ciphersuite/kp256", default-features = false, features = ["std"] }
|
||||||
|
dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
|
||||||
|
dkg = { package = "dkg-evrf", path = "../../crypto/dkg/evrf", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
bitcoin-serai = { path = "../../networks/bitcoin" }
|
bitcoin-serai = { path = "../../networks/bitcoin" }
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ use zeroize::Zeroizing;
|
|||||||
|
|
||||||
use ciphersuite::{
|
use ciphersuite::{
|
||||||
group::{ff::PrimeField, GroupEncoding},
|
group::{ff::PrimeField, GroupEncoding},
|
||||||
Ciphersuite, Secp256k1, Ed25519, Ristretto,
|
Ciphersuite,
|
||||||
};
|
};
|
||||||
use dkg::evrf::*;
|
use ciphersuite_kp256::Secp256k1;
|
||||||
|
use dalek_ff_group::{Ed25519, Ristretto};
|
||||||
|
use dkg::*;
|
||||||
|
|
||||||
use serai_client::primitives::{ExternalNetworkId, insecure_arbitrary_key_from_name};
|
use serai_client::primitives::{ExternalNetworkId, insecure_arbitrary_key_from_name};
|
||||||
use messages::{ProcessorMessage, CoordinatorMessage};
|
use messages::{ProcessorMessage, CoordinatorMessage};
|
||||||
|
|||||||
Reference in New Issue
Block a user