Snowman Merkle Airdrop

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

Missing Zero Balance Check Allows Wasteful Gas Consumption in Snow.sol::collectFee

Root + Impact

Root: The collectFee function executes transfer operations without checking if there are any fees to collect, performing unnecessary operations when contract balances are zero.

Impact: Collectors waste gas on empty transactions and the function lacks proper event emission, making fee collection tracking difficult and inefficient.

Description

  • Normal Behavior: The fee collection function should only execute transfers when there are actual fees to collect and should emit events for proper tracking.

  • Specific Issue: The function blindly transfers WETH and ETH balances without checking if they're greater than zero, and the missing FeeCollected event (despite being declared) prevents proper monitoring of collection activities.

Risk

Likelihood: High

  • Collectors will call collectFee() regularly during periods when no fees have accumulated, such as during protocol launch or low user activity phases

  • The function lacks any balance validation, making zero-balance collection attempts inevitable during routine fee harvesting operations

Impact: Low

  • Gas Inefficiency: Unnecessary gas consumption occurs when transferring zero amounts, leading to wasted transaction costs for collectors

  • Poor Monitoring: Missing FeeCollected event emission prevents proper tracking and auditing of fee collection activities, reducing operational transparency



Recommended Mitigation

This fix adds zero balance validation to prevent wasteful gas consumption.

function collectFee() external onlyCollector {
- uint256 collection = i_weth.balanceOf(address(this));
- i_weth.transfer(s_collector, collection);
-
- (bool collected,) = payable(s_collector).call{value: address(this).balance}("");
- require(collected, "Fee collection failed!!!");
+ uint256 wethBalance = i_weth.balanceOf(address(this));
+ uint256 ethBalance = address(this).balance;
+
+ if (wethBalance == 0 && ethBalance == 0) {
+ revert S__ZeroValue();
+ }
+
+ if (wethBalance > 0) {
+ i_weth.transfer(s_collector, wethBalance);
+ }
+
+ if (ethBalance > 0) {
+ (bool collected,) = payable(s_collector).call{value: ethBalance}("");
+ require(collected, "Fee collection failed!!!");
+ }
+
+ emit FeeCollected();
}
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.