test(amount): fix GetFeeTest int64 overflow causing 318-failure cascade#444
Open
JSanchezFDZ wants to merge 1 commit into
Open
test(amount): fix GetFeeTest int64 overflow causing 318-failure cascade#444JSanchezFDZ wants to merge 1 commit into
JSanchezFDZ wants to merge 1 commit into
Conversation
The `CFeeRate(MAX_MONEY, std::numeric_limits<size_t>::max() >> 1)` call inherited from Bitcoin/Dash overflows int64_t inside `CFeeRate`'s two-arg constructor on Raptoreum because Raptoreum's MAX_MONEY (21B * COIN = 2.1e18) is 1000x larger than Bitcoin's. The constructor computes `nFeePaid * 1000`, yielding 2.1e21 which overflows signed 64-bit (max ~9.2e18). Under signed-overflow sanitizers / `-ftrapv` (and recent GCC/glibc builds), the overflow aborts the process via SIGABRT. Boost.test catches the signal but unwinds without running BasicTestingSetup's destructor, so `ECC_Stop` is never called. The next test case's fixture constructor then trips `assert(secp256k1_context_sign == nullptr)` in `ECC_Start()`, and every subsequent case cascades into the same assertion. Locally this turns one abort in amount_tests into 318 follow-on failures across the suite. Switching the boundary case to OLD_MAX_MONEY (== Bitcoin's MAX_MONEY, 2.1e15) preserves the original test intent -- "Maximum size in bytes, should not crash" -- without triggering UB. The 1000x bump to MAX_MONEY predated this test; this is just catching up. After the fix the full Boost test suite passes (362/362 cases).
This was referenced May 12, 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.
Summary
amount_tests/GetFeeTestaborts in currentdevelopbecause the final boundary check feeds Raptoreum'sMAX_MONEY(21B * COIN = 2.1e18) intoCFeeRate's two-arg constructor. The constructor multiplies by 1000 internally, producing 2.1e21, which overflowsint64_t(max ~9.2e18). On modern toolchains the signed-overflow trap raisesSIGABRT, Boost.test catches the signal but unwinds without runningBasicTestingSetup's destructor, soECC_Stop()is never called. Every subsequent test case's fixture constructor then tripsassert(secp256k1_context_sign == nullptr)insideECC_Start(), cascading into hundreds of follow-on failures.The test was inherited verbatim from Bitcoin/Dash, where
MAX_MONEYis 21M * COIN (1000x smaller) andMAX_MONEY * 1000fits comfortably inint64_t. The 1000x bump to Raptoreum's cap predated this test; the boundary case just never got revisited.Fix: use
OLD_MAX_MONEY(= 21M * COIN, the Bitcoin-equivalent value already defined inamount.h) for that one line. The test still exercises the same "hugenBytes, should not crash" code path it always did, without triggering UB.Before
After
Why this matters
The cascade hides every other regression in the suite. Once
amount_testsaborts, anyone running the unit tests sees a sea of "secp256k1 context already initialised" assertions and can't tell whether unrelated suites pass or fail. This is the kind of test infrastructure bug that quietly degrades the signal of CI over time.Confirmed locally on
develop(commit 989ec2e) inside the project'sdepends/-based Ubuntu 22.04 + GCC 11.4 build environment.Test plan
test/test_raptoreumagainstdevelopHEAD with the patch../src/test/test_raptoreum --run_test=amount_tests: 4/4 cases pass../src/test/test_raptoreum: 362/362 cases pass (UTF-8 locale; without itfs_tests/fsbridge_fstreamfails on a separate locale-related issue, unrelated to this change).Note for reviewers
This is the minimal localized fix. The deeper question -- whether
CFeeRateshould be hardened to accept fee amounts up to Raptoreum's fullMAX_MONEYwithout overflowing -- is a wider design conversation (e.g. switch internal arithmetic to__int128orboost::multiprecision::int128_t, similar to howCAmount128is already used elsewhere in the codebase for asset balances). I'd be happy to open a separate issue for that if you'd like, but felt the boundary-case test fix should land independently so the suite stops hiding other regressions in the meantime.