2

According to the official Solidity documentation:

The low-level functions call, delegatecall and staticcall return true as their first return value if the account called is non-existent, as part of the design of the EVM. Account existence must be checked prior to calling if needed.

Does that mean that if I use call (/delegatecall/staticcall) in my contract, I should first check that the address is a contract?

For this example code:

function swap(
    IERC20 _asset,
    uint256 _amount,
    address _routingContract,
    bytes calldata _routingPayload)
internal
{
    IERC20(_asset).safeApprove(_routingContract, _amount);
    (bool success,) = _routingContract.call(_routingPayload);
    if (!success) revert SwapFailed();
}

Would call return true if the address is not a contract?

Which in this case I'm assuming the best practice will be to add the line:

if (_routingContract.code.length == 0) revert InvalidRoutingContract();

And also is there a way to know if the call actually passed to the contract's fallback function?

1 Answer 1

2

You could use Address.isContract() from the OpenZeppelin contracts.

There's no way to determine if the callback was executed or no. It shouldn't be too important since many important contracts use a proxy contract as a "frontend".

Your Answer

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

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