Mystery Box

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

Weak Source of Randomness

Summary

The code generates a random number using block.timestamp and msg.sender combined with the keccak256 hash function. However, this approach provides weak randomness and can be manipulated, making it unsuitable for secure random number generation in Solidity.

Vulnerability Details

In the current implementation, randomness is generated using block.timestamp and msg.sender, which are predictable and can be influenced by malicious actors, particularly miners. Miners can manipulate the block's timestamp to control the outcome, compromising the randomness of the generated value.

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

Impact

Using a weak source of randomness in Solidity can result in predictable outcomes, which may lead to vulnerabilities in openBox() functionality, where malicious actors can open most rare boxes.

Tools Used

Manual review

Recommendations

The best practice for secure random number generation in Solidity is to use verifiable randomness from external oracles like Chainlink VRF (Verifiable Random Function). This ensures that the random numbers are unpredictable and tamper-proof. Here's a suggested approach:

  • Integrate Chainlink VRF for generating secure random numbers.

  • Avoid using block.timestamp, msg.sender, or other on-chain parameters as sources 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!