@@ -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 std:: { 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]
@@ -553,4 +556,41 @@ mod test {
553556 assert!( shared_key. check_fingerprint:: <sha2:: Sha256 >( & fingerprint) , "fingerprint was grinded correctly" ) ;
554557 }
555558 }
559+
560+ #[ test]
561+ fn test_input_arrival_order ( ) {
562+ let schnorr = crate :: new_with_deterministic_nonces :: < sha2:: Sha256 > ( ) ;
563+ let mut rng = TestRng :: deterministic_rng ( RngAlgorithm :: ChaCha ) ;
564+ let threshold = 2u32 ;
565+
566+ let receiver_enckeys = [ (
567+ ShareIndex :: from ( core:: num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ,
568+ KeyPair :: new ( Scalar :: random ( & mut rng) ) . public_key ( ) ,
569+ ) ]
570+ . into_iter ( )
571+ . collect :: < BTreeMap < _ , _ > > ( ) ;
572+
573+ let mut coordinator = Coordinator :: new ( threshold, 3 , & receiver_enckeys) ;
574+
575+ // Create contributors with indices 0, 1, 2
576+ let contributors_and_inputs: Vec < _ > = ( 0 ..3 )
577+ . map ( |i| {
578+ Contributor :: gen_keygen_input ( & schnorr, threshold, & receiver_enckeys, i, & mut rng)
579+ } )
580+ . collect ( ) ;
581+
582+ // Add them to coordinator in different order
583+ let arrival_order = [ 2 , 0 , 1 ] ;
584+ for & contributor_idx in arrival_order. iter ( ) {
585+ let ( _, input) = & contributors_and_inputs[ contributor_idx as usize ] ;
586+ coordinator
587+ . add_input ( & schnorr, contributor_idx, input. clone ( ) )
588+ . unwrap ( ) ;
589+ }
590+
591+ let agg_input = coordinator. finish ( ) . unwrap ( ) ;
592+
593+ let ( contributor_1, _) = & contributors_and_inputs[ 1 ] ;
594+ contributor_1. clone ( ) . verify_agg_input ( & agg_input) . unwrap ( ) ; // This should fail
595+ }
556596}
0 commit comments