policy: make unstructured Taproot annexes standard #36466

Open
RobinLinus wants to merge 4 commits from policy-unstructured-annex into master AGit
RobinLinus commented 2026-10-08 07:23:31 +00:00 (Migrated from github.com)

Make Taproot annexes standard for key and script paths:

  • 0x50: marker-only opt-in.
  • 0x50 0x00 <data>: arbitrary data; other prefixes remain nonstandard.
  • All non-P2A inputs must carry an annex, or none may. P2A witnesses must be empty.

No annex-specific size limit; the existing 400,000 WU standard transaction limit applies.

This opt-in rule protects transactions that do not opt in. It does not prevent annex inflation by opted-in participants. Consensus and witness replacement are unchanged.

Builds on #27926 and Libre Relay.

Validation: full build, 17 transaction unit tests, full feature_taproot.py, and git diff --check passed.

AI-assisted implementation and tests.

Make Taproot annexes standard for key and script paths: - `0x50`: marker-only opt-in. - `0x50 0x00 <data>`: arbitrary data; other prefixes remain nonstandard. - All non-P2A inputs must carry an annex, or none may. P2A witnesses must be empty. No annex-specific size limit; the existing 400,000 WU standard transaction limit applies. This opt-in rule protects transactions that do not opt in. It does not prevent annex inflation by opted-in participants. Consensus and witness replacement are unchanged. Builds on #27926 and [Libre Relay](https://github.com/petertodd/bitcoin/commit/04c8e449a34e74e048bf5751d13592a22763ff7e). Validation: full build, 17 transaction unit tests, full `feature_taproot.py`, and `git diff --check` passed. AI-assisted implementation and tests.
DrahtBot commented 2026-10-08 07:23:41 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK petertodd
Concept ACK Rob1Ham

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36918 (Witness stacks in serialized form (optimization follow-ups) by sipa)
  • #36909 (kernel: add btck_witness_stack_get_items by pzafonte)
  • #36895 (Keep witness stacks in serialized form in CScriptWitness by sipa)
  • #36794 (test: make script_combineSigs and spends_witness_prog cases independent by alexanderwiederin)
  • #36455 (Test: Add legacy script edge case spender test by benthecarman)
  • #36122 (BIP460: CISA for Taproot key path spends by fjahr)
  • #29491 ([EXPERIMENTAL] Schnorr batch verification for blocks by fjahr)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36466 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36466.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36466#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [petertodd](https://github.com/bitcoin/bitcoin/pull/36466#issuecomment-6129681032) | | Concept ACK | [Rob1Ham](https://github.com/bitcoin/bitcoin/pull/36466#issuecomment-6390126363) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36918](https://github.com/bitcoin/bitcoin/pull/36918) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36918.svg"></sub> (Witness stacks in serialized form (optimization follow-ups) by sipa) * [#36909](https://github.com/bitcoin/bitcoin/pull/36909) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36909.svg"></sub> (kernel: add btck_witness_stack_get_items by pzafonte) * [#36895](https://github.com/bitcoin/bitcoin/pull/36895) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36895.svg"></sub> (Keep witness stacks in serialized form in CScriptWitness by sipa) * [#36794](https://github.com/bitcoin/bitcoin/pull/36794) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36794.svg"></sub> (test: make script_combineSigs and spends_witness_prog cases independent by alexanderwiederin) * [#36455](https://github.com/bitcoin/bitcoin/pull/36455) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36455.svg"></sub> (Test: Add legacy script edge case spender test by benthecarman) * [#36122](https://github.com/bitcoin/bitcoin/pull/36122) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36122.svg"></sub> (BIP460: CISA for Taproot key path spends by fjahr) * [#29491](https://github.com/bitcoin/bitcoin/pull/29491) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/29491.svg"></sub> ([EXPERIMENTAL] Schnorr batch verification for blocks by fjahr) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🟠 Minor · Signature-less Taproot annexes permit third-party inflation

For opted-in transactions spending a signature-less tapscript leaf, a relayer can race a larger, lower-feerate, same-txid variant into mempools, subject to admission limits.

Location: src/policy/policy.cpp:338 (head).

🔵 Suggestion · Annex relay-policy change has no release note

This PR changes default annex relay policy but includes no release note for the accepted encodings and transaction-wide opt-in rule.

Location: src/policy/policy.cpp:333 (head).

🔵 Suggestion · Anchor-stuffing test initializes the same witness twice

The pre-loop assignment to input 0's witness is overwritten before any assertion, so it adds redundant setup to the unit test.

Location: src/test/transaction_tests.cpp:1364 (head).

🔵 Suggestion · Clarify why annex payloads remain unbounded

policy.cpp:338 checks only the prefix. One annex can use nearly the whole 400,000-WU budget (test at 1379-1384), which exposes opted-in participants to large inflation. The PR gives no stated payload requirement explaining why it drops #27926's 256-byte cap.

