Skip to content

descriptor: reduce tr() keys to x-only for taproot expansion - #10952

Open
fametrano wants to merge 1 commit into
spesmilo:masterfrom
fametrano:btclib-1872-tr-expand-xonly
Open

fametrano wants to merge 1 commit into
spesmilo:masterfrom
fametrano:btclib-1872-tr-expand-xonly

Conversation

@fametrano

Copy link
Copy Markdown
Contributor

A tr() descriptor whose internal key — or a tapscript leaf key — resolves to a 33-byte compressed point cannot be expanded. TRDescriptor.expand passes the 33-byte value to taproot_output_script, whose assert len(pubkey32) == 32 fails; 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 in tr() 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.

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.
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.

1 participant