Eggstravaganza

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

On-Chain Randomness Exploit in searchForEgg Function

Summary

The searchForEgg function in the smart contract relies on an insecure method of generating randomness using on-chain variables such as block.timestamp, block.prevrandao, msg.sender, and eggCounter. This approach allows attackers to guess the outcome and mint an EggstravaganzaNFT.

Vulnerability Details

The vulnerability arises from the following line in the searchForEgg function:

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

This method is not truly random because an attacker can estimate block.timestamp, block.prevrandao, and eggCounter values since they are publicly accessible or can be influenced.

Impact

An attacker can manipulate randomness to increase their chances of finding EggstravaganzaNFT unfairly, affecting game integrity.

Tools Used

Manual code review

Recommendations

Consider generating random numbers off-chain, either using services like Chainlink VRF or using your own internal server.

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.