The MysteryBox
contract lacks proper input validation in two key functions: addReward
and setBoxPrice
. The addReward
function does not validate the reward value or name, potentially allowing zero-value or improperly named rewards to be added. Similarly, setBoxPrice
does not implement minimum or maximum limits, which could lead to unreasonably low or high box prices. This lack of input validation could result in unexpected behavior, economic imbalances, or user frustration.
The vulnerability stems from two functions in the MysteryBox
contract:
In the addReward
function:
This function allows the owner to add new rewards without any checks on the _value
or _name
parameters. There's no validation to ensure that:
The _value
is greater than zero
The _name
is not an empty string
The _name
is unique among existing rewards
In the setBoxPrice
function:
This function allows the owner to set any price without restrictions. There are no checks to ensure that:
The price is greater than zero
The price doesn't exceed a reasonable maximum value
These lack of validations could lead to various issues, including the creation of worthless rewards, duplicate reward names, or extreme (either too low or too high) box prices.
The lack of input validation in these functions can lead to several negative consequences:
Economic Imbalance:
Zero-value rewards could be added, disappointing users who receive them.
Extremely high-value rewards could be added, potentially draining the contract of funds.
Box prices could be set to zero, allowing free acquisition, or set extremely high, deterring purchases.
User Experience:
Duplicate or empty reward names could confuse users about what they've won.
Unreasonable box prices could frustrate users and damage the project's reputation.
Contract Integrity:
A flood of worthless rewards could bloat the reward pool, potentially leading to gas limit issues in functions that iterate over all rewards.
Extreme box prices could break assumptions in other parts of the contract or in front-end applications interacting with it.
Potential for Abuse:
A malicious or compromised owner could exploit these functions to manipulate the economy of the mystery box system.
Could be used in combination with other vulnerabilities (like the unrestricted owner change) to quickly drain value from the contract.
While these issues require owner access to exploit, they represent a significant risk to the overall stability, fairness, and user trust in the mystery box system. The lack of safeguards could lead to both intentional abuse and accidental misconfigurations.
Manual review of the smart contract code
To address the lack of input validation, we recommend implementing the following changes:
For the addReward
function:
For the setBoxPrice
function:
These changes will add necessary checks to prevent the addition of invalid rewards and the setting of unreasonable box prices, thereby mitigating the risks associated with the current lack of input validation.
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.