Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SegwitAddress: allow instantiation of P2A (pay-to-anchor) address #3542

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johnzweng
Copy link
Contributor

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

Copy link
Member

@schildbach schildbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@schildbach schildbach added this to the 0.17 milestone Nov 8, 2024
@johnzweng
Copy link
Contributor Author

Thank you for looking into it so quickly.

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.

2 participants