Skip to content

Add overflow protection and fuzz tests for claimable amount calculation #331

Description

@ogazboiz

Join our community: https://t.me/+DOylgFv1jyJlNzM0

Description

get_claimable_amount() multiplies rate_per_second * elapsed_seconds in i128. For high-rate or long-duration streams this can overflow, returning an incorrect or negative value. No invariant fuzz tests exist.

What Needs to Happen

  • Replace raw multiplication with checked_mul in the contract
  • Cap at deposited_amount - withdrawn_amount on overflow
  • Apply same protection to claimable.service.ts (BigInt)
  • Add fuzz tests: withdrawn <= deposited, claimable <= remaining, cancel_refund + withdrawn <= deposited
  • 10,000+ iterations with random amounts, durations, pause sequences

Files

  • contracts/stream_contract/src/lib.rs
  • backend/src/services/claimable.service.ts

Acceptance Criteria

  • No panic for any valid i128 input
  • Fuzz test runs 10,000+ iterations without violation
  • Both contract and service protected

Activity

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

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programsecuritySecurity related taskssmart-contractSoroban smart contract

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions