The searchForEgg() function in EggHuntGame.sol uses predictable on-chain data for randomness generation, making it vulnerable to manipulation by miners and attackers. This allows malicious actors to game the system by predicting favorable conditions for finding eggs.
The vulnerability occurs in the pseudo-random number generation:
URL: https://github.com/CodeHawks-Contests/2025-04-eggstravaganza/blob/f83ed7dff700c4319bdfd0dff796f74db5be4538/src/EggHuntGame.sol#L71
Predictable Inputs: All parameters (block.timestamp, block.prevrandao, msg.sender, eggCounter) are publicly visible and can be predicted in advance
Miner Manipulation: Miners can influence block.timestamp and block.prevrandao to create favorable conditions
Frontrunning Possible: Attackers can compute the random number off-chain and only submit transactions when they know they'll win
The provided PoC demonstrates how an attacker (Alice) can systematically exploit this by:
Precomputing the random number before each transaction attempt
Only sending transactions when conditions are favorable (random < threshold)
Forcing block changes (vm.warp/vm.roll) to manipulate inputs
High Severity: Attackers can guarantee egg discoveries, breaking game fairness
Economic Damage: Malicious users could accumulate all available eggs
Reputation Risk: Game becomes exploitable, losing player trust
Foundry for testing (vm.warp, vm.roll)
Manual code analysis
PoC test case demonstrating the exploit
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.