fix(compute_split): reject self-payouts that strand funds in the cont… - #425
Merged
chonilius merged 1 commit intoSep 28, 2026
Conversation
…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)
|
Someone is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…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:
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):
Summary
Related issues
Closes #19
Closes #8
Closes #29
Closes #28
Changes
Test plan
make test)Checklist
maincargo fmtandcargo clippyare clean