MyCut

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

`ContestManager::fundContest` is not called instantly after `ContestManager::createContest` , making the pot unusable till it is funded

Summary

ContestManager::fundContest is not called instantly after ContestManager::createContest , making the pot unusable till it is funded

Vulnerability Details

createContest function is used to create a new contest/pot. The main functionality of the pot is that users can collect their rewards. But for this, the pot must have the necessary funds. To give the pot these funds , the owner/creater/manager must call the fundContest function after which the pot functions normally. The problem being the time after the pot is deployed but not funded . Users see their transactions getting reverted . Also the '90 day deadline' starts when the pot is created , not when it is funded. So there is no point in having 2 specific functions , rather fund the deployed contest in the same function.

Impact

Users can't claim their rewards till the pot is funded.

Proof of Concepts Here is a test which shows what happens when a pot is deployed but not funded

  1. Owner creates the pot

  2. Player tries to claim their reward but cannot.

Place this test into TestMyCut.t.sol

function test_LateFundingOfContractIsBad() public mintAndApproveTokens {
vm.startPrank(user);
contest = ContestManager(conMan).createContest(players, rewards, IERC20(ERC20Mock(weth)), 4);
// ContestManager(conMan).fundContest(0); --> DIDNT FUND
vm.stopPrank();
vm.startPrank(player1);
vm.expectRevert();
Pot(contest).claimCut();
vm.stopPrank();
}

Tools Used

Manual review , foundry tests

Recommendations

Fund the pot inside the createContest function itself and remove the fundContest completely

function createContest(address[] memory players, uint256[] memory rewards, IERC20 token, uint256 totalRewards)
public
onlyOwner
returns (address)
{
// Create a new Pot contract
Pot pot = new Pot(players, rewards, token, totalRewards);
contests.push(address(pot));
contestToTotalRewards[address(pot)] = totalRewards;
+ if (token.balanceOf(msg.sender) < totalRewards) {
+ revert ContestManager__InsufficientFunds();
+ }
+ token.transferFrom(msg.sender, address(pot), totalRewards);
return address(pot);
}
- function fundContest(uint256 index) public onlyOwner {
- Pot pot = Pot(contests[index]);
- IERC20 token = pot.getToken();
- uint256 totalRewards = contestToTotalRewards[address(pot)];
- if (token.balanceOf(msg.sender) < totalRewards) {
- revert ContestManager__InsufficientFunds();
- }
- token.transferFrom(msg.sender, address(pot), totalRewards);
}
Updates

Lead Judging Commences

equious Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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