Mystery Box

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

Randomness Vulnerability Using Block Timestamp

Summary

The contract uses block.timestamp and msg.sender to generate randomness when opening a mystery box. This method is insecure and allows miners to manipulate the outcome of the rewards by controlling the block timestamp.

Vulnerability Details

In the openBox() function, the following line generates randomness:

uint256 randomValue = uint256(keccak256(abi.encodePacked(block.timestamp, msg.sender))) % 100;```

Using block.timestamp for randomness is unsafe because miners can adjust the timestamp within a small range, allowing them to predict or influence the generated random value, thus skewing the reward probabilities in their favor.

Impact

An attacker, especially a miner, can manipulate the block timestamp to increase their chances of getting high-value rewards. This compromises the fairness of the reward distribution, potentially leading to financial losses for the contract and users.

Tools Used

Manual code review

Recommendations

Replace the pseudo-random number generation with a secure method, such as using Chainlink VRF to ensure unbiased and tamper-proof randomness.

Updates

Appeal created

inallhonesty Lead Judge 11 months 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.