Skip to content

Overflow/panic-DoS surface analysis of i128 arithmetic under overflow-checks = true #7

Description

@chonilius

Background / Context

Cargo.toml's [profile.release] sets overflow-checks = true and panic = "abort". This means any arithmetic overflow anywhere in the contract's arithmetic (pool.balance += amount, milestone.remaining_budget -= amount, total * fee_bps / BPS_DENOMINATOR, distributable * bps / BPS_DENOMINATOR, allocated += share, etc.) causes an immediate panic/abort — a full transaction failure, not a graceful error return. In Soroban, a panicking contract invocation fails the whole transaction, so this is effectively a denial-of-service vector against a specific escrow/milestone/pool if triggerable by an adversary rather than only by pathological legitimate use.

Problem Statement

Walk every arithmetic expression in contracts/escrow/src/lib.rs, contracts/milestones/src/lib.rs, and contracts/maintenance-pool/src/lib.rs and determine: (1) which are reachable with attacker- or sponsor-controlled inputs (amount, total_budget, repeated deposit/allocate calls accumulating toward i128::MAX), (2) whether any panic path can be triggered by someone other than the party who would be harmed by the panic (e.g., can a third party cause pool.balance += amount to overflow via a huge single deposit, bricking withdraw for the pool's legitimate maintainers, i.e., a DoS against other sponsors' funds already in the same pool)? i128::MAX is astronomically large in absolute terms, but Stellar tokens can have configurable decimals, and total_deposited/total_withdrawn are monotonically-accumulating counters that never decrease — a sufficiently long-lived, high-volume maintenance pool is a realistic path to large accumulated values worth modeling precisely, not dismissing.

Requirements

  • Produce a call-graph-level audit table: expression, file:line, operands' provenance (attacker-controlled / sponsor-controlled / accumulated-over-time), and overflow reachability verdict.
  • For any expression judged realistically reachable (even over a multi-year time horizon, given total_deposited/total_withdrawn never shrink), implement checked arithmetic (checked_add/checked_mul/checked_sub) that returns a proper Error variant instead of panicking, preserving the "no fund loss, no bricked pool" property.
  • For expressions judged unreachable, add an explicit comment justifying why, plus a test using extreme values (e.g., deposits summing near i128::MAX) proving the code behaves as expected (either succeeds correctly or fails gracefully, never panics uncontrolled).
  • Add fuzz or property tests specifically targeting arithmetic boundaries.

Acceptance Criteria

  • Full audit table delivered (as PR description/comments)
  • Checked arithmetic + new Error variants where reachable, across all three contracts
  • Boundary tests (near-i128::MAX scenarios) added to each contract's test module
  • No behavior change for realistic, non-adversarial input ranges
  • cargo test --workspace and wasm build both green

Technical Notes / Hints

  • Key accumulation points: maintenance-pool/src/lib.rs:84-87 (pool.balance += amount, pool.total_deposited += amount), milestones/src/lib.rs:110 (milestone.remaining_budget -= amount), compute_split's fee/distributable/allocated arithmetic in both escrow and milestones.
  • fee_bps is a u32 cast to i128 at multiple sites — verify the cast itself can't be a vector (it can't overflow going u32→i128, but check multiplication total * fee_bps for large total).

Difficulty Justification

Requires systematically reasoning about a panic=abort failure mode's real-world exploitability across three contracts and many call sites, distinguishing "theoretically possible with i128" from "actually reachable given realistic Stellar token decimal/volume assumptions over realistic pool lifetimes," and implementing checked-arithmetic error handling without silently changing success-path behavior anywhere.

Activity

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

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26Stellar WaveIssues in the Stellar wave programsecuritySecurity-related issuetestingTesting/QA infrastructurevery hardVery difficult task, expert-level effort required

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions