Skip to content

[UTXO-BUG] MED-3: Float precision loss in transfer endpoint — systematic rounding errors - #2072

Merged
Scottcjn merged 1 commit into
Scottcjn:mainfrom
ArokyaMatthew:utxo-bug/med3-float-precision-loss
Apr 5, 2026
Merged

Scottcjn merged 1 commit into
Scottcjn:mainfrom
ArokyaMatthew:utxo-bug/med3-float-precision-loss

Conversation

@ArokyaMatthew

Copy link
Copy Markdown
Contributor

Vulnerability Class

Medium — Fee calculation exploit (50 RTC bounty)

The Bug

The transfer endpoint converts RTC amounts using float multiplication:

amount_nrtc = int(amount_rtc * UNIT)  # float * int → float → int

Floating-point imprecision means:

python

int(0.1 * 100_000_000)
9999999 # WRONG — should be 10_000_000
int() truncates toward zero, so every transaction with a non-round RTC amount loses 1 nanoRTC. Over thousands of transactions, the cumulative error is non-trivial and is silently absorbed as miner fee.

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

…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: Scottcjn#2819 (Medium, 50 RTC)
@github-actions

github-actions Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Your PR has a BCOS-L1 or BCOS-L2 label
  • New code files include an SPDX license header
  • You've tested your changes against the live node

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!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related size/S PR: 11-50 lines labels Apr 5, 2026
@zhuzhushiwojia

Copy link
Copy Markdown

Important fix! Float precision issues can cause significant problems in financial systems.

@Scottcjn
Scottcjn merged commit 155d70c into Scottcjn:main Apr 5, 2026
3 checks passed
@Scottcjn

Scottcjn commented Apr 5, 2026

Copy link
Copy Markdown
Owner

✅ Merged. Good catch — #2088 fixed float truncation in the account-model endpoints, but this same bug existed independently in utxo_endpoints.py. Different file, same class of vulnerability.

40 RTC paid.

Wallet: ArokyaMatthew | Reason: bounty #2819 MED-3 float precision in utxo_endpoints.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related size/S PR: 11-50 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants