EIPs Explained

EIP-1186 · Stagnant · Interface · 2018-06-24

EIP-1186: RPC-Method to get Merkle Proofs - eth_getProof

Defines the eth_getProof JSON-RPC method, which returns an account's state plus Merkle proofs so anyone holding a trusted state root can verify it without trusting the node.

What problem does it solve?

Normal RPC calls like eth_getBalance or eth_getStorageAt return a value and ask you to trust the node. Ethereum's state is stored in a Merkle Patricia trie, so every value could be proven against the stateRoot in a block header, but the standard RPC offered no way to get that proof.

EIP-1186 adds eth_getProof. With it, a mobile app, an IoT device, a bridge or a Layer 2 can ask an untrusted node for data and check the answer itself, as long as it knows a trusted block header.

How it works

Parameters

  1. The account address (20 bytes).
  2. An array of storage keys (32 bytes each) to prove.
  3. A block number or tag such as "latest".

Result

Field Meaning
balance, nonce Account values
codeHash Hash of the account's code
storageHash Root of the account's storage trie
accountProof RLP-encoded trie nodes from the stateRoot down to the account, following keccak256(address)
storageProof For each requested key: key, value, and proof nodes from storageHash down, following keccak256(key)

To verify, you take the block's stateRoot, walk accountProof to recover the account record [nonce, balance, storageHash, codeHash], then walk each storage proof starting from that storageHash.

Proofs also work for values that do not exist: the proof follows the path as far as it goes and shows that it ends in an empty branch slot or a leaf for a different path.

Sample code

Requesting a proof with ethers v6:

import { JsonRpcProvider, zeroPadValue } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);

const slot0 = zeroPadValue("0x00", 32);
const proof = await provider.send("eth_getProof", [
  "0x7F0d15C7FAae65896648C8273B6d7E43f58Fa842", // account
  [slot0],                                       // storage keys
  "latest",
]);

console.log(proof.balance, proof.nonce, proof.storageHash);
console.log("account proof nodes:", proof.accountProof.length);
console.log("slot 0 =", proof.storageProof[0].value);

Raw JSON-RPC request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_getProof",
  "params": ["0x7F0d15C7FAae65896648C8273B6d7E43f58Fa842", ["0x0000000000000000000000000000000000000000000000000000000000000000"], "latest"]
}

To actually verify, feed accountProof and the header's stateRoot into a Merkle Patricia trie proof verifier (for example from a trie library in your language).

Things to know

  • Status: Stagnant as an EIP, yet eth_getProof is widely implemented by execution clients and used by bridges, light clients and storage-proof tooling.
  • A proof is only as trustworthy as the block header you check it against. Get the stateRoot from a source you trust, not from the same node.
  • For an account without code, codeHash is the hash of empty bytes, 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470.
  • Many nodes only keep recent state, so proofs for old blocks may require an archive node.
  • The spec suggested a block hash parameter as a possible improvement; EIP-1898 added that style of block identifier to state-reading RPC methods in general.

#json-rpc #merkle #proof #light-client #state

Details

Authors
Simon Jentzsch <[email protected]>, Christoph Jentzsch <[email protected]>
Status
Stagnant
Type
Standards Track / Interface
Created
2018-06-24
Requires

Machine-readable: Markdown · JSON