The searchForEgg
function in the EggHuntGame
contract uses on-chain data that is predictable or manipulatable by users to generate "random" numbers. This implementation creates an unfair advantage for technically sophisticated users who can predict or manipulate the outcome of egg searches, undermining the game's fairness.
The randomness generation in the searchForEgg
function relies on three inputs:
Previous block hash
Current block timestamp
Message sender address
This approach has several critical flaws:
Predictability: Validators can see the blockhash and timestamp before finalizing a block, allowing them to predict outcomes
Manipulation: Users can control when they submit transactions, potentially manipulating the block.timestamp within a small range
Selective Execution: Users can compute the randomness outcome off-chain before sending their transaction, only proceeding when the result is favorable
These issues allow sophisticated users to gain an unfair advantage in the egg-finding game by:
Predicting when they will successfully find an egg
Timing their transactions to maximize success probability
Avoiding transaction costs when they know they'll fail to find an egg
This vulnerability significantly impacts the game's fairness:
Unfair Advantage: Technically sophisticated users can dramatically increase their chances of finding eggs compared to regular players
Economic Imbalance: The ability to predict success means some users can avoid wasting gas on failed searches, giving them an economic advantage
Game Integrity: The core randomness mechanism is fundamentally flawed, undermining the game's intended random-chance design
Market Manipulation: If NFTs from the game have value, predictable randomness could lead to market manipulation and unfair distribution
While this isn't a direct fund loss vulnerability, it significantly impacts the core gameplay mechanics and fairness of the system.
Manual code review
Foundry for testing randomness manipulation
Option 1: Use Chainlink VRF
Option 2: Commit-Reveal Scheme
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.