Eggstravaganza

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

Predictable Pseudorandom Number Generation

Summary

The current randomness mechanism in EggHuntGame is deterministic and vulnerable to manipulation.

Vulnerability Details
The searchForEgg() function uses predictable on-chain data for random number generation:

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

All these values are deterministic and can be known or predicted by miners/validators. While block.prevrandao offers some improved randomness post-Merge compared to the older block.difficulty, it's still not truly random

Impact

Miners or validators can potentially manipulate the random number generation to increase their chances of finding eggs, allowing them to unfairly mint more NFTs than regular players. This undermines the entire game mechanics and fairness.

Tools Used

Code review

Recommendations

Use a verifiable random function (VRF) from Chainlink or similar oracle service to provide secure randomness. Alternatively, implement a commit-reveal scheme where users commit to a value in one transaction and reveal in another, combining user input with block data for better randomness.

Updates

Lead Judging Commences

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

Give us feedback!