test(core): pin compute_merkle_branches pure-tx producer/consumer contract - #579
Merged
Merged
Conversation
…tract Sibling guard to #570 (BTC stratum merkle leaf-0) + #574 (BIP141 witness leaf-0). core::MiningInterface::compute_merkle_branches is the LTC/core stratum consumer of WorkData::m_hashes and had ZERO test coverage -- the same untested merkle-branch contract class #570 arose from. Audit finding: #570 prepends its ZERO coinbase placeholder LOCALLY in the BTC-fenced consumer (get_stratum_merkle_branches), leaving the producer contract (m_hashes = pure [tx1..txN], no coinbase slot) intact. This core consumer already honours that contract (folds input[0] as tx1). No cross-coin regression from #570 -- this pins it so a future mistaken producer-side prepend goes RED on the LTC path. - new core_merkle_branches_test.cpp: leaf-0 == tx1 (not coinbase placeholder) + flip-RED ZERO-prepend tripwire + empty/single degenerate sizes. core_test 46 -> 48 green; flip-RED proven. - promote static pure helpers compute_merkle_branches/reconstruct_merkle_root to public (test-accessible; stateless, no behaviour change).
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
Flip-RED KAT pinning the LTC/core consumer of
WorkData::m_hashes—core::MiningInterface::compute_merkle_branches— which had zero test coverage (the same untested merkle-branch-contract class PR #570 arose from). Sibling guard to #570 (BTC stratum leaf-0) and #574 (BIP141 witness leaf-0).Why (audit finding — de-risks the #570 tap)
Confirmed #570 prepends its ZERO coinbase placeholder locally in the BTC-fenced consumer (
get_stratum_merkle_branches/ newbtc::coin::stratum_merkle_siblings), leaving the producer contract unchanged:m_hashes= pure[tx1..txN], no coinbase slot. This core consumer already honours that contract (foldsinput[0]as tx1). No cross-coin regression from #570. This pins it so a future mistaken producer-side prepend goes RED on the LTC path.Changes
core_merkle_branches_test.cpp: leaf-0 == tx1 (not a coinbase placeholder) + flip-RED ZERO-prepend tripwire + empty/single degenerate sizes.compute_merkle_branches/reconstruct_merkle_rootprivate→public (test-accessible; stateless, no behaviour change).Evidence
core_test46 → 48 green; flip-RED proven (injected ZERO-prepend → leaf-0 assertion FAILED, reverted → green).Scope / routing
Touches shared core (
web_server.hppvisibility +core/test) — test-only + a visibility widen, no behaviour change. Routing-flagged for integrator review. SAFE-ADDITIVE, BTC-lane-authored. Held for operator tap — I don't self-merge.