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

`getActivePlayerIndex()` returns 0 both when `the player is not active` and when `the player is active at index 0`.

Summary

  • getActivePlayerIndex() function returns 0 if the player is not active and also if the player is active at index 0 which creates confusion that the player is active at index 0 or inactive player.

  • We can fix this by returning -1 when the player is not active.

Vulnerability Details

Click this to see Code
/// @notice a way to get the index in the array
/// @param player the address of a player in the raffle
@> /// @return the index of the player in the array, if they are not active, it returns 0
function getActivePlayerIndex(address player) external view returns (uint256) {
for (uint256 i = 0; i < players.length; i++) {
if (players[i] == player) {
return i;
}
}
@> return 0;
}
  • Here, the function getActivePlayerIndex() returns 0 when the player is not active which creates confusion that the player is active at index 0 or inactive player.

Impact

  • getActivePlayerIndex() returns 0 whether the player is not active or the player is active at index 0 .

Tools Used

  • Manual Review

Recommendations

/// @notice a way to get the index in the array
/// @param player the address of a player in the raffle
- /// @return the index of the player in the array, if they are not active, it returns 0
+ /// @return the index of the player in the array, if they are not active, it returns -1
function getActivePlayerIndex(address player) external view returns (uint256) {
for (uint256 i = 0; i < players.length; i++) {
if (players[i] == player) {
return i;
}
}
- return 0;
+ return -1;
}
  • To avoid confusion, it is recommended to return -1 instead of 0 when the player is not active.

Updates

Lead Judging Commences

patrickalphac Lead Judge
about 2 years ago
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!