MyCut

First Flight #23
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Invalid

`ContestManager::createContest` function doesn't verify totalRewards is the sum of all rewards.

Description:

totalRewards param should be equal to the sum of all rewards and there is not a check of that.

Impact:

If by error owner create a contest a totalRewards amount less than the sum of all reward some claimants won't be able to claim their cut.

Proof of Concept:

Paste next code in the TestMyCut.sol file

function testUserCantClaimCutDueToLackOfMatchingTotalRewardsCheck() mintAndApproveTokens public {
address player3 = makeAddr("player3");
vm.startPrank(user);
rewards = [20, 50, 100];
players = [player1, player2, player3];
totalRewards = 100;
contest = ContestManager(conMan).createContest(players, rewards, IERC20(ERC20Mock(weth)), totalRewards);
ContestManager(conMan).fundContest(0);
vm.stopPrank();
vm.startPrank(player1);
Pot(contest).claimCut();
vm.stopPrank();
vm.startPrank(player2);
Pot(contest).claimCut();
vm.stopPrank();
vm.startPrank(player3);
vm.expectRevert(); // Will revert due to panic: arithmetic underflow or overflow error
Pot(contest).claimCut();
vm.stopPrank();
}

Recommended Mitigation:

Add a conditional to check if totalRewards is equal to the sum of the rewards.

function createContest(address[] memory players, uint256[] memory rewards, IERC20 token, uint256 totalRewards)
public
onlyOwner
returns (address)
{
+ uint256 _totalRewards = 0;
+ for (uint256 i = 0; i < rewards.length; i++) {
+ _totalRewards += rewards[i];
+ }
+ if(_totalRewards != totalRewards){
+ revert ContestManager__WrongTotalRewards();
+ }
Pot pot = new Pot(players, rewards, token, totalRewards);
contests.push(address(pot));
contestToTotalRewards[address(pot)] = totalRewards;
return address(pot);
}
Updates

Lead Judging Commences

equious Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.