Skip to content

fix(compute_split): reject self-payouts that strand funds in the cont… - #425

Merged
chonilius merged 1 commit into
MergeFi:mainfrom
still-working-1010:fix/compute-split-self-payout-validation
Sep 28, 2026
Merged

chonilius merged 1 commit into
MergeFi:mainfrom
still-working-1010:fix/compute-split-self-payout-validation

Conversation

@Dove1010

Copy link
Copy Markdown

…ract

compute_split previously validated only that recipients is non-empty and bps values sum to exactly 10_000 — it performed no validation on the addresses themselves. This adds a dedicated SplitError::SelfPayout variant (Error::SelfPayout in both escrow and milestones) that fires when any recipient equals env.current_contract_address().

Why this case specifically: a self-transfer leaves tokens in the contract, but the escrow/milestone status is marked Paid/Released before the transfer loop runs, so release/refund are permanently blocked by the terminal status and the funds are stranded with no recovery path.

The other address-collision scenarios were audited and intentionally left unvalidated:

  • Duplicate addresses: compute_split pushes each (addr, share) pair into shares independently, and the payout loop transfers per entry, so two entries for the same address correctly produce two separate transfers summing to the full combined entitlement.
  • Treasury as recipient: the fee transfer and the recipient transfer are separate token::Client::transfer calls, so the treasury simply receives fee + share across two sequential transfers — no double-counting or loss.
  • Admin address (milestones): the admin is a plain address with no special token-receiving semantics, so it is a valid recipient like any other.

Also fixes a pre-existing missing closing brace in escrow's set_treasury that prevented the crate from compiling at all.

Tests added (7 new, all passing):

  • escrow: duplicate recipients, treasury-as-recipient, self-payout rejection
  • milestones: duplicate recipients, treasury-as-recipient, self-payout rejection, admin-as-recipient
  • common: updated fuzz tests to run inside a contract context (required by the new current_contract_address() call)

Summary

Related issues

Closes #19
Closes #8
Closes #29
Closes #28

Changes

Test plan

  • Existing tests pass (make test)
  • New tests added for changed behaviour
  • Manually verified against a local node / testnet where applicable

Checklist

  • Branch is up to date with main
  • No debug / dead code left in
  • cargo fmt and cargo clippy are clean

…ract

compute_split previously validated only that recipients is non-empty and
bps values sum to exactly 10_000 — it performed no validation on the
addresses themselves. This adds a dedicated SplitError::SelfPayout variant
(Error::SelfPayout in both escrow and milestones) that fires when any
recipient equals env.current_contract_address().

Why this case specifically: a self-transfer leaves tokens in the contract,
but the escrow/milestone status is marked Paid/Released *before* the
transfer loop runs, so release/refund are permanently blocked by the
terminal status and the funds are stranded with no recovery path.

The other address-collision scenarios were audited and intentionally left
unvalidated:
- Duplicate addresses: compute_split pushes each (addr, share) pair into
  shares independently, and the payout loop transfers per entry, so two
  entries for the same address correctly produce two separate transfers
  summing to the full combined entitlement.
- Treasury as recipient: the fee transfer and the recipient transfer are
  separate token::Client::transfer calls, so the treasury simply receives
  fee + share across two sequential transfers — no double-counting or loss.
- Admin address (milestones): the admin is a plain address with no special
  token-receiving semantics, so it is a valid recipient like any other.

Also fixes a pre-existing missing closing brace in escrow's set_treasury
that prevented the crate from compiling at all.

Tests added (7 new, all passing):
- escrow: duplicate recipients, treasury-as-recipient, self-payout rejection
- milestones: duplicate recipients, treasury-as-recipient, self-payout
  rejection, admin-as-recipient
- common: updated fuzz tests to run inside a contract context (required by
  the new current_contract_address() call)
@Dove1010
Dove1010 requested a review from chonilius as a code owner September 28, 2026 07:48
@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Sep 28, 2026

Copy link
Copy Markdown

@Dove1010 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@chonilius
chonilius merged commit dc83689 into MergeFi:main Sep 28, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment