Mystery Box

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

Predictable Randomness Can Be Exploited

Summary

The random number generation in the openBox() function is based on block.timestamp and msg.sender, which are predictable. This can allow an attacker to manipulate the randomness to consistently win valuable rewards.

Vulnerability Details

The contract uses the following logic to generate a random value:

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

Both block.timestamp and msg.sender are predictable and can be influenced by miners or attackers. An attacker can manipulate these values to predict or control the outcome of the randomness, allowing them to obtain more valuable rewards unfairly.

Impact

An attacker could game the system to maximize their chances of winning high-value rewards, such as Silver or Gold Coins, at the expense of other users. Over time, this could drain the contract’s valuable rewards and damage its reputation.

Tools Used

Manual code review

Recommendations

Use a more secure randomness mechanism, such as Chainlink VRF (Verifiable Random Function), which provides a secure and verifiable source of randomness.

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!