Support multiple key shares per validator (#416)

* Update the coordinator to give key shares based on weight, not based on existence

Participants are now identified by their starting index. While this compiles,
the following is unimplemented:

1) A conversion for DKG `i` values. It assumes the threshold `i` values used
will be identical for the MuSig signature used to confirm the DKG.
2) Expansion from compressed values to full values before forwarding to the
processor.

* Add a fn to the DkgConfirmer to convert `i` values as needed

Also removes TODOs regarding Serai ensuring validator key uniqueness +
validity. The current infra achieves both.

* Have the Tributary DB track participation by shares, not by count

* Prevent a node from obtaining 34% of the maximum amount of key shares

This is actually mainly intended to set a bound on message sizes in the
coordinator. Message sizes are amplified by the amount of key shares held, so
setting an upper bound on said amount lets it determine constants. While that
upper bound could be 150, that'd be unreasonable and increase the potential for
DoS attacks.

* Correct the mechanism to detect if sufficient accumulation has occured

It used to check if the latest accumulation hit the required threshold. Now,
accumulations may jump past the required threshold. The required mechanism is
to check the threshold wasn't prior met and is now met.

* Finish updating the coordinator to handle a multiple key share per validator environment

* Adjust stategy re: preventing noce reuse in DKG Confirmer

* Add TODOs regarding dropped transactions, add possible TODO fix

* Update tests/coordinator

This doesn't add new multi-key-share tests, it solely updates the existing
single key-share tests to compile and run, with the necessary fixes to the
coordinator.

* Update processor key_gen to handle generating multiple key shares at once

* Update SubstrateSigner

* Update signer, clippy

* Update processor tests

* Update processor docker tests
This commit is contained in:
Luke Parker
2023-11-04 19:26:13 -04:00
committed by GitHub
parent 5970a455d0
commit e05b77d830
28 changed files with 866 additions and 437 deletions

View File

@@ -48,7 +48,7 @@ pub(crate) async fn recv_batch_preprocesses(
messages::coordinator::ProcessorMessage::BatchPreprocess {
id: this_id,
block: this_block,
preprocess,
preprocesses: mut these_preprocesses,
},
) => {
if id.is_none() {
@@ -60,7 +60,8 @@ pub(crate) async fn recv_batch_preprocesses(
assert_eq!(&this_id, id.as_ref().unwrap());
assert_eq!(&this_block, block.as_ref().unwrap());
preprocesses.insert(i, preprocess);
assert_eq!(these_preprocesses.len(), 1);
preprocesses.insert(i, these_preprocesses.swap_remove(0));
}
_ => panic!("processor didn't send batch preprocess"),
}
@@ -107,10 +108,14 @@ pub(crate) async fn sign_batch(
if preprocesses.contains_key(&i) {
match coordinator.recv_message().await {
messages::ProcessorMessage::Coordinator(
messages::coordinator::ProcessorMessage::BatchShare { id: this_id, share },
messages::coordinator::ProcessorMessage::BatchShare {
id: this_id,
shares: mut these_shares,
},
) => {
assert_eq!(&this_id, &id);
shares.insert(i, share);
assert_eq!(these_shares.len(), 1);
shares.insert(i, these_shares.swap_remove(0));
}
_ => panic!("processor didn't send batch share"),
}

View File

@@ -46,14 +46,16 @@ pub(crate) async fn key_gen(coordinators: &mut [Coordinator], network: NetworkId
participant,
)
.unwrap(),
shares: 1,
},
|participant, msg| match msg {
messages::key_gen::ProcessorMessage::Commitments {
id: this_id,
commitments: these_commitments,
commitments: mut these_commitments,
} => {
assert_eq!(this_id, id);
commitments.insert(participant, these_commitments);
assert_eq!(these_commitments.len(), 1);
commitments.insert(participant, these_commitments.swap_remove(0));
}
_ => panic!("processor didn't return Commitments in response to GenerateKey"),
},
@@ -69,9 +71,10 @@ pub(crate) async fn key_gen(coordinators: &mut [Coordinator], network: NetworkId
commitments: clone_without(&commitments, &participant),
},
|participant, msg| match msg {
messages::key_gen::ProcessorMessage::Shares { id: this_id, shares: these_shares } => {
messages::key_gen::ProcessorMessage::Shares { id: this_id, shares: mut these_shares } => {
assert_eq!(this_id, id);
shares.insert(participant, these_shares);
assert_eq!(these_shares.len(), 1);
shares.insert(participant, these_shares.swap_remove(0));
}
_ => panic!("processor didn't return Shares in response to GenerateKey"),
},
@@ -85,12 +88,12 @@ pub(crate) async fn key_gen(coordinators: &mut [Coordinator], network: NetworkId
coordinators,
|participant| messages::key_gen::CoordinatorMessage::Shares {
id,
shares: shares
shares: vec![shares
.iter()
.filter_map(|(this_participant, shares)| {
shares.get(&participant).cloned().map(|share| (*this_participant, share))
})
.collect(),
.collect()],
},
|_, msg| match msg {
messages::key_gen::ProcessorMessage::GeneratedKeyPair {

View File

@@ -30,7 +30,7 @@ pub(crate) async fn recv_sign_preprocesses(
match msg {
messages::ProcessorMessage::Sign(messages::sign::ProcessorMessage::Preprocess {
id: this_id,
preprocess,
preprocesses: mut these_preprocesses,
}) => {
if id.is_none() {
assert_eq!(&this_id.key, &key);
@@ -39,7 +39,8 @@ pub(crate) async fn recv_sign_preprocesses(
}
assert_eq!(&this_id, id.as_ref().unwrap());
preprocesses.insert(i, preprocess);
assert_eq!(these_preprocesses.len(), 1);
preprocesses.insert(i, these_preprocesses.swap_remove(0));
}
_ => panic!("processor didn't send sign preprocess"),
}
@@ -87,10 +88,11 @@ pub(crate) async fn sign_tx(
match coordinator.recv_message().await {
messages::ProcessorMessage::Sign(messages::sign::ProcessorMessage::Share {
id: this_id,
share,
shares: mut these_shares,
}) => {
assert_eq!(&this_id, &id);
shares.insert(i, share);
assert_eq!(these_shares.len(), 1);
shares.insert(i, these_shares.swap_remove(0));
}
_ => panic!("processor didn't send TX shares"),
}