use new `_eckey_pubkey_serialize{33,65}` functions in modules (ellswift,musig)
What changed, and why it matters
This commit is a small internal cleanup in the Bitcoin Core secp256k1 cryptography library. It replaces several verbose public-key serialization calls with simpler, purpose-built helper functions that always produce 33-byte compressed public keys. There is no indication this fixes a security bug; it appears to be a code-quality refactor that removes redundant error checks and boilerplate.
No security action required. Treat as ordinary code-quality/maintenance refactor. If reviewing the new helper functions, confirm they enforce the same non-infinity and compressed-output invariants as the old code.
Security signals we found
No security-relevant keywords in commit title or message
Diff is a pure refactor with no semantic change to serialization output
Removed VERIFY_CHECK assertions are replaced by equivalent invariants in the new helper functions
No input validation changes, no buffer size changes, no new memory operations
No vendor or researcher attribution for a security issue
Evidence from the diff
The patch switches three module files (ellswift, musig key aggregation, musig session) from the generic secp256k1_eckey_pubkey_serialize(..., output, &size, 1) API to new specialized helpers _eckey_pubkey_serialize33 and _eckey_pubkey_serialize65. Because the new helpers are hard-coded for the desired output size, the callers no longer need local size_t size variables, int ret return values, or VERIFY_CHECK/(void)ret patterns. The removed VERIFY_CHECKs assert that serialization succeeds and that the size is 33 bytes; those invariants are preserved by the new functions, so the change is behaviorally equivalent under normal operation. No new failure modes are introduced.
Changed components
src/modules/ellswift/main_impl.hsrc/modules/musig/keyagg_impl.hsrc/modules/musig/session_impl.hInspect captured patch +5 / −42
diff --git a/src/modules/ellswift/main_impl.h b/src/modules/ellswift/main_impl.h
index 0d13f73..096f4a3 100644
--- a/src/modules/ellswift/main_impl.h
+++ b/src/modules/ellswift/main_impl.h
@@ -406,19 +406,12 @@ int secp256k1_ellswift_encode(const secp256k1_context *ctx, unsigned char *ell64
if (secp256k1_pubkey_load(ctx, &p, pubkey)) {
secp256k1_fe t;
unsigned char p64[64] = {0};
- size_t ser_size;
- int ser_ret;
secp256k1_sha256 hash;
/* Set up hasher state; the used RNG is H(pubkey || "\x00"*31 || rnd32 || cnt++), using
* BIP340 tagged hash with tag "secp256k1_ellswift_encode". */
secp256k1_ellswift_sha256_init_encode(&hash);
- ser_ret = secp256k1_eckey_pubkey_serialize(&p, p64, &ser_size, 1);
-#ifdef VERIFY
- VERIFY_CHECK(ser_ret && ser_size == 33);
-#else
- (void)ser_ret;
-#endif
+ secp256k1_eckey_pubkey_serialize33(&p, p64);
secp256k1_sha256_write(&hash, p64, sizeof(p64));
secp256k1_sha256_write(&hash, rnd32, 32);
diff --git a/src/modules/musig/keyagg_impl.h b/src/modules/musig/keyagg_impl.h
index 0db4fce..87869a4 100644
--- a/src/modules/musig/keyagg_impl.h
+++ b/src/modules/musig/keyagg_impl.h
@@ -124,18 +124,11 @@ static void secp256k1_musig_keyaggcoef_internal(secp256k1_scalar *r, const unsig
} else {
secp256k1_sha256 sha;
unsigned char buf[33];
- size_t buflen = sizeof(buf);
- int ret;
secp256k1_musig_keyaggcoef_sha256(&sha);
secp256k1_sha256_write(&sha, pks_hash, 32);
- ret = secp256k1_eckey_pubkey_serialize(pk, buf, &buflen, 1);
-#ifdef VERIFY
/* Serialization does not fail since the pk is not the point at infinity
* (according to this function's precondition). */
- VERIFY_CHECK(ret && buflen == sizeof(buf));
-#else
- (void) ret;
-#endif
+ secp256k1_eckey_pubkey_serialize33(pk, buf);
secp256k1_sha256_write(&sha, buf, sizeof(buf));
secp256k1_sha256_finalize(&sha, buf);
secp256k1_scalar_set_b32(r, buf, NULL);
diff --git a/src/modules/musig/session_impl.h b/src/modules/musig/session_impl.h
index 2c8778b..6a80a27 100644
--- a/src/modules/musig/session_impl.h
+++ b/src/modules/musig/session_impl.h
@@ -25,15 +25,8 @@ static void secp256k1_musig_ge_serialize_ext(unsigned char *out33, secp256k1_ge*
if (secp256k1_ge_is_infinity(ge)) {
memset(out33, 0, 33);
} else {
- int ret;
- size_t size = 33;
- ret = secp256k1_eckey_pubkey_serialize(ge, out33, &size, 1);
-#ifdef VERIFY
/* Serialize must succeed because the point is not at infinity */
- VERIFY_CHECK(ret && size == 33);
-#else
- (void) ret;
-#endif
+ secp256k1_eckey_pubkey_serialize33(ge, out33);
}
}
@@ -224,15 +217,8 @@ int secp256k1_musig_pubnonce_serialize(const secp256k1_context* ctx, unsigned ch
return 0;
}
for (i = 0; i < 2; i++) {
- int ret;
- size_t size = 33;
- ret = secp256k1_eckey_pubkey_serialize(&ges[i], &out66[33*i], &size, 1);
-#ifdef VERIFY
/* serialize must succeed because the point was just loaded */
- VERIFY_CHECK(ret && size == 33);
-#else
- (void) ret;
-#endif
+ secp256k1_eckey_pubkey_serialize33(&ges[i], &out66[33*i]);
}
return 1;
}
@@ -398,11 +384,9 @@ static int secp256k1_musig_nonce_gen_internal(const secp256k1_context* ctx, secp
secp256k1_gej nonce_ptj[2];
int i;
unsigned char pk_ser[33];
- size_t pk_ser_len = sizeof(pk_ser);
unsigned char aggpk_ser[32];
unsigned char *aggpk_ser_ptr = NULL;
secp256k1_ge pk;
- int pk_serialize_success;
int ret = 1;
ARG_CHECK(pubnonce != NULL);
@@ -429,15 +413,8 @@ static int secp256k1_musig_nonce_gen_internal(const secp256k1_context* ctx, secp
if (!secp256k1_pubkey_load(ctx, &pk, pubkey)) {
return 0;
}
- pk_serialize_success = secp256k1_eckey_pubkey_serialize(&pk, pk_ser, &pk_ser_len, 1);
-
-#ifdef VERIFY
/* A pubkey cannot be the point at infinity */
- VERIFY_CHECK(pk_serialize_success);
- VERIFY_CHECK(pk_ser_len == sizeof(pk_ser));
-#else
- (void) pk_serialize_success;
-#endif
+ secp256k1_eckey_pubkey_serialize33(&pk, pk_ser);
secp256k1_nonce_function_musig(k, input_nonce, msg32, seckey, pk_ser, aggpk_ser_ptr, extra_input32);
VERIFY_CHECK(!secp256k1_scalar_is_zero(&k[0]));
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.