Skip to content

Commit

Permalink
pass keep_constant from start_dkg_round down
Browse files Browse the repository at this point in the history
  • Loading branch information
xoloki committed Oct 8, 2024
1 parent 69c40d5 commit 7a53a8d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 24 deletions.
58 changes: 44 additions & 14 deletions src/state_machine/coordinator/fire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl<Aggregator: AggregatorTrait> Coordinator<Aggregator> {
// that we start the next round at the correct id. (Do this rather
// than overwriting afterwards to ensure logging is accurate)
self.current_dkg_id = dkg_begin.dkg_id.wrapping_sub(1);
let packet = self.start_dkg_round()?;
let packet = self.start_dkg_round(dkg_begin.keep_constant)?;
return Ok((Some(packet), None));
} else if let Message::NonceRequest(nonce_request) = &packet.msg {
if self.current_sign_id >= nonce_request.sign_id {
Expand All @@ -249,7 +249,9 @@ impl<Aggregator: AggregatorTrait> Coordinator<Aggregator> {
return Ok((None, None));
}
State::DkgPublicDistribute => {
let packet = self.start_public_shares()?;
// XXX does this ever happen? start_dkg_round should call start_public_shares
panic!("Got message in DkgPublicDistribute");
let packet = self.start_public_shares(false)?;

Check failure on line 254 in src/state_machine/coordinator/fire.rs

View workflow job for this annotation

GitHub Actions / clippy

unreachable statement

Check warning on line 254 in src/state_machine/coordinator/fire.rs

View workflow job for this annotation

GitHub Actions / check

unreachable statement

Check warning on line 254 in src/state_machine/coordinator/fire.rs

View workflow job for this annotation

GitHub Actions / test-all

unreachable statement
return Ok((Some(packet), None));
}
State::DkgPublicGather => {
Expand Down Expand Up @@ -353,7 +355,7 @@ impl<Aggregator: AggregatorTrait> Coordinator<Aggregator> {
}

/// Ask signers to send DKG public shares
pub fn start_public_shares(&mut self) -> Result<Packet, Error> {
pub fn start_public_shares(&mut self, keep_constant: bool) -> Result<Packet, Error> {
self.dkg_public_shares.clear();
self.party_polynomials.clear();
self.dkg_wait_signer_ids = (0..self.config.num_signers).collect();
Expand All @@ -363,7 +365,7 @@ impl<Aggregator: AggregatorTrait> Coordinator<Aggregator> {
);
let dkg_begin = DkgBegin {
dkg_id: self.current_dkg_id,
keep_constant: false,
keep_constant,
};
let dkg_begin_packet = Packet {
sig: dkg_begin
Expand Down Expand Up @@ -1197,11 +1199,11 @@ impl<Aggregator: AggregatorTrait> CoordinatorTrait for Coordinator<Aggregator> {
}

/// Start a DKG round
fn start_dkg_round(&mut self) -> Result<Packet, Error> {
fn start_dkg_round(&mut self, keep_constant: bool) -> Result<Packet, Error> {
self.current_dkg_id = self.current_dkg_id.wrapping_add(1);
info!("Starting DKG round {}", self.current_dkg_id);
self.move_to(State::DkgPublicDistribute)?;
self.start_public_shares()
self.start_public_shares(keep_constant)
}

/// Start a signing round
Expand Down Expand Up @@ -1321,7 +1323,7 @@ pub mod test {

coordinator.state = State::DkgPublicDistribute; // Must be in this state before calling start public shares

let result = coordinator.start_public_shares().unwrap();
let result = coordinator.start_public_shares(false).unwrap();

assert!(matches!(result.msg, Message::DkgBegin(_)));
assert_eq!(coordinator.get_state(), State::DkgPublicGather);
Expand Down Expand Up @@ -1379,7 +1381,11 @@ pub mod test {
setup::<FireCoordinator<Aggregator>, SignerType>(num_signers, keys_per_signer);

// We have started a dkg round
let message = coordinators.first_mut().unwrap().start_dkg_round().unwrap();
let message = coordinators
.first_mut()
.unwrap()
.start_dkg_round(false)
.unwrap();
assert!(coordinators.first().unwrap().aggregate_public_key.is_none());
assert_eq!(coordinators.first().unwrap().state, State::DkgPublicGather);

Expand Down Expand Up @@ -1457,7 +1463,11 @@ pub mod test {
);

// Start a DKG round where we will not allow all signers to recv DkgBegin, so they will not respond with DkgPublicShares
let message = coordinators.first_mut().unwrap().start_dkg_round().unwrap();
let message = coordinators
.first_mut()
.unwrap()
.start_dkg_round(false)
.unwrap();
assert!(coordinators.first().unwrap().aggregate_public_key.is_none());
assert_eq!(coordinators.first().unwrap().state, State::DkgPublicGather);

Expand Down Expand Up @@ -1538,7 +1548,11 @@ pub mod test {
);

// Start a DKG round where we will not allow all signers to recv DkgBegin, so they will not respond with DkgPublicShares
let message = coordinators.first_mut().unwrap().start_dkg_round().unwrap();
let message = coordinators
.first_mut()
.unwrap()
.start_dkg_round(false)
.unwrap();
assert!(coordinators.first().unwrap().aggregate_public_key.is_none());
assert_eq!(coordinators.first().unwrap().state, State::DkgPublicGather);

Expand Down Expand Up @@ -1691,7 +1705,11 @@ pub mod test {
);

// Start a DKG round where we will not allow all signers to recv DkgBegin, so they will not respond with DkgPublicShares
let message = coordinators.first_mut().unwrap().start_dkg_round().unwrap();
let message = coordinators
.first_mut()
.unwrap()
.start_dkg_round(false)
.unwrap();
assert!(coordinators.first().unwrap().aggregate_public_key.is_none());
assert_eq!(coordinators.first().unwrap().state, State::DkgPublicGather);

Expand Down Expand Up @@ -1827,7 +1845,11 @@ pub mod test {
setup::<FireCoordinator<Aggregator>, SignerType>(num_signers, keys_per_signer);

// We have started a dkg round
let message = coordinators.first_mut().unwrap().start_dkg_round().unwrap();
let message = coordinators
.first_mut()
.unwrap()
.start_dkg_round(false)
.unwrap();
assert!(coordinators.first().unwrap().aggregate_public_key.is_none());
assert_eq!(coordinators.first().unwrap().state, State::DkgPublicGather);

Expand Down Expand Up @@ -1949,7 +1971,11 @@ pub mod test {
setup::<FireCoordinator<Aggregator>, SignerType>(num_signers, keys_per_signer);

// We have started a dkg round
let message = coordinators.first_mut().unwrap().start_dkg_round().unwrap();
let message = coordinators
.first_mut()
.unwrap()
.start_dkg_round(false)
.unwrap();
assert!(coordinators.first().unwrap().aggregate_public_key.is_none());
assert_eq!(coordinators.first().unwrap().state, State::DkgPublicGather);

Expand Down Expand Up @@ -2323,7 +2349,11 @@ pub mod test {
let config = coordinators.first().unwrap().get_config();

// We have started a dkg round
let message = coordinators.first_mut().unwrap().start_dkg_round().unwrap();
let message = coordinators
.first_mut()
.unwrap()
.start_dkg_round(false)
.unwrap();
assert!(coordinators.first().unwrap().aggregate_public_key.is_none());
assert_eq!(coordinators.first().unwrap().state, State::DkgPublicGather);

Expand Down
14 changes: 7 additions & 7 deletions src/state_machine/coordinator/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<Aggregator: AggregatorTrait> Coordinator<Aggregator> {
// that we start the next round at the correct id. (Do this rather
// then overwriting afterwards to ensure logging is accurate)
self.current_dkg_id = dkg_begin.dkg_id.wrapping_sub(1);
let packet = self.start_dkg_round()?;
let packet = self.start_dkg_round(dkg_begin.keep_constant)?;
return Ok((Some(packet), None));
} else if let Message::NonceRequest(nonce_request) = &packet.msg {
if self.current_sign_id >= nonce_request.sign_id {
Expand All @@ -91,7 +91,7 @@ impl<Aggregator: AggregatorTrait> Coordinator<Aggregator> {
return Ok((None, None));
}
State::DkgPublicDistribute => {
let packet = self.start_public_shares()?;
let packet = self.start_public_shares(false)?;
return Ok((Some(packet), None));
}
State::DkgPublicGather => {
Expand Down Expand Up @@ -184,7 +184,7 @@ impl<Aggregator: AggregatorTrait> Coordinator<Aggregator> {
}

/// Ask signers to send DKG public shares
pub fn start_public_shares(&mut self) -> Result<Packet, Error> {
pub fn start_public_shares(&mut self, keep_constant: bool) -> Result<Packet, Error> {
self.dkg_public_shares.clear();
self.party_polynomials.clear();
self.ids_to_await = (0..self.config.num_signers).collect();
Expand All @@ -194,7 +194,7 @@ impl<Aggregator: AggregatorTrait> Coordinator<Aggregator> {
);
let dkg_begin = DkgBegin {
dkg_id: self.current_dkg_id,
keep_constant: false,
keep_constant,
};

let dkg_begin_packet = Packet {
Expand Down Expand Up @@ -716,11 +716,11 @@ impl<Aggregator: AggregatorTrait> CoordinatorTrait for Coordinator<Aggregator> {
}

/// Start a DKG round
fn start_dkg_round(&mut self) -> Result<Packet, Error> {
fn start_dkg_round(&mut self, keep_constant: bool) -> Result<Packet, Error> {
self.current_dkg_id = self.current_dkg_id.wrapping_add(1);
info!("Starting DKG round {}", self.current_dkg_id);
self.move_to(State::DkgPublicDistribute)?;
self.start_public_shares()
self.start_public_shares(keep_constant)
}

/// Start a signing round
Expand Down Expand Up @@ -827,7 +827,7 @@ pub mod test {

coordinator.state = State::DkgPublicDistribute; // Must be in this state before calling start public shares

let result = coordinator.start_public_shares().unwrap();
let result = coordinator.start_public_shares(false).unwrap();

assert!(matches!(result.msg, Message::DkgBegin(_)));
assert_eq!(coordinator.get_state(), State::DkgPublicGather);
Expand Down
10 changes: 7 additions & 3 deletions src/state_machine/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub trait Coordinator: Clone + Debug + PartialEq {
fn get_state(&self) -> State;

/// Trigger a DKG round
fn start_dkg_round(&mut self) -> Result<Packet, Error>;
fn start_dkg_round(&mut self, keep_constant: bool) -> Result<Packet, Error>;

/// Trigger a signing round
fn start_signing_round(
Expand Down Expand Up @@ -415,7 +415,7 @@ pub mod test {
let mut rng = OsRng;
let config = Config::new(10, 40, 28, Scalar::random(&mut rng));
let mut coordinator = Coordinator::new(config);
let result = coordinator.start_dkg_round();
let result = coordinator.start_dkg_round(false);

assert!(result.is_ok());
if let Message::DkgBegin(dkg_begin) = result.unwrap().msg {
Expand Down Expand Up @@ -593,7 +593,11 @@ pub mod test {
setup::<Coordinator, SignerType>(num_signers, keys_per_signer);

// We have started a dkg round
let message = coordinators.first_mut().unwrap().start_dkg_round().unwrap();
let message = coordinators
.first_mut()
.unwrap()
.start_dkg_round(false)
.unwrap();
assert!(coordinators
.first_mut()
.unwrap()
Expand Down

0 comments on commit 7a53a8d

Please sign in to comment.