@@ -6,7 +6,8 @@ use rand_core::{CryptoRng, RngCore};
66
77use crate as frost;
88use crate :: keys:: dkg:: { round1, round2} ;
9- use crate :: keys:: SigningShare ;
9+ use crate :: keys:: { SecretShare , SigningShare } ;
10+ use crate :: round1:: SigningNonces ;
1011use crate :: round2:: SignatureShare ;
1112use crate :: {
1213 keys:: PublicKeyPackage , Error , Field , Group , Identifier , Signature , SigningKey , SigningPackage ,
@@ -26,6 +27,8 @@ pub fn check_zero_key_fails<C: Ciphersuite>() {
2627/// Test share generation with a Ciphersuite
2728pub fn check_share_generation < C : Ciphersuite , R : RngCore + CryptoRng > ( mut rng : R ) {
2829 let secret = crate :: SigningKey :: < C > :: new ( & mut rng) ;
30+ // Simulate serialization / deserialization to ensure it works
31+ let secret = SigningKey :: deserialize ( & secret. serialize ( ) ) . unwrap ( ) ;
2932
3033 let max_signers = 5 ;
3134 let min_signers = 3 ;
@@ -110,20 +113,28 @@ pub fn check_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>(
110113
111114 let max_signers = 5 ;
112115 let min_signers = 3 ;
113- let ( shares, pubkeys ) = frost:: keys:: generate_with_dealer (
116+ let ( shares, pub_key_package ) = frost:: keys:: generate_with_dealer (
114117 max_signers,
115118 min_signers,
116119 frost:: keys:: IdentifierList :: Default ,
117120 & mut rng,
118121 )
119122 . unwrap ( ) ;
123+ // Simulate serialization / deserialization to ensure it works
124+ let pub_key_package =
125+ PublicKeyPackage :: deserialize ( & pub_key_package. serialize ( ) . unwrap ( ) ) . unwrap ( ) ;
120126
121127 // Verifies the secret shares from the dealer
122128 let mut key_packages: BTreeMap < frost:: Identifier < C > , frost:: keys:: KeyPackage < C > > =
123129 BTreeMap :: new ( ) ;
124130
125131 for ( k, v) in shares {
132+ // Simulate serialization / deserialization to ensure it works
133+ let v = SecretShare :: < C > :: deserialize ( & v. serialize ( ) . unwrap ( ) ) . unwrap ( ) ;
126134 let key_package = frost:: keys:: KeyPackage :: try_from ( v) . unwrap ( ) ;
135+ // Simulate serialization / deserialization to ensure it works
136+ let key_package =
137+ frost:: keys:: KeyPackage :: deserialize ( & key_package. serialize ( ) . unwrap ( ) ) . unwrap ( ) ;
127138 key_packages. insert ( k, key_package) ;
128139 }
129140 // Check if it fails with not enough signers. Usually this would return an
@@ -146,11 +157,11 @@ pub fn check_sign_with_dealer<C: Ciphersuite, R: RngCore + CryptoRng>(
146157 } )
147158 . collect ( ) ,
148159 & mut rng,
149- pubkeys . clone ( ) ,
160+ pub_key_package . clone ( ) ,
150161 ) ;
151162 assert_eq ! ( r, Err ( Error :: InvalidSignature ) ) ;
152163
153- check_sign ( min_signers, key_packages, rng, pubkeys ) . unwrap ( )
164+ check_sign ( min_signers, key_packages, rng, pub_key_package ) . unwrap ( )
154165}
155166
156167/// Test FROST signing with trusted dealer fails with invalid numbers of signers.
@@ -205,7 +216,10 @@ pub fn check_sign<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(
205216 // Round 1: generating nonces and signing commitments for each participant
206217 ////////////////////////////////////////////////////////////////////////////
207218
208- for participant_identifier in key_packages. keys ( ) . take ( min_signers as usize ) . cloned ( ) {
219+ for participant_identifier in key_packages. keys ( ) . take ( min_signers as usize ) {
220+ // Simulate serialization / deserialization to ensure it works
221+ let participant_identifier =
222+ Identifier :: deserialize ( & participant_identifier. serialize ( ) ) . unwrap ( ) ;
209223 // Generate one (1) nonce and one SigningCommitments instance for each
210224 // participant, up to _min_signers_.
211225 let ( nonces, commitments) = frost:: round1:: commit (
@@ -215,6 +229,11 @@ pub fn check_sign<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(
215229 . signing_share ( ) ,
216230 & mut rng,
217231 ) ;
232+ // Simulate serialization / deserialization to ensure it works
233+ let nonces = SigningNonces :: deserialize ( & nonces. serialize ( ) . unwrap ( ) ) . unwrap ( ) ;
234+ let commitments =
235+ frost:: round1:: SigningCommitments :: deserialize ( & commitments. serialize ( ) . unwrap ( ) )
236+ . unwrap ( ) ;
218237 nonces_map. insert ( participant_identifier, nonces) ;
219238 commitments_map. insert ( participant_identifier, commitments) ;
220239 }
@@ -225,6 +244,9 @@ pub fn check_sign<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(
225244 let mut signature_shares = BTreeMap :: new ( ) ;
226245 let message = "message to sign" . as_bytes ( ) ;
227246 let signing_package = SigningPackage :: new ( commitments_map, message) ;
247+ // Simulate serialization / deserialization to ensure it works
248+ let signing_package =
249+ SigningPackage :: deserialize ( & signing_package. serialize ( ) . unwrap ( ) ) . unwrap ( ) ;
228250
229251 ////////////////////////////////////////////////////////////////////////////
230252 // Round 2: each participant generates their signature share
@@ -243,6 +265,8 @@ pub fn check_sign<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(
243265
244266 // Each participant generates their signature share.
245267 let signature_share = frost:: round2:: sign ( & signing_package, nonces_to_use, key_package) ?;
268+ // Simulate serialization / deserialization to ensure it works
269+ let signature_share = SignatureShare :: deserialize ( & signature_share. serialize ( ) ) . unwrap ( ) ;
246270 signature_shares. insert ( * participant_identifier, signature_share) ;
247271 }
248272
@@ -267,6 +291,8 @@ pub fn check_sign<C: Ciphersuite + PartialEq, R: RngCore + CryptoRng>(
267291
268292 // Aggregate (also verifies the signature shares)
269293 let group_signature = frost:: aggregate ( & signing_package, & signature_shares, & pubkey_package) ?;
294+ // Simulate serialization / deserialization to ensure it works
295+ let group_signature = Signature :: deserialize ( & group_signature. serialize ( ) . unwrap ( ) ) . unwrap ( ) ;
270296
271297 // Check that the threshold signature can be verified by the group public
272298 // key (the verification key).
@@ -453,6 +479,16 @@ where
453479 frost:: keys:: dkg:: part1 ( participant_identifier, max_signers, min_signers, & mut rng)
454480 . unwrap ( ) ;
455481
482+ // Simulate serialization / deserialization to ensure it works
483+ let round1_secret_package = frost:: keys:: dkg:: round1:: SecretPackage :: < C > :: deserialize (
484+ & round1_secret_package. serialize ( ) . unwrap ( ) ,
485+ )
486+ . unwrap ( ) ;
487+ let round1_package = frost:: keys:: dkg:: round1:: Package :: < C > :: deserialize (
488+ & round1_package. serialize ( ) . unwrap ( ) ,
489+ )
490+ . unwrap ( ) ;
491+
456492 // Store the participant's secret package for later use.
457493 // In practice each participant will store it in their own environment.
458494 round1_secret_packages. insert (
@@ -509,6 +545,12 @@ where
509545 let ( round2_secret_package, round2_packages) =
510546 frost:: keys:: dkg:: part2 ( round1_secret_package, round1_packages) . expect ( "should work" ) ;
511547
548+ // Simulate serialization / deserialization to ensure it works
549+ let round2_secret_package = frost:: keys:: dkg:: round2:: SecretPackage :: < C > :: deserialize (
550+ & round2_secret_package. serialize ( ) . unwrap ( ) ,
551+ )
552+ . unwrap ( ) ;
553+
512554 // Store the participant's secret package for later use.
513555 // In practice each participant will store it in their own environment.
514556 round2_secret_packages. insert (
@@ -524,6 +566,11 @@ where
524566 // Note that, in contrast to the previous part, here each other participant
525567 // gets its own specific package.
526568 for ( receiver_identifier, round2_package) in round2_packages {
569+ // Simulate serialization / deserialization to ensure it works
570+ let round2_package = frost:: keys:: dkg:: round2:: Package :: < C > :: deserialize (
571+ & round2_package. serialize ( ) . unwrap ( ) ,
572+ )
573+ . unwrap ( ) ;
527574 received_round2_packages
528575 . entry ( receiver_identifier)
529576 . or_insert_with ( BTreeMap :: new)
@@ -574,6 +621,13 @@ where
574621 & received_round2_packages[ & participant_identifier] ,
575622 )
576623 . unwrap ( ) ;
624+ // Simulate serialization / deserialization to ensure it works
625+ let key_package =
626+ frost:: keys:: KeyPackage :: deserialize ( & key_package. serialize ( ) . unwrap ( ) ) . unwrap ( ) ;
627+ let pubkey_package_for_participant = frost:: keys:: PublicKeyPackage :: deserialize (
628+ & pubkey_package_for_participant. serialize ( ) . unwrap ( ) ,
629+ )
630+ . unwrap ( ) ;
577631 verifying_keys. insert ( participant_identifier, key_package. verifying_share ) ;
578632 // Test if all verifying_key are equal
579633 if let Some ( previous_verifying_key) = verifying_key {
@@ -591,6 +645,9 @@ where
591645 }
592646
593647 let pubkeys = frost:: keys:: PublicKeyPackage :: new ( verifying_keys, verifying_key. unwrap ( ) ) ;
648+ // Simulate serialization / deserialization to ensure it works
649+ let pubkeys =
650+ frost:: keys:: PublicKeyPackage :: deserialize ( & pubkeys. serialize ( ) . unwrap ( ) ) . unwrap ( ) ;
594651
595652 // Proceed with the signing test.
596653 check_sign ( min_signers, key_packages, rng, pubkeys) . unwrap ( )
0 commit comments