getActivePlayerIndex
doesn't behave as stated in NATSPEC because it doesn't treat the 0 edge case.
The NATSPEC specifies the following @return the index of the player in the array, if they are not active, it returns 0
.
But given that the players are tracked in a list, the index of the first player will always be 0. Thus when we call getActivePlayerIndex
with the address of the first player the function will see that players[i] == player
when i = 0, thus returns 0. But 0 is returned when a player is not active. This leads to confusion.
Copy this in PuppyRaffleTest.t.sol
Weird behavior of a function that doesn't behave like the NATSPEC indicates.
Manual review
Use this instead:
The edge case is treated because -1 is not a valid index in a Solidity array. No need to use SafeCast for int256(players.length)
because it's impossible for that value to get too high.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.