Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposer selection upgrade and proposer set voting protocol in fallback case #633

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dkg-mock-blockchain = { path = "dkg-mock-blockchain", default-features = false }
dkg-test-orchestrator = { path = "dkg-test-orchestrator", default-features = false }

futures = "0.3.15"
ethabi = { version = "18.0.0", default-features = false }
clap = { version = "4.0.32", features = ["derive"] }
rand = "0.8.4"
hex-literal = { package = "hex-literal", version = "0.3.3" }
Expand Down
9 changes: 4 additions & 5 deletions dkg-gadget/src/async_protocols/blockchain_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ use crate::{
use codec::Encode;
use curv::{elliptic::curves::Secp256k1, BigInt};
use dkg_primitives::{
types::{
DKGError, DKGMessage, DKGPublicKeyMessage, DKGSignedPayload, SessionId, SignedDKGMessage,
},
types::{DKGError, DKGMessage, SessionId, SignedDKGMessage},
utils::convert_signature,
};
use dkg_runtime_primitives::{
crypto::{AuthorityId, Public},
gossip_messages::{DKGSignedPayload, PublicKeyMessage},
AggregatedPublicKeys, AuthoritySet, MaxAuthorities, MaxProposalLength, UnsignedProposal,
};
use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2020::{
Expand Down Expand Up @@ -72,7 +71,7 @@ pub trait BlockchainInterface: Send + Sync {
batch_key: BatchKey,
message: BigInt,
) -> Result<(), DKGError>;
fn gossip_public_key(&self, key: DKGPublicKeyMessage) -> Result<(), DKGError>;
fn gossip_public_key(&self, key: PublicKeyMessage) -> Result<(), DKGError>;
fn store_public_key(
&self,
key: LocalKey<Secp256k1>,
Expand Down Expand Up @@ -261,7 +260,7 @@ where
Ok(())
}

fn gossip_public_key(&self, key: DKGPublicKeyMessage) -> Result<(), DKGError> {
fn gossip_public_key(&self, key: PublicKeyMessage) -> Result<(), DKGError> {
gossip_public_key::<B, C, BE, GE>(
&self.keystore,
self.gossip_engine.clone(),
Expand Down
8 changes: 4 additions & 4 deletions dkg-gadget/src/async_protocols/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use dkg_primitives::types::{DKGError, DKGMessage, DKGMsgPayload, SessionId, SignedDKGMessage};
use dkg_primitives::types::{DKGError, DKGMessage, NetworkMsgPayload, SessionId, SignedDKGMessage};
use dkg_runtime_primitives::{crypto::Public, MaxAuthorities};
use futures::Stream;
use round_based::Msg;
Expand Down Expand Up @@ -95,9 +95,9 @@ impl TransformIncoming for Arc<SignedDKGMessage<Public>> {
Self: Sized,
{
match (stream_type, &self.msg.payload) {
(ProtocolType::Keygen { .. }, DKGMsgPayload::Keygen(..)) |
(ProtocolType::Offline { .. }, DKGMsgPayload::Offline(..)) |
(ProtocolType::Voting { .. }, DKGMsgPayload::Vote(..)) => {
(ProtocolType::Keygen { .. }, NetworkMsgPayload::Keygen(..)) |
(ProtocolType::Offline { .. }, NetworkMsgPayload::Offline(..)) |
(ProtocolType::Voting { .. }, NetworkMsgPayload::Vote(..)) => {
// only clone if the downstream receiver expects this type
let sender = self
.msg
Expand Down
8 changes: 4 additions & 4 deletions dkg-gadget/src/async_protocols/keygen/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::{
debug_logger::DebugLogger,
};
use async_trait::async_trait;
use dkg_primitives::types::{DKGError, DKGMessage, DKGMsgPayload, DKGPublicKeyMessage};
use dkg_runtime_primitives::{crypto::Public, MaxAuthorities};
use dkg_primitives::types::{DKGError, DKGMessage, NetworkMsgPayload};
use dkg_runtime_primitives::{crypto::Public, gossip_messages::PublicKeyMessage, MaxAuthorities};
use futures::channel::mpsc::UnboundedSender;
use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2020::state_machine::keygen::{
Keygen, ProtocolMessage,
Expand All @@ -42,7 +42,7 @@ impl<BI: BlockchainInterface + 'static> StateMachineHandler<BI> for Keygen {
let DKGMessage { payload, session_id, .. } = msg.body;
// Send the payload to the appropriate AsyncProtocols
match payload {
DKGMsgPayload::Keygen(msg) => {
NetworkMsgPayload::Keygen(msg) => {
logger.info_keygen(format!(
"Handling Keygen inbound message from id={}, session={}",
msg.sender_id, session_id
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<BI: BlockchainInterface + 'static> StateMachineHandler<BI> for Keygen {
// public_key_gossip.rs:gossip_public_key [2] store public key locally (public_keys.rs:
// store_aggregated_public_keys)
let session_id = params.session_id;
let pub_key_msg = DKGPublicKeyMessage {
let pub_key_msg = PublicKeyMessage {
session_id,
pub_key: local_key.public_key().to_bytes(true).to_vec(),
signature: vec![],
Expand Down
14 changes: 7 additions & 7 deletions dkg-gadget/src/async_protocols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ pub mod test_utils;
use curv::elliptic::curves::Secp256k1;
use dkg_primitives::{
crypto::Public,
types::{
DKGError, DKGKeygenMessage, DKGMessage, DKGMsgPayload, DKGMsgStatus, DKGOfflineMessage,
SessionId,
},
types::{DKGError, DKGMessage, DKGMsgStatus, NetworkMsgPayload, SessionId},
AuthoritySet,
};
use dkg_runtime_primitives::{MaxAuthorities, UnsignedProposal};
use dkg_runtime_primitives::{
gossip_messages::{DKGKeygenMessage, DKGOfflineMessage},
MaxAuthorities, UnsignedProposal,
};
use futures::{
channel::mpsc::{UnboundedReceiver, UnboundedSender},
Future, StreamExt,
Expand Down Expand Up @@ -575,12 +575,12 @@ where
None => None,
};
let payload = match &proto_ty {
ProtocolType::Keygen { .. } => DKGMsgPayload::Keygen(DKGKeygenMessage {
ProtocolType::Keygen { .. } => NetworkMsgPayload::Keygen(DKGKeygenMessage {
sender_id: party_id,
keygen_msg: serialized_body,
}),
ProtocolType::Offline { unsigned_proposal, .. } =>
DKGMsgPayload::Offline(DKGOfflineMessage {
NetworkMsgPayload::Offline(DKGOfflineMessage {
key: Vec::from(
&unsigned_proposal.hash().expect("Cannot hash unsigned proposal!")
as &[u8],
Expand Down
8 changes: 4 additions & 4 deletions dkg-gadget/src/async_protocols/sign/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use curv::{arithmetic::Converter, elliptic::curves::Secp256k1, BigInt};
use dkg_runtime_primitives::UnsignedProposal;
use dkg_runtime_primitives::{gossip_messages::DKGVoteMessage, UnsignedProposal};
use futures::{stream::FuturesUnordered, StreamExt, TryStreamExt};
use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2020::state_machine::{
keygen::LocalKey,
Expand All @@ -29,7 +29,7 @@ use crate::async_protocols::{
BatchKey, GenericAsyncHandler, KeygenPartyId, OfflinePartyId, ProtocolType, Threshold,
};
use dkg_primitives::types::{
DKGError, DKGMessage, DKGMsgPayload, DKGMsgStatus, DKGVoteMessage, SignedDKGMessage,
DKGError, DKGMessage, DKGMsgStatus, NetworkMsgPayload, SignedDKGMessage,
};
use dkg_runtime_primitives::{crypto::Public, MaxAuthorities};
use futures::FutureExt;
Expand Down Expand Up @@ -217,7 +217,7 @@ where
DKGError::GenericError { reason: "Partial signature is invalid".to_string() }
})?;

let payload = DKGMsgPayload::Vote(DKGVoteMessage {
let payload = NetworkMsgPayload::Vote(DKGVoteMessage {
party_ind: *offline_i.as_ref(),
// use the hash of proposal as "round key" ONLY for purposes of ensuring
// uniqueness We only want voting to happen amongst voters under the SAME
Expand Down Expand Up @@ -249,7 +249,7 @@ where
));

while let Some(msg) = incoming_wrapper.next().await {
if let DKGMsgPayload::Vote(dkg_vote_msg) = msg.body.payload {
if let NetworkMsgPayload::Vote(dkg_vote_msg) = msg.body.payload {
// only process messages which are from the respective proposal
if dkg_vote_msg.round_key.as_slice() == hash_of_proposal {
params.logger.info_signing("Found matching round key!".to_string());
Expand Down
4 changes: 2 additions & 2 deletions dkg-gadget/src/async_protocols/sign/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
debug_logger::DebugLogger,
};
use async_trait::async_trait;
use dkg_primitives::types::{DKGError, DKGMessage, DKGMsgPayload, SignedDKGMessage};
use dkg_primitives::types::{DKGError, DKGMessage, NetworkMsgPayload, SignedDKGMessage};
use dkg_runtime_primitives::{crypto::Public, MaxAuthorities, UnsignedProposal};
use futures::channel::mpsc::UnboundedSender;
use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2020::state_machine::sign::{
Expand Down Expand Up @@ -52,7 +52,7 @@ impl<BI: BlockchainInterface + 'static> StateMachineHandler<BI> for OfflineStage

// Send the payload to the appropriate AsyncProtocols
match payload {
DKGMsgPayload::Offline(msg) => {
NetworkMsgPayload::Offline(msg) => {
let message: Msg<OfflineProtocolMessage> =
match serde_json::from_slice(msg.offline_msg.as_slice()) {
Ok(msg) => msg,
Expand Down
12 changes: 7 additions & 5 deletions dkg-gadget/src/async_protocols/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ use crate::{
use codec::Encode;
use curv::{elliptic::curves::Secp256k1, BigInt};
use dkg_primitives::{
types::{
DKGError, DKGMessage, DKGPublicKeyMessage, DKGSignedPayload, SessionId, SignedDKGMessage,
},
types::{DKGError, DKGMessage, SessionId, SignedDKGMessage},
utils::convert_signature,
};
use dkg_runtime_primitives::{crypto::Public, MaxProposalLength, UnsignedProposal};
use dkg_runtime_primitives::{
crypto::Public,
gossip_messages::{DKGSignedPayload, PublicKeyMessage},
MaxProposalLength, UnsignedProposal,
};
use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2020::{
party_i::SignatureRecid, state_machine::keygen::LocalKey,
};
Expand Down Expand Up @@ -87,7 +89,7 @@ impl BlockchainInterface for TestDummyIface {
Ok(())
}

fn gossip_public_key(&self, _key: DKGPublicKeyMessage) -> Result<(), DKGError> {
fn gossip_public_key(&self, _key: PublicKeyMessage) -> Result<(), DKGError> {
// we do not gossip the public key in the test interface
Ok(())
}
Expand Down
12 changes: 6 additions & 6 deletions dkg-gadget/src/gossip_messages/misbehaviour_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use crate::{
};
use codec::Encode;
use dkg_primitives::types::{
DKGError, DKGMessage, DKGMisbehaviourMessage, DKGMsgPayload, DKGMsgStatus, SignedDKGMessage,
DKGError, DKGMessage, DKGMsgStatus, NetworkMsgPayload, SignedDKGMessage,
};
use dkg_runtime_primitives::{
crypto::AuthorityId, AggregatedMisbehaviourReports, DKGApi, MaxAuthorities, MaxProposalLength,
MaxReporters, MaxSignatureLength, MisbehaviourType,
crypto::AuthorityId, gossip_messages::MisbehaviourMessage, AggregatedMisbehaviourReports,
DKGApi, MaxAuthorities, MaxProposalLength, MaxReporters, MaxSignatureLength, MisbehaviourType,
};
use sc_client_api::Backend;
use sp_runtime::traits::{Block, Get, NumberFor};
Expand All @@ -49,7 +49,7 @@ where
return Err(DKGError::NoAuthorityAccounts)
}

if let DKGMsgPayload::MisbehaviourBroadcast(msg) = dkg_msg.payload {
if let NetworkMsgPayload::MisbehaviourBroadcast(msg) = dkg_msg.payload {
dkg_worker.logger.debug("Received misbehaviour report".to_string());

let is_main_round = {
Expand Down Expand Up @@ -111,7 +111,7 @@ where

pub(crate) fn gossip_misbehaviour_report<B, BE, C, GE>(
dkg_worker: &DKGWorker<B, BE, C, GE>,
report: DKGMisbehaviourMessage,
report: MisbehaviourMessage,
) -> Result<(), DKGError>
where
B: Block,
Expand All @@ -135,7 +135,7 @@ where

if let Ok(signature) = dkg_worker.key_store.sign(&public.clone(), &payload) {
let encoded_signature = signature.encode();
let payload = DKGMsgPayload::MisbehaviourBroadcast(DKGMisbehaviourMessage {
let payload = NetworkMsgPayload::MisbehaviourBroadcast(MisbehaviourMessage {
signature: encoded_signature.clone(),
..report.clone()
});
Expand Down
1 change: 1 addition & 0 deletions dkg-gadget/src/gossip_messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
//
pub mod dkg_message;
pub mod misbehaviour_report;
pub mod proposer_vote_gossip;
pub mod public_key_gossip;
Loading