Eggstravaganza

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

Weak PRNG in `EggHuntGame::searchForEgg` allows players to manipulate the random number

Description: The EggHuntGame::searchForEgg function uses a weak PRNG method for generating a random number within the threshold. The use of keccak256 hash functions with predictable values like block.timestamp, block.prevrandao, and msg.sender is not a good way to generate random numbers. These values can be manipulated by miners and/or players.

Found in src/EggHuntGame::searchForEgg:

uint256 random = uint256(
keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender, eggCounter))
) % 100;

Impact: Users can manipulate the random number in EggHuntGame::searchForEgg so that they will always have a number lower than the eggFindThreshold which will cause them to always find and mint new eggs. There will be no real randomness in this function and the purpose of the game will be defeated. They will "find" as much eggs as they want to.

Recommended Mitigation: Instead of using keccak256 and block data for generating the random number, I would recommend using Chainlink VRF for cryptographically secure and provably random values to ensure protocol integrity.

Updates

Lead Judging Commences

m3dython Lead Judge 4 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.