Puppy Raffle

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

Unused state variable `previousWinner` wastes gas

Description

  • State variables that are updated but never read cost the protocol gas without providing any functionality.

  • The previousWinner variable is set during selectWinner but is never utilized anywhere else in the contract.

// Root cause in the codebase with @> marks to highlight the relevant section
@> address public previousWinner;
function selectWinner() external {
// ...
@> previousWinner = winner;
// ...
}

Risk

Likelihood:

  • Every time selectWinner is called, an expensive SSTORE operation takes place to update this variable.

  • Always present on contract deployment.

Impact:

  • Unnecessary gas expenditures for all participants/callers.

Proof of Concept

Not applicable - Gas Optimization

Recommended Mitigation

Remove the previousWinner variable completely.

- address public previousWinner;
function selectWinner() external {
// ...
- previousWinner = winner;
// ...
}
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!