Repository navigation
bip360: follow-ups to the spend-path test vectors - #2382
Open
jeanpablojp wants to merge 6 commits into
Open
jeanpablojp wants to merge 6 commits into
jeanpablojp wants to merge 6 commits into
Conversation
The control byte's last bit is masked off for the leaf version, so neither the tapleaf hash nor the signature message commits to it. The text says it must be 1 but gives no failure condition, unlike the length rule above it, and without one anyone relaying a spend can flip the bit and change its wtxid. BIP 341 fails on the same bit for P2TR, where it carries the parity of Q. The list of changes from BIP 341 now names the bit too. p2mr_spend_control_byte_low_bit_zero in p2mr_spending.json already expects failure. mossein raised this in bitcoin#2232 and jonatack agreed there.
p2mr_spending.json was added next to p2mr_construction.json in bitcoin#2232, but Test Vectors and Reference Code still names only the construction file.
Contributor
Author
|
I have one open point, i left out |
jonatack
reviewed
Dec 3, 2026
The depth-128 scriptTree in p2mr_spending.json puts the file at a JSON nesting depth of 135, past serde_json's default limit of 128. The top-level comment now says so, as jonatack suggested in bitcoin#2232. It also says that the prevout txids are in internal byte order, which until now only the commit message of bitcoin#2232 said.
p2mr_spend_explicit_default_hash_type signs correctly for SIGHASH_DEFAULT but appends 0x00, which BIP 341 rejects in a 65-byte signature. A fourth transaction spends a depth-0 output with an annex, three witness elements, so the annex has to come off before the depth-0 rule applies. Both were among the follow-ups jonatack listed in bitcoin#2232. The top-level comment now also says that the fourth group reuses p2mr_single_leaf_script_tree.
Record the new failure condition on the last bit of c[0] and the spend-path test vectors, which went in with bitcoin#2232 without an entry, and move the Version header to 0.12.2.
jeanpablojp
force-pushed
the
bip360-spend-vectors-followup
branch
from
December 3, 2026 21:53
411a7ed to
7e34385
Compare
Contributor
Author
|
Both taken, thanks. |
The Security section still tells key path wallets that moving to a simple OP_CHECKSIG leaf script is enough. A single leaf is a depth-zero tree, which bitcoin#2198 made anyone-can-spend in 0.12.0, and the p2mr_single_leaf_script_tree spend vector spends one with no signature. That PR updated the other places that described depth-zero trees but left this sentence. Add a line to the 0.12.2 changelog entry.
|
tACK 605a46e Verified the spec updates and test vectors with a standalone Python script (no Core build):
|
Member
|
re-tACK 605a46e |
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.
Follow-ups to #2232, one commit each.
c[0]is 0. Neither the tapleaf hash nor the signature message commits to that bit, and without a failure condition anyone relaying a spend can flip it and change the wtxid. mossein raised it in bip360: add spend-path test vectors #2232 and jonatack agreed. The list of changes from BIP 341 now names the bit too.p2mr_spending.jsonin Test Vectors and Reference Code.scriptTreeputs it at a JSON nesting depth of 135, past serde_json's default limit of 128.The vectors come from the same generator as before, now on the p2mr-spend-vectors-followup branch of my Core fork, where
src/test/p2mr_vector_tests.cppruns every case throughVerifyScript. For each new vector I took the rule it covers out of Core, and that vector was the only one to change result.I left out SIGHASH_SINGLE without a matching output. It needs an invalid transaction with two inputs, and every invalid case in the file has one input, so covering it means a new field in the invalid format.
Running
p2mr_spending.jsonfromp2mr.pytouches the same function as #2380, so I'll do that once it is in.