Repository navigation
BIP 360: restore depth-zero Script execution - #2388
JeremyRubin wants to merge 2 commits into
Conversation
Revert the depth-zero auto-success rule from bitcoin#2198 so a single-leaf P2MR output executes its selected Script after Merkle commitment validation. Note that wallets and relay policy may discourage depth-zero spends without consensus failure. Bump the BIP version to 0.13.0. Rebuild the positive spending vector with a depth-zero signature and add the old unsigned witness as an invalid case.
Scope the 37-byte example to a signed CHECKSIG leaf and account for the CompactSize boundary at depth eight. Short P2MR scripts can have smaller witnesses than P2TR key-path spends, so remove the unconditional size claim.
|
@JeremyRubin can you add a motivation in the PR description (risk/footgun reduction, etc.) cc @cryptoquick @EthanHeilman for feedback |
|
Under #2198, a single-leaf output becomes free money that only a miner can reliably claim. That puts miners in an awkward spot
The person who sent or received those coins just loses them, usually by mistake. keep miners out of that position |
jonatack
left a comment
There was a problem hiding this comment.
Concept ACK and ACK, restores full P2TR/P2MR script-tree parity, includes some good fixups and accuracy improvements, test vectors look correct and ran
| P2WSH, for instance, does not support tapscript and as such does not support the OP_SUCCESSx opcode update path that will be critical for the integration of post-quantum OP_CHECKSIG opcodes into Bitcoin.<ref><code>OP_SUCCESSx</code> is a mechanism to upgrade tapscript</ref> | ||
|
|
||
| P2MR encourages script trees of depth 1 or more, so that P2MR addresses contain at least two spending paths, even if one is not used. This is intended to incentivize the use of a post-quantum-secure leaf script once available, and to better align P2MR's privacy profile with P2TR. | ||
| Depth-zero script trees can be discouraged by wallet policy when creating outputs or by relay policy when revealed in a spend, without changing consensus validity. |
There was a problem hiding this comment.
nit, without the #2198 context, this sentence seems a little out of the blue, could say why such discouragement would be needed
|
|
||
| The control block is a ''1 + 32 * m'' byte array, where the first byte is the control byte and the next ''32 * m'' bytes are the Merkle path to the leaf script. The control byte is the same as the control byte in a P2TR control block, including the 7 bits which are used to specify the leaf version. The parity bit of the control byte is always 1, since P2MR does not have a key path spend. Unlike P2TR, we omit the public key from the control block as it is not needed in P2MR. We maintain support for the optional annex in the witness (see Specification section below for more details). | ||
|
|
||
| Unlike P2TR, script trees of depth 0 - those with a single leaf script - are considered anyone-can-spend in P2MR, which discourages the use of depth-zero script trees today while still allowing them to be repurposed in a future soft-fork. |
There was a problem hiding this comment.
Pre-existing nit made more visible by restoring depth-zero execution, clarify TapLeaf vs TapBranch root for depth-zero trees
--- a/bip-0360.mediawiki
+++ b/bip-0360.mediawiki
@@ -124,11 +124,11 @@ In other words, P2MR outputs commit to the Merkle root of a script tree without
This output type is designed to offer users protection against long exposure quantum attacks as well as a practical output type with which post-quantum signatures may be used if such signatures are adopted in the future.
-Since P2MR outputs have no key path spend, they omit the Taproot internal key. Instead, a P2MR output includes the 32-byte root of the script tree as defined in [[bip-0341.mediawiki|BIP 341]] hashed with the tag "TapBranch" as shown below.
+Since P2MR outputs have no key path spend, they omit the Taproot internal key. Instead, a P2MR output includes the 32-byte Merkle root of the script tree as defined in [[bip-0341.mediawiki|BIP 341]] (tagged "TapLeaf" for a single-leaf tree, or "TapBranch" for a multi-leaf tree, as shown below).
[[File:bip-0360/media/merkletree.png|thumb|Construction of P2MR script tree root, scriptPubkey, and Witness]]
-To construct a P2MR output, we follow the process outlined in [[bip-0341.mediawiki|BIP 341]] to compute the final tapbranch hash, which is the merkle root of the script leaves; however, instead of tweaking the internal key with the root of the Merkle tree (as is the case with P2TR outputs), P2MR outputs commit only to final tapbranch hash, which is tagged, "TapBranch".
+To construct a P2MR output, we follow the process outlined in [[bip-0341.mediawiki|BIP 341]] to compute the Merkle root of the script tree (the tapleaf hash for a single leaf, or the final tapbranch hash for multiple leaves); however, instead of tweaking an internal key with that root (as is the case with P2TR outputs), P2MR outputs commit directly to the Merkle root.
<source>
@DagzTagz This is no different than disabled opcodes in tapscript being OP_SUCCESSx or any number of other similar features that resolve to anyone can spent. If that situation was a problem, the miners are already in this position. Single leaf = anyone can spend would not materially change things. Don't read this as an opinion on the above PR in any particular direction. I'm still putting my thoughts together. |
|
@EthanHeilman Fair point that anyone-can-spend paths already exist. The difference is how likely they are to be hit by accident. OP_SUCCESSx opcodes are reserved upgrade hooks, nonstandard under relay policy, and ordinary wallets never produce them. P2MR has no key path, so a single-leaf tree is the natural shape for a plain single-key wallet. Under #2198 that routine construction resolves to anyone-can-spend, and the coins are exposed the moment the script is revealed in a spend. That widens the set of outputs lost by mistake, which is the practical concern behind restoring script execution here (or requiring m ≥ 1 so the mistake is unspendable rather than stealable). Cross reference: @jonatack's note
Coinciding w/ OG rationale and PR announcement in "Aligning privacy incentives in P2MR" on bitcoindev vvv linked https://www.mail-archive.com/bitcoindev@googlegroups.com/msg01732.html |
|
Concept ACK |
cryptoquick
left a comment
There was a problem hiding this comment.
Thank you so much for your review, Jeremy. You make good points. I recall when this topic first came up we hadn't had enough time to consider deeply the deeper implications.
ACK, of course.
|
nACK from me for the same reason i originally submitted #2198: Depth zero script trees hurt the privacy of the network overall by providing incentive to distinguish your wallet with a single identifiable script. It would be better if everyone used at least depth 1. Not a hill i'm willing to die on though. |
|
Concept ACK, the original reasons were not super convincing to begin with. |
Then this should be a relay policy option, not in consensus. If you still want to advocate for it, please revise #2198 as a relay policy option to consider, but it should always be up to the individual node runner. |
Motivation
Originally, BIP-360 was structured as it is in this patch. It was patched to remove depth-0 to be somehow "fair" to taproot with respect to incentives based on a conversation on the dev mailing list.
However, this was a massive userland footgun because it means that any e.g. merkle tree constructing wallet code reused from taproot could accidentally make a single script into an anyonecanspend output.
While disabling 0 depth may ultimately be the right tradeoff to make, this version of BIP-360 is more straightforward, and the patch to introduce a major "non-linearity" in the consensus rules for P2MR should be had with much more conversation and awareness of the impact on wallet developers.
Further, as it is currently in the zeitgeist of the conversation to accelerate PQAI timelines, consideration to Taproot incentives seems no longer as relevant as it was a few months ago.
Summary
Verification
python3 -B p2mr.pyfrombip-0360/ref-impl/python: 7/7 construction tests and 3/3 negative structure tests pass.git diff --checkpasses.