stake.link

stake.link
DeFiHardhatBridge
27,500 USDC
View results
Submission Details
Severity: low
Invalid

Zero-Balance check in `recoverTokens`

Summary

The recoverTokens function currently lacks a check for the token balance before initiating transfers. The absence of this check results in unnecessary gas consumption when attempting to transfer zero tokens.

Impact

The absence of a zero-balance check may lead to unnecessary gas consumption when attempting to transfer tokens, even when the balance is zero. The recommended enhancement improves gas efficiency by ensuring transfers are executed only when the token balance is greater than zero.

Tools used

Manual review.

Recommendation Implementation

To address this issue, it is advised to incorporate the provided code snippet into the recoverTokens function. This ensures a more gas-efficient execution of token transfers, avoiding unnecessary transaction costs when the token balance is zero.

uint256 balance = tokenToTransfer.balanceOf(address(this));
if (balance > 0) {
tokenToTransfer.safeTransfer(_receiver, balance);
}

Additionally, enhance efficiency by replacing the current if condition check in recoverTokens with the require statement:

require(_receiver != address(0), "InvalidReceiver");
Updates

Lead Judging Commences

0kage Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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