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

Hardhat's console.log precompiled contract execution inconsistency #4050

Open
2 tasks done
Tracked by #8269
michprev opened this issue Jan 6, 2023 · 2 comments
Open
2 tasks done
Tracked by #8269

Hardhat's console.log precompiled contract execution inconsistency #4050

michprev opened this issue Jan 6, 2023 · 2 comments
Labels
A-compatibility Area: compatibility A-evm Area: EVM C-anvil Command: anvil T-bug Type: bug
Milestone

Comments

@michprev
Copy link
Contributor

michprev commented Jan 6, 2023

Component

Anvil

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (a44159a 2023-01-03T00:04:00.577535633Z)

What command(s) is the bug in?

anvil --prune-history --port 8545 --gas-price 0 --base-fee 0 --steps-tracing

Operating System

Linux

Describe the bug

From my understanding, precompiled contracts behave differently when called (CALL, CALLCODE, DELEGATECALL, STATICCALL opcodes) in a way that an execution context for the precompiled contract is not even started, and the execution continues in the caller contract.

If you consider the following function:

function callDatacopy(bytes memory data) public returns (bytes memory) {
    bytes memory ret = new bytes(data.length);
    assembly {
        let len := mload(data)
        if iszero(call(gas(), 0x04, 0, add(data, 0x20), len, add(ret,0x20), len)) {
            invalid()
        }
    }

    return ret;
}

It calls the identity (0x4) precompiled contract.

Looking at the CALL trace in debug_traceTransaction for this function call:

{'depth': 1, 'gas': 29977308, 'gasCost': 118, 'op': 'CALL', 'pc': 229, 'stack': ['0xcaa26032', '0x5f', '0x80', '0x60', '0xc0', '0x6', '0x6', '0xe0', '0x6', '0xa0', '0x0', '0x4', '0x1c96adc']}
{'depth': 1, 'gas': 29977190, 'gasCost': 3, 'op': 'PUSH2', 'pc': 230, 'stack': ['0xcaa26032', '0x5f', '0x80', '0x60', '0xc0', '0x6', '0x1']}

There is no STOP opcode (or any other opcode) with depth 2. This is consistent with other development chains (hardhat, ganache) and especially with geth.

However, for the Hardhat's console.log precompiled contract (0x000000000000000000636F6e736F6c652e6c6f67), Anvil behaves differently:

{'depth': 2, 'gas': 29468076, 'gasCost': 2600, 'op': 'STATICCALL', 'pc': 18898, 'stack': ['0x0', '0xffffffffffffffffffffffffffffffffffffffff', '0x80', '0x120', '0x63b89b50', '0x0', '0x0', '0xa513e6e4b8f2a923d98304ec87f64353c4d5c853', '0x0', '0x2a0', '0xa513e6e4b8f2a923d98304ec87f64353c4d5c853', '0x4', '0xc87b56dd00000000000000000000000000000000000000000000000000000000', '0x1621', '0x707', '0x0', '0x0', '0xe4', '0x360', '0x636f6e736f6c652e6c6f67', '0x1c1a5ac']}
{'depth': 3, 'gas': 29005078, 'gasCost': 0, 'op': 'STOP', 'pc': 0, 'stack': []}

The first trace is the call to the console.log contract. The second trace is STOP in the context of the console.log contract, which differs from the behavior for other precompiled contracts.

@michprev michprev added the T-bug Type: bug label Jan 6, 2023
@mattsse
Copy link
Member

mattsse commented Jan 8, 2023

I see, I think we can just mark the contract as precompile?

@michprev
Copy link
Contributor Author

Yes, I don't know the exact implications of marking an address as a precompiled contract, but it sounds like something that should fix this issue.

@rkrasiuk rkrasiuk added A-evm Area: EVM C-anvil Command: anvil labels Jan 31, 2023
@zerosnacks zerosnacks added the A-compatibility Area: compatibility label Jun 27, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compatibility Area: compatibility A-evm Area: EVM C-anvil Command: anvil T-bug Type: bug
Projects
None yet
Development

No branches or pull requests

4 participants