Mystery Box

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

Bad randomness in `MysteryBox.sol::openBox`

Summary

The openBox function generates a random number in order to determine the reward the user sill receive, to do so, it uses the timestamp and the address of the sender, this method is not a good way to generate randomness, since users can predict the generated number by simulating the outcome and eventually, always getting the most favorable outcome.

Vulnerability Details

The issue lies in the following lines of code:

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

Malicious user can open boxes predicting the outcome, and thus, always getting the greatest reward.

Tools Used

Manual review

Recommendations

Use an external provider to get true randomness, such as chainlink.

Updates

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!