The MysteryBox contract allows the owner to change the price of boxes instantly using the setBoxPrice()
function. This implementation is vulnerable to front-running attacks, where users can potentially purchase boxes at a lower price just before a price increase takes effect, or avoid buying just before a price decrease.
The vulnerable code is in the setBoxPrice()
function:
The issue lies in the immediate price change:
The new price is set instantly in a single transaction.
There is no delay or timelock mechanism to prevent front-running.
The price change is visible in the transaction pool before it's confirmed.
The impact of this vulnerability is medium:
Economic Loss: The contract owner may lose potential revenue if users exploit this to buy boxes at a lower price just before an intended price increase.
User Frustration: Some users might unknowingly buy at a higher price just before a price decrease, leading to frustration and perceived unfairness.
Market Manipulation: Sophisticated users with access to real-time transaction monitoring could gain an unfair advantage.
Trust Issues: Frequent exploitation could lead to a loss of trust in the fairness of the system.
Manual code review.
To address this vulnerability, consider implementing one or more of the following solutions:
Implement a timelock mechanism for price changes:
Implement a gradual price change mechanism:
Use an oracle for price feeds to make price changes more predictable and less susceptible to manipulation.
By implementing one of these solutions, particularly the timelock mechanism, the contract can significantly reduce the risk of front-running during price changes, ensuring a fairer system for all users.
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.