SegwitAddress: allow instantiation of P2A (pay-to-anchor) address #3542
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.
Hi! 🙂
Overview
As you may remember, in pullrequest #2663, I introduced a length check for the witness programs of v1 addresses, allowing only 32-byte long programs. Reviewing our discussion from back then, we decided to merge this check even though, according to BIP 341, such v1 witness programs aren’t prohibited. Instead, they produce "anyone-can-spend" outputs (per consensus rules).
Additionally spending from these outputs is disallowed by policy (non-standard), so we came to the conclusion that it probably might not make sense to instantiate such
SegwitAddress
(especially when bitcoinJ is used in the context of a client).Change in this PR
In this PR, I’ve relaxed the restriction slightly to permit one specific v1 witness program shorter than 32 bytes: the P2A (pay-to-anchor) output script.
A P2A output script is a segwit output with a witness version of
1
and a hardcoded witness program of[0x4e, 0x73]
.You can find the definition of this output type here in Bitcoin Core. Since the merge of bitcoin/bitcoin#30352 (released in 28.0) spending from this specific output script is now allowed by policy.
Rationale
Following our discussion when we introduced the taproot witness program length check in #2663, where we talked that bitcoinJ should follow policy, and the fact that spending from P2A is now allowed by policy, I allowed creation of this address.
References