Skip to content

BIP-374: treat challenge hash result e as scalar - #2262

Open
theStack wants to merge 2 commits into
bitcoin:masterfrom
theStack:bip374_treat-e-as-scalar
Open

BIP-374: treat challenge hash result e as scalar#2262
theStack wants to merge 2 commits into
bitcoin:masterfrom
theStack:bip374_treat-e-as-scalar

Conversation

@theStack

Copy link
Copy Markdown
Contributor

The purpose of this change is primarily to improve clarity for implementers (e.g. in libsecp [1]) and for consistency with existing BIPs like e.g. BIP-340 and BIP-327, where the challenge hash result is reduced modulo the curve order as well:

* Let ''e = int(hash<sub>BIP0340/challenge</sub>(bytes(R) || bytes(P) || m)) mod n''.

* Let ''e = int(hash<sub>BIP0340/challenge</sub>(xbytes(R) || xbytes(Q) || m)) mod n''

It seems not strictly needed from a pure specification point of view, but I think it makes sense to treat e as scalar throughout, given that we perform scalar operations at the proof generation side for calculating $s = (k + e \cdot a) \bmod n$, so implementers would need to do a conversion (and hence decide whether to wrap-around or not) anyways.

Under the assumption that reaching a challenge hash with e >= n is negligible, I think this change can be treated as logically equivalent and thus backwards compatible (but maybe there is more subtlety to it that I don't see); note that the newly introduced test vectors would also fail without the new early rejection branch, but at a later point due to not fulfilling the verification equation.

Thanks to @macgyver13 for making me aware that e is currently not specified to be in the scalar range.

[1] see PRs bitcoin-core/secp256k1#1651 and bitcoin-core/secp256k1#1802

….3.0

Note that the purpose of this change is primarily to improve clarity
for implementers and consistency with existing BIPs like BIP-340 and
BIP-327. Under the assumption that reaching a challenge hash with
`e >= n` is negligible, the newly introduced test vectors in the next
commit would also fail without the new rejection branch.
@theStack

Copy link
Copy Markdown
Contributor Author

pinging the BIP-374 co-authors and some "friendly cryptographers from next-door" :-) @andrewtoth @jonasnick @real-or-random @RubenSomsen @sipa

@jonatack jonatack added the BIP Update by Owner PR by Author or Deputy to modify their own BIP label Aug 19, 2026
Comment thread bip-0374/reference.py
),
"big",
)
) % GE.ORDER

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving a note for reviewers that we could also take better use of secp256k1lab's types in the reference implementation (e.g. directly return a Scalar here instead of working with ints), but that's out of scope for this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BIP Update by Owner PR by Author or Deputy to modify their own BIP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants