The randomness mechanism in openBox() is predictable and can be manipulated, allowing attackers to influence the outcome of rewards.
Affected Code:
Using block.timestamp and msg.sender for randomness is insecure because:
block.timestamp: Can be influenced within a range by miders/validators.
msg.sender: Known to the attacker.
An attacker aims to win the "Gold Coin" reward (1% chance):
Preparation:
Deploys a contract to repeatedly call openBox() until they receive the desired reward.
Manipulation:
Adjusts the timing of transactions to affect block.timestamp.
Uses multiple addresses (controlled accounts) to influence msg.sender.
Execution:
Calls openBox() in rapid succession.
Monitors the randomValue outcome (if possible).
Result:
Increases chances of hitting randomValue == 99.
Successfully obtains the "Gold Coin".
This vulnerability is not directly demonstrated in the test code but can be emphasized by adding a test that shows the predictability:
By manipulating block.timestamp, we can influence randomValue.
Unfair Advantage: Attackers can manipulate outcomes to win valuable rewards.
Financial Loss: The contract may pay out more than intended.
Trust Issues: Users may distrust the fairness of the reward system.
Manual Code Analysis: Identified the insecure randomness source.
Testing with Manipulated Conditions: Used vm.warp to alter block.timestamp.
Implement secure randomness using Chainlink VRF:
note: this is an exmaple implementation of how this can be solved using chainlink VRF for secure randomness
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.