Root + Impact
Description
-
Describe the normal behavior in one or more sentences
-
The normal behavior should be: when a Pot is created, it immediately receives its full allocation of tokens from the creator.
-
Explain the specific issue or problem in one or more sentences
-
The Pot constructor has the critical funding line commented out, meaning newly created contests are never funded automatically.
constructor(address[] memory players, uint256[] memory rewards, IERC20 token, uint256 totalRewards) {
i_players = players;
i_rewards = rewards;
i_token = token;
i_totalRewards = totalRewards;
remainingRewards = totalRewards;
i_deployedAt = block.timestamp;
for (uint256 i = 0; i < i_players.length; i++) {
playersToRewards[i_players[i]] = i_rewards[i];
}
}
Risk
Likelihood:
Impact:
Proof of Concept
function testUnfundedPotOperation() public {
address[] memory players = new address[](3);
uint256[] memory rewards = new uint256[](3);
players[0] = alice;
players[1] = bob;
players[2] = charlie;
rewards[0] = 1000;
rewards[1] = 1000;
rewards[2] = 1000;
pot = new Pot(players, rewards, token, 3000);
assertEq(token.balanceOf(address(pot)), 0);
assertEq(pot.getRemainingRewards(), 3000);
vm.prank(alice);
pot.claimCut();
assertEq(token.balanceOf(alice), 0);
assertEq(pot.checkCut(alice), 0);
assertEq(pot.getRemainingRewards(), 2000);
vm.prank(alice);
vm.expectRevert(Pot__RewardNotFound.selector);
pot.claimCut();
}
Recommended Mitigation
- remove this code
+ add this code// Pot.sol
constructor(address[] memory players, uint256[] memory rewards, IERC20 token, uint256 totalRewards) {
i_players = players;
i_rewards = rewards;
i_token = token;
i_totalRewards = totalRewards;
remainingRewards = totalRewards;
i_deployedAt = block.timestamp;
- // i_token.transfer(address(this), i_totalRewards);
+ // Fund the pot immediately (caller must have approved tokens)
+ require(
+ i_token.transferFrom(msg.sender, address(this), i_totalRewards),
+ "Pot funding failed"
+ );
+
+ // Verify funding succeeded
+ require(
+ i_token.balanceOf(address(this)) >= i_totalRewards,
+ "Insufficient pot balance"
+ );
for (uint256 i = 0; i < i_players.length; i++) {
playersToRewards[i_players[i]] = i_rewards[i];
}
}