Mystery Box

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

Lack of randomness in the function openBox

Summary

The function openBox uses deterministic values for generating the variable randomValue which determines the reward for the user so the output can be determined in advance.

Vulnerability Details

The function openBoxdetermines the reward based on the output of the keccak256function:

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

The output depends on the timestamp of the block and on the address of the sender. Since the block timestamp can be predicted in advance (block times are 12 seconds on the Ethereum blockchain), the randomValue variable can be predicted.

Impact

A validator can include their own transaction in a block in which the predicted randomValueis 95 or greater (or even 99 for the highest reward). Even an ordinary user can calculate the block in which their odds are highest and submit the transaction right on time with a high gas fee to stimulate the validator to include their transaction in the desired block. This unintended behavior can break the desired random game mechanics.

Tools Used

Manual inspection.

Recommendations

It is recommended to use Chainlink VRF (Verifiable Random Function) for generating a 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!