The getActivePlayerIndex function in the PuppyRaffle contract returns 0 when querying the index of a non-existent player. This can result in the erroneous identification of a non-existent player as the first player in the players array.
In the PuppyRaffle contract, the getActivePlayerIndex function iterates through the players array searching for a matching address. If the function does not find a match, it defaults to returning 0. This is problematic because it does not differentiate between non-existent players and the first player in the array.
Here is the part of the function causing the issue:
If external systems or users rely on this function to identify or verify player participation, it may lead to false positives or unintended actions, such as false rewards, misallocation of resources, or other unexpected behaviors.
Enter two players into the raffle.
Query the index of a non-existent player.
The function will return 0, even though the non-existent player is not in the raffle.
Foundry
To resolve this issue, the function can be modified to return an invalid index (such as -1) when no match is found, clearly indicating the player does not exist.
This will ensure that the returned index is always within the bounds of the players array if the player exists, and clearly outside of it if they do not.
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.