The searchForEgg
function in EggHuntGame
contract relies on an insecure and manipulable source of randomness. This allows attackers to predict or manipulate the outcome of egg discovery, giving unfair advantages and undermining the integrity of the game.
The Vulnerability exists in generating the random number in line 71 of EggHuntGame
Contract: https://github.com/CodeHawks-Contests/2025-04-eggstravaganza/blob/main/src/EggHuntGame.sol#L71
The pseudo-random value is derived using predictable inputs:
block.timestamp – public and validator-controlled.
eggCounter – public state variable.
msg.sender – caller-controlled.
While block.prevrandao
is sourced from the block proposer in Ethereum’s PoS system and adds entropy, it’s not entirely unpredictable. In certain scenarios (especially for validators), this value can still be manipulated or anticipated with some level of confidence.
Since the game uses this value to determine if a player found an egg (random < eggFindThreshold)
, a malicious player can simulate calls off-chain or a validator can manipulate block inputs to meet the condition.
High Severity — This vulnerability does not just affect gameplay fairness; it can lead to loss of NFT assets meant to be uniquely discovered and earned. Malicious players or validators can:
Systematically and repeatedly claim rare eggs.
Prevent legitimate players from finding eggs.
Drain all available eggs unfairly, denying honest participation.
Manual code review and analysis of randomness entropy sources.
Scenario:
A malicious player can simulate random values off-chain and only call searchForEgg() when the outcome will succeed:
Alternatively, a validator can manipulate block.timestamp or withhold a valid block until they can craft a favorable outcome.
✅ Option One: Commit-Reveal Scheme below:
Replace searchForEgg() with a secure two-phase commit-reveal scheme:
✅ Option Two: Chainlink VRF (Minimal Setup):
For a trustless, on-chain verifiable solution:
Player initiates egg search → sends a VRF request.
Chainlink VRF callback fulfills randomness securely.
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.