Root + Impact
Description
function createContest(address[] memory players, uint256[] memory rewards, IERC20 token, uint256 totalRewards)
public
onlyOwner
returns (address)
{
Pot pot = new Pot(players, rewards, token, totalRewards);
}
for (uint256 i = 0; i < i_players.length; i++) {
playersToRewards[i_players[i]] = i_rewards[i];
}
Risk
Impact:
If rewards.length < players.length: Transaction reverts with out-of-bounds access.
If rewards.length > players.length: Extra rewards are ignored, potentially causing totalRewards mismatch.
Wrong players could receive wrong reward amounts due to index misalignment.
Proof of Concept
address[] memory players = [alice, bob, charlie];
uint256[] memory rewards = [100, 200];
address[] memory players = [alice, bob];
uint256[] memory rewards = [100, 200, 300];
Recommended Mitigation
function createContest(address[] memory players, uint256[] memory rewards, IERC20 token, uint256 totalRewards)
public
onlyOwner
returns (address)
{
require(players.length == rewards.length, "Array length mismatch");
require(players.length > 0, "Empty players array");
uint256 sum = 0;
for (uint256 i = 0; i < rewards.length; i++) {
sum += rewards[i];
}
require(sum == totalRewards, "Rewards sum mismatch");
Pot pot = new Pot(players, rewards, token, totalRewards);
}