Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<address>.call{value: value}(new bytes(0)) causes ERROR call may fail or behave unexpectedly due to empty code #793

Open
2 tasks done
vmaark opened this issue Dec 19, 2024 · 6 comments
Assignees
Labels
bug 🐛 Something isn't working needs triage ♟️ Issue needs to be picked up or assigned

Comments

@vmaark
Copy link

vmaark commented Dec 19, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.0.2 (68fcb7d 2024-12-16T00:45:46.210537000Z)

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

Sending eth with .call causes the following log in my forge test output:
2024-12-18T22:55:36.093440Z ERROR foundry_zksync_core::vm::tracers::cheatcode: call may fail or behave unexpectedly due to empty code target=0x0000000000000000000000000000000000989682 calldata=""

Although it displays it as an ERROR, the execution continues. Due to having a lot of tests and fuzzing, this really pollutes my console.

Proposed solution:
When calldata is empty, due not assume it's a function call, don't check the address for code.

@vmaark vmaark added bug 🐛 Something isn't working needs triage ♟️ Issue needs to be picked up or assigned labels Dec 19, 2024
@vmaark
Copy link
Author

vmaark commented Dec 20, 2024

Also I suspect that this is making somehow my tests running extremely slow (30 minutes on github actions, instead of like 5 mins), not sure if there's some retry mechanism under the hood, or it's just the fuzzing, but I have 100s of lines of the same error being reported (and ignored, execution continues).

@Jrigada
Copy link
Contributor

Jrigada commented Jan 6, 2025

Hey @vmaark can you share an example of a test that is printing the error? A simple

.call{value: value}("") is not printing it out for me.

contract A {
    receive() external payable {}
}

contract AddressCallTest is Test {
    A internal a;
    function setUp() public {
        a = new A();
    }
    function testAddressCall() public {
        (bool success, ) = address(a).call("");
        assertTrue(success);
    }

    function testAddressCallValue() public {
        (bool success, ) = address(a).call{value: 1 ether}("");
        assertTrue(success);
        assertEq(address(a).balance, 1 ether);
    }
}

From what I've seen it depends on how and where you do the deployment of the contract you are then calling.

@Jrigada Jrigada self-assigned this Jan 7, 2025
@vmaark
Copy link
Author

vmaark commented Jan 8, 2025

contract A {
receive() external payable {}
}

contract AddressCallTest is Test {
A internal a;
function setUp() public {
a = new A();
}
function testAddressCall() public {
(bool success, ) = address(a).call("");
assertTrue(success);
}

function testAddressCallValue() public {
    (bool success, ) = address(a).call{value: 1 ether}("");
    assertTrue(success);
    assertEq(address(a).balance, 1 ether);
}

}

in this example you're sending to a contract which works fine. It happens when sending eth to an EOA using .call - sorry if that wasn't clear from the original description.

Also additionally this ERROR / warning is making the test run extremely slow.

@Jrigada
Copy link
Contributor

Jrigada commented Jan 9, 2025

Hey @vmaark we just merged a fix for this exact case. It should spare you from the error you were getting. Thanks for raising it.

@vmaark
Copy link
Author

vmaark commented Jan 9, 2025

hey @Jrigada, thanks for the quick fix, sounds great! Updated zksync-forge, I assume it is not yet included in the following version:

✗ forge --version
forge 0.0.2 (04e701d 2025-01-09T00:34:37.572492000Z)

@Jrigada
Copy link
Contributor

Jrigada commented Jan 10, 2025

Yes, is not present yet in the release. To use it right now you would have to build directly from main. Probably by today or early next week it will be on the new release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working needs triage ♟️ Issue needs to be picked up or assigned
Projects
None yet
Development

No branches or pull requests

2 participants