@@ -390,14 +390,18 @@ where
390390 /// Returns a scalar of the unblinded signature
391391 pub fn sign_single ( & mut self , sig_request : SignatureRequest ) -> Option < Scalar < Public , Zero > > {
392392 let secret_nonce = self . use_secret_nonce ( sig_request. public_nonce ) ;
393- match secret_nonce {
393+ let signature_response = match secret_nonce {
394394 Some ( secret_nonce) => {
395395 let sig = s ! ( secret_nonce + sig_request. blind_challenge * self . secret) . public ( ) ;
396- Some ( sig) //.secret().non_zero()
396+ Some ( sig)
397397 }
398398 // Did not expect this nonce
399399 None => None ,
400- }
400+ } ;
401+ // Store this signature
402+ self . already_signed
403+ . insert ( sig_request. public_nonce , signature_response) ;
404+ signature_response
401405 }
402406
403407 /// Sign multiple blind schnorr signatures concurrently once enough have been requested
@@ -430,16 +434,21 @@ where
430434 . clone ( )
431435 . into_iter ( )
432436 . enumerate ( )
433- . map ( |( i, sig_req ) | {
434- let sig = self . sign_single ( sig_req . clone ( ) ) ;
437+ . map ( |( i, sig_request ) | {
438+ let sig = self . sign_single ( sig_request . clone ( ) ) ;
435439 let response = if self . max_sessions > 1 && i as u32 == skip_i {
436440 // Maybe don't return the signature
441+ // ⚠ IMPORTANT: Overwrite the stored signature for this nonce
442+ self . already_signed . insert ( sig_request. public_nonce , None ) ;
443+ assert ! ( self
444+ . already_signed
445+ . get( & sig_request. public_nonce)
446+ . expect( "history has to have None written for this nonce" )
447+ . is_none( ) ) ;
437448 None
438449 } else {
439450 sig
440451 } ;
441- // Store signature (or None) for this public nonce
442- self . already_signed . insert ( sig_req. public_nonce , response) ;
443452 response
444453 } )
445454 . collect ( ) ;
0 commit comments