Mystery Box

First Flight #25
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: medium
Valid

Mystery Box Vulnerability

Summary: Weak PRNG(Pseudo random number generator).

PRNGs are often used for generating random numbers in smartContract. But, how ever certain sources used in this generators can make them easily predictable making them "weak"

Vulnerability Details:

function openBox() public {
require(boxesOwned[msg.sender] > 0, "No boxes to open");
// Generate a random number between 0 and 99
uint256 randomValue = uint256(keccak256(abi.encodePacked(block.timestamp, msg.sender))) % 100;

Impact: A malicious miner can call the openBox() in thier own trabsaction and the, mine the block themselves.

As miners they can they can reorder transactions within the block and select a block hash( block.blockhash(10000)) that ensures a desired outcome when % 10 is calculated.

By doing this they can "win" the game as they can influence the random value to be a predictable one.

Tools Used: Slither

Recommendations: The chainlink VRF is a better option because it provides cryptographically random numbers.

  1. Avoid using miner-influenced-variables like, blockhash, block.timestamp or now for randomness.

Updates

Lead Judging Commences

inallhonesty Lead Judge
about 1 year ago

Appeal created

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Weak Randomness

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!