Mystery Box

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

Weak randomness in `MysteryBox::openBox` allows anyone to manipulate reward

Weak randomness in MysteryBox::openBox allows anyone to manipulate reward

Summary

Hashing block.timestamp and msg.sender together leads to a predictable final number, making the random number generation vulnerable. This allows malicious users to manipulate or anticipate values to select specific rewards.

Vulnerability Details

Using block.timestamp and msg.sender for randomness creates predictable outcomes. Attackers can exploit this by knowing the block timestamp or by manipulating their address to receive desirable rewards.

Proof of Concept

There are two primary attack vectors:

  1. Validators can predict block.timestamp, enabling them to time their participation advantageously. More information can be found in the Solidity blog on prevrandao.

  2. Users can manipulate the msg.sender to secure the "rarest" reward.

The following function illustrates the predictability by calculating a non-zero reward based on block.timestamp:

function calculateWinTimestampValue(address addr) public view returns (uint256) {
uint256 value;
uint256 winTime = block.timestamp;
do {
winTime++;
value = uint256(keccak256(abi.encodePacked(winTime, addr))) % 100;
} while (value < 95);
return winTime;
}

Using on-chain values as randomness seeds is a well-known attack vector in the blockchain space.

Impact

Any user can select rewards, including the "rarest" ones, undermining the randomness of the rewards system.

Recommended Mitigation

To enhance randomness, consider using an oracle solution such as Chainlink VRF for secure and unpredictable random number generation.

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!