Repository navigation
fix(consensus): handle transfer sum overflow with activation height & MN version gate - #1
Merged
heddes24 merged 8 commits intoNov 9, 2026
Conversation
AddBalances() reports Err("overflow") on overflow, but the return value was
ignored in SumAllTransfers(). The sum therefore silently stayed at the first
amount while the destination accounts were credited with the full amounts -
up to INT64_MAX (~92.2 billion DFI) of DFI created from nothing per
transaction.
SumAllTransfers() now returns ResVal<CBalances> and propagates the error.
The 12 call sites are adapted in the following commits.
Adapt the three consensus call sites of SumAllTransfers() to its new ResVal<CBalances> return type and propagate the error explicitly. The error has to be checked explicitly: ResVal has an implicit conversion operator to T, so the previous one-liners would still compile and would dereference an empty optional in release builds (see Issue 0006). - AccountToAccount: the source account is now debited with the real sum instead of a truncated one. On overflow the transaction is rejected. - AnyAccountsToAccounts: both sums are checked individually. The attacker controls both sides, so a single check would not be enough. - UtxosToAccount: unchanged behaviour, more precise error message.
Finish the adaptation of SumAllTransfers() to its ResVal<CBalances> return type. All call sites now handle the error explicitly - the error must not be ignored, otherwise the sum would silently be truncated again. Error handling follows the role of each call site: - consensus (AddPoolLiquidity): reject the transaction - account selection for masternode transfers: no selection - RPC endpoints: reject the request with the error message - decodecustomtx output: report the error instead of failing silently
SumAllTransfers() ignored the return value of AddBalances(): when the sum exceeded INT64_MAX, SafeAdd() reported "overflow" and Add() aborted before the balances were mutated - the sum silently stayed at the first amount. The source account was debited with the truncated sum while every destination was credited with the full amount. The difference was newly created DFI. The test builds the transaction raw because ParseFixedPoint() rejects amounts with more than 18 significant digits, and the destinations have to be ordered by their script bytes because CAccounts is a std::map<CScript, CBalances>. The test asserts that - the transaction is rejected with "overflow" - no DFI is created on either destination account - the control case (sum exactly INT64_MAX, no overflow) is still rejected because the source account cannot cover it Verified in both directions: fails with "No exception raised" on the unpatched code (the transaction is accepted there) and passes with the fix.
The fix from 0001 (overflow in the transfer sum) changes the consensus rule globally: the strict SumAllTransfers() rule applies implicitly from block 1. Every history in which a transfer sum overflows would therefore be invalidated - the extent of the reset would be undetermined. With an activation height: - below the height the historical behaviour (bit-exact like v4.2.5), - from that height on the strict rule. Main change: - new consensus parameter nBalanceOverflowHeight (mainnet 6564035) - SumAllTransfersLegacy() reproduces the old behaviour bit-exactly. Decisive: the loop continues after an overflow, because CBalances::Add aborts before the mutation. A break would change the historical sum and invalidate already mined blocks. - CCustomTxVisitor::SumTransfers() selects between both behaviours based on txCtx.GetHeight()/GetConsensus(). The mainnet value is measured: a scan of the range up to block 6582242 found exactly three overflowing transactions (6564035, 6565374, 6566081). Test: feature_balance_overflow_height.py covers both sides of the activation height (strict rejection / legacy acceptance with the historical balances).
From consensus.nMNVersionGateHeight on (mainnet 6564035), all mined blocks must signal the overflow-fix capability in block.nVersion (VERSION_BIT_BALANCE_OVERFLOW, bit 24). Blocks minted by outdated nodes (e.g. v4.2.5 without this bit) are rejected with 'bad-version' in ContextualCheckBlockHeader. This ensures outdated masternodes cannot mint invalid blocks or slow down block production on the updated network. Test: feature_mn_version_gate.py verifies legacy acceptance below the gate height and rejection of outdated blocks at/above the gate height.
Collaborator
Author
🔬 20-Node Heterogeneous Cluster Test Results: Masternode Version Gate VerificationTo rigorously verify the consensus safety of the Masternode Version Gate under real P2P network conditions, we conducted an automated end-to-end test on a 20-node cluster in full mesh topology. Test Configuration:
Test Phases & Observed Behavior:
Cluster Monitoring Snapshot:Conclusion:The Masternode Version Gate functions reliably under cluster conditions:
|
heddes24
marked this pull request as draft
November 9, 2026 20:22
heddes24
marked this pull request as ready for review
November 9, 2026 20:22
heddes24
marked this pull request as draft
November 9, 2026 20:22
heddes24
marked this pull request as ready for review
November 9, 2026 20:22
30 tasks
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.
Summary
CBalances::AddBalances()where summing transfer amounts could exceedint64::max(), allowing unauthorized DFI minting.nBalanceOverflowHeight(Mainnet: block 6564035) to preserve historical blockchain consensus below the activation block.nMNVersionGateHeight, Bit 24 innVersion/0x21000000) starting at the same activation height:bad-versioninContextualCheckBlockHeader.Tests & Verification
feature_account_overflow.py(verifies transfer sum overflow detection)feature_balance_overflow_height.py(verifies activation height dual-side behavior)feature_mn_version_gate.py(verifies Bit 24 version gate enforcement and legacy rejection)Flags
-balanceoverflowheight=<height>: Regtest/debug flag to configure overflow activation height.-mnversiongateheight=<height>: Regtest/debug flag to configure version gate activation height.Implications