test(btc): pin BIP141 witness-commitment merkle leaf-0 contract + SSOT helper - #574
Merged
Merged
Conversation
…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
force-pushed
the
btc/witness-commitment-merkle-ssot
branch
from
June 28, 2026 01:35
1164a40 to
91d6080
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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), refactorswork_source.cppto call it (behaviour-identical), and addswitness_commitment_merkle_test.cpp.Why
The witness-commitment merkle root was computed inline in
work_source.cppwith 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 rejectedbad-witness-merkle-matchby 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
btc_share_test39 -> 43, all green; build clean.src/impl/btc/); no cross-coin / core changes.Held for review + operator tap — I do not self-merge.