What is the redundant extcodesize check and returndatasize check that is mentioned here?

/// @dev This function is gas optimized to avoid a redundant extcodesize check in addition to the returndatasize check
function balance0() private view returns (uint256) {
    (bool success, bytes memory data) =
        token0.staticcall(abi.encodeWithSelector(IERC20Minimal.balanceOf.selector, address(this)));
    require(success && data.length >= 32);
    return abi.decode(data, (uint256));

1 Answer 1


The "extcodesize check" is a check that decides whether the target address (token0 in this example) is a contract (non-zero code size) or a EOA (zero code size). Low level calls to EOA are going to succeed, but the returned data size is going to be zero. The optimization is to check just if the returned data size is correct instead of checking whether token0 is a smart contract before calling the balanceOf function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.