[L-1] Lack of Event Emissions in MysteryBox
Description
The MysteryBox contract does not emit any events, which limits transparency and usability for users and external interfaces. Without event logging, users cannot track important contract actions such as:
Who wins rewards from opening a mystery box.
Changes to the price of mystery boxes by the owner.
The remaining balance or rewards after claiming a single reward.
Impact
The lack of emitted events reduces the transparency of the contract’s operations. Users and off-chain systems cannot easily monitor or verify key actions like reward distribution, price changes, or balances.
Recommendation
Add event emissions for key actions, such as setting the box price, claiming rewards, and opening mystery boxes. This would improve the user experience by providing clear on-chain logs of important events.
[L-2] Missing Minimum Box Price Check in MysteryBox#buyBox()
Description
The setBoxPrice() function currently allows the owner to set the box price to any value, including 0. This could allow users to purchase mystery boxes for free, resulting in unintended behavior or exploitation.
Impact
Without a minimum price check, users could potentially exploit the contract by purchasing boxes at zero cost, leading to financial loss for the contract owner and undermining the intended value of the mystery box system.
Recommendation
Add a check in the setBoxPrice() function to ensure the price of a mystery box is always greater than zero.
By implementing this fix, the contract will prevent the owner from setting an invalid box price and ensure users always pay for the boxes.
[L-3] Missing Checks-Effects-Interactions (CEI) Pattern
Description
The MysteryBox contract does not follow the Checks-Effects-Interactions (CEI) pattern in several functions. The CEI pattern is a best practice in Solidity, as it helps prevent reentrancy attacks by updating state before external calls. Failure to implement CEI can leave the contract vulnerable to exploits.
The following functions are missing CEI checks:
claimAllRewards()
claimSingleReward()
withdrawFunds()
openBox()
Recommendation
Ensure that state changes are made before making any external calls. This can be achieved by following the CEI pattern:
Checks: Validate conditions (e.g., ownership or balance checks).
Effects: Update the contract’s internal state.
Interactions: Interact with external contracts or make transfers.
Here’s an example for fixing the claimAllRewards() 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.