The claimSingleReward function contains an incorrect index validation check. This flaw could potentially lead to out-of-bounds access, causing unexpected behavior or errors when users attempt to claim rewards.
The issue occurs in the claimSingleReward function of the smart contract. The function uses an incorrect condition to check whether the provided index _index is within bounds of the rewardsOwned array.
The issue arises from the <= comparison operator, which allows the index to be equal to the length of the array. In Solidity, arrays are zero-indexed, meaning that the valid indices for an array with n elements range from 0 to n - 1. If _index is equal to rewardsOwned[msg.sender].length, it will be out of bounds, leading to potential errors when accessing the array.
For example, if rewardsOwned[msg.sender] has a length of 3, the valid indices would be 0, 1, and 2. The current check would allow _index to be 3, which is outside the valid range and could cause a transaction failure.
Users may encounter runtime errors when attempting to claim a reward at an invalid index, disrupting the user experience.
Manual Review
To mitigate this vulnerability, the contract should use the < operator instead of <= to ensure that the index is strictly less than the length of the array. This will prevent out-of-bounds access and ensure the index is valid for array operations.
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.