The EggHuntGame contract contains a critical vulnerability in its random number generation mechanism used for determining egg discovery. This vulnerability allows attackers to predict and manipulate the outcome of the egg hunt, enabling them to consistently find eggs and gain an unfair advantage in the game.
The vulnerability exists in the searchForEgg
function of the EggHuntGame
contract. The function uses a predictable combination of:
block.timestamp
block.prevrandao
msg.sender
eggCounter
to generate a "random" number. This implementation is vulnerable because:
block.timestamp
is predictable and can be manipulated by miners
block.prevrandao
can be influenced by validators
An attacker can pre-compute the random number by trying different addresses
The eggCounter
is public and its value is known
High Severity: This vulnerability allows attackers to predict and guarantee egg discoveries
Game Balance Impact: Disrupts the fair distribution of NFTs
Economic Impact: Potential market manipulation of NFT values
Reputation Damage: Loss of trust in the game's fairness
The vulnerability can be demonstrated with the following test case:
run the test
the part of result as follows:
Foundry
To fix this vulnerability, implement the following changes:
Use a secure random number generation method:
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.