Repository navigation
Conversation
This was referenced Sep 9, 2026
Contributor
Author
|
The one red check on this PR is That looks like a port collision starting the daemon, not a descriptor-parsing failure. There's a single run on this head ( Could someone re-run that job, and take a look at the change itself? The branch is even with master, so there's no rebase that would produce a fresh run, and I can't trigger one myself. |
fametrano
force-pushed
the
btclib-666-validate-pubkey
branch
from
September 23, 2026 21:14
b5b8e25 to
43a0ba3
Compare
A public key written as raw hex in a descriptor is checked against the secp256k1 curve for the context it appears in. A 33-byte compressed key is accepted everywhere; a 32-byte x-only key only inside tr(); a 65-byte uncompressed key only at the top level and under sh(), and never under the segwit contexts wpkh() and wsh() or inside tr(). A key whose length, prefix, or encoded point is invalid is rejected with a ValueError. Previously such keys were only tested for being hex rather than an extended key, so a descriptor carrying off-curve, wrong-length, bad-prefix, or context-inappropriate bytes parsed without complaint.
fametrano
force-pushed
the
btclib-666-validate-pubkey
branch
from
September 29, 2026 21:07
43a0ba3 to
165d43a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A raw-hex public key in a descriptor is never checked to be a valid point. So
pkh(020000000000000000000000000000000000000000000000000000000000000005)parses, although no curve point has that x-coordinate. Bitcoin Core rejects an invalid key at parse time.This PR checks a raw-hex key with the same rules as Core's
ParsePubkeyInner. What is accepted depends on where the key appears:tr(): a 32-byte x-only key or a 33-byte compressed key;sh()(rejected underwpkh()/wsh(), per BIP141);0x06/0x07) and off-curve or wrong-length keys are rejected everywhere.hwilib/key.pygains two small on-curve checks,point_on_curveandx_coord_on_curve. The existing point helpers recover a coordinate without checking the curve equation. Extended keys (xpubs) are not affected. Tests cover the accepted and rejected cases.The same change for Electrum's descriptor parser, which shares this code, is spesmilo/electrum#10951.
Made with my usual tools: a computer, the Internet and an LLM. The mistakes, as usual, are all mine.