Description:
In the claimSingleReward() function of the MysteryBox contract, the condition checking for the validity of the _index is incorrect. The current check allows out-of-bounds access to the rewardsOwned array.
In Solidity, arrays are 0-based, meaning the valid index range is from 0 to rewardsOwned[msg.sender].length - 1. The current condition require(_index <= rewardsOwned[msg.sender].length, "Invalid index"); incorrectly allows _index == rewardsOwned[msg.sender].length, which would result in out-of-bounds access.
Impact:
This could cause a runtime error due to accessing an invalid index, potentially leading to the function reverting unexpectedly and causing issues for users trying to claim rewards.
Recommendation:
Change the condition to ensure the index is strictly less than the length of the array, as the array indices range from 0 to length - 1.
This fix will ensure that only valid indices are used, preventing any out-of-bounds errors when accessing the rewardsOwned array.
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.