@@ -87,7 +87,7 @@ static const unsigned char secp256k1_musig_session_cache_magic[4] = { 0x9d, 0xed
87
87
/* A session consists of
88
88
* - 4 byte session cache magic
89
89
* - 1 byte the parity of the final nonce
90
- * - 32 byte final nonce
90
+ * - 32 byte serialized x-only final nonce
91
91
* - 32 byte nonce coefficient b
92
92
* - 32 byte signature challenge hash e
93
93
* - 32 byte scalar s that is added to the partial signatures of the signers
@@ -386,7 +386,7 @@ int secp256k1_musig_nonce_agg(const secp256k1_context* ctx, secp256k1_musig_aggn
386
386
return 1 ;
387
387
}
388
388
389
- /* hash (aggnonce[0], aggnonce[1], agg_pk, msg) */
389
+ /* tagged_hash (aggnonce[0], aggnonce[1], agg_pk, msg) */
390
390
static int secp256k1_musig_compute_noncehash (unsigned char * noncehash , secp256k1_ge * aggnonce , const unsigned char * agg_pk32 , const unsigned char * msg ) {
391
391
unsigned char buf [33 ];
392
392
secp256k1_sha256 sha ;
@@ -542,7 +542,7 @@ int secp256k1_musig_partial_sign(const secp256k1_context* ctx, secp256k1_musig_p
542
542
* P_agg := mu[0]*|P[0]| + ... + mu[n-1]*|P[n-1]|
543
543
* - P_tweak[i] is the tweaked public key after the i-th tweaking operation
544
544
* P_tweak[0] := P_agg
545
- * P_tweak[i] := |P_tweak[i-1]| + t[i]*G for i = 1, ..., m-1
545
+ * P_tweak[i] := |P_tweak[i-1]| + t[i]*G for i = 1, ..., m
546
546
*
547
547
* Note that our goal is to produce a partial signature corresponding to
548
548
* the final public key after m tweaking operations P_final = |P_tweak[m]|.
@@ -644,7 +644,7 @@ int secp256k1_musig_partial_sig_verify(const secp256k1_context* ctx, const secp2
644
644
}
645
645
646
646
/* Compute "effective" nonce rj = aggnonce[0] + b*aggnonce[1] */
647
- /* TODO: use multiexp to compute -s*G + e*pubkey + aggnonce[0] + b*aggnonce[1] */
647
+ /* TODO: use multiexp to compute -s*G + e*mu* pubkey + aggnonce[0] + b*aggnonce[1] */
648
648
if (!secp256k1_musig_pubnonce_load (ctx , nonce_pt , pubnonce )) {
649
649
return 0 ;
650
650
}
@@ -670,6 +670,43 @@ int secp256k1_musig_partial_sig_verify(const secp256k1_context* ctx, const secp2
670
670
* negated exactly when the aggregate key parity is odd. If the aggregate
671
671
* key is tweaked, then negation happens when the aggregate key has an odd Y
672
672
* coordinate XOR the internal key has an odd Y coordinate.*/
673
+
674
+ /* When producing a partial signature, signer i uses a possibly
675
+ * negated secret key:
676
+ *
677
+ * sk[i] = (d_tweak*d_agg*d[i])*x[i]
678
+ *
679
+ * to ensure that the aggregate signature will correspond to
680
+ * an aggregate public key with even Y coordinate (see the
681
+ * notation and explanation in musig_partial_sign).
682
+ *
683
+ * We use the following additional notation:
684
+ * - e is the (Schnorr signature) challenge
685
+ * - r[i] is the i-th signer's secret nonce
686
+ * - R[i] = r[i]*G is the i-th signer's public nonce
687
+ * - R is the aggregated public nonce
688
+ * - d_nonce is chosen so that |R| = d_nonce*R
689
+ *
690
+ * The i-th partial signature is:
691
+ *
692
+ * s[i] = d_nonce*r[i] + mu[i]*e*sk[i]
693
+ *
694
+ * In order to verify this partial signature, we need to check:
695
+ *
696
+ * s[i]*G = d_nonce*R[i] + mu[i]*e*sk[i]*G
697
+ *
698
+ * The verifier doesn't have access to sk[i]*G, but can construct
699
+ * it using the xonly public key |P[i]| as follows:
700
+ *
701
+ * sk[i]*G = d_tweak*d_agg*d[i]*x[i]*G
702
+ * = d_tweak*d_agg*d[i]*P[i]
703
+ * = d_tweak*d_agg*|P[i]|
704
+ *
705
+ * The if condition is below is true whenever d_tweak*d_agg is
706
+ * negative (again, see the explanation in musig_partial_sign). In
707
+ * this case, the verifier negates e which will have the same end
708
+ * result as negating |P[i]|, since they are multiplied later anyway.
709
+ */
673
710
if (secp256k1_fe_is_odd (& cache_i .pk .y )
674
711
!= cache_i .internal_key_parity ) {
675
712
secp256k1_scalar_negate (& e , & e );
@@ -678,7 +715,7 @@ int secp256k1_musig_partial_sig_verify(const secp256k1_context* ctx, const secp2
678
715
if (!secp256k1_musig_partial_sig_load (ctx , & s , partial_sig )) {
679
716
return 0 ;
680
717
}
681
- /* Compute -s*G + e*pkj + rj */
718
+ /* Compute -s*G + e*pkj + rj (e already includes the keyagg coefficient mu) */
682
719
secp256k1_scalar_negate (& s , & s );
683
720
secp256k1_gej_set_ge (& pkj , & pkp );
684
721
secp256k1_ecmult (& tmp , & pkj , & e , & s );
0 commit comments