diff --git a/Cargo.lock b/Cargo.lock index 59700472..a016fafd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9787,7 +9787,6 @@ dependencies = [ "hex", "log", "modular-frost", - "parity-scale-codec", "rand_core 0.6.4", "schnorr-signatures", "schnorrkel", @@ -9854,7 +9853,6 @@ dependencies = [ "dkg", "futures", "log", - "parity-scale-codec", "serai-client", "serai-cosign", "serai-db", @@ -9892,7 +9890,6 @@ dependencies = [ "blake2 0.11.0-rc.0", "borsh", "log", - "parity-scale-codec", "schnorrkel", "serai-client", "serai-cosign-types", diff --git a/coordinator/Cargo.toml b/coordinator/Cargo.toml index e30208e3..192bd1ba 100644 --- a/coordinator/Cargo.toml +++ b/coordinator/Cargo.toml @@ -33,7 +33,6 @@ frost = { package = "modular-frost", path = "../crypto/frost" } frost-schnorrkel = { path = "../crypto/schnorrkel" } hex = { version = "0.4", default-features = false, features = ["std"] } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std", "derive", "bit-vec"] } borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] } zalloc = { path = "../common/zalloc" } diff --git a/coordinator/cosign/Cargo.toml b/coordinator/cosign/Cargo.toml index 425018be..ab5041ba 100644 --- a/coordinator/cosign/Cargo.toml +++ b/coordinator/cosign/Cargo.toml @@ -21,7 +21,6 @@ workspace = true blake2 = { version = "0.11.0-rc.0", default-features = false, features = ["alloc"] } schnorrkel = { version = "0.11", default-features = false, features = ["std"] } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std", "derive"] } borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] } serai-client = { path = "../../substrate/client", default-features = false, features = ["serai"] } diff --git a/coordinator/cosign/src/lib.rs b/coordinator/cosign/src/lib.rs index e1e5dbf9..16e2091e 100644 --- a/coordinator/cosign/src/lib.rs +++ b/coordinator/cosign/src/lib.rs @@ -7,7 +7,6 @@ use std::{sync::Arc, collections::HashMap, time::Instant}; use blake2::{Digest, Blake2s256}; -use scale::{Encode, Decode}; use borsh::{BorshSerialize, BorshDeserialize}; use serai_client::{ @@ -80,68 +79,6 @@ enum HasEvents { No, } -/// An intended cosign. -#[derive(Clone, Copy, PartialEq, Eq, Debug, BorshSerialize, BorshDeserialize)] -pub struct CosignIntent { - /// The global session this cosign is being performed under. - pub global_session: [u8; 32], - /// The number of the block to cosign. - pub block_number: u64, - /// The hash of the block to cosign. - pub block_hash: [u8; 32], - /// If this cosign must be handled before further cosigns are. - pub notable: bool, -} - -/// A cosign. -#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, BorshSerialize, BorshDeserialize)] -pub struct Cosign { - /// The global session this cosign is being performed under. - pub global_session: [u8; 32], - /// The number of the block to cosign. - pub block_number: u64, - /// The hash of the block to cosign. - pub block_hash: [u8; 32], - /// The actual cosigner. - pub cosigner: ExternalNetworkId, -} - -impl CosignIntent { - /// Convert this into a `Cosign`. - pub fn into_cosign(self, cosigner: ExternalNetworkId) -> Cosign { - let CosignIntent { global_session, block_number, block_hash, notable: _ } = self; - Cosign { global_session, block_number, block_hash, cosigner } - } -} - -impl Cosign { - /// The message to sign to sign this cosign. - /// - /// This must be signed with schnorrkel, the context set to `COSIGN_CONTEXT`. - pub fn signature_message(&self) -> Vec { - // We use a schnorrkel context to domain-separate this - self.encode() - } -} - -/// A signed cosign. -#[derive(Clone, Debug, BorshSerialize, BorshDeserialize)] -pub struct SignedCosign { - /// The cosign. - pub cosign: Cosign, - /// The signature for the cosign. - pub signature: [u8; 64], -} - -impl SignedCosign { - fn verify_signature(&self, signer: serai_client::Public) -> bool { - let Ok(signer) = schnorrkel::PublicKey::from_bytes(&signer.0) else { return false }; - let Ok(signature) = schnorrkel::Signature::from_bytes(&self.signature) else { return false }; - - signer.verify_simple(COSIGN_CONTEXT, &self.cosign.signature_message(), &signature).is_ok() - } -} - create_db! { Cosign { // The following are populated by the intend task and used throughout the library diff --git a/coordinator/src/tributary.rs b/coordinator/src/tributary.rs index c5ecdf5b..9502d09e 100644 --- a/coordinator/src/tributary.rs +++ b/coordinator/src/tributary.rs @@ -11,7 +11,6 @@ use tokio::sync::mpsc; use serai_db::{Get, DbTxn, Db as DbTrait, create_db, db_channel}; -use scale::Encode; use serai_client::validator_sets::primitives::ExternalValidatorSet; use tributary_sdk::{TransactionKind, TransactionError, ProvidedError, TransactionTrait, Tributary}; @@ -479,7 +478,8 @@ pub(crate) async fn spawn_tributary( return; } - let genesis = <[u8; 32]>::from(Blake2s::::digest((set.serai_block, set.set).encode())); + let genesis = + <[u8; 32]>::from(Blake2s::::digest(borsh::to_vec(&(set.serai_block, set.set)).unwrap())); // Since the Serai block will be finalized, then cosigned, before we handle this, this time will // be a couple of minutes stale. While the Tributary will still function with a start time in the diff --git a/coordinator/substrate/Cargo.toml b/coordinator/substrate/Cargo.toml index d78ace99..0e3c330e 100644 --- a/coordinator/substrate/Cargo.toml +++ b/coordinator/substrate/Cargo.toml @@ -20,7 +20,6 @@ workspace = true [dependencies] bitvec = { version = "1", default-features = false, features = ["std"] } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["std", "derive", "bit-vec"] } borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] } dkg = { path = "../../crypto/dkg", default-features = false, features = ["std"] } diff --git a/coordinator/substrate/src/lib.rs b/coordinator/substrate/src/lib.rs index 902234dc..9d5ba755 100644 --- a/coordinator/substrate/src/lib.rs +++ b/coordinator/substrate/src/lib.rs @@ -4,7 +4,6 @@ use std::collections::HashMap; -use scale::{Encode, Decode}; use borsh::{BorshSerialize, BorshDeserialize}; use dkg::Participant; @@ -178,14 +177,13 @@ impl Keys { signature_participants, signature, ); - _public_db::Keys::set(txn, set.network, &(set.session, tx.encode())); + _public_db::Keys::set(txn, set.network, &(set.session, tx)); } pub(crate) fn take( txn: &mut impl DbTxn, network: ExternalNetworkId, ) -> Option<(Session, Transaction)> { - let (session, tx) = _public_db::Keys::take(txn, network)?; - Some((session, <_>::decode(&mut tx.as_slice()).unwrap())) + _public_db::Keys::take(txn, network) } } @@ -226,13 +224,12 @@ impl SlashReports { slash_report, signature, ); - _public_db::SlashReports::set(txn, set.network, &(set.session, tx.encode())); + _public_db::SlashReports::set(txn, set.network, &(set.session, tx)); } pub(crate) fn take( txn: &mut impl DbTxn, network: ExternalNetworkId, ) -> Option<(Session, Transaction)> { - let (session, tx) = _public_db::SlashReports::take(txn, network)?; - Some((session, <_>::decode(&mut tx.as_slice()).unwrap())) + _public_db::SlashReports::take(txn, network) } } diff --git a/processor/bin/src/coordinator.rs b/processor/bin/src/coordinator.rs index e5defdc3..dd6bdee5 100644 --- a/processor/bin/src/coordinator.rs +++ b/processor/bin/src/coordinator.rs @@ -34,7 +34,7 @@ static SEND_LOCK: LazyLock> = LazyLock::new(|| Mutex::new(())); db_channel! { ProcessorBinCoordinator { - SentCoordinatorMessages: () -> Vec, + SentCoordinatorMessages: () -> messages::ProcessorMessage, } } @@ -48,7 +48,7 @@ impl CoordinatorSend { fn send(&mut self, msg: &messages::ProcessorMessage) { let _lock = SEND_LOCK.lock().unwrap(); let mut txn = self.db.txn(); - SentCoordinatorMessages::send(&mut txn, &borsh::to_vec(msg).unwrap()); + SentCoordinatorMessages::send(&mut txn, msg); txn.commit(); self .sent_message @@ -114,12 +114,9 @@ impl Coordinator { let mut txn = db.txn(); match SentCoordinatorMessages::try_recv(&mut txn) { Some(msg) => { - let metadata = Metadata { - from: service, - to: Service::Coordinator, - intent: borsh::from_slice::(&msg).unwrap().intent(), - }; - message_queue.queue_with_retry(metadata, msg).await; + let metadata = + Metadata { from: service, to: Service::Coordinator, intent: msg.intent() }; + message_queue.queue_with_retry(metadata, borsh::to_vec(&msg).unwrap()).await; txn.commit(); } None => { diff --git a/processor/scheduler/utxo/standard/src/db.rs b/processor/scheduler/utxo/standard/src/db.rs index 07b63d3c..69611465 100644 --- a/processor/scheduler/utxo/standard/src/db.rs +++ b/processor/scheduler/utxo/standard/src/db.rs @@ -7,7 +7,6 @@ use serai_primitives::{ balance::{Amount, ExternalBalance}, }; -use borsh::BorshDeserialize; use serai_db::{Get, DbTxn, create_db, db_channel}; use primitives::{Payment, ReceivedOutput}; @@ -22,9 +21,10 @@ create_db! { } } +#[rustfmt::skip] db_channel! { UtxoScheduler { - PendingBranch: (key: &[u8], balance: ExternalBalance) -> Vec, + PendingBranch: (key: &[u8], balance: ExternalBalance) -> TreeTransaction>, } } @@ -103,14 +103,13 @@ impl Db { balance: ExternalBalance, child: &TreeTransaction>, ) { - PendingBranch::send(txn, key.to_bytes().as_ref(), balance, &borsh::to_vec(child).unwrap()) + PendingBranch::::send(txn, key.to_bytes().as_ref(), balance, child) } pub(crate) fn take_pending_branch( txn: &mut impl DbTxn, key: KeyFor, balance: ExternalBalance, ) -> Option>> { - PendingBranch::try_recv(txn, key.to_bytes().as_ref(), balance) - .map(|bytes| TreeTransaction::>::deserialize(&mut bytes.as_slice()).unwrap()) + PendingBranch::::try_recv(txn, key.to_bytes().as_ref(), balance) } } diff --git a/processor/signers/src/cosign/mod.rs b/processor/signers/src/cosign/mod.rs index 4c215e61..aae12b60 100644 --- a/processor/signers/src/cosign/mod.rs +++ b/processor/signers/src/cosign/mod.rs @@ -123,10 +123,7 @@ impl ContinuallyRan for CosignerTask { let cosign = self.current_cosign.take().unwrap(); LatestCosigned::set(&mut txn, self.session, &cosign.block_number); - let cosign = SignedCosign { - cosign, - signature: borsh::to_vec(&Signature::from(signature)).unwrap().try_into().unwrap(), - }; + let cosign = SignedCosign { cosign, signature: Signature::from(signature).0 }; // Send the cosign Cosign::send(&mut txn, self.session, &cosign); }