Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secp256k1proto: deserialize x-only-pk with from_bytes_xonly (schnorr_verify) #80

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Feb 2, 2025

If the passed x-only-pubkey overflows (x >= p), this method fails immediately rather than silently wrapping around and then likely failing later (either because x % p is not on the curve or because the actual signature verification fails [1]). For the user of schnorr_verify this shouldn't make any difference, as False is returned with both variants, so this is probably more of a cosmetic change.

[1] b'\xff'*32 is an example x-only-pubkey for the latter case

…r_verify)

If the passed x-only-pubkey overflows (x >= p), this method fails
immediately rather than silently wrapping around and then likely
failing later (either because x % p is not on the curve or because the
actual signature verification fails). For the user of `schnorr_verify`
this shouldn't make any difference, as `False` is returned with both
variants, so this is probably more of a cosmetic change.
@real-or-random
Copy link
Collaborator

real-or-random commented Feb 3, 2025

ACK

If the passed x-only-pubkey overflows (x >= p), this method fails immediately rather than silently wrapping around and then likely failing later (either because x % p is not on the curve or because the actual signature verification fails [1]). For the user of schnorr_verify this shouldn't make any difference, as False is returned with both variants, so this is probably more of a cosmetic change.

Hm yes, but any implementation of verification should be 100% compatible with the BIP because it's consensus critical. And I think it's easy to come up with a signature (by changing the signing algorithm) that would pass verification here, but not according to the BIP.

So this is a real bug. I think (or hope) that this should be covered by one of the BIP340 test vectors.

The underlying problem here is that lift_x in the BIP fails on overflow, but here it does not. The idea is that you can use ints wherever field elements are expected, and we'll call the FE constructor, which simply takes the mod.

I tend to think that this constructor should require a normalized representation, i.e., be checked. There could still be a FE.from_int_wrapping factory method. But explicit is better than implicit.

@real-or-random real-or-random merged commit 3bcc648 into BlockstreamResearch:master Feb 3, 2025
1 check passed
@real-or-random
Copy link
Collaborator

note: We may want to squash this into 843d165 when moving secp256k1proto into a separate repo (because the latter will create a new history anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants