Skip to content

[Contracts] Reject create_stream when rate_per_second rounds to zero #464

@ogazboiz

Description

@ogazboiz

Join the discussion on Telegram

Why this matters

The contract intentionally allows rate_per_second == 0 (when amount < duration, integer division rounds the rate to 0 — see test_create_stream_zero_rate in contracts/stream_contract/src/test.rs). The result is a "stream" that locks the sender's tokens in the contract but never accrues anything to the recipient and can only be recovered via cancel_stream. This is almost always a user mistake (wrong decimals / too-long duration), and it is the root cause of the backend indexer division-by-zero bug. Rejecting it at creation protects users from accidentally bricking funds and removes the foot-gun.

Acceptance criteria

  • In create_stream (contracts/stream_contract/src/lib.rs), after computing rate_per_second, return a new StreamError::InvalidRate (add to contracts/stream_contract/src/errors.rs) when the rate would be 0.
  • Apply the same guard to top_up_stream if a top-up could leave the effective rate at 0 (evaluate whether needed).
  • Update test_create_stream_zero_rate to assert the call is now rejected, and add a boundary test where amount == duration (rate exactly 1) still succeeds.
  • Note the behavior change in the contract docs / changelog so the backend zero-rate guard can be simplified later.

Files to touch

  • contracts/stream_contract/src/lib.rs
  • contracts/stream_contract/src/errors.rs
  • contracts/stream_contract/src/test.rs

Out of scope

  • The backend indexer guard (tracked separately and should remain defensive regardless).

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions