EIPs Explained

EIP-2014 · Stagnant · Core · 2019-05-10

EIP-2014: Extended State Oracle

Proposed a single ABI-speaking system contract, the Extended State Oracle, through which the EVM could expose extra chain data such as the chain ID, instead of spending a new opcode or a bespoke precompile on each one.

What problem does it solve?

People kept proposing new pieces of chain data that contracts should be able to read: the current chain ID, older block hashes (EIP-210) and so on. There were two existing options, and both were awkward:

  • New opcodes use up the limited opcode space for features few contracts call.
  • New precompiles each need their own custom input and output format agreed and implemented.

EIP-2014 suggests one extensible contract that speaks the standard Solidity ABI. Languages could call it like any other contract, and future data could be added as new functions rather than new opcodes.

How it works

  • A precompile called the Extended State Oracle (ESO) is placed at address 0x0000000000000000000000000000000000000009.
  • It is called with CALL or STATICCALL, using normal ABI-encoded inputs and outputs. Simple elementary types are encouraged.
  • The first and only function defined is getCurrentChainId() returns (uint64), a non-payable pure function. Sending value reverts, as with EIP-140 REVERT.
  • Calling it means sending the 4-byte selector 0x5cf0e8a4; on Ethereum mainnet the reply would be the 32-byte encoding of 1.
  • Later proposals that want to expose data not found in blocks or transactions are encouraged to extend the ESO. The spec imagines it might one day hold state and become a real contract.

Sample code

How a contract would have called the ESO (illustrative; nothing like this is deployed at 0x09):

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

interface IExtendedStateOracle {
    function getCurrentChainId() external pure returns (uint64);
}

contract UsesESO {
    IExtendedStateOracle constant ESO =
        IExtendedStateOracle(0x0000000000000000000000000000000000000009);

    function chainId() external view returns (uint64) {
        return ESO.getCurrentChainId(); // calldata: 0x5cf0e8a4
    }
}

What is actually used today, via the CHAINID opcode:

uint256 id = block.chainid;

Things to know

  • Status is Stagnant. Its rationale, compatibility and test sections were never written ("TBA").
  • Reading the chain ID was solved by a dedicated opcode instead: CHAINID, from EIP-1344, shipped in Istanbul.
  • Address 0x09 went to a different precompile: the BLAKE2 F compression function from EIP-152. Calling 0x09 with the ESO selector does not return a chain ID.
  • The idea of an explicit system contract for extra state reappears in other proposals; EIP-2029 compares itself with the ESO approach.

#precompile #system-contract #chain-id #abi #core

Details

Authors
Alex Beregszaszi (@axic)
Status
Stagnant
Type
Standards Track / Core
Created
2019-05-10
Requires

Machine-readable: Markdown · JSON