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:
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:
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.
Component
Anvil
Have you ensured that all of these are up to date?
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:
It calls the identity (0x4) precompiled contract.
Looking at the
CALL
trace indebug_traceTransaction
for this function call: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:The first trace is the call to the
console.log
contract. The second trace isSTOP
in the context of theconsole.log
contract, which differs from the behavior for other precompiled contracts.