[UTXO-BUG] MED-3: Float precision loss in transfer endpoint — systematic rounding errors#2072
Open
ArokyaMatthew wants to merge 1 commit intoScottcjn:mainfrom
Open
Conversation
…tic rounding errors int(amount_rtc * UNIT) uses float multiplication which truncates: int(0.1 * 100_000_000) = 9_999_999 instead of 10_000_000 Over thousands of transactions, the lost nanoRTC accumulates as implicit fee absorbed by miners. Fix: use Decimal(str(amount_rtc)) * UNIT for exact conversion. Test added: - test_transfer_float_precision (transfers 0.1 RTC, verifies exact 10_000_000 nanoRTC) All 16 endpoint tests pass. Bounty: #2819 (Medium, 50 RTC)
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
|
Important fix! Float precision issues can cause significant problems in financial systems. |
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.
Vulnerability Class
Medium — Fee calculation exploit (50 RTC bounty)
The Bug
The transfer endpoint converts RTC amounts using float multiplication:
Floating-point imprecision means:
python
Fix
Use Decimal for exact conversion:
python
from decimal import Decimal
amount_nrtc = int(Decimal(str(amount_rtc)) * UNIT)
Test Added
test_transfer_float_precision — transfers 0.1 RTC and asserts recipient gets exactly 10,000,000 nanoRTC
All 16 endpoint tests pass.
Files Changed
node/utxo_endpoints.py — 2 lines changed + Decimal import
node/test_utxo_endpoints.py — 1 test added
Ref: Bounty #2819
MY WALLET IS aroky-x86-miner