Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

Deterministic game

Summary

The winner and rarity of a raffle is calculated in a deterministic way and not in a random one.

Vulnerability Details

The winner is calculated like this:

uint256 winnerIndex = uint256(
keccak256(
abi.encodePacked(
msg.sender, block.timestamp, block.difficulty)
)
) % players.length;
address winner = players[winnerIndex];

This whole calculation is deterministic, as the block.timestamp and the block.difficulty can be known before executing the function.

The same holds true for the calculation of the NFTs rarity:

uint256 rarity = uint256(
keccak256(abi.encodePacked(msg.sender, block.difficulty))
) % 100;

Impact

Players can calculate the result of calling the selectWinner function and therefore abuse this vulnerability to cheat.

Tools Used

Manual Review

Recommendations

Use chainlinks VRF oracle.

Updates

Lead Judging Commences

Hamiltonite Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

weak-randomness

Root cause: bad RNG Impact: manipulate winner

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!