Skip to content

test(btc): pin BIP141 witness-commitment merkle leaf-0 contract + SSOT helper - #574

Merged
frstrtr merged 1 commit into
masterfrom
btc/witness-commitment-merkle-ssot
Jun 28, 2026
Merged

test(btc): pin BIP141 witness-commitment merkle leaf-0 contract + SSOT helper#574
frstrtr merged 1 commit into
masterfrom
btc/witness-commitment-merkle-ssot

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 27, 2026

Copy link
Copy Markdown
Owner

What

Extracts btc::coin::witness_merkle_root() as the single source of truth for the BIP141 segwit witness-commitment merkle tree (coinbase wtxid = 32 zero bytes at leaf 0, other wtxids in block order), refactors work_source.cpp to call it (behaviour-identical), and adds witness_commitment_merkle_test.cpp.

Why

The witness-commitment merkle root was computed inline in work_source.cpp with the coinbase leaf-0 placeholder — the same contract PR #570 just fixed for the stratum txid merkle, but untested. A populated segwit block that dropped the first tx wtxid (or omitted the placeholder) is rejected bad-witness-merkle-match by bitcoind — the witness-tree analogue of the #570 bug class, latent because the pool had never connected a populated won block. Hardens the G3b POPULATED segwit path before the live re-drive.

Proof

  • 4 new KATs, flip-RED proven: removing the placeholder reds the two leaf-0 contract tests.
  • btc_share_test 39 -> 43, all green; build clean.
  • BTC-fenced (only src/impl/btc/); no cross-coin / core changes.

Held for review + operator tap — I do not self-merge.

…T helper

The segwit witness-commitment merkle root was computed inline in
work_source.cpp with the coinbase wtxid placeholder (BIP141 32 zero
bytes) at leaf 0 -- the same coinbase leaf-0 contract that PR #570 just
fixed for the stratum txid merkle, but untested. A populated segwit
block that dropped the first tx wtxid (or omitted the placeholder) would
be rejected bad-witness-merkle-match by bitcoind, the witness-tree
analogue of the #570 bug class, latent because the pool had never
connected a populated won block.

Extract btc::coin::witness_merkle_root() as the single source of truth
for the leaf-0 placeholder + ordering, refactor work_source.cpp to call
it (behaviour-identical), and add witness_commitment_merkle_test.cpp
(4 KATs, flip-RED proven: removing the placeholder reds the two leaf-0
contract tests). btc_share_test 39 -> 43, BTC-fenced.
@frstrtr
frstrtr force-pushed the btc/witness-commitment-merkle-ssot branch from 1164a40 to 91d6080 Compare June 28, 2026 01:35
@frstrtr frstrtr closed this Jun 28, 2026
@frstrtr frstrtr reopened this Jun 28, 2026
@frstrtr
frstrtr merged commit d5c3738 into master Jun 28, 2026
42 of 43 checks passed
frstrtr added a commit that referenced this pull request Jul 25, 2026
… (reconstructor slice 4/7) (#838)

Port the FRAMING half of p2pool data.py Share.as_block into
btc::coin::assemble_won_block: reconstruct the full block header from the
share's stored SmallBlockHeader + gentx txid walked up the (segwit-resolved)
merkle link via the sealed btc::check_merkle_link, frame [gentx] ++ other_txs
with the coinbase at index 0, and emit {bytes, hex} through the live BlockType
TX_WITH_WITNESS conditional codec (the NodeRPC::submit_block wire path).

BTC divergence from the DGB slice: BTC commits the BIP141 witness root inside
the coinbase at gentx-BUILD time (share_check.hpp:2166/:2296), so slices 1-3
hand this framer an already-committed gentx. It therefore does NOT re-inject a
witness commitment — doing so would mutate the coinbase, change its txid,
invalidate the share-committed header root, and open a second merkle path the
sealed merkle family (#570/#574/#579) forbids. The segwit-vs-legacy link
selection stays in the caller (slice 5); this framer takes a resolved MerkleLink.

Adds a fail-closed body/header guard: body_merkle_root folds [gentx_hash] ++ the
non-witness other-tx txids through the sealed btc::coin::compute_merkle_root and
assemble_won_block throws rather than emit a bad-txnmrklroot block. On a
template_capture miss this passes for empty-link (coinbase-only) shares and
correctly refuses the never-valid non-empty-link coinbase-only case.

Slice cut off origin/master. btc-tree-only. btc_share_test 82/82 (10 new
BtcBlockAssembly KATs, self-derived merkle branches).

Co-authored-by: frstrtr <frstrtr@users.noreply.github.com>
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.

1 participant