totalRewards
variable in ContestManager::createContest
will lead to Denial of Service via underflow when a player tries to claim rewards.Description: Contest manager can create a contest via ContestManager::createContest
function. It takes in among other arguments rewards
array (it contains reward for each player) and a totalRewards
(the sum of all players' rewards). When the contest manager accidentally sends totalRewards
less than the sum of rewards
array it will lead to denial of service when a player tries to claim rewards using Pot::claimCut
which will throw an error because remainingRewards
would underflow.
Vulnerability Analysis: The vulnerability occurs at https://github.com/Cyfrin/2024-08-MyCut/blob/main/src/Pot.sol#L44
Imagine a scenario. The contest manager creates a contest with 2 players whose addresses are [a1, a2] and their corresponding rewards are [5, 12]. The sum of rewards is 17. The contest manager accidentally set totalRewards
to 13 in ContestManager::createContest
. The pot is now deployed and is online for players to interact with. Let's say players will start claiming their rewards in the following way.
When address a2 claims their rewards using Pot::claimCut
, players reward reward
is subtracted from remainingRewards
which would be 13 - 12 = 1
Now when address a1 tries to claim rewards, since remaningRewards
is 1 which is less than players reward 5, performing remainingRewards -= reward;
would underflow which results in a revert because remainingRewards
is a uint
. This underflow exception prevents a player from claiming their rewards.
Impact: Players won't be able to claim rewards assigned to them. Since players can't withdraw rewards. They cannot become claimants. This means that players loose their funds breaking the core functionality of the protocol.
Proof of code:
Paste the below code in test/TestMyCut.t.sol
Run the below test command in terminal
Which yields the below output
You will see that the test failed due to below reason
Mitigation Recommendations: validate the totalRewards parameter to make sure that it matches the sum of rewards
array. This can be done in ContestManager::createContest
function as shown below
The second way is to remove the totalRewards
function argument and populate the value in the ContestManager::createContest
function itself.
Tools used: Foundry, VSCode.
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.