The EggHuntGame
contract uses a weak pseudo-random number generator in its searchForEgg()
function. The randomness is derived from predictable values (block.timestamp, block.prevrandao, msg.sender, and eggCounter), making it vulnerable to precomputation attacks. An attacker can reliably farm eggs by iterating over potential timestamps, undermining the fairness of the game.
The contract computes randomness with the following expression:
Both block.timestamp
and block.prevrandao
are susceptible to prediction and minor manipulation by miners. When combined with the deterministic msg.sender
and the predictable state variable eggCounter
, an attacker can easily simulate the random number generation off-chain or via automated tests to identify winning conditions. This predictability renders the game susceptible to exploitation.
This vulnerability disrupts the fairness of the game by allowing an attacker to predict the outcome and farm multiple eggs, undermining the value of in-game rewards. The issue is classified as high severity due to its impact on the integrity and fairness of the game, though it may not lead to immediate financial loss. Given that this exploit can be repeated, it poses a significant risk to the game's ecosystem.
To mitigate the vulnerability, it is recommended to replace the current PRNG with a secure randomness source, such as Chainlink VRF, or implement a commit-reveal scheme to introduce unpredictability.
foundry
The provided PoC demonstrates how an attacker can precompute a winning block timestamp within a small range. By repeating this process, the PoC shows that multiple eggs can be farmed reliably, highlighting the systemic flaw in the randomness generation mechanism.
Trace:
The weak PRNG in EggHuntGame
poses a significant risk to the fairness and integrity of the game. The PoC confirms that an attacker can predict and exploit the random number generation to farm eggs repeatedly. This issue, while not immediately financially damaging, can severely affect the game's ecosystem, and its exploitation undermines the trust of players. Addressing this issue is crucial to ensuring a fair and secure gaming experience.
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.