Skip to content

btc(#744): unpack_gentx_coinbase -- gentx bytes -> MutableTransaction codec - #822

Merged
frstrtr merged 1 commit into
masterfrom
btc/gentx-unpack-reconstruct
Jul 24, 2026
Merged

btc(#744): unpack_gentx_coinbase -- gentx bytes -> MutableTransaction codec#822
frstrtr merged 1 commit into
masterfrom
btc/gentx-unpack-reconstruct

Conversation

@frstrtr

@frstrtr frstrtr commented Jul 23, 2026

Copy link
Copy Markdown
Owner

First landed sub-slice of the faithful share->block reconstructor. The #744 dispatch handler (won_block_dispatch.hpp, merged in #820) still carries the reconstructor only as an injected std::function stub; this adds btc::coin::unpack_gentx_coinbase, the codec that turns a share's SSOT non-witness gentx (coinbase) bytes back into the {MutableTransaction, txid} that reconstruct_won_block will inject at block tx index 0.

Parses TX_NO_WITNESS (coinbase vin count 0x01, never the segwit 0x00 dummy) so the recovered tx is empty-witness and re-serializes byte-identically; the txid (SHA256d of the non-witness bytes == p2pool gentx_hash) is what the merkle_root walk consumes. Trailing bytes past a complete tx throw std::out_of_range (fail-closed).

gentx_unpack_test.cpp adds 4 KATs riding the allowlisted btc_share_test target (no build.yml change): oracle round-trip bytes-exact + txid-stable for the no-segwit and witness-commitment-first layouts, coinbase-shape sanity, trailing-byte throw. Ground-truth (bytes,txid) vectors are coin-agnostic, shared verbatim with the DGB sibling KAT. Local build: btc_share_test 72/72 green. Mirrors src/impl/dgb/coin/gentx_unpack.hpp. Per-coin isolation: src/impl/btc/ only; p2pool-merged-v36 surface: NONE.

… codec

First landed sub-slice of the faithful share->block reconstructor the #744
dispatch handler (won_block_dispatch.hpp) still carries only as an injected
std::function stub. btc::coin::unpack_gentx_coinbase turns a share's SSOT
non-witness gentx (coinbase) bytes back into the MutableTransaction + txid that
reconstruct_won_block will inject at block tx index 0.

Parsed TX_NO_WITNESS (coinbase vin count 0x01, never the segwit 0x00 dummy) so
the recovered tx is empty-witness and re-serializes byte-identically -- the txid
(SHA256d of the non-witness bytes == p2pool gentx_hash) is what the merkle_root
walk consumes, so any drift would corrupt the assembled block. Trailing bytes
past a complete tx throw std::out_of_range (fail-closed; the reconstruct closure
catches and never broadcasts a partial block).

gentx_unpack_test.cpp: 4 KATs on btc_share_test (rides the allowlisted target,
no build.yml change) -- oracle round-trip bytes-exact + txid-stable for the
no-segwit and witness-commitment-first layouts, coinbase-shape sanity, and the
trailing-byte throw. Ground-truth (bytes,txid) vectors are coin-agnostic and
shared verbatim with the DGB sibling KAT; BTC 72/72 green. Mirrors
src/impl/dgb/coin/gentx_unpack.hpp. Per-coin isolation: src/impl/btc/ only.
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