Repository navigation
Conversation
fametrano
force-pushed
the
computepkscript-taproot
branch
from
October 13, 2026 11:27
7e29426 to
49c0e4a
Compare
lucasdbr05
approved these changes
Oct 29, 2026
lucasdbr05
left a comment
There was a problem hiding this comment.
LGTM
This correctly extends ComputePkScript to derive a P2TR pkScript for script path spends. It removes an annex when present, parses the control block, reconstructs the Taproot merkle root, and derives the output key according to BIP-341.
I also ran go test and go test -race successfully.
Contributor
Author
|
@yyforyongyu @Roasbeef, could you approve the Build and Test runs waiting on this PR and on #2630 before they expire at 11:27 UTC on 12 November, and the one on #2651 before 22:17 UTC on 16 November? A review of any of the three would also help. |
ComputePkScript treated every witness it could not match to P2WPKH as a P2WSH one. A taproot witness was therefore given a made-up P2WSH script, which neutrino's block filter check used as if it were real. A script path spend reveals what the output key commits to: the leaf script and a control block. Compute the output key from them as BIP 341 does and return the P2TR script. A witness ends in a control block if its last item has a valid length and a leaf version of at least 0xc0, or in an annex if it starts with 0x50. Both are opcodes that fail when a witness script starts with them, so no spendable P2WSH or P2WPKH witness ends that way. A key path spend reveals only a signature, so the output key is not in the witness. A lone 64 or 65 byte item, or a lone item followed by an annex, returns ErrUnsupportedScriptType, as btcsuite#1767 suggests. A P2WSH witness made of a single 64 or 65 byte script, which takes no input, now returns the same error. The tests use the 12 script path leaves of the BIP 341 wallet test vectors. Fixes btcsuite#1817. Refs btcsuite#1767.
fametrano
force-pushed
the
computepkscript-taproot
branch
from
November 13, 2026 01:15
49c0e4a to
6d32d6d
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.
Change Description
I changed
ComputePkScriptso that it no longer returns a made-up P2WSHscript for a taproot witness (#1817, #1767).
A script path spend reveals the leaf script and the control block, so the
output key is computed from them as BIP 341 does and the P2TR script is
returned. A key path spend reveals only a signature, so it returns
ErrUnsupportedScriptType, as suggested in #1767.A witness is taken as taproot if it ends in an annex (first byte
0x50)or in a well-formed control block with a leaf version of at least
0xc0.A spendable P2WSH or P2WPKH witness cannot end that way. A lone 64 or 65
byte item is taken as a key path signature. These rules follow sipa's
comment linked in #1817.
Not covered: a P2WSH witness made of a single 64 or 65 byte script now
returns
ErrUnsupportedScriptTypeinstead of its P2WSH script, and aP2WSH witness can still be mistaken for P2WPKH, as noted in #1767.
Fixes #1817.
Steps to Test
TestComputePkScriptTaprootuses the 12 script path leaves of the BIP 341wallet test vectors (with and without an annex) and fails on master.
Pull Request Checklist
Testing
Code Style and Documentation
📝 Please see our Contribution Guidelines for further guidance.
Assisted-by: my usual tools (LLM, Internet, computer). Mistakes are mine.