EIP-2488 · Stagnant · Core · 2019-12-20
EIP-2488: Deprecate the CALLCODE opcode
Proposes switching off the legacy CALLCODE opcode by making it always return failure, removing a feature that was superseded by DELEGATECALL in 2016.
What problem does it solve?
CALLCODE (0xf2) shipped with Frontier. It was meant to let a contract run another contract's code against its own storage, like a library call. In practice it got one thing wrong: inside the borrowed code, msg.sender and msg.value were not preserved from the original call, which made it awkward to use safely.
EIP-7 fixed this in Homestead (early 2016) by adding DELEGATECALL, which does preserve the caller context. Since then CALLCODE has been effectively unused, but every EVM implementation still has to support it. ERC-2488 proposes retiring it.
How it works
The specification is one line. After a fork block:
- Executing
CALLCODEalways pushes0onto the stack, which signals a failed call.
The opcode is not removed and does not abort execution. That is deliberate: by returning failure, a contract that still calls CALLCODE gets a chance to notice and recover, instead of reverting outright.
The spec notes this would not help clients that sync from genesis (they must still execute historical CALLCODEs), but would help light clients and clients that start from a later state.
Sample code
Illustrative pseudocode for the proposed rule:
def op_callcode(evm, gas, addr, value, in_off, in_len, out_off, out_len):
if evm.block_number >= FORK_BLOCK:
evm.stack.push(0) # always "call failed"
return
legacy_callcode(evm, gas, addr, value, in_off, in_len, out_off, out_len)
What contracts should use instead, DELEGATECALL via Solidity:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Caller {
uint256 public x;
// Runs `lib`'s code against this contract's storage, keeping msg.sender
function useLib(address lib, bytes calldata data) external {
(bool ok, ) = lib.delegatecall(data);
require(ok, "delegatecall failed");
}
}
Things to know
- Status is Stagnant. It has not been scheduled, and
CALLCODEstill works on Ethereum mainnet today. - It is a breaking change. The author expects no valuable contracts to be affected, but the spec itself marks that claim as not yet validated, and security considerations, tests and implementation are left as "TBA".
- Modern Solidity does not expose
callcode; usedelegatecall. - The EVM Object Format (EIP-3540) takes a different route: EIP-3670 code validation rejects
CALLCODEin new EOF contracts, while leaving legacy contracts untouched.