EIPs Explained

EIP-1352 · Stagnant · Core · 2018-07-27

EIP-1352: Specify restricted address range for precompiles/system contracts

Reserves the addresses 0x0000…0000 to 0x0000…ffff for precompiles and system contracts, so protocol code can recognise them by range instead of maintaining lists of exceptions.

What problem does it solve?

Precompiled contracts sit at tiny addresses such as 0x01 (ecrecover) and 0x02 (SHA-256). New precompiles and "system contracts" keep being proposed, and several features need to treat them specially, for example by charging less to call them.

Without a defined range, every such rule must list the special addresses one by one and be updated each time a new one is added. EIP-1352 proposes a simple convention: the first 65,536 addresses are reserved for the protocol.

How it works

The whole specification is one rule:

The address range from 0x0000000000000000000000000000000000000000 to 0x000000000000000000000000000000000000ffff is reserved for precompiles and system contracts.

  • Regular accounts and contracts are not supposed to be able to obtain these addresses.
  • No explicit checks are added. The chance of a key pair or a CREATE producing an address with 18 leading zero bytes is negligible, so the spec deliberately does not add validation to transaction signing or contract creation.
  • The spec notes that no contracts had been created at these addresses on mainnet, so reserving the range causes no compatibility problems.

Other proposals could then say "if the target is in the reserved range" instead of naming addresses. EIP-2046, for example, cites this EIP to define which STATICCALL targets get a discount.

Sample code

A helper that applies the convention (illustrative; the range is not enforced by the protocol):

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

library ReservedRange {
    uint160 internal constant MAX_RESERVED = 0xffff;

    /// True if `a` falls in the EIP-1352 precompile / system-contract range.
    function isReserved(address a) internal pure returns (bool) {
        return uint160(a) <= MAX_RESERVED;
    }
}

The same check in TypeScript:

const isReserved = (addr: string) => BigInt(addr) <= 0xffffn;

isReserved("0x0000000000000000000000000000000000000002"); // true  (SHA-256 precompile)
isReserved("0x0000000000000000000000000000000000010000"); // false (0x10000, just past the range)

Things to know

  • Status is Stagnant. The range was never formally adopted as a consensus rule.
  • Precompiles have in practice been added at low addresses inside this range. Several later system contracts, such as those from EIP-4788 and EIP-2935, were instead deployed at ordinary-looking addresses outside it.
  • EIP-2929 solved the "cheaper calls to precompiles" problem differently, by treating all precompile addresses as always warm.
  • Do not rely on this range for security decisions in contracts. It is a convention, not something the EVM enforces.

#precompile #system-contract #address #evm #core

Details

Authors
Alex Beregszaszi (@axic)
Status
Stagnant
Type
Standards Track / Core
Created
2018-07-27
Required by

Machine-readable: Markdown · JSON