fix(circle): reject zero-net payouts in trigger_payout - #186
Open
fridaypetra55-afk wants to merge 1 commit into
Open
fix(circle): reject zero-net payouts in trigger_payout#186fridaypetra55-afk wants to merge 1 commit into
fridaypetra55-afk wants to merge 1 commit into
Conversation
If fees consume the entire contribution pool (e.g. a small contribution_amount combined with a high fee_bps), trigger_payout would previously transfer 0 tokens, still emit a PayoutExecuted event, and advance current_round — wasting gas and leaving a misleading audit trail. trigger_payout now rejects with the new CircleError::ZeroPayoutAmount before any state changes or transfers happen if net <= 0. Also fixes a pre-existing, unrelated compile break in this same file: 15 call sites wrote the bare `Ok()` instead of `Ok(())` for a Result<(), CircleError> return type, so packages/circle currently fails to build on master at all (confirmed on a clean checkout of upstream/master). This needed to be fixed for this file to compile and for the new test to run. Closes cocor-tech#117
|
@fridaypetra55-afk 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.
Summary
trigger_payoutcomputednet/feeviamath::apply_fee(pool, fee_bps)but never checked whethernetcame out to zero. If fees consume the whole pool (smallcontribution_amount+ highfee_bps), the function would still transfer 0 tokens, emit aPayoutExecutedevent, advancecurrent_round, and possibly mark the circleSTATUS_COMPLETED— wasted gas and a misleading audit trail for something that didn't actually pay anyone out.CircleError::ZeroPayoutAmountand anet <= 0check right afterapply_fee, before any transfers or state mutation occur.test_trigger_payout_rejects_zero_net_amount, which setsfee_bpsto 10000 (100%) so the whole pool is fee, and assertstrigger_payoutnow fails withZeroPayoutAmountinstead of silently no-op-succeeding.Note on a pre-existing, unrelated build break
packages/circle/src/contract.rscurrently fails to compile onmaster— confirmed on a clean checkout ofupstream/masterbefore any of my changes. 15 functions withResult<(), CircleError>return type end their body with the bareOk()instead ofOk(()), which doesn't compile (Okis a 1-argument tuple variant). I fixed all 15 occurrences in this PR since I have to touch this file anyway and couldn't otherwise build or test my change. This appears to have gone unnoticed because the CI workflow (.github/workflows/*.yml) triggers onbranches: ["main"], but the repo's default branch ismaster— socargo test --workspacehas not actually been running in CI.cargo build -p circleandcargo test -p circleboth pass locally after this change (6/6 tests, including the new one).Closes #117