I’ve noticed that the aggregated nonce points are converted from affine to jacobi coordinates here, and then again from jacobi to affine inside secp256k1_musig_nonce_process_internal
. Could pass as affine coordinates to the internal function instead in order to do only one conversion there. With the following patch, the tests still pass:
0diff --git a/src/modules/musig/session_impl.h b/src/modules/musig/session_impl.h
1index b0ea45d..b073ec0 100644
2--- a/src/modules/musig/session_impl.h
3+++ b/src/modules/musig/session_impl.h
4@@ -557,14 +557,14 @@ static int secp256k1_musig_compute_noncehash(unsigned char *noncehash, secp256k1
5 return 1;
6 }
7
8-static int secp256k1_musig_nonce_process_internal(int *fin_nonce_parity, unsigned char *fin_nonce, secp256k1_scalar *b, secp256k1_gej *aggnoncej, const unsigned char *agg_pk32, const unsigned char *msg) {
9+static int secp256k1_musig_nonce_process_internal(int *fin_nonce_parity, unsigned char *fin_nonce, secp256k1_scalar *b, secp256k1_ge *aggnonce, const unsigned char *agg_pk32, const unsigned char *msg) {
10 unsigned char noncehash[32];
11 secp256k1_ge fin_nonce_pt;
12 secp256k1_gej fin_nonce_ptj;
13- secp256k1_ge aggnonce[2];
14+ secp256k1_gej aggnoncej[2];
15
16- secp256k1_ge_set_gej(&aggnonce[0], &aggnoncej[0]);
17- secp256k1_ge_set_gej(&aggnonce[1], &aggnoncej[1]);
18+ secp256k1_gej_set_ge(&aggnoncej[0], &aggnonce[0]);
19+ secp256k1_gej_set_ge(&aggnoncej[1], &aggnonce[1]);
20 if (!secp256k1_musig_compute_noncehash(noncehash, aggnonce, agg_pk32, msg)) {
21 return 0;
22 }
23@@ -588,7 +588,6 @@ static int secp256k1_musig_nonce_process_internal(int *fin_nonce_parity, unsigne
24 int secp256k1_musig_nonce_process(const secp256k1_context* ctx, secp256k1_musig_session *session, const secp256k1_musig_aggnonce *aggnonce, const unsigned char *msg32, const secp256k1_musig_keyagg_cache *keyagg_cache) {
25 secp256k1_keyagg_cache_internal cache_i;
26 secp256k1_ge aggnonce_pt[2];
27- secp256k1_gej aggnonce_ptj[2];
28 unsigned char fin_nonce[32];
29 secp256k1_musig_session_internal session_i;
30 unsigned char agg_pk32[32];
31@@ -607,10 +606,8 @@ int secp256k1_musig_nonce_process(const secp256k1_context* ctx, secp256k1_musig_
32 if (!secp256k1_musig_aggnonce_load(ctx, aggnonce_pt, aggnonce)) {
33 return 0;
34 }
35- secp256k1_gej_set_ge(&aggnonce_ptj[0], &aggnonce_pt[0]);
36- secp256k1_gej_set_ge(&aggnonce_ptj[1], &aggnonce_pt[1]);
37
38- if (!secp256k1_musig_nonce_process_internal(&session_i.fin_nonce_parity, fin_nonce, &session_i.noncecoef, aggnonce_ptj, agg_pk32, msg32)) {
39+ if (!secp256k1_musig_nonce_process_internal(&session_i.fin_nonce_parity, fin_nonce, &session_i.noncecoef, aggnonce_pt, agg_pk32, msg32)) {
40 return 0;
41 }