Conversation
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 12, 2026 12:29
bcf5006 to
c399418
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
tr()descriptor whose internal key — or a tapscript leaf key — resolves to a 33-byte compressed point cannot be expanded.TRDescriptor.expandpasses the 33-byte value totaproot_output_script, whoseassert len(pubkey32) == 32fails; a tapscript leaf key silently produces a non-standard 33-byte-push script.So
tr(<xpub>/<path>)— the natural single-signer taproot form — is unusable, and a raw compressed key intr()expands to the wrong script.Bitcoin Core derives the x-only key from a compressed key by dropping the parity byte at script construction (
XOnlyPubKey(CPubKey)). This does the same: a small helper reduces a 33-byte compressed key to its 32-byte x-only form before it reaches the taproot output script — for both the internal key and tapscript leaf keys (pk(), the only function permitted as a leaf), covering both the extended-key and raw-compressed paths. A 32-byte key passes through unchanged, and the signing paths are untouched. The test checks the resulting output against the BIP-0386 x-only vector.