Puppy Raffle

AI First Flight #1
Beginner FriendlyFoundrySolidityNFT
EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

getActivePlayerIndex returns 0 for both the first player and "not found"

Root + Impact

Description

function getActivePlayerIndex(address player) external view returns (uint256) {
for (uint256 i = 0; i < players.length; i++) {
if (players[i] == player) {
return i;
}
}
@> return 0; // same value as a valid index 0 -> ambiguous
}

Risk

Likelihood: Low — only affects the player sitting at index 0.

Impact: Low — that player may believe they are not registered and enter again, wasting the entrance fee. No funds are at risk beyond the wasted gas.

Proof of Concept

No exploit test is needed; the ambiguity is evident from the return value.
A player whose address is stored at players[0] calls getActivePlayerIndex and
receives 0 — identical to the "not found" return — so they cannot tell whether
they are registered. The same 0 is returned in both cases:

  • players[0] == player -> returns 0 (valid index)

- player not in array -> returns 0 (not found)

​

Recommended Mitigation

Revert when the player is not found instead of returning 0, or return a
sentinel that cannot be a valid index (e.g. type(uint256).max). This removes
the ambiguity with the valid index 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;
+ revert("PuppyRaffle: Player is not active");
}
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 2 hours ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!