Eggstravaganza

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

Pseudo-Randomness Vulnerability.

**Description:** The `searchForEgg` function uses a pseudo-random number generator. This method is not secure as it relies on block variables (like block.timestamp and block.prevrandao) and predictable inputs (such as msg.sender and eggCounter).
**Impact:** An attacker (or miner with influence over block properties) could potentially manipulate or predict the outcome, skewing the egg-finding chance in their favor.
**Proof of Concept:** Include the following test in the `EggHuntGameTest.t.sol` file:
```solidity
function testRandomNumberGeneration() public {
uint256 eggFindThreshold = game.eggFindThreshold();
uint256 eggCounter = game.eggCounter();
uint256 random1 =
uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, address(this), eggCounter))) % 100;
uint256 random2 =
uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, address(this), eggCounter))) % 100;
assertEq(random1, random2);
}
```
**Recommended Mitigation:** For applications where fairness and unpredictability are critical, using a verifiable random function (VRF) such as Chainlink VRF is recommended.
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.