Description: The openBox function in the Mysterybox contract uses an insecure method for generating random numbers by hashing the block.timestamp and the sender’s address (keccak256(abi.encodePacked(block.timestamp, msg.sender))). This approach allows miners or users to manipulate the outcome by controlling the block.timestamp or making multiple contract calls until the desired result is achieved. Since block.timestamps are predictable and can be influenced by miners within a certain range, this introduces a significant vulnerability to the randomness mechanism.
Impact:
Predictable Outcomes: Users or miners can predict or manipulate the random number generated in the openBox function, leading to unfair rewards distribution.
Exploitation for Higher Rewards: A malicious user can repeatedly attempt to open boxes at specific times or under specific conditions, increasing their chances of receiving rare rewards like "Gold Coin" or "Silver Coin".
Proof of Concept:
A user can observe the block.timestamp and call the openBox function repeatedly, leveraging the predictable nature of the random number generation.
A miner can influence the block.timestamp to increase their chances of receiving higher-tier rewards by adjusting the block's timestamp to force favorable outcomes.
example:
In this example, the random value can be influenced by manipulating the block's timestamp
Recommended Mitigation:
Use a secure source of randomness like Chainlink VRF (Verifiable Random Function) to ensure that random number generation is truly unpredictable and cannot be manipulated by users or miners.
Chainlink VRF provides a verifiable proof that the random number generated is fair and tamper-proof, as it involves off-chain computation that cannot be influenced by any party.
This mitigates the risk of random number manipulation and ensures a fair and secure distribution of rewards in the openBox function.
Tools Used: Manual Review
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.