Mystery Box

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

Weakness of random number generation in MysteryBox.sol::openBox()

Vulnerability Details

Let's see the following code below

function openBox() public {
...
@> uint256 randomValue = uint256(keccak256(abi.encodePacked(block.timestamp, msg.sender))) % 100;
...
}

From the code above, we know that every user can open the box whenever they want. This code computes the randomValue statically from msg.sender and block.timestamp. From this, it is easy for users to achieve the best randomValue.

Impact

Users can predict or manipulate the outcome of the randomValue, allowing them to consistently receive the best rewards, such as gold coins. This undermines the fairness of the contract and can lead to exploitative behavior, resulting in financial losses for other users and the integrity of the system.

Tools Used

Manual review.

Recommendations

Implement a secure randomness oracle like Chainlink VRF (Verifiable Random Function) to generate unpredictable random values. This will enhance the security and fairness of the reward distribution.

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!