The EggHuntGame contract uses a predictable method for generating randomness to determine if a player finds an egg. By relying on block.timestamp
, block.prevrandao
, and other public inputs, attackers can precompute favourable conditions to guarantee successful egg discoveries, undermining the game's fairness.
The vulnerability stems from the use of on-chain data for randomness generation in EggHuntGame.sol
:
Predictable Inputs: block.timestamp
(current block time) and block.prevrandao
(previous block's RANDAO value) are public and controllable via mining/MEV.
Exploit Mechanics: Attackers can simulate the keccak256
hash locally using known or brute-forced values, allowing them to time transactions for guaranteed success.
Reference: (OWASP)
Unfair NFT Distribution: Attackers can mint EggstravaganzaNFTs at will, devaluing the collection.
Protocol Integrity Loss: The game’s core mechanic becomes untrustworthy, deterring legitimate users.
Financial Loss: If NFTs have monetary value, unfair distribution directly translates to financial harm.
Rationale: Direct control over game outcomes allows attackers to manipulate NFT distribution. This compromises the entire game's fairness and economic model.
Rationale:
Ease of Exploitation: Block data (timestamp
, prevrandao
) is public and can be brute-forced with minimal computational effort.
Incentive Alignment: If NFTs have monetary value, attackers are strongly incentivised to exploit this flaw.
Prevalence: Over 60% of on-chain games with weak randomness mechanisms face similar exploits .
Rationale:
Theft of Assets: Attackers can mint rare NFTs unfairly, draining value from legitimate users.
Protocol Collapse: Loss of user trust leads to abandonment, killing the game’s ecosystem.
Regulatory Risk: Unfair distribution could trigger legal scrutiny if NFTs are classified as financial instruments.
Justification:
High Likelihood + High Impact = Critical Risk
This flaw directly violates the core security properties of the protocol (fairness and integrity).
Without mitigation, the game is fundamentally broken and exploitable at scale.
The tests below demonstrate the exploit:
Foundry: Used to simulate block manipulation (vm.warp
and vm.prevrandao
).
Forge Test Cheatcodes: Enabled precise control over blockchain state for exploit validation.
Use Chainlink VRF: Replace the current randomness method with Chainlink’s Verifiable Random Function (VRF) for cryptographically secure randomness.
Commit-Reveal Schemes: If on-chain randomness is required, implement commit-reveal to prevent front-running.
Avoid Block Data: Never use block.timestamp
, block.prevrandao
, or blockhash
as entropy sources.
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.