A vulnerability exists in the openBox function of the contract where the randomValue used to determine rewards is predictable. The random number is generated using block.timestamp and msg.sender, both of which are public information that can be accessed by an attacker. This allows an attacker to front-run the contract and manipulate the outcome of the reward generation.
An attacker can observe the current block.timestamp.
By pre-calculating the keccak256 hash using the known msg.sender and block.timestamp, the attacker can determine the randomValue that will be generated.
Based on this, the attacker can choose the optimal time to submit a transaction to receive the most valuable reward (such as the "Gold Coin").
The following test demonstrates how the random value in the openBox function can be predicted:
Test Logs:
This vulnerability allows an attacker to manipulate the rewards in the openBox function. An attacker can repeatedly call the function at specific times to increase their chances of receiving higher-value rewards (e.g., the "Gold Coin"). This breaks the intended fairness of the reward system and could lead to a significant financial loss for the contract and its users.
Manual Review
Foundry
Use a more secure source of randomness like, Verifiable Random Function (VRF)
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.