@@ -291,7 +291,7 @@ impl Coordinator {
291291 Self {
292292 inner : simplepedpop:: Coordinator :: new ( threshold, n_contribtors) ,
293293 agg_encrypted_shares,
294- encryption_nonces : Default :: default ( ) ,
294+ encryption_nonces : vec ! [ Point :: default ( ) ; n_contribtors as usize ] ,
295295 }
296296 }
297297
@@ -328,8 +328,7 @@ impl Coordinator {
328328 * agg_encrypted_share += encrypted_share_contrib;
329329 }
330330
331- self . encryption_nonces . push ( input. encryption_nonce ) ;
332-
331+ self . encryption_nonces [ from as usize ] = input. encryption_nonce ;
333332 Ok ( ( ) )
334333 }
335334
@@ -496,13 +495,17 @@ where
496495
497496#[ cfg( test) ]
498497mod test {
499- use crate :: frost:: { Fingerprint , chilldkg:: encpedpop} ;
498+ use alloc:: { collections:: BTreeMap , vec:: Vec } ;
499+
500+ use crate :: frost:: { Fingerprint , ShareIndex , chilldkg:: encpedpop} ;
500501
501502 use proptest:: {
502503 prelude:: * ,
503504 test_runner:: { RngAlgorithm , TestRng } ,
504505 } ;
505- use secp256kfun:: proptest;
506+ use secp256kfun:: { KeyPair , Scalar , proptest} ;
507+
508+ use super :: { Contributor , Coordinator } ;
506509
507510 proptest ! {
508511 #[ test]
@@ -557,4 +560,41 @@ mod test {
557560 assert!( shared_key. check_fingerprint:: <sha2:: Sha256 >( & fingerprint) , "fingerprint was grinded correctly" ) ;
558561 }
559562 }
563+
564+ #[ test]
565+ fn test_input_arrival_order ( ) {
566+ let schnorr = crate :: new_with_deterministic_nonces :: < sha2:: Sha256 > ( ) ;
567+ let mut rng = TestRng :: deterministic_rng ( RngAlgorithm :: ChaCha ) ;
568+ let threshold = 2u32 ;
569+
570+ let receiver_enckeys = [ (
571+ ShareIndex :: from ( core:: num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ,
572+ KeyPair :: new ( Scalar :: random ( & mut rng) ) . public_key ( ) ,
573+ ) ]
574+ . into_iter ( )
575+ . collect :: < BTreeMap < _ , _ > > ( ) ;
576+
577+ let mut coordinator = Coordinator :: new ( threshold, 3 , & receiver_enckeys) ;
578+
579+ // Create contributors with indices 0, 1, 2
580+ let contributors_and_inputs: Vec < _ > = ( 0 ..3 )
581+ . map ( |i| {
582+ Contributor :: gen_keygen_input ( & schnorr, threshold, & receiver_enckeys, i, & mut rng)
583+ } )
584+ . collect ( ) ;
585+
586+ // Add them to coordinator in different order
587+ let arrival_order = [ 2 , 0 , 1 ] ;
588+ for & contributor_idx in arrival_order. iter ( ) {
589+ let ( _, input) = & contributors_and_inputs[ contributor_idx as usize ] ;
590+ coordinator
591+ . add_input ( & schnorr, contributor_idx, input. clone ( ) )
592+ . unwrap ( ) ;
593+ }
594+
595+ let agg_input = coordinator. finish ( ) . unwrap ( ) ;
596+
597+ let ( contributor_1, _) = & contributors_and_inputs[ 1 ] ;
598+ contributor_1. clone ( ) . verify_agg_input ( & agg_input) . unwrap ( ) ; // This should fail
599+ }
560600}
0 commit comments