MyCut

AI First Flight #8
Beginner FriendlyFoundry
EXP
View results
Submission Details
Severity: medium
Valid

`claimCut` can be called before `fundContest` funds the pot, burning a claim against an empty balance

Description


Contest creation and funding are two separate steps: ContestManager::createContestdeploys the Pot(the commented-out transfer in the constructor confirms the Pot is NOT funded on creation), and the tokens are only moved in later via a separate ContestManager::fundContestcall. Nothing prevents a player from calling Pot::claimCutin the window before the pot is funded.


// ContestManager.createContest: deploys Pot, does NOT fund it
Pot pot = new Pot(players, rewards, token, totalRewards);
​
// Pot.claimCut: no check that the pot holds tokens yet
function claimCut() public {
uint256 reward = playersToRewards[player];
if (reward <= 0) revert Pot__RewardNotFound();
playersToRewards[player] = 0; // @> state zeroed
remainingRewards -= reward; // @> accounting decremented
claimants.push(player);
_transferReward(player, reward); // @> transfers against a possibly-empty balance
}
```
​
## Risk
​
**Likelihood: Medium**
​
- There is a real window between `createContest` and `fundContest` (they are distinct transactions, possibly separated in time). A player who knows they are in a pot can call `claimCut` during it.
​
**Impact: Medium**
​
- `claimCut` zeroes the player's `playersToRewards` and decrements `remainingRewards` **before** the transfer. If the pot is unfunded, the raw `i_token.transfer` either reverts (griefing the player) or, with the unchecked return value, silently fails — leaving the player's reward permanently burned (set to 0) while they received nothing. It also corrupts `remainingRewards` relative to the real balance, breaking later distribution. Loss of user funds.
​
## Proof of Concept
​
```solidity
// admin: createContest([A,B], [100,100], token, 200) // Pot deployed, NOT funded
// A: claimCut()
// playersToRewards[A] = 0; remainingRewards -= 100; claimants.push(A);
// i_token.transfer(A, 100) against balance 0 -> reverts, or (unchecked) silently fails
// => A's reward is zeroed with no payout; accounting now inconsistent.
```
​
## Recommended Mitigation
​
Gate claims until the pot is funded (e.g. a `funded` flag set by `fundContest`, or fund the pot atomically inside `createContest`):
​
```solidity
bool public funded;
function claimCut() public { require(funded, "not funded yet"); ... }
// set funded = true when fundContest transfers the tokens in.
```
}
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 4 hours ago
Submission Judgement Published
Validated
Assigned finding tags:

[M-02] **[L-1] users can invoke `claimCut` prior to the contest being funded**

````markdown **Description:** It is possible that once the contest has been created, it is not necessarily funded at the same time, these are separate operations, which may result in users attempting to invoke `claimCut`, however there would be no funds and we would most likely get a `ERC20InsufficientBalance` error. Users have most probably assumed that at the time of claiming their cut that the contest is funded. The more insidious issue lies in the fact that the timer of 90 days begins when the Pot contract is constructed not when it's funded, hence if the contract is not funded at the time of creation, users will not be entitled to the whole 90 day duration claim period. **Impact:** Bad UX, as users would be able to attempt claim their cut but this would result in a reversion. **Proof of Concept:** The below test can be added to `TestMyCut.t.sol:TestMyCut` contracts test suite. **Recommended Mitigation:** We must ensure the contest is funded at the time it is created. Otherwise we should state a clearer error message. In the event where we want to give the users a more gracious error message, we could add the following changes which leverages a boolean to track if the Pot has been funded: ```diff contract Pot is Ownable(msg.sender) { /** Existing Code... */ + boolean private s_isFunded; // Ensure this is updated correctly when the contract is funded. function claimCut() public { + if (!s_isFunded) { + revert Pot__InsufficientFunds(); + } address player = msg.sender; uint256 reward = playersToRewards[player]; if (reward <= 0) { revert Pot__RewardNotFound(); } playersToRewards[player] = 0; remainingRewards -= reward; claimants.push(player); _transferReward(player, reward); } } ``` In the scenario where we want to ensure the contest is funded at the time of being created employ the following code. ```diff 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; + fundContest(contests.length - 1); return address(pot); } - function fundContest(uint256 index) public onlyOwner { + function fundContest(uint256 index) internal 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); } ``` ````

Support

FAQs

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

Give us feedback!