EIPs Explained

EIP-7666 · Draft · Core · 2024-03-31

EIP-7666: EVM-ify the identity precompile

A Draft proposal to retire the identity precompile at 0x04 and replace it with seven bytes of ordinary EVM code that does the same thing, as a first step toward removing rarely used precompiles.

What problem does it solve?

Ethereum has many precompiles: special addresses whose behaviour is hard-coded into every client rather than written in EVM bytecode. Nearly half see little use, yet each adds maintenance burden, consensus-bug risk and work for every new client, especially ZK-EVMs and formally verified implementations.

The identity precompile (0x04) simply returns its input. It existed because early on there was no cheap way to copy memory. Since EIP-5656 added MCOPY, that reason is gone. EIP-7666 proposes removing it and replacing it with plain EVM code, as a template for later retiring more complex precompiles (such as little-used hash functions and MODEXP).

How it works

At the start of the fork block:

  • The code of address 0x0000000000000000000000000000000000000004 is set to 0x365f5f37365ff3.
  • From that block on, 0x04 is no longer treated as a precompile; calls to it run this bytecode like any other contract.

The bytecode disassembles to:

36  CALLDATASIZE      ; size
5f  PUSH0             ; offset in calldata = 0
5f  PUSH0             ; destination in memory = 0
37  CALLDATACOPY      ; memory[0:size] = calldata
36  CALLDATASIZE      ; size
5f  PUSH0             ; offset = 0
f3  RETURN            ; return memory[0:size]

It relies on PUSH0 from EIP-3855, hence the dependency.

Sample code

Callers do not need to change anything; this still returns a copy of data before and after the fork:

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

contract CopyViaIdentity {
    function copy(bytes memory data) external view returns (bytes memory out) {
        (bool ok, bytes memory ret) = address(0x04).staticcall(data);
        require(ok, "identity call failed");
        out = ret;
    }
}

New code that just needs a memory copy should use MCOPY instead:

function copyMem(uint256 dst, uint256 src, uint256 len) internal pure {
    assembly { mcopy(dst, src, len) }
}

Things to know

  • Status: Draft. It has not been scheduled for any network upgrade.
  • Functionality is identical, but gas costs change slightly because the call now executes normal opcodes instead of the precompile's fixed pricing. Contracts that pass a tightly calculated gas stipend to 0x04 should be checked.
  • No new functionality is added or made cheaper, so the spec sees no new security risk.
  • If adopted, the same "replace with EVM code" pattern could be applied to other precompiles in future proposals.

#evm #precompiles #core #simplification

Details

Authors
Vitalik Buterin (@vbuterin), Kevaundray Wedderburn (@kevaundray)
Status
Draft
Type
Standards Track / Core
Created
2024-03-31
Requires
Required by

Machine-readable: Markdown · JSON