The EggHuntGame contract uses an insecure random number generation mechanism that relies on predictable blockchain variables. This vulnerability allows attackers to potentially manipulate or predict the outcome of egg searches, compromising the fairness and integrity of the game.
The random number generation in the searchForEgg() function uses a combination of block.timestamp, block.prevrandao, msg.sender, and eggCounter as entropy sources:
These sources are problematic because:
block.timestamp can be manipulated by miners within a small range
block.prevrandao (formerly known as block.difficulty) is also predictable
The combination of these values creates a pseudo-random number that is vulnerable to exploitation
An attacker can:
Calculate the expected random value in advance
Time their transactions to coincide with favorable random outcomes
Potentially gain an unfair advantage in finding eggs compared to other players
This vulnerability has significant impact on the game's fairness and economy:
Players can manipulate the randomness to consistently find eggs at a higher rate than intended
The game's scarcity mechanism is compromised, potentially devaluing the NFTs
The core gameplay mechanic becomes exploitable, undermining the entire game experience
Trust in the game's fairness is eroded, potentially leading to player abandonment
Manual code review
Solidity compiler analysis
Foundry testing framework
Implement a more secure randomness source such as Chainlink VRF (Verifiable Random Function)
Consider a commit-reveal scheme where users commit to actions before the random value is generated
If external oracles aren't feasible, implement a multi-block confirmation pattern to make manipulation more difficult
Add time delays between user actions to prevent rapid exploitation attempts
Example implementation with Chainlink VRF:
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.