fix(dao): add updateEpochTotalAmount to ClisBNBLaunchPoolDistributor - #124
Closed
toccata-yy-lista wants to merge 1 commit into
Closed
fix(dao): add updateEpochTotalAmount to ClisBNBLaunchPoolDistributor#124toccata-yy-lista wants to merge 1 commit into
toccata-yy-lista wants to merge 1 commit into
Conversation
An epoch whose totalAmount was configured lower than the sum of its merkle tree makes the remaining users unable to claim: `epoch.unclaimedAmount -= _amount` underflows once the shortfall is reached. Add an admin-only `updateEpochTotalAmount(epochId, totalAmount)` which adjusts totalAmount of a not-yet-ended epoch and applies the difference to `unclaimedAmount` / `totalUnclaimedAmount`, so already claimed rewards stay untouched. Decreases are capped by the unclaimed part, and the new total must be fully covered by the contract balance of the epoch token.
Pull Request ReviewThis Solidity smart contract PR adds an admin-only function to correct an active epoch’s total reward amount while preserving already-claimed rewards and updating aggregate liabilities. It also adds an update event and comprehensive Foundry tests covering increases, decreases, balance requirements, epoch state, BNB/ERC20 rewards, and access control. Sensitive ContentNo sensitive content detected. Security IssuesNo serious security issues detected. Generated by Hashdit Bot. This tool can absolutely NOT replace manual audits. |
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.
Problem
One epoch of
ClisBNBLaunchPoolDistributorwas created with atotalAmountlower than the sum of its merkle tree. Sinceclaim()does:once cumulative claims exceed the configured
totalAmount,unclaimedAmountunderflows and every remaining user's claim reverts. There was no way to correct an epoch after it started —setEpochMerkleRootonly appendsnextEpochId, andrevokeEpochrequires the epoch to not have started yet.Fix
Add an admin-only
updateEpochTotalAmount(uint64 _epochId, uint256 _totalAmount):DEFAULT_ADMIN_ROLEonly (more sensitive thansetEpochMerkleRoot, which isOPERATOR).epoch.unclaimedAmountandtotalUnclaimedAmount[token], so already-claimed amounts and theclaimedflags are untouched.unclaimedAmount("Amount already claimed"), so it can never underflow.totalUnclaimedAmount[token]— the contract must be funded before calling, otherwise it reverts with"Insufficient balance".UpdateEpochTotalAmount(epochId, token, oldTotalAmount, newTotalAmount, unclaimedAmount).No new storage variables, so the upgrade is storage-layout safe.
scripts/foundry/dao/deploy_ClisBNBLaunchPoolDistributor_impl.solalready covers the impl-only deploy.Tests
forge test --match-path test/dao/ClisBNBLaunchPoolDistributor.t.sol— 30 passed, 0 failed (16 for the new method).The main one,
test_updateEpochTotalAmount_fix_insufficient_total_amount, reproduces the incident (totalAmount1000e18vs merkle sum1737e18→ third claimer reverts), applies the fix and shows all four users claiming down to a zero balance. Also covered: event payload, multiple epochs sharing one token (totalUnclaimedAmountaggregation + balance check),collectUnclaimedafter an increase, decrease / decrease-to-claimed-boundary / decrease-below-claimed, BNB and ERC20 insufficient balance, ended epoch, revoked and unknown epochId, zero and unchanged amount, and ACL (incl.OPERATORbeing rejected).