Location: src/policy/policy.cpp:335 (head).

Review coverage was incomplete.


Reviewed: b4179ad2fb61 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:8541d3fafd3ea45d3ad824914bf78a806527457ae4801671a2c4a580beddb288:1e657457416e20a18d8d2d136919c48e28e1bfed7a76c26939ab1ca10a232c6a --> <!-- ralph-base:ab7e668cc6af5d716ad40166d1f88235a2f6d25d --> <!-- ralph-head:b4179ad2fb6154a4e93f46389cca00b6926fbd2f --> <!-- ralph-case:2212a884589fef4eba7889636ae06d6d2f00a63f0eeb337f7d90c3a3cd377f0a --> **🟠 Minor · Signature-less Taproot annexes permit third-party inflation** For opted-in transactions spending a signature-less tapscript leaf, a relayer can race a larger, lower-feerate, same-txid variant into mempools, subject to admission limits. Location: [`src/policy/policy.cpp:338`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/b4179ad2fb6154a4e93f46389cca00b6926fbd2f/src/policy/policy.cpp#L338>) (head). **🔵 Suggestion · Annex relay-policy change has no release note** This PR changes default annex relay policy but includes no release note for the accepted encodings and transaction-wide opt-in rule. Location: [`src/policy/policy.cpp:333`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/b4179ad2fb6154a4e93f46389cca00b6926fbd2f/src/policy/policy.cpp#L333>) (head). **🔵 Suggestion · Anchor-stuffing test initializes the same witness twice** The pre-loop assignment to input 0's witness is overwritten before any assertion, so it adds redundant setup to the unit test. Location: [`src/test/transaction_tests.cpp:1364`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/b4179ad2fb6154a4e93f46389cca00b6926fbd2f/src/test/transaction_tests.cpp#L1364>) (head). **🔵 Suggestion · Clarify why annex payloads remain unbounded** policy.cpp:338 checks only the prefix. One annex can use nearly the whole 400,000-WU budget (test at 1379-1384), which exposes opted-in participants to large inflation. The PR gives no stated payload requirement explaining why it drops #27926's 256-byte cap. Location: [`src/policy/policy.cpp:335`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/b4179ad2fb6154a4e93f46389cca00b6926fbd2f/src/policy/policy.cpp#L335>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`b4179ad2fb61`](<https://git.fish.foo/bitcoin/bitcoin/commit/b4179ad2fb6154a4e93f46389cca00b6926fbd2f>) · [Full review report](<https://review.fish.foo/traces/36466-b4179ad2fb6154a4e93f46389cca00b6926fbd2f-1888-8.html>) · [Previous reports](<https://review.fish.foo/traces/36466/>) [permalink](<https://review.fish.foo/traces/36466-b4179ad2fb6154a4e93f46389cca00b6926fbd2f-1888-8.html>)
petertodd commented 2026-10-08 10:07:16 +00:00 (Migrated from github.com)

All inputs must carry an annex, or none may.

We should exclude spends of P2A outputs here, as they can't contain an annex.

> All inputs must carry an annex, or none may. We should exclude spends of P2A outputs here, as they can't contain an annex.
RobinLinus commented 2026-10-08 10:52:34 +00:00 (Migrated from github.com)

@petertodd Thanks, fixed in bb6ccd0. Native P2A inputs are exempt; their witnesses must remain empty.

@petertodd Thanks, fixed in bb6ccd0. Native P2A inputs are exempt; their witnesses must remain empty.
petertodd (Migrated from github.com) reviewed 2026-10-08 11:00:14 +00:00
petertodd (Migrated from github.com) commented 2026-10-08 11:00:15 +00:00

You should re-add the "witness stuffing detected" comment here to explain what this line is doing.

You should re-add the "witness stuffing detected" comment here to explain what this line is doing.
petertodd (Migrated from github.com) reviewed 2026-10-08 11:00:56 +00:00
petertodd (Migrated from github.com) commented 2026-10-08 11:00:56 +00:00

...and the comment about P2A inputs and the annex probably makes more sense here.

...and the comment about P2A inputs and the annex probably makes more sense here.
petertodd (Migrated from github.com) reviewed 2026-10-08 11:03:14 +00:00
petertodd (Migrated from github.com) commented 2026-10-08 11:03:14 +00:00

I'm confused by this fragment. It doesn't look like it's related to the annex stuff at all. Rather it's just skipping further checks if scriptWitness is empty.

I'm confused by this fragment. It doesn't look like it's related to the annex stuff at all. Rather it's just skipping further checks if scriptWitness is empty.
petertodd (Migrated from github.com) reviewed 2026-10-08 11:04:13 +00:00
petertodd (Migrated from github.com) commented 2026-10-08 11:04:13 +00:00

It'd be more clear to say that "Annexes must be zero-length, or start with the unstructured data prefix, 0x00"

It'd be more clear to say that "Annexes must be zero-length, or start with the unstructured data prefix, 0x00"
petertodd (Migrated from github.com) reviewed 2026-10-08 11:07:26 +00:00
petertodd (Migrated from github.com) commented 2026-10-08 11:07:26 +00:00

We should explain why the unstructured marker is being used here: 0x00 is reserved, so that future consensus-related usage of the annex can use a different prefix (quite possibly an entire encoding scheme).

We should explain why the unstructured marker is being used here: 0x00 is reserved, so that future consensus-related usage of the annex can use a different prefix (quite possibly an entire encoding scheme).
petertodd (Migrated from github.com) reviewed 2026-10-08 11:09:23 +00:00
petertodd (Migrated from github.com) commented 2026-10-08 11:09:24 +00:00

You should use the term "transaction pinning attack" here, so people have something to google.

You should use the term "transaction pinning attack" here, so people have something to google.
RobinLinus commented 2026-10-08 18:15:36 +00:00 (Migrated from github.com)

@petertodd Thanks, addressed in b4179ad. The empty-witness check moved below P2A handling so anchors are counted before the early continue.

@petertodd Thanks, addressed in b4179ad. The empty-witness check moved below P2A handling so anchors are counted before the early `continue`.
petertodd commented 2026-10-12 17:55:36 +00:00 (Migrated from github.com)

utACK b4179ad2fb

utACK b4179ad2fb6154a4e93f46389cca00b6926fbd2f
sipa commented 2026-10-20 10:24:26 +00:00 (Migrated from github.com)

What is the purpose of this? I was imagining that annex standardness would be added at the same time consensus-relevant meaning would be given to annexes.

Of course, if there were active use of annexes on the network it would be useful to accommodate relay, but as of now I don't see the point.

What is the purpose of this? I was imagining that annex standardness would be added at the same time consensus-relevant meaning would be given to annexes. Of course, if there were active use of annexes on the network it would be useful to accommodate relay, but as of now I don't see the point.
RobinLinus commented 2026-10-22 03:39:05 +00:00 (Migrated from github.com)

@sipa The motivation is data availability for metaprotocols, including a range of shielded protocols such as Shielded CSV.

Annexes would let these protocols publish data directly in a Taproot key-path spend, avoiding the script-path commitment and reveal required by inscription-style encoding.

The motivation for enabling relay now is to support these applications. They need data availability independently of future consensus semantics for the annex; the proposed 0x00 prefix distinguishes this unstructured use from future extensions.

Standard relay would also let these applications reach miners through the public P2P network, reducing the incentive to build private mempools or depend on arrangements with individual mining pools.

@sipa The motivation is data availability for metaprotocols, including a range of shielded protocols such as [Shielded CSV](https://github.com/ShieldedCSV/ShieldedCSV). Annexes would let these protocols publish data directly in a Taproot key-path spend, avoiding the script-path commitment and reveal required by inscription-style encoding. The motivation for enabling relay now is to support these applications. They need data availability independently of future consensus semantics for the annex; the proposed `0x00` prefix distinguishes this unstructured use from future extensions. Standard relay would also let these applications reach miners through the public P2P network, reducing the incentive to build private mempools or depend on arrangements with individual mining pools.
Rob1Ham commented 2026-10-24 22:07:00 +00:00 (Migrated from github.com)

ACK

ACK
AndreaDiazCorreia (Migrated from github.com) reviewed 2026-11-25 05:04:56 +00:00
AndreaDiazCorreia (Migrated from github.com) left a comment

I tested this on b4179ad2fb, the unit and functional tests pass, and they fail with master's policy.cpp. I also changed the policy code in 7 ways (no P2A exemption, no opt-in rule, no prefix check, empty-witness skip before the P2A check, etc.) and annex_standardness catches all of them.

A tx with one 399,580-byte annex (exactly 400,000 WU) is accepted, also by a node with -datacarrier=0. #27926 had a 256-byte limit. Why remove it? Should node operators have an option to turn off annex relay?

I tested this on b4179ad2fb6154a4e93f46389cca00b6926fbd2f, the unit and functional tests pass, and they fail with master's `policy.cpp`. I also changed the policy code in 7 ways (no P2A exemption, no opt-in rule, no prefix check, empty-witness skip before the P2A check, etc.) and `annex_standardness` catches all of them. A tx with one 399,580-byte annex (exactly 400,000 WU) is accepted, also by a node with `-datacarrier=0`. #27926 had a 256-byte limit. Why remove it? Should node operators have an option to turn off annex relay?
DrahtBot commented 2026-11-26 17:40:51 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36466
No description provided.