Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Valid

Weak Randomness in `EggHuntGame::searchForEgg` function might lead to game manipulation risk

Description: The contract relies on block.timestamp, block.prevrandao, and msg.sender to generate pseudo-random numbers. These values can be partially controlled or predicted by malicious actors (e.g., miners), especially in a public network, making it possible to manipulate the result of EggHuntGame::searchForEgg function.

Impact: A malicious player or miner could increase their chances of finding an egg, gaining unfair advantage in the game, and disrupting game fairness and token economy

Proof of Concept:

uint256 random = uint256(
keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender, eggCounter))
) % 100;
if (random < eggFindThreshold) {
eggCounter++;
eggsFound[msg.sender] += 1;
eggNFT.mintEgg(msg.sender, eggCounter); // unfair minting opportunity
}

An attacker could call EggHuntGame::searchForEgg function in a block they mine themselves or repeatedly call it across multiple transactions and blocks to eventually hit a winning result

Recommended Mitigation: Avoid relying on block variables for randomness. Instead:

  • Use Chainlink VRF for secure randomness.

  • Or, if full trustless randomness isn't required, make randomness off-chain and verifiable (signed results from backend + ECDSA).

Updates

Lead Judging Commences

m3dython Lead Judge 2 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Insecure Randomness

Insecure methods to generate pseudo-random numbers

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.