The contract contains a vulnerability in its random number generation mechanism, allowing players to predict and manipulate the outcomes of box openings. This vulnerability can be exploited to consistently obtain high-value rewards, undermining the fairness of the system and potentially draining the contract of valuable assets.
The vulnerability exists in the openBox function:
The random number generation relies on block.timestamp and msg.sender, both of which can be predicted or manipulated by players. This allows malicious players to calculate the exact moment when opening a box will result in the highest value rewards.
The randomness of reward distribution is compromised allowing malicious players to obtain high-value rewards consistently.
The protocol could rapidly lose its high-value assets.
Regular users may lose trust in the system upon discovering the unfair advantage held by exploiters.
A malicious player can create an exploit contract as following:
Let’s consider the following:
Player buys 5 boxes for 0.5 ETH (~$1314.54 at the time of writing this)
Gold Coin = 0.5 ether | Silver Coin = 0.25 ether
Attacker deploys the ExploitContract with the address of the target MysteryBox contract.
calls buyBoxes() to purchase 5 mystery boxes. Total spent so far = 0.5 ETH ($1314.54) plus fees to deploy the contract
Repeatedly calls openBoxAtRightTime() until probeOutcome() returns ≥ 95 or 99. This may be Gas inefficient since openBoxAtRightTime() has a while loop, but the gains from the attack will cover the costs and yield profit.
While testing this on Remix, Player was able to obtain 5 Silver coins:
The attacker now can withdraw the high-value rewards using withdrawRewards()
Total rewards value = 2.5 ether ~$6572.69
Total profit = 6572 - 1314 = 5,258 (Not including fees)
Manual Review
Remix IDE
Use a secure source of randomness, such as Chainlink VRF.
https://docs.chain.link/vrf/v2/subscription/examples/get-a-random-number
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.