Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: low
Valid

First player who joined the raffle can't know if its in the raffle

Summary

There's a situation than can happen, if the first player who joined the raffle wants to know after some time if he is in the raffle, and to know it he wants to use the PuppyRaffle contract instead of looking through his transaction history.

We can use one function to know it, getActivePlayerIndex() but there's a flaw in the function:

function getActivePlayerIndex(address player) external view returns (uint256) {
for (uint256 i = 0; i < players.length; i++) {
if (players[i] == player) {
return i;
}
}
return 0;
}

If the player passed through the function happens to be in the 0 position in the array, it will have the same result as an address that it's not participating in the raffle

Recommendations

Add a second value (bool) to the return statement that will indicate that is a player in the game. In this way we can differentiate between (0, true) in case of being the first player in the raffle, or (0, false) the player is not in the raffle.

Or

Change the visibility of the function _isActivePlayer to external, to have a definitive way to know is a player is participating in the raffle, and We can at the same time use this function instead of not being use anytime through out the contract.

Updates

Lead Judging Commences

Hamiltonite Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

getActivePlayerIndex can say a player is both entered at slot 0 and inactive

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!