Skip to content

[SYNC-BUG] HIGH-SYNC-2: Peer sync accepts arbitrary balance increases… - #2089

Merged
Scottcjn merged 1 commit into
Scottcjn:mainfrom
ArokyaMatthew:sync-bug/high-sync2-balance-inflation
Apr 5, 2026
Merged

Scottcjn merged 1 commit into
Scottcjn:mainfrom
ArokyaMatthew:sync-bug/high-sync2-balance-inflation

Conversation

@ArokyaMatthew

Copy link
Copy Markdown
Contributor

🛡️ Vulnerability Class

High — Arbitrary wallet inflation via peer sync (100 RTC bounty)


🧠 The Bug

The sync_payload() in rustchain_sync.py has a balance conflict resolution check that only rejects sync data that would decrease a local balance.

This allows malicious peers to increase balances silently, resulting in unauthorized inflation.

❌ Before (vulnerable)

# Before (line 220): only decreases blocked
if int(local_row[0]) > int(sanitized[candidate_balance_col]):
    self.logger.warning("Rejected sync: Balance reduction")
    continue

# increases fall through → wallet inflation

⚔️ Attack Vector

A compromised peer can send a manipulated sync payload:

# Compromised peer sends sync payload:
sync_payload = [{"miner_id": "victim_wallet", "amount_s64": 999000000}]

# Result: victim's balance silently increased from 5 RTC to 999 RTC

💥 Impact
Any peer node can inflate any wallet to arbitrary values
Breaks financial integrity of the system
No authentication or authority required
✅ Fix

Reject ALL balance modifications (both increases AND decreases) for wallets that already exist locally.

Allow sync only for:

New wallets (initial propagation)
Non-financial metadata
✔️ After (fixed)

# After: any difference is rejected
if remote_val != local_val:
    self.logger.warning(f"Rejected sync: Balance modification for {pk}")
    continue

Files Changed
node/rustchain_sync.py — reject all balance modifications from peers
node/test_sync_balance_inflation.py — NEW test file (4 tests)
Wallet: aroky-x86-miner

… — wallet inflation

apply_sync_payload() for the 'balances' table only rejects sync data
that would DECREASE a local balance, but accepts any INCREASE. A
compromised peer node can sync a fabricated row setting any wallet
to any value (e.g. miner-alice: 999,000,000 µRTC).
Balances are authoritative state that must only change through local
transaction processing (rewards, transfers, epoch settlements), never
via peer sync.
Fix: Reject ALL balance modifications (increases AND decreases) from
peer sync for wallets that already have a local row. New wallets
(no local row) can still be created via sync for initial propagation.
Tests added (new file test_sync_balance_inflation.py):
- test_balance_increase_rejected (demonstrates the bug)
- test_balance_decrease_still_rejected (existing protection)
- test_new_wallet_from_sync_allowed (non-regression)
- test_unchanged_balance_passes (identical sync is a no-op)
All 4 tests pass.
Bounty: Scottcjn#2819 (High, 100 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/M PR: 51-200 lines labels Apr 5, 2026
@Scottcjn

Scottcjn commented Apr 5, 2026

Copy link
Copy Markdown
Owner

Excellent find. The old code only rejected balance decreases from peers — a compromised node could inflate any wallet by syncing a higher value. Your fix correctly blocks ALL balance modifications via sync (both up and down), while still allowing new wallet creation for initial propagation.

The test suite is thorough: covers inflation, decrease, new wallet, and no-op cases.

Payment: 75 RTC (balance inflation via peer sync, high severity — single compromised node could mint arbitrary funds)

Merging.

@Scottcjn
Scottcjn merged commit 1e3f1cd into Scottcjn:main Apr 5, 2026
3 checks passed
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/M PR: 51-200 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants