Description
To end, Snek Raffle needs to last at least 1 day, have one player, be open, and have a balance. However, the same error is returned for any of these conditions, preventing a user from understanding why the function reverts.
def request_raffle_winner() -> uint256:
"""Request a random winner from the VRF Coordinator after a raffle has completed."""
is_open: bool = RaffleState.OPEN == self.raffle_state
time_passed: bool = (block.timestamp - self.last_timestamp) > RAFFLE_DURATION
has_players: bool = len(self.players) > 0
has_balance: bool = self.balance > 0
@> assert is_open and time_passed and has_players and has_balance, ERROR_NOT_ENDED
self.raffle_state = RaffleState.CALCULATING
request_id: uint256 = VRF_COORDINATOR.requestRandomWords(
GAS_LANE,
SUBSCRIPTION_ID,
REQUEST_CONFIRMATIONS,
CALLBACK_GAS_LIMIT,
NUM_WORDS
)
return ERC721._total_supply()
Risk
Likelyhood: Low
Impact: Low
Recommended Mitigation
Create separate error messages for each condition to provide more clarity to the user and add them in the function like below.
def request_raffle_winner() -> uint256:
"""Request a random winner from the VRF Coordinator after a raffle has completed."""
is_open: bool = RaffleState.OPEN == self.raffle_state
time_passed: bool = (block.timestamp - self.last_timestamp) > RAFFLE_DURATION
has_players: bool = len(self.players) > 0
has_balance: bool = self.balance > 0
- assert is_open and time_passed and has_players and has_balance, ERROR_NOT_ENDED
+ assert is_open, ERROR_NOT_OPEN
+ assert time_passed, ERROR_NOT_ENDED
+ assert has_players, ERROR_NO_PLAYER
+ assert has_balance, ERROR_NO_BALANCE
self.raffle_state = RaffleState.CALCULATING
request_id: uint256 = VRF_COORDINATOR.requestRandomWords(
# c gas lane dans chainlink permet de definir du premium
GAS_LANE,
SUBSCRIPTION_ID,
REQUEST_CONFIRMATIONS,
CALLBACK_GAS_LIMIT,
NUM_WORDS
)
return ERC721._total_supply()