Skip to content

btc(stratum): integer-exact unconditional v35 finder fee in mined-block coinbase (D2)#737

Merged
frstrtr merged 1 commit into
masterfrom
btc/finder-fee-integer-exact-d2
Jul 18, 2026
Merged

btc(stratum): integer-exact unconditional v35 finder fee in mined-block coinbase (D2)#737
frstrtr merged 1 commit into
masterfrom
btc/finder-fee-integer-exact-d2

Conversation

@frstrtr

@frstrtr frstrtr commented Jul 18, 2026

Copy link
Copy Markdown
Owner

D2 — integer-exact, unconditional v35 finder fee in the mined-block coinbase

Closes the June-audit D2 residual. The audit cited coin/work_source.cpp ~421-433; the actual live code is src/impl/btc/stratum/work_source.cpp (path moved), where the block-coinbase finder fee still computed as float coinbasevalue/200.0 and applied all-or-nothing (skipped entirely when the donation output could not cover the full fee).

Both diverge from the p2pool reference — data.py generate_transaction, verified against ~/p2pool-jtoomim@ece15b0:

amounts[finder]   += subsidy // 200          # 0.5%, integer floor, unconditional
amounts[donation] += subsidy - sum(amounts)  # residual balances to subsidy

The consensus share gentx was already integer-exact; this is only the block-coinbase path, but it is a latent satoshi-rounding divergence on the money path of a won block.

Change

  • New SSOT src/impl/btc/stratum/finder_fee.hppv35_finder_fee_split(coinbasevalue, donation_sats) = floor(coinbasevalue/200) (integer, subsidy//200), capped at the donation available so the coinbase stays balanced (total == subsidy) and no output goes negative. No float in the split.
  • work_source.cpp calls the SSOT; fee is now applied unconditionally (never all-or-nothing skipped — the cap only binds in a pathological rounding edge).
  • Base stays coinbasevalue, matching core/web_server.cpp:1888 (in p2pool subsidy = template coinbasevalue, incl. fees).

Test

finder_fee_integer_exact_test.cpp, compiled into the existing allowlisted btc_share_test target. Pins the split vs the subsidy//200 formula at round + odd coinbase values, the sub-200 zero edge, the donation cap, and a float-vs-integer divergence witness (at cbv=312500199 the old float rounds to a different satoshi than the integer floor).

Results: D2 KAT 4/4 green; full btc_share_test 50/50 (no regression).

Review -> integrator. No self-merge.

…ck coinbase (D2)

The mined-block coinbase computed the block-finder fee as a float
(coinbasevalue/200.0) and applied it only when the donation output
could cover the full amount (all-or-nothing skip). Both diverge from
the p2pool reference (data.py generate_transaction:
amounts[finder] += subsidy//200, integer floor, unconditional) and
were a latent satoshi-rounding divergence on the money path of a won
block. The consensus share gentx was already integer-exact; this makes
the block-coinbase path identical.

Extract v35_finder_fee_split() (finder_fee.hpp SSOT): floor(cbv/200),
capped at the donation available so the coinbase stays balanced
(total == subsidy) and no output goes negative. No float in the split.
Base stays coinbasevalue, matching core/web_server.cpp:1888 (p2pool
subsidy = template coinbasevalue incl. fees).

KAT finder_fee_integer_exact_test.cpp (btc_share_test): pins the split
vs the jtoomim subsidy//200 formula at round and odd coinbase values,
the sub-200 zero edge, the donation cap, and a float-vs-integer
divergence witness. 4/4 green; full btc_share_test 50/50.
@frstrtr
frstrtr merged commit 435e975 into master Jul 18, 2026
26 checks passed
@frstrtr
frstrtr deleted the btc/finder-fee-integer-exact-d2 branch July 18, 2026 09:57
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