Skip to content

BIP352: ECDSA verify compare x(R) modulo n to r#1959

Closed
radik878 wants to merge 1 commit intobitcoin:masterfrom
radik878:fix/ecdsa-verify-mod-n-compare
Closed

BIP352: ECDSA verify compare x(R) modulo n to r#1959
radik878 wants to merge 1 commit intobitcoin:masterfrom
radik878:fix/ecdsa-verify-mod-n-compare

Conversation

@radik878
Copy link
Contributor

@radik878 radik878 commented Sep 8, 2025

The signer computes r = x(R) mod n, but the verifier compared the affine x-coordinate directly to r. This could incorrectly reject valid signatures when x(R) ≥ n (rare but possible). Update ECPubKey.verify_ecdsa to check (x(R) % n) == r, aligning verification with ECDSA as defined in SEC1/FIPS 186 and matching our signer’s behavior.

@jonatack jonatack added Proposed BIP modification Pending acceptance This BIP modification requires sign-off by the champion of the BIP being modified labels Sep 10, 2025
@murchandamus
Copy link
Member

Ping authors, @RubenSomsen, @josibake

@murchandamus
Copy link
Member

cc: @theStack

@theStack
Copy link
Contributor

theStack commented Mar 2, 2026

ECDSA signature verification is not relevant to BIP-352 (neither in the reference implementation nor in test vector generation/execution), and secp256k1.py is planned to be replaced with secp256k1lab anyway (see #2087), which currently doesn't even have ECDSA support.

I was going to suggest the possibility of submitting this upstream to Bitcoin Core (since this code appears to be based on its test framework), but it looks like the modulo logic is already there:
https://github.com/bitcoin/bitcoin/blob/6b0a980de94bc5b64703151be708991f954161ea/test/functional/test_framework/key.py#L109

This PR can be closed.

@murchandamus murchandamus removed the Pending acceptance This BIP modification requires sign-off by the champion of the BIP being modified label Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants