* Remove NetworkId from processor-messages

Because intent binds to the sender/receiver, it's not needed for intent.

The processor knows what the network is.

The coordinator knows which to use because it's sending this message to the
processor for that network.

Also removes the unused zeroize.

* ProcessorMessage::Completed use Session instead of key

* Move SubstrateSignId to Session

* Finish replacing key with session
This commit is contained in:
Luke Parker
2023-11-26 12:14:23 -05:00
committed by GitHub
parent b79cf8abde
commit 571195bfda
31 changed files with 304 additions and 455 deletions

View File

@@ -22,6 +22,7 @@ use serai_client::{
primitives::{Batch, SignedBatch, batch_message},
InInstructionsEvent,
},
validator_sets::primitives::Session,
};
use messages::{
coordinator::{SubstrateSignableId, SubstrateSignId},
@@ -33,16 +34,13 @@ use crate::{*, tests::*};
pub async fn batch(
processors: &mut [Processor],
processor_is: &[u8],
session: Session,
substrate_key: &Zeroizing<<Ristretto as Ciphersuite>::F>,
batch: Batch,
) -> u64 {
let mut id = [0; 5];
OsRng.fill_bytes(&mut id);
let id = SubstrateSignId {
key: (<Ristretto as Ciphersuite>::generator() * **substrate_key).to_bytes(),
id: SubstrateSignableId::Batch(id),
attempt: 0,
};
let id = SubstrateSignId { session, id: SubstrateSignableId::Batch(id), attempt: 0 };
for processor in processors.iter_mut() {
processor
@@ -232,7 +230,6 @@ pub async fn batch(
serai_time: last_block.time().unwrap() / 1000,
network_latest_finalized_block: batch.batch.block,
},
network: batch.batch.network,
block: last_serai_block,
burns: vec![],
batches: vec![batch.batch.id],
@@ -244,7 +241,6 @@ pub async fn batch(
processor
.send_message(messages::ProcessorMessage::Coordinator(
messages::coordinator::ProcessorMessage::SubstrateBlockAck {
network: batch.batch.network,
block: last_serai_block,
plans: vec![],
},
@@ -283,6 +279,7 @@ async fn batch_test() {
batch(
&mut processors,
&processor_is,
Session(0),
&substrate_key,
Batch {
network: NetworkId::Bitcoin,

View File

@@ -28,7 +28,7 @@ pub async fn key_gen<C: Ciphersuite>(
let mut participant_is = vec![];
let set = ValidatorSet { session: Session(0), network: NetworkId::Bitcoin };
let id = KeyGenId { set, attempt: 0 };
let id = KeyGenId { session: set.session, attempt: 0 };
for (i, processor) in processors.iter_mut().enumerate() {
let msg = processor.recv_message().await;
@@ -173,7 +173,7 @@ pub async fn key_gen<C: Ciphersuite>(
CoordinatorMessage::Substrate(
messages::substrate::CoordinatorMessage::ConfirmKeyPair {
context,
set: this_set,
session,
ref key_pair,
},
) => {
@@ -186,7 +186,7 @@ pub async fn key_gen<C: Ciphersuite>(
70
);
assert_eq!(context.network_latest_finalized_block.0, [0; 32]);
assert_eq!(set, this_set);
assert_eq!(set.session, session);
assert_eq!(key_pair.0 .0, substrate_key);
assert_eq!(&key_pair.1, &network_key);
}

View File

@@ -4,10 +4,9 @@ use std::{
collections::{HashSet, HashMap},
};
use zeroize::Zeroizing;
use rand_core::{RngCore, OsRng};
use ciphersuite::{group::GroupEncoding, Ciphersuite, Secp256k1};
use ciphersuite::Secp256k1;
use dkg::Participant;
@@ -22,23 +21,20 @@ use serai_client::{
CoinsEvent,
},
in_instructions::primitives::{InInstruction, InInstructionWithBalance, Batch},
validator_sets::primitives::Session,
SeraiCoins,
};
use messages::{coordinator::PlanMeta, sign::SignId, SubstrateContext, CoordinatorMessage};
use crate::tests::*;
pub async fn sign<C: Ciphersuite>(
pub async fn sign(
processors: &mut [Processor],
processor_is: &[u8],
network_key: &Zeroizing<C::F>,
session: Session,
plan_id: [u8; 32],
) {
let id = SignId {
key: (C::generator() * **network_key).to_bytes().as_ref().to_vec(),
id: plan_id,
attempt: 0,
};
let id = SignId { session, id: plan_id, attempt: 0 };
// Select a random participant to exclude, so we know for sure who *is* participating
assert_eq!(COORDINATORS - THRESHOLD, 1);
@@ -150,7 +146,7 @@ pub async fn sign<C: Ciphersuite>(
&mut processors[processor_is.iter().position(|p_i| u16::from(*p_i) == u16::from(i)).unwrap()];
processor
.send_message(messages::sign::ProcessorMessage::Completed {
key: id.key.clone(),
session,
id: id.id,
tx: b"signed_tx".to_vec(),
})
@@ -163,7 +159,7 @@ pub async fn sign<C: Ciphersuite>(
assert_eq!(
processor.recv_message().await,
CoordinatorMessage::Sign(messages::sign::CoordinatorMessage::Completed {
key: id.key.clone(),
session,
id: id.id,
tx: b"signed_tx".to_vec()
})
@@ -196,8 +192,7 @@ async fn sign_test() {
}
let mut processors = new_processors;
let (participant_is, substrate_key, network_key) =
key_gen::<Secp256k1>(&mut processors).await;
let (participant_is, substrate_key, _) = key_gen::<Secp256k1>(&mut processors).await;
// 'Send' external coins into Serai
let serai = processors[0].serai().await;
@@ -230,6 +225,7 @@ async fn sign_test() {
let block_included_in = batch(
&mut processors,
&participant_is,
Session(0),
&substrate_key,
Batch {
network: NetworkId::Bitcoin,
@@ -331,7 +327,6 @@ async fn sign_test() {
serai_time: last_serai_block.time().unwrap() / 1000,
network_latest_finalized_block: coin_block,
},
network: NetworkId::Bitcoin,
block: last_serai_block.number(),
burns: vec![out_instruction.clone()],
batches: vec![],
@@ -343,18 +338,14 @@ async fn sign_test() {
processor
.send_message(messages::ProcessorMessage::Coordinator(
messages::coordinator::ProcessorMessage::SubstrateBlockAck {
network: NetworkId::Bitcoin,
block: last_serai_block.number(),
plans: vec![PlanMeta {
key: (Secp256k1::generator() * *network_key).to_bytes().to_vec(),
id: plan_id,
}],
plans: vec![PlanMeta { session: Session(0), id: plan_id }],
},
))
.await;
}
sign::<Secp256k1>(&mut processors, &participant_is, &network_key, plan_id).await;
sign(&mut processors, &participant_is, Session(0), plan_id).await;
})
.await;
}