Eggstravaganza

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

Insecure Pseudo-Random Number Generation in EggHuntGame::searchForEgg()

Summary

  • The searchForEgg() function uses predictable on-chain data for randomness, enabling manipulation of egg-finding outcomes.


Vulnerability Details

Location: EggHuntGame.sol, searchForEgg() function
Code Snippet:

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

Impact

Issue

  1. Predictable Inputs:

    • block.timestamp: Miners/validators can manipulate this value within a small range.

    • block.prevrandao: Designed to be random but still partially miner-influenceable (not fully trustless).

  2. Deterministic Output: Combining these inputs with msg.sender and eggCounter creates a pseudo-random number that attackers can precompute.

Attack Scenario:

  1. A miner submits a transaction when block.prevrandao is favorable.

  2. A bot monitors pending transactions and front-runs the searchForEgg() call with parameters that guarantee random < eggFindThreshold.


Tools Used

  • Mannual review


Recommendations

Use Chainlink VRF (Recommended):

// Step 1: Request randomness
bytes32 requestId = COORDINATOR.requestRandomWords(...);
// Step 2: Use verified random number in callback
function fulfillRandomWords(bytes32 requestId, uint256[] memory randomWords) internal override {
uint256 random = randomWords[0] % 100;
// Proceed with egg-finding logic
}
  • Pros: Provably fair, tamper-proof randomness.

  • Cons: Requires LINK tokens and additional setup.

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.