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

Miners can influence block.timestamp to alter winnerIndex

Summary

Dangerous use of block.timestamp exists in L128-L130 in PuppyRaffle.sol. block.timestamp can be manipulated by miners. This causes a weak PRNG in the mentioned LOC.

Vulnerability Details

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

In the code, winnerIndex is being computed after taking the keccak256 hash of the encoding of msg.sender, block.timestamp and block.difficulty. Miners can manipulate block.difficulty to change the winnerIndex.

Impact

Miners can alter the block.timestamp to influence the randomness. The winner's address is initialized by the winnerIndex which is being computed using block.timestamp. Miners can manipulate the winner's address by slightly adjusting the block.timestamp.

This allows miners to control the randomness and in turn changing the Winner of the raffle. This causes loss of funds for the actual winner and disrupts the protocol from giving out the rewards to the actual Winner.

Tools Used

Slither and Manual Review

Recommendations

Use ChainlinkVRF to produce randomness for all cases where RNG is required.

Updates

Lead Judging Commences

Hamiltonite Lead Judge almost 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.