https://github.com/Cyfrin/2024-08-MyCut/blob/946231db0fe717039429a11706717be568d03b54/src/Pot.sol#L49
The closePot()
function in the Pot.sol
contract miscalculates the claimantCut
that should be sent to all claimants when the contest manager closes the Pot.
The closePot()
function in the Pot.sol
contract uses incorrect formula to calculate the claimantCut
on closing the pot by incorrectly dividing the remaining rewards (after subtracting the managerCut) by the total number of participating players i_players.length
as the denominator instead of dividing by the actual number of claimants claimants.length
. This error results in a diluted claimant cut, causing the rewards to be unfairly distributed among those who claimed, and part of the remaining rewards will be left unused on the Pot ERC20 token balance.
Example Pot Scenario:
Number of participating players: 4
Rewards for each player: 50
Total Rewards: 200
Two players have claimed his cut. When the admin calls Pot::closePot function, the calculations will be as follows as per current implementation:
remainingRewards = 100
managerCut = remainingRewards / managerCutPercent = 100/10 = 10
claimantCut = (100-10)/4 = 22 (Rounded down from 22.5)
Each claimant will get 22 token as claimant cut, and 46 rewards will be left on the Pot ERC20 token balance due to the incorrect claimant cut calculation.
Pot rewards balance after claimant cut distribution = 46
The correct claimant cut calculation should be (100-10)/claimants.length = (100-10)/2 which should results to 45. As a result each claimant gets 45 tokens cut of the remaining rewards on closing the Pot, and each claimant should have a total token balance of (50 + 45) = 95 tokens in our example. Also the Pot ERC20 token balance should be 0 on closing the Pot if the correct formula is used
1- Unfair distribution of claimant cut: Claimants will get less claimant cut on closing put than they should get leads to unfair distribution of remaining claimant cut among all claimants.
2- Part of the remaining reward tokens are left on the Pot balance: Part of the remainingReward will be still in the pot contract ERC20 token balance since a less claimant cut has been calculated and distributed than it should have been calculated.
To demonstrate the issue, add the following test in TestMyCut.t.sol
, and execute the following command:
forge test --mt testCloseContenstClaimantCut -vv
Manual code review and Foundry
It is recommended to fix the formula inside the Pot::closePot
function used to calculate the claimantCut
when closing the Pot by dividing by the total number of claimants claimants.length
as the denominator rather than by the total number of participating players i_players.length
. This adjustment ensures that claimants receive the correct share of the remaining rewards when the contest manager closes the Pot and avoids leaving unused ERC20 tokens in the balance of the Pot contract.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.