PuppyRaffle::getActivePlayerIndex
checks if a player is active by looping through the players
array and returning the index at which the address provided matches the address at the current index. If the address is not found in the array, the function returns 0
. Since Solidity arrays are 0
indexed, the first player in the players
array will also return an index of 0
. This makes it seem as though the non-active player is the first player even though they have not joined the raffle.
In PuppyRaffle::getActivePlayerIndex
, on line 110-117, the address provided as an argument is checked against the players
array to check if they match if they do, the index is returned:
If the player address provided matches the first address in the players
array, an index of 0
will be returned. However, if no address is found to match in the players
array, 0
is also returned, erroneously making it seem as though the provided address is the first address in the players
array.
If a user is attempting to determine their index in the raffle, they may think they have entered as the first player even though they have yet to enter the raffle. This function could also be used externally to retrieve the player's index before using it to call refund()
leading to revert as the caller is not the first element in the array, wasting the user's gas.
This function is not used internally so does not cause any downhill errors however incorrect, externally facing APIs should be fixed to avoid confusion and wasting gas, which makes this finding a low-severity vulnerability.
The following test enters players in a raffle and then checks for the index of an address that has not entered the raffle. The test passing demonstrates that an index of 0
has been returned even though the address provided has not entered the raffle:
Running the test yields the following output:
The test passes showing that an index of 0
has incorrectly been returned.
Either remove the necessity for users to determine their index in the array by changing the argument for refund()
to be an address and checking the address' activity status before proceeding with the refund or if no index is found to match, revert with the following statement:
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.