Snowman Merkle Airdrop

First Flight #42
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Impact: low
Likelihood: medium
Invalid

[M-5] Inefficient loop usage in mintSnowman() can cause gas fees exceeding block gas limit

[M-5] Inefficient loop usage in mintSnowman() can cause gas fees exceeding block gas limit

Description

  • The mintSnowman() function uses a for loop to mint the NFTs

  • Due to the unbound loop the execution is very gas costly and can exceed the block gas limit

function mintSnowman(address receiver, uint256 amount) external {
for (uint256 i = 0; i < amount; i++) {
_safeMint(receiver, s_TokenCounter);
@> emit SnowmanMinted(receiver, s_TokenCounter);
@> s_TokenCounter++;
}
}

Risk

Likelihood:

  • Whenever a very high value for amount is passed while calling mintSnowman()

Impact:

  • The execution may exceed block gas limit

  • Function will revert

Proof of Concept

Add the following test case to the test suite of snowman:

function test_gasInefficiency() public {
uint256 start = gasleft();
nft.mintSnowman(alice, 1);
uint256 lessFee = start - gasleft();
start = gasleft();
nft.mintSnowman(alice, 1000);
uint256 moreFee = start - gasleft();
assert(lessFee < moreFee);
}

Recommended Mitigation

- for (uint256 i = 0; i < amount; i++) {
- _safeMint(receiver, s_TokenCounter);
- emit SnowmanMinted(receiver, s_TokenCounter);
- s_TokenCounter++;
- }
+ for (uint256 i = 0; i < amount; i++) {
+ _safeMint(receiver, s_TokenCounter + i);
+ }
+ s_TokenCounter = s_TokenOwner + amount;
+ emit SnowmanMinted(receiver, s_TokenCounter);
Updates

Lead Judging Commences

yeahchibyke Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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