Skip to content

test(core): pin compute_merkle_branches pure-tx producer/consumer contract - #579

Merged
frstrtr merged 1 commit into
masterfrom
btc/core-merkle-branch-pure-tx-pin
Jun 28, 2026
Merged

test(core): pin compute_merkle_branches pure-tx producer/consumer contract#579
frstrtr merged 1 commit into
masterfrom
btc/core-merkle-branch-pure-tx-pin

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 27, 2026

Copy link
Copy Markdown
Owner

What

Flip-RED KAT pinning the LTC/core consumer of WorkData::m_hashescore::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 / new btc::coin::stratum_merkle_siblings), leaving the producer contract unchanged: m_hashes = pure [tx1..txN], no coinbase slot. 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.

Changes

  • new core_merkle_branches_test.cpp: leaf-0 == tx1 (not a coinbase placeholder) + flip-RED ZERO-prepend tripwire + empty/single degenerate sizes.
  • promote static pure helpers compute_merkle_branches/reconstruct_merkle_root private→public (test-accessible; stateless, no behaviour change).

Evidence

  • core_test 46 → 48 green; flip-RED proven (injected ZERO-prepend → leaf-0 assertion FAILED, reverted → green).

Scope / routing

Touches shared core (web_server.hpp visibility + 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.

…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
frstrtr merged commit c562407 into master Jun 28, 2026
23 of 25 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