almurhasan - minTicketsThreshold check inconsistency in function _checkShouldDraw and function _checkShouldCancel. #475
Labels
Duplicate
A valid issue that is a duplicate of an issue with `Has Duplicates` label
Medium
A Medium severity issue.
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
almurhasan
Medium
minTicketsThreshold check inconsistency in function _checkShouldDraw and function _checkShouldCancel.
Summary
currentTicketSold must be equal to/greater than minTicketsThreshold in function _checkShouldDraw but in function _checkShouldCancel, currentTicketSold must be equal to/less than minTicketsThreshold.so if currentTicketSold is reached to/equal to minTicketsThreshold, then cancelRaffle is still possible which is unfair.
Vulnerability Detail
Let’s assume, the current raffleId is 1 and the raffleId’s minTicketsThreshold = 100.
Now raffleId 1’s 100 tickets are sold. So currentTicketSold = 100.
After That, no one buys raffleId 1’s tickets(i.e currentTicketSold is still 100) and raffle.endsAt is also reached(i.e current time is bigger than raffle.endsAt).
Now function drawWinner is called which calls function _checkShouldDraw, see function _checkShouldDraw, as currentTicketSold is equal to minTicketsThreshold and current time is bigger than raffle.endsAt, so function drawWinner will be executed.
If before calling function drawWinner, the function cancelRaffle is called which calls function _checkShouldCancel, the function cancelRaffle will be executed even though raffleId’s minTicketsThreshold is reached.
Impact
Attackers can frontrun the function cancelRaffle before function drawWinner when currentTicketSold is equal to minTicketsThreshold and current time is bigger than raffle.endsAt.
Code Snippet
https://github.com/sherlock-audit/2024-08-winnables-raffles/blob/main/public-contracts/contracts/WinnablesTicketManager.sol#L440
Tool used
Manual Review
Recommendation
Instead of if (supply > raffle.minTicketsThreshold) revert TargetTicketsReached();
Put this, if (supply >= raffle.minTicketsThreshold) revert TargetTicketsReached(); in function _checkShouldCancel.
Duplicate of #26
The text was updated successfully, but these errors were encountered: