From 40b292041200d38539ea0378b94c397cc3fcec3b Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sat, 13 May 2023 22:43:13 -0400 Subject: [PATCH] Remove signed Substrate TXs from Coordinator --- coordinator/src/main.rs | 65 +++++++---------------------- substrate/client/src/serai/mod.rs | 2 +- substrate/primitives/src/account.rs | 5 +-- 3 files changed, 17 insertions(+), 55 deletions(-) diff --git a/coordinator/src/main.rs b/coordinator/src/main.rs index 9d3c3377..50eda721 100644 --- a/coordinator/src/main.rs +++ b/coordinator/src/main.rs @@ -12,22 +12,11 @@ use std::{ use zeroize::Zeroizing; use rand_core::OsRng; -use blake2::Digest; - -use ciphersuite::{ - group::{ - ff::{Field, PrimeField}, - GroupEncoding, - }, - Ciphersuite, Ristretto, -}; +use ciphersuite::{group::ff::Field, Ciphersuite, Ristretto}; use serai_db::{DbTxn, Db, MemDb}; -use serai_client::{ - subxt::{config::extrinsic_params::BaseExtrinsicParamsBuilder, tx::Signer}, - Public, PairSigner, Serai, -}; +use serai_client::{Public, Signature, Serai}; use tokio::{ sync::{ @@ -385,19 +374,6 @@ pub async fn handle_processors( ) { let pub_key = Ristretto::generator() * key.deref(); - // TODO: This is cursed. serai_client has to handle this for us - let substrate_signer = { - let mut bytes = Zeroizing::new([0; 96]); - // Private key - bytes[.. 32].copy_from_slice(&key.to_repr()); - // Nonce - let nonce = Zeroizing::new(blake2::Blake2s256::digest(&bytes)); - bytes[32 .. 64].copy_from_slice(nonce.as_ref()); - // Public key - bytes[64 ..].copy_from_slice(&pub_key.to_bytes()); - PairSigner::new(schnorrkel::keys::Keypair::from_bytes(bytes.as_ref()).unwrap().into()) - }; - loop { let msg = processors.recv().await; @@ -429,31 +405,18 @@ pub async fn handle_processors( ); // TODO: Also check the other KeyGenId fields - // TODO: Publish an unsigned TX with a Musig signature here, instead of on-chain voting - // That removes the need for this nonce - let Ok(nonce) = serai.get_nonce(&substrate_signer.address()).await else { - log::error!("couldn't get nonce from Serai node"); - todo!() - }; + // TODO: Sign a MuSig signature here - let tx = serai - .sign( - &substrate_signer, - &Serai::vote( - msg.network, - ( - Public(substrate_key), - coin_key - .try_into() - .expect("external key from processor exceeded max external key length"), - ), - ), - nonce, - BaseExtrinsicParamsBuilder::new(), - ) - .expect( - "tried to sign an invalid payload despite creating the payload via serai_client", - ); + let tx = Serai::set_validator_set_keys( + id.set.network, + ( + Public(substrate_key), + coin_key + .try_into() + .expect("external key from processor exceeded max external key length"), + ), + Signature([0; 64]), // TODO + ); match serai.publish(&tx).await { Ok(hash) => { @@ -547,7 +510,7 @@ pub async fn handle_processors( // TODO: Check this key's key pair's substrate key is authorized to publish batches // TODO: Check the batch ID is an atomic increment - match serai.publish(&serai.execute_batch(batch.clone())).await { + match serai.publish(&Serai::execute_batch(batch.clone())).await { Ok(hash) => { log::info!( "executed batch {:?} {} (block {}) in TX {}", diff --git a/substrate/client/src/serai/mod.rs b/substrate/client/src/serai/mod.rs index a7d9eb7b..7e3ca443 100644 --- a/substrate/client/src/serai/mod.rs +++ b/substrate/client/src/serai/mod.rs @@ -24,7 +24,7 @@ use subxt::{ }; pub use serai_runtime::primitives; -use primitives::{Signature, SeraiAddress}; +pub use primitives::{Signature, SeraiAddress}; use serai_runtime::{ system::Config, support::traits::PalletInfo as PalletInfoTrait, PalletInfo, Runtime, diff --git a/substrate/primitives/src/account.rs b/substrate/primitives/src/account.rs index 49228835..ae6371f9 100644 --- a/substrate/primitives/src/account.rs +++ b/substrate/primitives/src/account.rs @@ -7,7 +7,8 @@ use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; -use sp_core::sr25519::{Public, Signature as RistrettoSignature}; +use sp_core::sr25519::Public; +pub use sp_core::sr25519::Signature; #[cfg(feature = "std")] use sp_core::{Pair as PairTrait, sr25519::Pair}; @@ -76,8 +77,6 @@ impl StaticLookup for AccountLookup { } } -pub type Signature = RistrettoSignature; - pub const fn pallet_address(pallet: &'static [u8]) -> SeraiAddress { let mut address = [0; 32]; let mut set = false;