From 9b7666b61f4ab1ef4cd2b4ff63cb828a49c79b9c Mon Sep 17 00:00:00 2001 From: Marcella Hastings Date: Thu, 15 Jun 2023 16:43:54 -0400 Subject: [PATCH] reduces passing of inputs in protocols #290 --- src/auxinfo/participant.rs | 9 +---- src/broadcast/participant.rs | 1 - src/keygen/participant.rs | 9 +---- src/participant.rs | 8 ++-- src/presign/participant.rs | 72 ++++++++++++++---------------------- src/protocol.rs | 4 +- 6 files changed, 35 insertions(+), 68 deletions(-) diff --git a/src/auxinfo/participant.rs b/src/auxinfo/participant.rs index f0bb6b44..2a72d004 100644 --- a/src/auxinfo/participant.rs +++ b/src/auxinfo/participant.rs @@ -198,7 +198,6 @@ impl ProtocolParticipant for AuxInfoParticipant { &mut self, rng: &mut R, message: &Message, - input: &Self::Input, ) -> Result> { info!("Processing auxinfo message."); @@ -212,7 +211,7 @@ impl ProtocolParticipant for AuxInfoParticipant { let broadcast_outcome = self.handle_broadcast(rng, message)?; // Handle the broadcasted message if all parties have agreed on it - broadcast_outcome.convert(self, Self::handle_round_one_msg, rng, input) + broadcast_outcome.convert(self, Self::handle_round_one_msg, rng) } MessageType::Auxinfo(AuxinfoMessageType::R2Decommit) => { self.handle_round_two_msg(rng, message) @@ -333,7 +332,6 @@ impl AuxInfoParticipant { &mut self, rng: &mut R, broadcast_message: BroadcastOutput, - _input: &(), ) -> Result::Output>> { info!("Handling round one auxinfo message."); @@ -720,10 +718,7 @@ mod tests { &message.message_type(), &message.from(), ); - Some(( - index, - participant.process_message(rng, &message, &()).unwrap(), - )) + Some((index, participant.process_message(rng, &message).unwrap())) } #[cfg_attr(feature = "flame_it", flame)] diff --git a/src/broadcast/participant.rs b/src/broadcast/participant.rs index 2820963f..88639b9e 100644 --- a/src/broadcast/participant.rs +++ b/src/broadcast/participant.rs @@ -153,7 +153,6 @@ impl ProtocolParticipant for BroadcastParticipant { &mut self, rng: &mut R, message: &Message, - _: &Self::Input, ) -> Result> { info!("Processing broadcast message."); diff --git a/src/keygen/participant.rs b/src/keygen/participant.rs index 65a46542..3dd3bf5c 100644 --- a/src/keygen/participant.rs +++ b/src/keygen/participant.rs @@ -250,7 +250,6 @@ impl ProtocolParticipant for KeygenParticipant { &mut self, rng: &mut R, message: &Message, - input: &Self::Input, ) -> Result> { info!("Processing keygen message."); @@ -264,7 +263,7 @@ impl ProtocolParticipant for KeygenParticipant { let broadcast_outcome = self.handle_broadcast(rng, message)?; // Handle the broadcasted message if all parties have agreed on it - broadcast_outcome.convert(self, Self::handle_round_one_msg, rng, input) + broadcast_outcome.convert(self, Self::handle_round_one_msg, rng) } MessageType::Keygen(KeygenMessageType::R2Decommit) => { self.handle_round_two_msg(message) @@ -392,7 +391,6 @@ impl KeygenParticipant { &mut self, rng: &mut R, broadcast_message: BroadcastOutput, - _input: &(), ) -> Result::Output>> { info!("Handling round one keygen message."); @@ -748,10 +746,7 @@ mod tests { &message.message_type(), &message.from(), ); - Some(( - index, - participant.process_message(rng, &message, &()).unwrap(), - )) + Some((index, participant.process_message(rng, &message).unwrap())) } #[cfg_attr(feature = "flame_it", flame)] diff --git a/src/participant.rs b/src/participant.rs index 7ef6c811..087897a7 100644 --- a/src/participant.rs +++ b/src/participant.rs @@ -84,16 +84,15 @@ where participant: &mut P, mut handle_output: F, rng: &mut R, - storage: &P::Input, ) -> Result> where P: InnerProtocolParticipant, - F: FnMut(&mut P, &mut R, O, &P::Input) -> Result>, + F: FnMut(&mut P, &mut R, O) -> Result>, R: CryptoRng + RngCore, { let (output, messages) = self.into_parts(); let outcome = match output { - Some(o) => handle_output(participant, rng, o, storage)?, + Some(o) => handle_output(participant, rng, o)?, None => ProcessOutcome::Incomplete, }; Ok(outcome.with_messages(messages)) @@ -241,7 +240,6 @@ pub trait ProtocolParticipant { &mut self, rng: &mut R, message: &Message, - input: &Self::Input, ) -> Result>; /// The status of the protocol execution. @@ -413,7 +411,7 @@ pub(crate) trait Broadcast { let outcome = self .broadcast_participant() - .process_message(rng, &broadcast_input, &())?; + .process_message(rng, &broadcast_input)?; // ...and then re-wrap the output messages. let (output, mut messages) = outcome.into_parts(); diff --git a/src/presign/participant.rs b/src/presign/participant.rs index dfca2a03..aa1f23a6 100644 --- a/src/presign/participant.rs +++ b/src/presign/participant.rs @@ -425,7 +425,6 @@ impl ProtocolParticipant for PresignParticipant { &mut self, rng: &mut R, message: &Message, - input: &Self::Input, ) -> Result> { info!("Processing presign message."); @@ -434,23 +433,21 @@ impl ProtocolParticipant for PresignParticipant { } match message.message_type() { - MessageType::Presign(PresignMessageType::Ready) => { - self.handle_ready_msg(rng, message, input) - } + MessageType::Presign(PresignMessageType::Ready) => self.handle_ready_msg(rng, message), MessageType::Presign(PresignMessageType::RoundOneBroadcast) => { let broadcast_outcome = self.handle_broadcast(rng, message)?; // Handle the broadcasted message if all parties have agreed on it - broadcast_outcome.convert(self, Self::handle_round_one_broadcast_msg, rng, input) + broadcast_outcome.convert(self, Self::handle_round_one_broadcast_msg, rng) } MessageType::Presign(PresignMessageType::RoundOne) => { - self.handle_round_one_msg(rng, message, input) + self.handle_round_one_msg(rng, message) } MessageType::Presign(PresignMessageType::RoundTwo) => { - self.handle_round_two_msg(rng, message, input) + self.handle_round_two_msg(rng, message) } MessageType::Presign(PresignMessageType::RoundThree) => { - self.handle_round_three_msg(message, input) + self.handle_round_three_msg(message) } message_type => { error!( @@ -500,15 +497,13 @@ impl PresignParticipant { &mut self, rng: &mut R, message: &Message, - input: &Input, ) -> Result::Output>> { info!("Handling ready presign message."); let (ready_outcome, is_ready) = self.process_ready_message::(message)?; if is_ready { - let round_one_messages = - run_only_once!(self.gen_round_one_msgs(rng, message.id(), input))?; + let round_one_messages = run_only_once!(self.gen_round_one_msgs(rng, message.id()))?; Ok(ready_outcome.with_messages(round_one_messages)) } else { Ok(ready_outcome) @@ -528,12 +523,11 @@ impl PresignParticipant { &mut self, rng: &mut R, sid: Identifier, - input: &Input, ) -> Result> { info!("Generating round one presign messages."); - let info = PresignKeyShareAndInfo::new(self.id, input)?; - let other_public_auxinfo = input.all_but_one_auxinfo_public(self.id); + let info = PresignKeyShareAndInfo::new(self.id, self.input())?; + let other_public_auxinfo = self.input().all_but_one_auxinfo_public(self.id); // Run round one. let (private, r1_publics, r1_public_broadcast) = @@ -578,7 +572,6 @@ impl PresignParticipant { &mut self, rng: &mut R, broadcast_message: BroadcastOutput, - input: &Input, ) -> Result::Output>> { info!("Presign: Handling round one broadcast message."); @@ -603,7 +596,7 @@ impl PresignParticipant { return Err(InternalError::ProtocolError); } match retrieved_messages.get(0) { - Some(message) => self.handle_round_one_msg(rng, message, input), + Some(message) => self.handle_round_one_msg(rng, message), None => Ok(ProcessOutcome::Incomplete), } } @@ -618,7 +611,6 @@ impl PresignParticipant { &mut self, rng: &mut R, message: &Message, - input: &Input, ) -> Result::Output>> { use crate::round_one::Public as RoundOnePublic; @@ -642,8 +634,8 @@ impl PresignParticipant { .local_storage .retrieve::(message.from())?; - let info = PresignKeyShareAndInfo::new(self.id, input)?; - let auxinfo_public = input.find_auxinfo_public(message.from())?; + let info = PresignKeyShareAndInfo::new(self.id, self.input())?; + let auxinfo_public = self.input().find_auxinfo_public(message.from())?; let round_one_public = RoundOnePublic::try_from(message)?; round_one_public.verify( &self.retrieve_context(), @@ -665,13 +657,12 @@ impl PresignParticipant { { info!("Presign: Round one complete. Generating round two messages."); // Finish round one by generating messages for round two. - let round_two_messages = - run_only_once!(self.gen_round_two_msgs(rng, message.id(), input))?; + let round_two_messages = run_only_once!(self.gen_round_two_msgs(rng, message.id()))?; // Process any round two messages we may have received early. let round_two_outcomes = self .fetch_messages(MessageType::Presign(PresignMessageType::RoundTwo))? .iter() - .map(|msg| self.handle_round_two_msg(rng, msg, input)) + .map(|msg| self.handle_round_two_msg(rng, msg)) .collect::>>()?; ProcessOutcome::collect_with_messages(round_two_outcomes, round_two_messages) } else { @@ -689,7 +680,6 @@ impl PresignParticipant { &mut self, rng: &mut R, sid: Identifier, - input: &Input, ) -> Result> { info!("Presign: Generating round two messages."); @@ -701,11 +691,11 @@ impl PresignParticipant { .local_storage .contains::(self.id) { - let more_messages = run_only_once!(self.gen_round_one_msgs(rng, sid, input))?; + let more_messages = run_only_once!(self.gen_round_one_msgs(rng, sid))?; messages.extend_from_slice(&more_messages); } - let info = PresignKeyShareAndInfo::new(self.id, input)?; + let info = PresignKeyShareAndInfo::new(self.id, self.input())?; // We need this clone as the map below uses a mutable `self`. let pids = self.other_participant_ids.clone(); let more_messages: Vec = pids @@ -717,7 +707,7 @@ impl PresignParticipant { let r1_public_broadcast = self .local_storage .retrieve::(pid)?; - let sender_auxinfo_public = input.find_auxinfo_public(pid)?; + let sender_auxinfo_public = self.input().find_auxinfo_public(pid)?; let (r2_priv, r2_pub) = info.round_two( rng, &self.retrieve_context(), @@ -750,7 +740,6 @@ impl PresignParticipant { &mut self, rng: &mut R, message: &Message, - input: &Input, ) -> Result::Output>> { info!("Presign: Handling round two message."); @@ -765,7 +754,7 @@ impl PresignParticipant { return Ok(ProcessOutcome::Incomplete); } - self.validate_and_store_round_two_public(input, message)?; + self.validate_and_store_round_two_public(message)?; // Check if storage has all of the other participants' round two values // (both private and public), and start generating the messages for @@ -779,13 +768,13 @@ impl PresignParticipant { if all_privates_received && all_publics_received { info!("Presign: Round two complete. Generating round three messages."); // Generate messages for round three... - let messages = run_only_once!(self.gen_round_three_msgs(rng, message.id(), input))?; + let messages = run_only_once!(self.gen_round_three_msgs(rng, message.id()))?; // ... and handle any messages that other participants have sent for round // three. let outcomes = self .fetch_messages(MessageType::Presign(PresignMessageType::RoundThree))? .iter() - .map(|msg| self.handle_round_three_msg(msg, input)) + .map(|msg| self.handle_round_three_msg(msg)) .collect::>>()?; ProcessOutcome::collect_with_messages(outcomes, messages) } else { @@ -806,16 +795,15 @@ impl PresignParticipant { &mut self, rng: &mut R, sid: Identifier, - input: &Input, ) -> Result> { info!("Generating round three presign messages."); - let info = PresignKeyShareAndInfo::new(self.id, input)?; + let info = PresignKeyShareAndInfo::new(self.id, self.input())?; // Collect the other participant's values from storage needed for round // three. let mut hashmap = HashMap::new(); for pid in self.other_participant_ids.clone() { - let auxinfo_public = input.find_auxinfo_public(pid)?; + let auxinfo_public = self.input().find_auxinfo_public(pid)?; let r2_private = self .local_storage .retrieve::(pid)?; @@ -863,7 +851,6 @@ impl PresignParticipant { fn handle_round_three_msg( &mut self, message: &Message, - input: &Input, ) -> Result::Output>> { info!("Handling round three presign message."); @@ -878,7 +865,7 @@ impl PresignParticipant { return Ok(ProcessOutcome::Incomplete); } - self.validate_and_store_round_three_public(input, message)?; + self.validate_and_store_round_three_public(message)?; // If we have round three public values from all other participants, we // are done with the protocol! All we have left to do is create the @@ -939,11 +926,9 @@ impl PresignParticipant { } #[cfg_attr(feature = "flame_it", flame("presign"))] - fn validate_and_store_round_two_public( - &mut self, - input: &Input, - message: &Message, - ) -> Result<()> { + fn validate_and_store_round_two_public(&mut self, message: &Message) -> Result<()> { + let input = self.input(); + let receiver_auxinfo_public = input.find_auxinfo_public(message.to())?; let sender_auxinfo_public = input.find_auxinfo_public(message.from())?; let sender_keyshare_public = input.find_keyshare_public(message.from())?; @@ -971,11 +956,8 @@ impl PresignParticipant { } #[cfg_attr(feature = "flame_it", flame("presign"))] - fn validate_and_store_round_three_public( - &mut self, - input: &Input, - message: &Message, - ) -> Result<()> { + fn validate_and_store_round_three_public(&mut self, message: &Message) -> Result<()> { + let input = self.input(); let receiver_auxinfo_public = input.find_auxinfo_public(message.to())?; let sender_auxinfo_public = input.find_auxinfo_public(message.from())?; let sender_r1_public_broadcast = self diff --git a/src/protocol.rs b/src/protocol.rs index a00e73bb..87b4380a 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -190,9 +190,7 @@ impl Participant

{ } // Handle it! - let outcome = - self.participant - .process_message(rng, message, &self.participant.input().clone())?; + let outcome = self.participant.process_message(rng, message)?; let (output, messages) = outcome.into_parts(); Ok((output, messages)) }