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

selectWinner function can be exploited via MEV

Summary

Raffle loosers can use MEV to determine the next winner and rescue stake.

Vulnerability Details

selectWinner function calculates winner thus:

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

Using a MEV transaction call, a caller can easily calculate the winner since all the three calculation parameters are known at the time the block is generated. On determining that they have lost, they can easily call refund + selectWinner.

Impact

  1. The contest looses fee from MEV users.

Tools Used

Manual review

Recommendations

Disable refund after contest period has ended. Add this code to refund function:

require(block.timestamp < raffleStartTime + raffleDuration, "PuppyRaffle: Raffle is over");
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

selectWinner can be frontran

Support

FAQs

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

Give us feedback!