stake.link

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

Reduce Redundant Balance Checks

Instead of calling tokenToTransfer.balanceOf(address(this)) within the loop for each token, we can call it once per token, store it in a local variable, and then use the variable for the transfer. This reduces the number of external calls to the token contract.

Also if the balance is zero, we can skip the transfer call altogether, saving gas.

function recoverTokens(address[] calldata _tokens, address _receiver) external onlyOwner {
require(_receiver != address(0), "Invalid receiver address");
for (uint256 i = 0; i < _tokens.length; ++i) {
address tokenAddress = _tokens[i];
require(tokenAddress != address(0), "Token address cannot be zero");
IERC20 tokenToTransfer = IERC20(tokenAddress);
uint256 tokenBalance = tokenToTransfer.balanceOf(address(this));
if (tokenBalance > 0) {
tokenToTransfer.safeTransfer(_receiver, tokenBalance);
}
}
}
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.