@@ -404,8 +404,13 @@ impl<H: Digest<OutputSize = U32> + Clone, NG: AddTag> Frost<H, NG> {
404404 . ok_or ( NewKeyGenError :: ZeroFrostKey ) ?
405405 . into_point_with_even_y ( ) ;
406406
407- // TODO set keygen id
408- let keygen_id = Scalar :: from_hash ( self . keygen_id_hash . clone ( ) . add ( joint_public_key) ) ;
407+ let mut keygen_hash = self . keygen_id_hash . clone ( ) ;
408+ for poly in point_polys. clone ( ) {
409+ for point in poly. 0 . iter ( ) {
410+ keygen_hash = keygen_hash. add ( point) ;
411+ }
412+ }
413+ let keygen_id = Scalar :: from_hash ( keygen_hash) ;
409414
410415 let verification_shares = ( 1 ..=point_polys. len ( ) )
411416 . map ( |i| joint_poly. eval ( i as u32 ) . normalize ( ) . mark :: < NonZero > ( ) )
@@ -672,13 +677,14 @@ impl<H: Digest<OutputSize = U32> + Clone, NG: NonceGen + AddTag> Frost<H, NG> {
672677impl < H : Digest < OutputSize = U32 > + Clone , NG : NonceGen + AddTag > Frost < H , NG > {
673678 /// Generate nonces for secret shares
674679 ///
675- /// It is very important to carefully consider the implications of your choice of underlying
676- /// [`NonceGen`].
680+ /// It is very important that you use a unique `sid` for this signing session and to also carefully
681+ /// consider the implications of your choice of underlying [`NonceGen`].
677682 ///
678- /// If you are generating nonces prior to KeyGen completion, use the static first coefficient
679- /// for your `secret`. Otherwise you can use your secret share of the joint FROST key.
683+ /// When choosing a `secret` to use, if you are generating nonces prior to KeyGen completion,
684+ /// use the static first coefficient of your polynomial.
685+ /// Otherwise you can use your secret share of the joint FROST key.
680686 ///
681- /// The application must decide upon a unique `sid` (session id) for this FROST multisignature.
687+ /// The application must decide upon a unique `sid` for this FROST multisignature.
682688 /// For example, the concatenation of: my_signing_index, joint_key, verfication_shares
683689 ///
684690 /// ## Return Value
@@ -799,8 +805,19 @@ mod test {
799805 if signer_indexes. len( ) < threshold as usize {
800806 dbg!( "pseudorandomly chose less signers than threshold.. skipping" ) ;
801807 } else {
802- let sid = frost_keys[ 0 ] . joint_public_key. to_bytes( ) ;
803- let nonces: Vec <NonceKeyPair > = signer_indexes. iter( ) . map( |i| frost. gen_nonce( & secret_shares[ * i as usize ] , & sid) ) . collect( ) ;
808+ let verification_shares_bytes: Vec <_> = frost_keys[ signer_indexes[ 0 ] ]
809+ . verification_shares
810+ . iter( )
811+ . map( |share| share. to_bytes( ) )
812+ . collect( ) ;
813+
814+ let sid = [
815+ frost_keys[ signer_indexes[ 0 ] ] . joint_public_key. to_bytes( ) . as_slice( ) ,
816+ verification_shares_bytes. concat( ) . as_slice( ) ,
817+ b"frost-prop-test" . as_slice( ) ,
818+ ]
819+ . concat( ) ;
820+ let nonces: Vec <NonceKeyPair > = signer_indexes. iter( ) . map( |i| frost. gen_nonce( & secret_shares[ * i as usize ] , & [ sid. as_slice( ) , [ * i as u8 ] . as_slice( ) ] . concat( ) ) ) . collect( ) ;
804821 // dbg!(&nonces);
805822
806823 let mut recieved_nonces: Vec <_> = vec![ ] ;
@@ -913,15 +930,31 @@ mod test {
913930 jk2 = jk2. tweak ( tweak. clone ( ) ) . expect ( "tweak worked" ) ;
914931 jk3 = jk3. tweak ( tweak) . expect ( "tweak worked" ) ;
915932
916- // TODO USE PROPER SID
917- // public => [ b"r2-frost", my_index.to_be_bytes(), frost_key.joint_public_key, &frost_key.verification_shares[..], sid]
918- let sid = frost_key. joint_public_key . to_bytes ( ) ;
919- // for share in frost_key.verification_shares {
920- // // [sid, share].concat(share.to_bytes());
921- // }
933+ let verification_shares_bytes: Vec < _ > = frost_key
934+ . verification_shares
935+ . iter ( )
936+ . map ( |share| share. to_bytes ( ) )
937+ . collect ( ) ;
922938
923- let nonce1 = frost. gen_nonce ( & secret_share1, & sid) ;
924- let nonce3 = frost. gen_nonce ( & secret_share3, & sid) ;
939+ // Create unique session IDs for these signing sessions
940+ let sid1 = [
941+ frost_key. joint_public_key . to_bytes ( ) . as_slice ( ) ,
942+ verification_shares_bytes. concat ( ) . as_slice ( ) ,
943+ b"frost-end-to-end-test-1" . as_slice ( ) ,
944+ b"0" . as_slice ( ) ,
945+ ]
946+ . concat ( ) ;
947+
948+ let sid2 = [
949+ frost_key. joint_public_key . to_bytes ( ) . as_slice ( ) ,
950+ verification_shares_bytes. concat ( ) . as_slice ( ) ,
951+ b"frost-end-to-end-test-2" . as_slice ( ) ,
952+ b"2" . as_slice ( ) ,
953+ ]
954+ . concat ( ) ;
955+
956+ let nonce1 = frost. gen_nonce ( & secret_share1, & sid1) ;
957+ let nonce3 = frost. gen_nonce ( & secret_share3, & sid2) ;
925958 let nonces = vec ! [ ( 0 , nonce1. public( ) ) , ( 2 , nonce3. public( ) ) ] ;
926959 let nonces2 = vec ! [ ( 0 , nonce1. public( ) ) , ( 2 , nonce3. public( ) ) ] ;
927960
0 commit comments