btc(#744): unpack_gentx_coinbase -- gentx bytes -> MutableTransaction codec - #822
Merged
Conversation
… 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.
This was referenced Jul 24, 2026
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.
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.