Why assembly delegatecall() returns 1 instead of 0 when calling zero (0x000...) address?

744 Views Asked by At

I have this code in a proxy fallback:

assembly {
    calldatacopy(mload(0x40), 0, calldatasize())
    let result := delegatecall(gas(), destination, mload(0x40), calldatasize(), mload(0x40), 0)
    returndatacopy(mload(0x40), 0, returndatasize())
    switch result
    case 1 { return(mload(0x40), returndatasize()) }
    default { revert(mload(0x40), returndatasize()) }
}

The problem arises when destination is a zero address (0x0000000000000000000000). delegatecall goes through, returns 1, then hits case 1 with return data completely empty which triggers ... did it run out of gas error (which is not really related to the question).

I have just swapped to newest Hardhat and web3 (v1.6.1) from Ganache where this would hit default case and revert. Is there something I do not know or was changed recently?

0

There are 0 best solutions below