Eggstravaganza

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

Incorrect random number generation in EggHuntGame::searchForEgg allow attackers to guess the percentage to obtain an Egg.

Summary

In the EggHuntGame::searchForEgg function we can see the next lines of code:

// Pseudo-random number generation (for demonstration purposes only)
uint256 random = uint256(
keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender, eggCounter))
) % 100;

As the comments says, is a pseudo-random number generation, for demonstrations purposes only. So my question as an auditor is...

Which is the real code that the smart contract is going to use to generate a random number ?

We are auditors, not guessers. So in order to do well our job we need the full code. The number generated is not random (as the comment says) so this mustn't be deployed.

Vulnerability Details

Weak random number generation can allow attackers to guess the number and decide when to call the EggHuntGame::searchForEgg function to always win.

Using elements like:

- `block.timestamp`
- `block.prevrandao`
- `msg.sender`
- Variables like `eggCounter`

Doesn't give you randomness.

Impact

Attackers can guess the "random" number and decide when to call the EggHuntGame::searchForEgg function to always win.

Tools Used

  1. Manual Review

  2. Foundry

Recommendations

Use Chainlink VRF to obtain a demonstrable random number.

Link to docs here

Updates

Lead Judging Commences

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