Eggstravaganza

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

Predictable Random Number Generation Vulnerability in EggHuntGame Contract

Summary
A security vulnerability has been identified in the EggHuntGame contract's random number generation mechanism. The current implementation uses predictable variables that can be manipulated by miners or players, potentially compromising the game's fairness and allowing for exploitation of the egg distribution system.

Vulnerability Details
The vulnerability exists in the searchForEgg() function, which generates random numbers using the following code:

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

Root Cause
The vulnerability stems from using predictable variables in the random number generation:

block.timestamp: Can be manipulated by miners within certain constraints
block.prevrandao: While designed for randomness, can be predicted and manipulated
msg.sender: Known and predictable
eggCounter: Publicly visible and predictable


Impact
This vulnerability could allow malicious actors to:

Predict and manipulate egg distribution outcomes
Exploit the game's reward system
Drain game funds through repeated successful attempts
Compromise the fairness of the game


Tools Used
Testing was performed using Foundry, which provided a controlled environment to verify the vulnerability and test potential mitigations.

Proof of Concept (PoC)
The vulnerability was verified using Foundry's testing framework. The PoC demonstrated that an attacker can:

Calculate the exact random number using the same variables
Predict the outcome of egg searches
Manipulate the game's reward system
Recommended Mitigation
To address this vulnerability, we recommend implementing Chainlink VRF (Verifiable Random Function) for secure random number generation. This solution provides:

Cryptographically secure random numbers
On-chain verification of randomness
Protection against manipulation by miners or players
Maintained game fairness
The implementation should include:

Integration with Chainlink VRF contract
Request randomness before game state changes
Verification of random number generation

Updates

Lead Judging Commences

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