flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[Contracts] Fix fee-split truncation that permanently strands dust in the contract

Open blurbeast opened this issue 2 weeks ago • 4 comments

Overview & Background

Per-recipient fee splits are computed as split_amount = total_fee * share_bps / 10_000 (truncated), and tiny shares are dropped entirely (if split_amount > 0), while the stream is credited only the full-fee remainder. The sum of split payouts can be strictly less than total_fee (e.g. 1000 split three ways at 3333 bps pays 333×3 = 999). The 1-unit difference is deducted from the stream deposit but paid to nobody — it accumulates as unaccounted tokens locked in the contract forever. Separately, splits.iter().map(|s| s.share_bps).sum() in configure_protocol_fees can panic on u32 overflow under overflow-checks instead of returning InvalidFeeSplit.


Technical Specification & Architecture

  1. In contracts/stream_contract/src/lib.rs:3046-3056, assign the division remainder (e.g. total_fee - sum(split_amounts) to the first recipient).
  2. Use checked addition when summing share_bps in configure_protocol_fees (lib.rs:176) and return InvalidFeeSplit on overflow/over-10000.
  3. Add a split-fee test asserting the sum of payouts equals total_fee exactly.

Target Files

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

Acceptance Criteria

  • [ ] Sum of fee-split payouts always equals total_fee exactly (no stranded dust).
  • [ ] Overflowing share_bps sums return InvalidFeeSplit instead of panicking.
  • [ ] Tests cover non-divisible splits (e.g. 3-way 3333 bps).

blurbeast avatar Nov 18 '26 19:11 blurbeast

@abdulqudus-dev has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

Hi, I'd like to work on this project,, please assign me this issue for a quick fix

ℹ️ Repo Maintainers: To accept this application, review their application or assign @abdulqudus-dev to this issue.

abdulqudus-dev avatar Nov 20 '26 20:11 abdulqudus-dev

@abrcrmb has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

i’ve got this boss

ℹ️ Repo Maintainers: To accept this application, review their application or assign @abrcrmb to this issue.

abrcrmb avatar Nov 21 '26 07:11 abrcrmb

Congratulations, @abrcrmb! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on November 25, 2026.

🧑‍💻 @abrcrmb: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

🌊 Happy Wave 🌊

drips-wave[bot] avatar Nov 21 '26 07:11 drips-wave[bot]

This issue has been completed by @abrcrmb as part of the Stellar Wave Program's 11th Wave 🥳

😎 @abrcrmb: You earned 200 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

drips-wave[bot] avatar Nov 21 '26 14:11 drips-wave[bot]