Skip to content

doc: fix msg argument description of nonce function typedefs - #1985

Open
amartya1523 wants to merge 2 commits into
bitcoin-core:masterfrom
amartya1523:doc-api-fixes
Open

amartya1523 wants to merge 2 commits into
bitcoin-core:masterfrom
amartya1523:doc-api-fixes

Conversation

@amartya1523

Copy link
Copy Markdown
Contributor

The docs for secp256k1_nonce_function and secp256k1_nonce_function_hardened both describe the message argument as the one "being verified". Nonce functions are only ever called from the signing functions, so the first commit changes this to "being signed".

The hardened nonce function docs also say msg is NULL if and only if msglen is 0. That is stricter than what secp256k1_schnorrsig_sign_custom enforces: it only checks msg != NULL || msglen == 0 and passes msg through to the nonce function unchanged, so a custom nonce function can see a non-NULL msg with msglen == 0. The second commit uses the same "Can only be NULL if msglen is 0" wording that sign_custom already has.

Both nonce function typedefs described the msg argument as the message
"being verified", but nonce functions are only ever invoked by the
signing functions (secp256k1_ecdsa_sign, secp256k1_ecdsa_sign_recoverable
and secp256k1_schnorrsig_sign_*).
The hardened nonce function docs claimed msg is NULL if and only if
msglen is 0. secp256k1_schnorrsig_sign_custom only requires that msg is
non-NULL when msglen is non-zero and hands msg through to the nonce
function unchanged, so a caller signing an empty message may pass either
NULL or a non-NULL pointer. Use the same wording as sign_custom.
@amartya1523 amartya1523 closed this Nov 3, 2026
@real-or-random

Copy link
Copy Markdown
Contributor

The docs for secp256k1_nonce_function and secp256k1_nonce_function_hardened both describe the message argument as the one "being verified". Nonce functions are only ever called from the signing functions, so the first commit changes this to "being signed".

Nice catch, ACK.

The hardened nonce function docs also say msg is NULL if and only if msglen is 0. That is stricter than what secp256k1_schnorrsig_sign_custom enforces: it only checks msg != NULL || msglen == 0 and passes msg through to the nonce function unchanged, so a custom nonce function can see a non-NULL msg with msglen == 0. The second commit uses the same "Can only be NULL if msglen is 0" wording that sign_custom already has.

Hm, I think this is a genuine bug. There's a non-zero probability that there's a custom nonce function out there that relies on the promise and just hasn't been called with an empty message so far. So I tend to think that we should err on the safe side here and rather change the semantics to what the API promised, i.e., add an if (msglen == 0) msg = NULL; with an appropriate comment to secp256k1_schnorrsig_sign_internal(). Ideally, this should get a test, too.

@real-or-random real-or-random reopened this Nov 5, 2026
@real-or-random real-or-random added user-documentation user-facing documentation bug labels Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug user-documentation user-facing documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants