The claimSingleReward function incorrectly validates the reward index, allowing out-of-bounds access and potential unintended behavior. Specifically, the comparison should use < instead of <=, leading to acceptance of an index equal to the array length, which is invalid.
In the MysteryBox.sol contract, the claimSingleReward function performs index validation as follows:
The condition require(_index <= rewardsOwned[msg.sender].length, "Invalid index"); allows _index to be equal to rewardsOwned[msg.sender].length, which is out of bounds. Accessing rewardsOwned[msg.sender][_index] with an index equal to the array length will cause a runtime error and revert the transaction.
This prevents users from correctly claiming specific rewards and can result in failed transactions. Users attempting to claim the last reward in the array will encounter an error due to incorrect index validation, leading to a poor user experience.
Attempting to claim a reward with an index equal to the array length will fail:
Manual code review
Correct the index validation to ensure that _index is strictly less than the array length, preventing out-of-bounds access.
Revised claimSingleReward function:
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.