Join our community: https://t.me/+DOylgFv1jyJlNzM0
Description
get_claimable_amount() multiplies rate_per_second * elapsed_seconds in i128. For very high-rate or long-duration streams this multiplication can overflow, returning a negative or incorrect value with no panic.
What Needs to Happen
- Replace raw
* with checked_mul in the claimable calculation
- On overflow: cap at
deposited_amount - withdrawn_amount
- Apply the same protection to
claimable.service.ts in the backend (BigInt arithmetic)
- Add test:
test_claimable_near_max_i128_no_overflow
- Add test:
test_claimable_always_capped_at_remaining_balance
Files
contracts/stream_contract/src/lib.rs (get_claimable_amount)
backend/src/services/claimable.service.ts
Acceptance Criteria
Description
get_claimable_amount()multipliesrate_per_second * elapsed_secondsini128. For very high-rate or long-duration streams this multiplication can overflow, returning a negative or incorrect value with no panic.What Needs to Happen
*withchecked_mulin the claimable calculationdeposited_amount - withdrawn_amountclaimable.service.tsin the backend (BigInt arithmetic)test_claimable_near_max_i128_no_overflowtest_claimable_always_capped_at_remaining_balanceFiles
contracts/stream_contract/src/lib.rs(get_claimable_amount)backend/src/services/claimable.service.tsAcceptance Criteria