diff --git a/ferveo/src/api.rs b/ferveo/src/api.rs index c8a9f6c3..32ec9f30 100644 --- a/ferveo/src/api.rs +++ b/ferveo/src/api.rs @@ -246,7 +246,12 @@ impl Dkg { for (validator, transcript) in messages { self.0.deal(validator, transcript)?; } - Ok(AggregatedTranscript(crate::pvss::aggregate(&self.0.vss)?)) + let pvss = messages + .iter() + .map(|(_, t)| t) + .cloned() + .collect::>>(); + Ok(AggregatedTranscript(crate::pvss::aggregate(&pvss)?)) } pub fn public_params(&self) -> DkgPublicParameters { @@ -269,8 +274,12 @@ pub struct AggregatedTranscript(PubliclyVerifiableSS); impl AggregatedTranscript { pub fn new(messages: &[ValidatorMessage]) -> Result { - let pvss_map = make_pvss_map(messages); - Ok(AggregatedTranscript(crate::pvss::aggregate(&pvss_map)?)) + let pvss_list = messages + .iter() + .map(|(_, t)| t) + .cloned() + .collect::>>(); + Ok(AggregatedTranscript(crate::pvss::aggregate(&pvss_list)?)) } pub fn verify( diff --git a/ferveo/src/dkg.rs b/ferveo/src/dkg.rs index 8259e5c3..3bba9b47 100644 --- a/ferveo/src/dkg.rs +++ b/ferveo/src/dkg.rs @@ -178,8 +178,9 @@ impl PubliclyVerifiableDkg { match self.state { DkgState::Dealt => { let public_key = self.public_key(); + let pvss_list = self.vss.values().cloned().collect::>(); Ok(Message::Aggregate(Aggregation { - vss: aggregate(&self.vss)?, + vss: aggregate(&pvss_list)?, public_key, })) } diff --git a/ferveo/src/lib.rs b/ferveo/src/lib.rs index f2eb357a..a7e5e7a4 100644 --- a/ferveo/src/lib.rs +++ b/ferveo/src/lib.rs @@ -152,7 +152,8 @@ mod test_dkg_full { Vec>, SharedSecret, ) { - let pvss_aggregated = aggregate(&dkg.vss).unwrap(); + let pvss_list = dkg.vss.values().cloned().collect::>(); + let pvss_aggregated = aggregate(&pvss_list).unwrap(); assert!(pvss_aggregated.verify_aggregation(dkg).is_ok()); let decryption_shares: Vec> = @@ -247,7 +248,8 @@ mod test_dkg_full { ) .unwrap(); - let pvss_aggregated = aggregate(&dkg.vss).unwrap(); + let pvss_list = dkg.vss.values().cloned().collect::>(); + let pvss_aggregated = aggregate(&pvss_list).unwrap(); pvss_aggregated.verify_aggregation(&dkg).unwrap(); let domain_points = dkg .domain @@ -434,7 +436,8 @@ mod test_dkg_full { // Creates updated private key shares // TODO: Why not using dkg.aggregate()? - let pvss_aggregated = aggregate(&dkg.vss).unwrap(); + let pvss_list = dkg.vss.values().cloned().collect::>(); + let pvss_aggregated = aggregate(&pvss_list).unwrap(); pvss_aggregated .update_private_key_share_for_recovery( &decryption_key, @@ -465,7 +468,9 @@ mod test_dkg_full { .enumerate() .map(|(share_index, validator_keypair)| { // TODO: Why not using dkg.aggregate()? - let pvss_aggregated = aggregate(&dkg.vss).unwrap(); + let pvss_list = + dkg.vss.values().cloned().collect::>(); + let pvss_aggregated = aggregate(&pvss_list).unwrap(); pvss_aggregated .make_decryption_share_simple( &ciphertext.header().unwrap(), @@ -577,7 +582,8 @@ mod test_dkg_full { // Creates updated private key shares // TODO: Why not using dkg.aggregate()? - let pvss_aggregated = aggregate(&dkg.vss).unwrap(); + let pvss_list = dkg.vss.values().cloned().collect::>(); + let pvss_aggregated = aggregate(&pvss_list).unwrap(); pvss_aggregated .update_private_key_share_for_recovery( &decryption_key, diff --git a/ferveo/src/pvss.rs b/ferveo/src/pvss.rs index 60910158..07328620 100644 --- a/ferveo/src/pvss.rs +++ b/ferveo/src/pvss.rs @@ -382,9 +382,9 @@ impl PubliclyVerifiableSS { /// into a new PVSS instance /// See: https://nikkolasg.github.io/ferveo/pvss.html?highlight=aggregate#aggregation pub(crate) fn aggregate( - pvss_map: &PVSSMap, + pvss_list: &[PubliclyVerifiableSS], ) -> Result> { - let mut pvss_iter = pvss_map.values(); + let mut pvss_iter = pvss_list.iter(); let first_pvss = pvss_iter .next() .ok_or_else(|| Error::NoTranscriptsToAggregate)?; @@ -494,6 +494,7 @@ mod test_pvss { assert!(!bad_pvss.verify_full(&dkg)); } + // TODO: Move this code to dkg.rs /// Check that the canonical share indices of validators are expected and enforced /// by the DKG methods. #[test] @@ -526,7 +527,8 @@ mod test_pvss { #[test] fn test_aggregate_pvss() { let (dkg, _) = setup_dealt_dkg(); - let aggregate = aggregate(&dkg.vss).unwrap(); + let pvss_list = dkg.vss.values().cloned().collect::>(); + let aggregate = aggregate(&pvss_list).unwrap(); // Check that a polynomial of the correct degree was created assert_eq!( aggregate.coeffs.len(), @@ -547,10 +549,12 @@ mod test_pvss { #[test] fn test_verify_aggregation_fails_if_constant_term_wrong() { let (dkg, _) = setup_dealt_dkg(); - let mut aggregated = aggregate(&dkg.vss).unwrap(); + let pvss_list = dkg.vss.values().cloned().collect::>(); + let mut aggregated = aggregate(&pvss_list).unwrap(); while aggregated.coeffs[0] == G1::zero() { let (dkg, _) = setup_dkg(0); - aggregated = aggregate(&dkg.vss).unwrap(); + let pvss_list = dkg.vss.values().cloned().collect::>(); + aggregated = aggregate(&pvss_list).unwrap(); } aggregated.coeffs[0] = G1::zero(); assert_eq!(