The constructor of the contract Pot.sol
fails to enforce a length check between the i_players and i_rewards arrays. This creates a vulnerability where an out-of-bounds error may occur if the lengths of these arrays are mismatched, leading to potential transaction reverts or incomplete initialization of the contract’s state.
In the constructor, i_players
and i_rewards
are passed as parameters and then used in a loop to initialize the playersToRewards mapping. However, the contract does not check whether the lengths of these two arrays are equal. If the arrays have different lengths, the loop may attempt to access an index in the shorter array that doesn't exist, which will cause the contract to revert due to an out-of-bounds error. Alternatively, if the players' array is shorter, some rewards might not be assigned, leaving part of the playersToRewards mapping uninitialized.
This lack of a length check can lead to unintended behavior and transaction failures during contract deployment.
Out-of-Bounds Revert: If i_players is longer than i_rewards, the contract will attempt to access an index of i_rewards that doesn't exist, causing a revert and preventing the contract from being deployed.
Incomplete State Initialization: If i_rewards is longer than i_players, the rewards may not be assigned to all players, resulting in incomplete initialization of the playersToRewards mapping.
Incorrect Data Logic: Even if no immediate revert occurs, mismatched lengths could result in incorrect reward distribution, causing incorrect associations between players and rewards.
Here’s a simplified example showing the vulnerability:
In a scenario where:
i_players.length = 3
i_rewards.length = 2
The loop will try to access i_rewards[2], which doesn't exist, causing a revert and failing the contract deployment.
Manual Analysis
To prevent this vulnerability, always check that the lengths of the i_players and i_rewards arrays are equal before proceeding with the loop.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.