Santa's List

AI First Flight #3
Beginner FriendlyFoundry
EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Gas Optimizations and Informational Findings — SantasList

[G-1] Redundant double SLOAD in collectPresent()
Severity: Gas

Location: SantasList.sol:154-161

Description: s_theListCheckedOnce[msg.sender] and s_theListCheckedTwice[msg.sender] are each read twice — once for the NICE branch check and again for the EXTRA_NICE branch check. Each warm SLOAD costs 100 gas after the first access.

// @> s_theListCheckedOnce read twice, s_theListCheckedTwice read twice
if (s_theListCheckedOnce[msg.sender] == Status.NICE
&& s_theListCheckedTwice[msg.sender] == Status.NICE) {
...
} else if (s_theListCheckedOnce[msg.sender] == Status.EXTRA_NICE
&& s_theListCheckedTwice[msg.sender] == Status.EXTRA_NICE) {
...
}

Impact: ~200 extra gas wasted per collectPresent() call.

Recommendation:

+ Status once = s_theListCheckedOnce[msg.sender];
+ Status twice = s_theListCheckedTwice[msg.sender];
- if (s_theListCheckedOnce[msg.sender] == Status.NICE
- && s_theListCheckedTwice[msg.sender] == Status.NICE) {
+ if (once == Status.NICE && twice == Status.NICE) {
_mintAndIncrement();
return;
- } else if (s_theListCheckedOnce[msg.sender] == Status.EXTRA_NICE
- && s_theListCheckedTwice[msg.sender] == Status.EXTRA_NICE) {
+ } else if (once == Status.EXTRA_NICE && twice == Status.EXTRA_NICE) {
_mintAndIncrement();
i_santaToken.mint(msg.sender);
return;
}

[G-2] tokenURI() should be external instead of public

Severity: Gas

Location: SantasList.sol:187

Description: tokenURI() is declared public pure but is never called internally within the contract. public functions generate additional bytecode to handle both internal and external call paths. Since this function is only ever called externally, declaring it public wastes deployment gas unnecessarily.

// @> never called internally — public is wasteful here
function tokenURI(uint256 /* tokenId */ ) public pure override returns (string memory) {
return TOKEN_URI;
}

Impact: Minor unnecessary bytecode and marginal deployment gas overhead.

Recommendation:

- function tokenURI(uint256 /* tokenId */ ) public pure override returns (string memory) {
+ function tokenURI(uint256 /* tokenId */ ) external pure override returns (string memory) {
return TOKEN_URI;
}

[G-3] Missing unchecked block on s_tokenCounter increment

Severity: Gas

Location: SantasList.sol:181

Description: s_tokenCounter is a uint256 that increments by 1 on each mint. Overflowing a uint256 would require 2^256 mints — an impossibility in practice. The Solidity 0.8+ default overflow check on s_tokenCounter++ wastes ~20 gas per mint with no safety benefit.

function _mintAndIncrement() private {
// @> overflow check on uint256 counter is unnecessary — wastes ~20 gas per mint
_safeMint(msg.sender, s_tokenCounter++);
}

Impact: ~20 gas wasted on every NFT mint.

Recommendation:

function _mintAndIncrement() private {
- _safeMint(msg.sender, s_tokenCounter++);
+ _safeMint(msg.sender, s_tokenCounter);
+ unchecked { s_tokenCounter++; }
}


Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 4 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!