The EggHuntGame.sol
contract uses a pseudo-random number generation method that is susceptible to prediction due to reliance on publicly available and manipulatable blockchain data. This vulnerability can be exploited by malicious actors to consistently win the egg-finding game, undermining the fairness and integrity of the gameplay.
The contract attempts to generate a pseudo-random number in the searchForEgg
function using the following line:
Each of these inputs (block.timestamp
, block.prevrandao
, msg.sender
, and eggCounter
) is either predictable, manipulable, or publicly known:
block.timestamp
: Can be influenced slightly by the block miner.
block.prevrandao
: While an improvement over blockhash
, it is still known at the time of execution.
msg.sender
: Known to the user calling the function.
eggCounter
: Public state variable, accessible to anyone.
This predictability enables players or bots to simulate or predict outcomes off-chain and only submit transactions when a successful result (e.g., finding an egg) is guaranteed. This was verified through automated testing.
A test was written to demonstrate that the pseudo-random number generator can yield repeatable values using known inputs:
add this to EggHuntGameTest.t.sol
This test failed due to duplicate random values being generated, clearly indicating that the randomness is not secure or truly random.
If left unaddressed, malicious users can:
Simulate and find optimal times to call searchForEgg()
off-chain.
Gain an unfair advantage by calling the function only when an egg will be found.
Potentially dominate the game and accumulate more NFTs than honest players.
Undermine trust in the game, disincentivizing fair participation.
Foundry
To mitigate this vulnerability, it is recommended to use a more secure source of randomness. Options include:
Chainlink VRF (Verifiable Random Function): A decentralized and verifiable randomness provider.
Pros: Secure, fair, and unpredictable.
Cons: Requires off-chain integration and LINK tokens.
Commit-reveal scheme: Have players commit a hashed value and later reveal it to determine randomness.
Pros: Doesn’t require external dependencies.
Cons: Adds complexity and delays.
Post-game randomness: Use randomness at the end of the game to determine egg assignments retroactively.
Pros: Reduces the attack surface during gameplay.
Cons: Changes gameplay dynamics.
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.