sign: verify schnorr sigs after creation
What changed, and why it matters
This commit adds a safety check when creating Schnorr digital signatures in libwally-core. After a signature is generated, the code now immediately verifies it using the corresponding public key. If the signature fails verification, it is erased and not returned to the caller. This prevents a rare but real risk: a corrupted or faulty Schnorr signature could leak information about the private key.
Treat this as a security-hardening fix and include it in the next release. Users generating Schnorr signatures should upgrade. No immediate incident response is indicated unless invalid Schnorr signatures have already been produced or exposed by affected versions.
Security signals we found
Schnorr signature verification immediately after signing
Output buffer cleared when signature generation or verification fails
Private-key leakage risk explicitly mentioned in commit message
Defensive fault-tolerance against corrupted signatures
Evidence from the diff
The patch modifies wally_ec_sig_from_bytes_aux() in src/sign.c for the EC_FLAG_SCHNORR path. It now derives the x-only public key from the keypair, signs with secp256k1_schnorrsig_sign32(), then immediately calls secp256k1_schnorrsig_verify() on the produced signature. If verification fails, the function returns WALLY_ERROR and clears the output buffer. This is a defensive countermeasure against nonce or signing faults that could produce invalid Schnorr signatures and potentially leak private-key material, as described in Schnorr security literature.
Changed components
src/sign.cwally_ec_sig_from_bytes_aux()Schnorr signature generation path (EC_FLAG_SCHNORR)Inspect captured patch +8 / −1
### src/sign.c
@@ -381,12 +381,19 @@ int wally_ec_sig_from_bytes_aux(const unsigned char *priv_key, size_t priv_key_l
if (flags & EC_FLAG_SCHNORR) {
secp256k1_keypair keypair;
+ secp256k1_xonly_pubkey xonly_pub;
int ret = WALLY_OK;
if (!keypair_create(&keypair, priv_key))
ret = WALLY_EINVAL;
+ else if (!secp256k1_keypair_xonly_pub(ctx, &xonly_pub, NULL, &keypair))
+ ret = WALLY_ERROR;
else if (!secp256k1_schnorrsig_sign32(ctx, bytes_out, bytes, &keypair, aux_rand))
ret = WALLY_ERROR;
- wally_clear(&keypair, sizeof(keypair));
+ else if (!secp256k1_schnorrsig_verify(ctx, bytes_out, bytes, bytes_len, &xonly_pub))
+ ret = WALLY_ERROR; /* Don't return sigs that fail to verify */
+ wally_clear_2(&keypair, sizeof(keypair), &xonly_pub, sizeof(xonly_pub));
+ if (ret != WALLY_OK)
+ wally_clear(bytes_out, len);
return ret;
} else {
unsigned char extra_entropy[32] = {0}, *entropy_p = (unsigned char *)aux_rand;Why this scored 64/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.