Skip to content

Commit

Permalink
fix validation bug in new signer #470
Browse files Browse the repository at this point in the history
  • Loading branch information
marsella authored Aug 17, 2023
1 parent d873f5a commit 3c4ee60
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ pub(crate) mod participant_config {
participant
}

/// Returns the total number of participants specified in the config
/// (both other and self).
pub fn count(&self) -> usize {
self.other_ids.len() + 1
}

pub(crate) fn into_parts(self) -> (ParticipantIdentifier, Vec<ParticipantIdentifier>) {
(self.id, self.other_ids)
}
Expand Down
27 changes: 21 additions & 6 deletions src/sign/non_interactive_sign/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// License, Version 2.0 found in the LICENSE-APACHE file in the root directory
// of this source tree.

use std::collections::HashSet;

use generic_array::{typenum::U32, GenericArray};
use k256::{
ecdsa::{signature::DigestVerifier, VerifyingKey},
Expand Down Expand Up @@ -202,6 +204,20 @@ impl ProtocolParticipant for SignParticipant {
Self: Sized,
{
let config = ParticipantConfig::new(id, &other_participant_ids)?;

// The input must contain exactly one public key per particpant ID.
let public_key_pids = input
.public_key_shares
.iter()
.map(|share| share.participant())
.collect::<HashSet<_>>();
let pids = std::iter::once(id)
.chain(other_participant_ids)
.collect::<HashSet<_>>();
if public_key_pids != pids || config.count() != input.public_key_shares.len() {
Err(CallerError::BadInput)?
}

Ok(Self {
sid,
config,
Expand Down Expand Up @@ -550,12 +566,11 @@ mod test {
keygen.public_key_shares().to_vec(),
)
});
let mut quorum =
std::iter::zip(ParticipantConfig::random_quorum(quorum_size, rng)?, inputs)
.map(|(config, input)| {
SignParticipant::new(sid, config.id(), config.other_ids().to_vec(), input)
})
.collect::<Result<Vec<_>>>()?;
let mut quorum = std::iter::zip(configs, inputs)
.map(|(config, input)| {
SignParticipant::new(sid, config.id(), config.other_ids().to_vec(), input)
})
.collect::<Result<Vec<_>>>()?;

// Prepare caching of data (outputs and messages) for protocol execution
let mut outputs = HashMap::with_capacity(quorum_size);
Expand Down

0 comments on commit 3c4ee60

Please sign in to comment.