✅Gas Saving Technique 19: Early Validation before external call
Introduction
Impact & Details
Example: Implementing Early Validation
solidityCopy code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract ExampleContract {
function withdrawAll() external returns (uint256) {
ILendingPool lp = getLp(); // External call placed before the validation check
if (balanceOf() == 0) {
return 0; // Function would fail here if balance is zero
}
// ... rest of the function ...
}
}Recommended Mitigation Steps
Conclusion
PreviousGas Saving Technique 18: Redundant codeNextGas Saving Technique 20: Storage vs Memory read optimizations
Last updated