Skip to content

Unchecked i128 Payout Multiplications #192

@hman38705

Description

@hman38705

Description
In high-inflation or large-pool scenarios, multiplying bet.amount * total_staked (from the planned fix in Issue 2/42) or related reward calculations could overflow i128. While i128 is massive, safe-math patterns are non-negotiable in financial smart contracts to prevent catastrophic accounting failures.

Requirements and context

  • Use checked_mul and checked_div for all payout and stake calculations.
  • Fail gracefully with clear error codes on overflow.

Suggested execution

  • Fork the repo and create a branch: git checkout -b fix/issue-89-safe-math
  • Globally refactor arithmetic in the rewards module.

Implementation changes

  • Modify bets.rs (around the payout logic) to use Soroban's safe math utilities.

Test and commit

  • Verify that extremely large pool sizes do not cause unexpected transaction failures.

Example commit message
fix: implement checked math for all pool-ratio payout calculations

Guidelines

  • Arithmetic safety.
  • Timeframe: 24 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave program

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions