Mystery Box

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

Insecure Random Number Generation Using Predictable Values in MysteryBox::openBox

Summary

The random number generation in the contract uses insecure methods (block.timestamp and msg.sender), which can be manipulated or predicted by miners or other actors, leading to an unfair advantage in the reward distribution system.

Vulnerability Details

The following line in the contract is used to generate a random number:

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

However, block.timestamp and msg.sender are predictable values, especially by miners who can manipulate the block timestamp. This opens up the possibility for an attacker to predict or manipulate the outcome of the random number generation, which affects the distribution of rewards.

In a reward system where the outcome heavily relies on randomness, this vulnerability can lead to unfair reward allocations and even loss of funds if high-value rewards are distributed in a predictable manner.

Impact

  • High Impact: An attacker could manipulate or predict the random number generation to consistently receive higher-value rewards, leading to an unfair distribution and potential loss of funds within the system.

  • Funds are directly at risk, as the reward distribution is based on the insecure randomness function.

Tools Used

  • Manual code review.

Recommendations

  • Replace the insecure random number generation with a secure method such as Chainlink VRF (Verifiable Random Function), which provides tamper-resistant and provably fair randomness.

  • Alternatively, use other secure oracle-based randomness sources or consider implementing randomness based on less predictable factors.

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!