The refund() function does not explicitly check if playerIndex is within the bounds of the players array before accessing it. While Solidity automatically reverts on out-of-bounds access, the error message is generic and unhelpful, leading to poor user experience.
Describe the normal behavior in one or more sentences:
The function should validate that the provided playerIndex is within the valid range of the players array
If an invalid index is provided, the function should revert with a clear, descriptive error message
Explain the specific issue or problem in one or more sentences:
The function accesses players[playerIndex] without first checking if playerIndex < players.length
When an out-of-bounds index is provided, Solidity reverts with a generic error message
Users receive unclear feedback about what went wrong, making debugging difficult
Likelihood:
Reason 1: Only occurs with user error or malicious input providing invalid index
Reason 2: Solidity prevents actual security exploit through automatic bounds checking
Impact:
Impact 1: Poor error messaging confuses users when they provide invalid index
Impact 2: Slightly higher gas cost for failed transactions due to lack of early validation
Place the following test in test/AuditTest.t.sol:
Run with: forge test --mt testOutOfBoundsRefund -vv
The test passes, showing the function reverts but with a generic error message.
Add explicit bounds check with clear error message:
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.