Repository navigation
Conversation
fametrano
force-pushed
the
btclib-1872-tr-expand-xonly
branch
from
September 12, 2026 12:29
bcf5006 to
c399418
Compare
A tr() internal key, or a pk() tapscript leaf key, can resolve to a 33-byte compressed point when it is derived from an extended key or written as a raw compressed key. Taproot uses x-only public keys, so such a key is reduced to its 32-byte x-coordinate before it reaches taproot_output_script, dropping the parity byte as Bitcoin Core does. This is correct for either parity, since taproot keys are lifted to even-y when tweaked. A key already in x-only form is left unchanged.
fametrano
force-pushed
the
btclib-1872-tr-expand-xonly
branch
from
September 27, 2026 23:02
c399418 to
7301e2d
Compare
Contributor
Author
Contributor
Author
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 key in a
tr()descriptor can resolve to a 33-byte compressed point. This happens when it is derived from an extended key, or written as a raw compressed key. Taproot needs a 32-byte x-only key, and Electrum does not reduce it. The two places where this happens fail in different ways:TRDescriptor.expandpasses the 33 bytes totaproot_output_script, andassert len(pubkey32) == 32fails. Sotr(<xpub>/<path>), the usual single-key taproot descriptor, cannot be expanded.pk()leaf key. Expansion succeeds, but the leaf script pushes a 33-byte key. BIP-0342 treats a key that is neither 0 nor 32 bytes as an unknown public key type, and signature validation for it succeeds. So under consensus anyone can spend through that leaf with any non-empty signature. Only relay policy makes such a spend non-standard.Bitcoin Core builds the x-only key by dropping the parity byte (
XOnlyPubKey(CPubKey)). This PR does the same. A small helper reduces a 33-byte key to its 32-byte x-only form. It runs on the internal key and onpk()leaf keys, both raw and derived from an extended key.pk()is the only leaf function Electrum's parser accepts. A 32-byte key is unchanged. Signing is not touched.The test checks the internal key, raw and derived from an extended key, and a raw compressed
pk()leaf key. The leaf case must give the BIP-0386 x-only vector.Made with my usual tools: a computer, the Internet and an LLM. The mistakes, as usual, are all mine.