The searchForEgg
function utilizes a pseudo-random number generator (PRNG) based on predictable blockchain variables (block.timestamp
, block.prevrandao
, msg.sender
, eggCounter
). This makes the outcome potentially predictable or manipulatable, undermining the fairness of the egg discovery mechanism.
The randomness used to determine if a player finds an egg is derived from hashing a combination of block.timestamp
, block.prevrandao
, msg.sender
, and the current eggCounter
:
All these inputs are either known or can be influenced/predicted by users or miners.
A malicious user could potentially time their transactions or observe the mempool to increase their chances of finding an egg when random < eggFindThreshold
evaluates to true. Miners have even greater control over block.timestamp
and transaction ordering, allowing potential manipulation.
The weak PRNG compromises the integrity and fairness of the game's core mechanic. Players might be able to predict or influence when they find an egg, deviating from the intended probability set by eggFindThreshold
. This could lead to an unfair distribution of NFTs. While exploitation might require some effort or specific conditions, the predictability itself is a vulnerability.
Manual Review
Avoid using on-chain variables like block.timestamp
, block.prevrandao
, msg.sender
, or internal counters for generating randomness in smart contracts, as they are generally predictable or manipulatable. Instead, consider using more secure and reliable methods for randomness generation. Options include:
Commit-Reveal Schemes: Where users commit to a hash of a secret value and reveal it later.
Verifiable Random Functions (VRFs): Cryptographic functions that produce verifiable pseudo-random outputs. Services like Chainlink VRF provide this on-chain.
Randomness Oracles: External services that provide random numbers to the smart contract, often secured through decentralization and cryptographic proofs.
These approaches provide stronger guarantees against prediction and manipulation compared to relying solely on on-chain data.
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.