According to the official Solidity documentation:
The low-level functions
call
,delegatecall
andstaticcall
returntrue
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?