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
Description
get_claimable_amount()multipliesrate_per_second * elapsed_secondsini128. 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
checked_mulin the contractdeposited_amount - withdrawn_amounton overflowclaimable.service.ts(BigInt)withdrawn <= deposited,claimable <= remaining,cancel_refund + withdrawn <= depositedFiles
contracts/stream_contract/src/lib.rsbackend/src/services/claimable.service.tsAcceptance Criteria