Skip to content

[BRIDGE-BUG] CRIT-BRIDGE-1: Float truncation in bridge transfer amount conversion - #2091

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

Scottcjn merged 1 commit into
Scottcjn:mainfrom
ArokyaMatthew:bridge-bug/float-precision

Conversation

@ArokyaMatthew

Copy link
Copy Markdown
Contributor

Vulnerability Class

Critical — Float truncation in cross-chain bridge (200 RTC bounty)

The Bug

create_bridge_transfer() line 280:

amount_i64 = int(request.amount_rtc * BRIDGE_UNIT)

Same IEEE 754 truncation as CRIT-TX-1: int(2.01 * 1000000) = 2009999.

Both bridge_transfers and lock_ledger store the wrong amount.

Fix: int(Decimal(str(request.amount_rtc)) * BRIDGE_UNIT)

All 3 tests pass.

Files Changed
node/bridge_api.py — Decimal conversion + import
node/test_bridge_precision.py — NEW (3 tests)
Wallet: aroky-x86-miner

…t conversion

create_bridge_transfer() uses int(request.amount_rtc * BRIDGE_UNIT)
which truncates for non-round amounts — same as CRIT-TX-1.
Example: 2.01 RTC bridge deposit records 2009999 uRTC instead of
2010000. The lock_ledger and bridge_transfers tables both store
the wrong amount, causing a 1 uRTC discrepancy per affected transfer.
Fix: Use Decimal(str(amount)) * BRIDGE_UNIT for exact conversion.
Tests added (new file test_bridge_precision.py):
- test_float_truncation_exists
- test_decimal_is_exact
- test_bridge_amounts_exact
All 3 tests pass.
Bounty: Scottcjn#2819 (Critical, 200 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
@Scottcjn

Scottcjn commented Apr 5, 2026

Copy link
Copy Markdown
Owner

Solid. int(2.01 * 1_000_000) = 2009999 is a classic Python float precision trap. Decimal conversion is the correct fix for financial amounts crossing the bridge. Test proves the bug and the fix.

Payment: 50 RTC (bridge fund precision, high severity — real money at stake on cross-chain transfers)

Merging.

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.

2 participants