Eggstravaganza

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

Weak random mechanism

Summary

Function for search eggs use weak random mechanism, which could be manipulated and sometimes could use constant values on some blockchains.

Vulnerability Details

Function searchForEgg use for getting random number weak mechanism.

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

This code has some disadvantages:

  1. block.timestamp - could be manupulated by miner/validator

  2. block.prevrandao - on linea, this function return always the same value - 2 https://docs.linea.build/get-started/build/ethereum-differences#:~:text=Returns a fixed number%3A

  3. if user sent more than 1 tx and they in one block, and if first random number is not less, than eggFindThreshold value, eggCounter will not increase and all next tx from this user in this block will not give eggs to user. Because random number will be the same during the block, because eggCounter does not increase previously.

Impact

Random number could be manipulated by miners/validators and using for receive egg in the game.

Tools Used

Manual review

Recommendations

Use chainlink vrf for getting random numbers.

Updates

Lead Judging Commences

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