Snowman Merkle Airdrop

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

Missing Zero Amount Check in mintSnowman()

Root + Impact

Description

  • Describe the normal behavior in one or more sentences
    The `mintSnowman()` function doesn't validate that `amount > 0` before entering the loop. While calling with `amount = 0` won't cause incorrect state changes, it wastes gas and could be used for griefing.

  • Explain the specific issue or problem in one or more sentences
    The function accepts any `uint256` value for `amount`, including zero. While the loop won't execute if `amount == 0`, the function still consumes gas for the external call and validation.

```solidity
// @> Snowman.sol:36-44
function mintSnowman(address receiver, uint256 amount) external {
for (uint256 i = 0; i < amount; i++) { // @> Loop doesn't execute if amount == 0
_safeMint(receiver, s_TokenCounter);
emit SnowmanMinted(receiver, s_TokenCounter);
s_TokenCounter++;
}
}
```

Risk

Likelihood:

  • * Users or contracts might accidentally call with amount = 0

    * Lower likelihood as it provides no benefit

    * Could be used for griefing if access control is added later

Impact:

  • * Unnecessary gas consumption

    * Potential for griefing attacks

    * Poor user experience

    * Minor issue but easy to fix

Proof of Concept

```solidity
function testZeroAmountMinting() public {
Snowman nft = deploySnowman();
address user = makeAddr("user");
// Call with zero amount - wastes gas but doesn't break
nft.mintSnowman(user, 0);
assert(nft.balanceOf(user) == 0);
// Function executed but did nothing
}
```

Recommended Mitigation

```diff
// Snowman.sol
function mintSnowman(address receiver, uint256 amount) external {
+ if (amount == 0) {
+ revert SM__ZeroAmount();
+ }
+
for (uint256 i = 0; i < amount; i++) {
_safeMint(receiver, s_TokenCounter);
emit SnowmanMinted(receiver, s_TokenCounter);
s_TokenCounter++;
}
}
```
Also add the error:
```diff
// Snowman.sol
error ERC721Metadata__URI_QueryFor_NonExistentToken();
error SM__NotAllowed();
+error SM__ZeroAmount();
```
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge 17 days 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!