Mystery Box

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

`MysteryBox::randomValue` is not random value what allows user to get the best reward

Summary

User can open a box bought earlier using MysteryBox::openBox function. Reward which user will get, depends on randomValue variable.

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

This varaible is calculated based on some inputs as block.timestamp and msg.sender. Block.timestamp is equal to actual block in the blockchain.

Vulnerability Details

User can calculate in which block randomValue will be equal 99 to get the best reward. Then user will wait till this block and call MysteryBox::openBox function during this block.

Impact

User can get the best reward (Gold Coin) every time he want.

Tools Used

Manual review.

Recommendations

Use Chainlink VRF solution to get real random number.

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!