Skip to content

add coinbase_witness field to NewTemplate#198

Draft
plebhash wants to merge 1 commit into
stratum-mining:mainfrom
plebhash:2026-06-09-new-template-coinbase-witness
Draft

add coinbase_witness field to NewTemplate#198
plebhash wants to merge 1 commit into
stratum-mining:mainfrom
plebhash:2026-06-09-new-template-coinbase-witness

Conversation

@plebhash

@plebhash plebhash commented Jun 9, 2026

Copy link
Copy Markdown
Member

close #166

as discussed in #156 (TLDR: future-proofing Sv2 TDP wrt future/potential BIP141-related consensus changes)


note: this PR is similar to #15, which was opened in 2022 and closed in 2023 with pending review comments and no merging

so I'm trying to preemptively address some confusion points that were left as pending review comments on #15

- add `NewTemplate.coinbase_witness` to TDP as `B0_32`
- define conditional encoding:
  - empty when witness commitment output is omitted
  - exactly 32 bytes when witness commitment output is present
- codify BIP141 empty-block behavior (witness commitment optional)
- require clients to preserve TP-provided output ordering as
  `<client-added-outputs> || <NewTemplate.coinbase_tx_outputs>`
- clarify field purpose: serialize coinbase witness coherently with TP
  commitment output; no witness-commitment recomputation required
- update Protocol Overview BIP141 text to match the new rules
@plebhash
plebhash force-pushed the 2026-06-09-new-template-coinbase-witness branch from 5faa219 to 1bd0189 Compare June 9, 2026 15:20
@coleFD

coleFD commented Jun 12, 2026

Copy link
Copy Markdown

ack

@Sjors

Sjors commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

ACK 1bd0189

I updated stratum-mining/sv2-tp#108 to match.

How do you want to go about deploying this? It's probably safest if you first update SRI to optionally handle this extra field. I could then release a new sv2-tp version that sets the field, and note in its release notes the minimum expected SRI release.

Or we could do something more graceful like bumping a protocol number?

| coinbase_tx_value_remaining | U64 | The value, in satoshis, available for spending in coinbase outputs added by the client. Includes both transaction fees and block subsidy. |
| coinbase_tx_outputs_count | U32 | The number of transaction outputs included in coinbase_tx_outputs |
| coinbase_tx_outputs | B0_64K | Bitcoin transaction outputs to be included as the last outputs in the coinbase transaction |
| coinbase_witness | B0_32 | Coinbase witness bytes. MUST be empty if no witness commitment output is present in `coinbase_tx_outputs`; otherwise MUST contain exactly 32 bytes |

@plebhash plebhash Jun 25, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

during WG call @Fi3 is suggesting we look into potentially usingOPTION[B0_32] instead of B0_32

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no hard opinions from me nor @Fi3

just observation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That seems more clear to me.

@plebhash plebhash Jun 25, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

here's a summary of how coinbase_witness description would be worded, according to the two potential types and the two different scenarios (with vs without witness commitment):

OPTION[B0_32] B0_32
✅ WITH witness commitment "MUST NOT be empty, and MUST contain exactly 32 bytes" "MUST contain exactly 32 bytes"
❌ WITHOUT witness commitment "MUST be empty" "MUST be empty"

or as whole description sentences:

B0_32 Coinbase witness bytes. MUST be empty if no witness commitment output is present in coinbase_tx_outputs; otherwise MUST contain exactly 32 bytes
OPTION[B0_32] Coinbase witness bytes. MUST be empty if no witness commitment output is present in coinbase_tx_outputs; otherwise MUST NOT be empty, and MUST contain exactly 32 bytes

@Sjors Sjors Jun 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Saying "MUST not be empty" makes the text more confusing :-)

With OPTION[B0_32] this should be enough:

Coinbase witness bytes. MUST be empty if no witness commitment output is present in coinbase_tx_outputs; otherwise MUST contain exactly 32 bytes.

Also why not OPTION[U256] so the length is non-ambiguous?

Coinbase witness (32 bytes by consensus rules). MUST be empty if no witness commitment output is present in coinbase_tx_outputs.

@plebhash plebhash Jun 26, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

eureka I think OPTION[U256] hits the sweet spot!

it optimally forbids both edge cases without room for interpretation footguns

cc @Fi3

@average-gary

Copy link
Copy Markdown

Ack

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.

Add coinbase_witness to NewTemplate

4 participants