The searchForEgg
function in the EggHuntGame
contract attempts to introduce game-like randomness by using a pseudo-random number generator based on on-chain parameters. However, the chosen method is insecure, making the random number predictable and therefore, exploitable by malicious users or bots to increase their chances of finding eggs.
The above line is responsible for generating a pseudo-random number. The randomness relies on the following parameters:
block.timestamp
: Can be influenced by miners/validators within a reasonable window (e.g., ±15 seconds).
block.prevrandao
: Introduced after Ethereum’s Merge to replace block.difficulty
, but it’s not cryptographically secure and can be biased under certain conditions.
msg.sender
: Fully known by the caller.
eggCounter
: A public or easily inferred state variable.
Since all of these values can be predicted off-chain, an attacker can simulate the exact outcome of searchForEgg()
before calling it. If the random < eggFindThreshold
condition is not met, they simply skip the transaction. If the result is favorable, they proceed — giving themselves a clear advantage over honest users.
Game Manipulation: Bots or malicious players can consistently win more eggs than intended.
Unfair Advantage: Legitimate players are at a disadvantage due to manipulation by those simulating the RNG.
Manual Code Review
Avoid using block variables for randomness in on-chain logic unless the outcome has no economic impact or can tolerate manipulation.
Replace the random generation logic with **Chainlink VRF (Verifiable Random Function)**
Insecure methods to generate pseudo-random numbers
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.