0

I have this simple contracts which forwards the calldata to and external contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract AccountTest {

    /**
     * execute a transaction (called directly from owner, or by entryPoint)
     */
    function execute(address dest, uint256 value, bytes calldata func) external {
        call(dest, value, func);
    }


    function call(address target, uint256 value, bytes memory data) internal {
        (bool success, bytes memory result) = target.call{value : value}(data);
        if (!success) {
            assembly {
                revert(add(result, 32), mload(result))
            }
        }
    }

And then I deployed it and called execute with a non-existing address in my local dev node:

  const walletContract = await ethers.getContractFactory("AccountTest");
  let factory = await walletContract.deploy();
  await factory.waitForDeployment();
  let tx = await factory.execute("0x1f9090aae28b8a3dceadf281b0f12828e676c326", 0, "0x");
  let r = await tx.wait()
  console.log(r.status == 1 ? "success" : "fail")

What I expect is that the tx should be reverted, and the status should be fail, but on the contrary, it returns success, and tx is not reverted.

I try to search for documents of the underlying behavior of CALL but didn't get a clue.

Does anyone knows why this is? Thanks!

2

1 Answer 1

2

That's a normal behavior.

This is because low level calls returns true if the address doesn't exist or even if you passed a zero address.

That's why it is always recommended to put checks for zero addresses before any low level call.

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.