The EggHuntGame
contract uses weak on-chain randomness derived from block.timestamp
and msg.sender
to generate random numbers for minting eggs. This predictable mechanism allows an attacker to repeatedly mint eggs by manipulating transaction timing and block conditions, enabling them to farm unlimited eggs without restriction.
The contract implements a randomness mechanism resembling the following:
This approach is vulnerable because both block.timestamp
and msg.sender
are predictable and manipulatable within the same block. An attacker can repeatedly call the egg-farming function in rapid succession, with each call resulting in a deterministic and easily calculable "random" number.
The proof-of-concept test cases demonstrate this vulnerability:
Single Egg PoC: A single transaction by the attacker reliably generates the correct random number to mint an egg.
Multiple Eggs PoC: The attacker is able to mint 10 eggs in 10 consecutive calls by exploiting the predictable randomness source. Each call generates a new but predictable number, allowing uninterrupted farming.
EggHuntGameTest.t.sol
This vulnerability allows any attacker to:
Bypass any intended rarity or game mechanics tied to randomness
Farm an unlimited number of eggs
Potentially drain contract resources, inflate scores, or disrupt fair competition in gameplay environments
In a production environment with rewards or incentives tied to egg minting, this could lead to severe economic exploitation.
Custom Solidity PoC with forge-std
logging to verify attacker control
Manual inspection of on-chain randomness sources
Avoid using block.timestamp
, msg.sender
, or block.number
as entropy sources for randomness. Instead:
Use a secure randomness oracle like 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.