mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-23 03:59:22 +00:00
Use an empty key for Batch's SignId
This commit is contained in:
parent
bccdabb53d
commit
ea8e26eca3
5 changed files with 18 additions and 21 deletions
|
@ -467,7 +467,7 @@ pub async fn handle_application_tx<
|
||||||
.send(
|
.send(
|
||||||
spec.set().network,
|
spec.set().network,
|
||||||
CoordinatorMessage::Coordinator(coordinator::CoordinatorMessage::BatchPreprocesses {
|
CoordinatorMessage::Coordinator(coordinator::CoordinatorMessage::BatchPreprocesses {
|
||||||
id: SignId { key: todo!(), id: data.plan, attempt: data.attempt },
|
id: SignId { key: vec![], id: data.plan, attempt: data.attempt },
|
||||||
preprocesses,
|
preprocesses,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
@ -489,9 +489,9 @@ pub async fn handle_application_tx<
|
||||||
.send(
|
.send(
|
||||||
spec.set().network,
|
spec.set().network,
|
||||||
CoordinatorMessage::Coordinator(coordinator::CoordinatorMessage::BatchShares {
|
CoordinatorMessage::Coordinator(coordinator::CoordinatorMessage::BatchShares {
|
||||||
id: SignId { key: todo!(), id: data.plan, attempt: data.attempt },
|
id: SignId { key: vec![], id: data.plan, attempt: data.attempt },
|
||||||
shares: shares
|
shares: shares
|
||||||
.drain()
|
.into_iter()
|
||||||
.map(|(validator, share)| (validator, share.try_into().unwrap()))
|
.map(|(validator, share)| (validator, share.try_into().unwrap()))
|
||||||
.collect(),
|
.collect(),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -6,7 +6,6 @@ use rand_core::OsRng;
|
||||||
use scale::Encode;
|
use scale::Encode;
|
||||||
use transcript::{Transcript, RecommendedTranscript};
|
use transcript::{Transcript, RecommendedTranscript};
|
||||||
|
|
||||||
use ciphersuite::group::GroupEncoding;
|
|
||||||
use frost::{
|
use frost::{
|
||||||
curve::Ristretto,
|
curve::Ristretto,
|
||||||
ThresholdKeys,
|
ThresholdKeys,
|
||||||
|
@ -179,7 +178,9 @@ impl<D: Db> SubstrateSigner<D> {
|
||||||
// Update the attempt number
|
// Update the attempt number
|
||||||
self.attempt.insert(id, attempt);
|
self.attempt.insert(id, attempt);
|
||||||
|
|
||||||
let id = SignId { key: self.keys.group_key().to_bytes().to_vec(), id, attempt };
|
// Doesn't set key since there's only one key active at a time
|
||||||
|
// TODO: BatchSignId
|
||||||
|
let id = SignId { key: vec![], id, attempt };
|
||||||
info!("signing batch {} #{}", hex::encode(id.id), id.attempt);
|
info!("signing batch {} #{}", hex::encode(id.id), id.attempt);
|
||||||
|
|
||||||
// If we reboot mid-sign, the current design has us abort all signs and wait for latter
|
// If we reboot mid-sign, the current design has us abort all signs and wait for latter
|
||||||
|
|
|
@ -20,14 +20,13 @@ use crate::substrate_signer::{SubstrateSignerEvent, SubstrateSigner};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_substrate_signer() {
|
async fn test_substrate_signer() {
|
||||||
let mut keys = key_gen::<_, Ristretto>(&mut OsRng);
|
let keys = key_gen::<_, Ristretto>(&mut OsRng);
|
||||||
|
|
||||||
let participant_one = Participant::new(1).unwrap();
|
let participant_one = Participant::new(1).unwrap();
|
||||||
|
|
||||||
let id: u32 = 5;
|
let id: u32 = 5;
|
||||||
let block = BlockHash([0xaa; 32]);
|
let block = BlockHash([0xaa; 32]);
|
||||||
let mut actual_id =
|
let mut actual_id = SignId { key: vec![], id: [0; 32], attempt: 0 };
|
||||||
SignId { key: keys[&participant_one].group_key().to_bytes().to_vec(), id: [0; 32], attempt: 0 };
|
|
||||||
|
|
||||||
let batch = Batch {
|
let batch = Batch {
|
||||||
network: NetworkId::Monero,
|
network: NetworkId::Monero,
|
||||||
|
@ -50,7 +49,7 @@ async fn test_substrate_signer() {
|
||||||
let mut t = 0;
|
let mut t = 0;
|
||||||
for i in 1 ..= keys.len() {
|
for i in 1 ..= keys.len() {
|
||||||
let i = Participant::new(u16::try_from(i).unwrap()).unwrap();
|
let i = Participant::new(u16::try_from(i).unwrap()).unwrap();
|
||||||
let keys = keys.remove(&i).unwrap();
|
let keys = keys.get(&i).unwrap().clone();
|
||||||
t = keys.params().t();
|
t = keys.params().t();
|
||||||
|
|
||||||
let mut signer = SubstrateSigner::<MemDb>::new(NetworkId::Monero, keys);
|
let mut signer = SubstrateSigner::<MemDb>::new(NetworkId::Monero, keys);
|
||||||
|
@ -62,7 +61,6 @@ async fn test_substrate_signer() {
|
||||||
signers.insert(i, signer);
|
signers.insert(i, signer);
|
||||||
dbs.insert(i, db);
|
dbs.insert(i, db);
|
||||||
}
|
}
|
||||||
drop(keys);
|
|
||||||
|
|
||||||
let mut signing_set = vec![];
|
let mut signing_set = vec![];
|
||||||
while signing_set.len() < usize::from(t) {
|
while signing_set.len() < usize::from(t) {
|
||||||
|
@ -144,7 +142,7 @@ async fn test_substrate_signer() {
|
||||||
signers.get_mut(i).unwrap().events.pop_front().unwrap()
|
signers.get_mut(i).unwrap().events.pop_front().unwrap()
|
||||||
{
|
{
|
||||||
assert_eq!(signed_batch.batch, batch);
|
assert_eq!(signed_batch.batch, batch);
|
||||||
assert!(Public::from_raw(actual_id.key.clone().try_into().unwrap())
|
assert!(Public::from_raw(keys[&participant_one].group_key().to_bytes())
|
||||||
.verify(&batch_message(&batch), &signed_batch.signature));
|
.verify(&batch_message(&batch), &signed_batch.signature));
|
||||||
} else {
|
} else {
|
||||||
panic!("didn't get signed batch back");
|
panic!("didn't get signed batch back");
|
||||||
|
|
|
@ -18,7 +18,6 @@ use crate::{*, tests::*};
|
||||||
|
|
||||||
pub(crate) async fn recv_batch_preprocesses(
|
pub(crate) async fn recv_batch_preprocesses(
|
||||||
coordinators: &mut [Coordinator],
|
coordinators: &mut [Coordinator],
|
||||||
key: [u8; 32],
|
|
||||||
attempt: u32,
|
attempt: u32,
|
||||||
) -> (SignId, HashMap<Participant, Vec<u8>>) {
|
) -> (SignId, HashMap<Participant, Vec<u8>>) {
|
||||||
let mut id = None;
|
let mut id = None;
|
||||||
|
@ -37,7 +36,7 @@ pub(crate) async fn recv_batch_preprocesses(
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
if id.is_none() {
|
if id.is_none() {
|
||||||
assert_eq!(&this_id.key, &key);
|
assert!(this_id.key.is_empty());
|
||||||
assert_eq!(this_id.attempt, attempt);
|
assert_eq!(this_id.attempt, attempt);
|
||||||
id = Some(this_id.clone());
|
id = Some(this_id.clone());
|
||||||
block = Some(this_block);
|
block = Some(this_block);
|
||||||
|
@ -66,6 +65,7 @@ pub(crate) async fn recv_batch_preprocesses(
|
||||||
|
|
||||||
pub(crate) async fn sign_batch(
|
pub(crate) async fn sign_batch(
|
||||||
coordinators: &mut [Coordinator],
|
coordinators: &mut [Coordinator],
|
||||||
|
key: [u8; 32],
|
||||||
id: SignId,
|
id: SignId,
|
||||||
preprocesses: HashMap<Participant, Vec<u8>>,
|
preprocesses: HashMap<Participant, Vec<u8>>,
|
||||||
) -> SignedBatch {
|
) -> SignedBatch {
|
||||||
|
@ -125,7 +125,7 @@ pub(crate) async fn sign_batch(
|
||||||
batch: this_batch,
|
batch: this_batch,
|
||||||
}) => {
|
}) => {
|
||||||
if batch.is_none() {
|
if batch.is_none() {
|
||||||
assert!(PublicKey::from_raw(id.key.clone().try_into().unwrap())
|
assert!(PublicKey::from_raw(key)
|
||||||
.verify(&batch_message(&this_batch.batch), &this_batch.signature));
|
.verify(&batch_message(&this_batch.batch), &this_batch.signature));
|
||||||
|
|
||||||
batch = Some(this_batch.clone());
|
batch = Some(this_batch.clone());
|
||||||
|
@ -232,8 +232,7 @@ fn batch_test() {
|
||||||
tokio::time::sleep(Duration::from_secs(10)).await;
|
tokio::time::sleep(Duration::from_secs(10)).await;
|
||||||
|
|
||||||
// Make sure the proceessors picked it up by checking they're trying to sign a batch for it
|
// Make sure the proceessors picked it up by checking they're trying to sign a batch for it
|
||||||
let (mut id, mut preprocesses) =
|
let (mut id, mut preprocesses) = recv_batch_preprocesses(&mut coordinators, 0).await;
|
||||||
recv_batch_preprocesses(&mut coordinators, key_pair.0 .0, 0).await;
|
|
||||||
// Trigger a random amount of re-attempts
|
// Trigger a random amount of re-attempts
|
||||||
for attempt in 1 ..= u32::try_from(OsRng.next_u64() % 4).unwrap() {
|
for attempt in 1 ..= u32::try_from(OsRng.next_u64() % 4).unwrap() {
|
||||||
// TODO: Double check how the processor handles this ID field
|
// TODO: Double check how the processor handles this ID field
|
||||||
|
@ -246,12 +245,11 @@ fn batch_test() {
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
(id, preprocesses) =
|
(id, preprocesses) = recv_batch_preprocesses(&mut coordinators, attempt).await;
|
||||||
recv_batch_preprocesses(&mut coordinators, key_pair.0 .0, attempt).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue with signing the batch
|
// Continue with signing the batch
|
||||||
let batch = sign_batch(&mut coordinators, id, preprocesses).await;
|
let batch = sign_batch(&mut coordinators, key_pair.0 .0, id, preprocesses).await;
|
||||||
|
|
||||||
// Check it
|
// Check it
|
||||||
assert_eq!(batch.batch.network, network);
|
assert_eq!(batch.batch.network, network);
|
||||||
|
|
|
@ -187,10 +187,10 @@ fn send_test() {
|
||||||
tokio::time::sleep(Duration::from_secs(10)).await;
|
tokio::time::sleep(Duration::from_secs(10)).await;
|
||||||
|
|
||||||
// Make sure the proceessors picked it up by checking they're trying to sign a batch for it
|
// Make sure the proceessors picked it up by checking they're trying to sign a batch for it
|
||||||
let (id, preprocesses) = recv_batch_preprocesses(&mut coordinators, key_pair.0 .0, 0).await;
|
let (id, preprocesses) = recv_batch_preprocesses(&mut coordinators, 0).await;
|
||||||
|
|
||||||
// Continue with signing the batch
|
// Continue with signing the batch
|
||||||
let batch = sign_batch(&mut coordinators, id, preprocesses).await;
|
let batch = sign_batch(&mut coordinators, key_pair.0 .0, id, preprocesses).await;
|
||||||
|
|
||||||
// Check it
|
// Check it
|
||||||
assert_eq!(batch.batch.network, network);
|
assert_eq!(batch.batch.network, network);
|
||||||
|
|
Loading…
Reference in a new issue