EIP-1186 Merkle proof retrieval RPC (eth_getProof) (RPC-Method to get Merkle Proofs - eth_getProof)
No call decision · Networking & nodes · EIP status Stagnant · created 2018-06-24
Adds the eth_getProof RPC method, which returns Merkle proofs for accounts and storage values, allowing data to be verified externally using only the state root in a block header.
Why it is needed
Ethereum's state is stored as a Merkle tree, so in theory every value can be verified with a proof. However, the existing RPCs eth_getBalance, eth_getTransactionCount, eth_getStorageAt, and eth_getCode only return a value without providing proof that the value is correct. Generating a proof requires access to the full state database, which standard RPCs cannot provide; the only option was the non-standard method of stopping the client and reading the leveldb files directly. The Light Ethereum Subprotocol (LES) already has internal functionality for generating proofs, but it is not exposed externally. Opening up this functionality as an RPC would let environments that cannot run a light client directly, such as IoT devices or mobile apps, verify responses from an untrusted remote node using only a single trusted block hash. This is also important for the security of layer 2 technologies.
What changes
Today
- Account balance, nonce, code, and storage values can be queried, but no proof that the value is correct can be obtained
- Generating a proof requires the non-standard method of stopping the client and reading the leveldb files directly
- Anything other than a light client (IoT, mobile apps) must simply trust the response from a remote node as is
After EIP-1186
- A single eth_getProof call returns the account information together with a Merkle proof and proofs for the requested storage keys
- Trusting only the stateRoot of a block header allows direct offline verification of account and storage values
- The fact that a value does not exist can also be received in the form of a proof
Who is affected
- Wallet & app developers: Logic can be built to directly verify account and storage values without trusting the remote node.
- IoT and mobile apps: Even without being able to run a light client directly, data can be verified using only a trusted block hash.
- Layer 2 technologies: Merkle proofs over state underpin the security of layer 2 technologies.
- Client teams: The proof-generation functionality that already exists internally must be exposed externally as the eth_getProof RPC method.
In depth
Method definition
Adds eth_getProof to the eth module. The parameters are (1) a DATA 20-byte account address, (2) an ARRAY of 32-byte storage keys (same keys as eth_getStorageAt), and (3) a QUANTITY|TAG block number or the "latest"/"earliest" tag. The return value is an account object with the fields balance, codeHash, nonce, storageHash, accountProof, and storageProof.
The 4 fields of the account object
Returns the 4 fields of the account object as defined in the yellow paper: [nonce, balance, storageHash, codeHash]. For a simple account with no code, the codeHash is "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470". Hashing these fields can also be used afterward to track whether the account state has changed.
Construction of accountProof
accountProof is an ARRAY of rlp-serialized Merkle tree nodes. It is constructed starting from the stateRoot node of the specified block, following the SHA3 hash of the account address as the path.
Construction of storageProof
storageProof is an ARRAY of the requested storage entries. Each entry consists of key (the requested storage key), value (the storage value), and proof (an ARRAY of Merkle tree nodes starting from the storageHash node, following the SHA3 hash of that key as the path).
Proofs for values that do not exist
It must also be possible to prove that an address or storage value does not exist. In this case, the nodes are provided from the root node along the path up to the last matching node. If the last node is of branch type, it shows that the value at that path is empty; if it is of leaf type, it shows that it points to a different relative path, thereby proving that the requested path does not exist.
Backward compatibility and remaining open discussion
Since only a new method is added, there are no backward compatibility issues. However, two proposals remain unresolved: using a block hash instead of a block number as the parameter, which would also allow proofs for uncle block state, and removing the balance, nonce, storageHash, and codeHash fields from the account object to reduce data volume, deriving them instead by deserializing the last node of the proof. Test cases have also not yet been written (TODO). This EIP's status is Stagnant, and discussion is currently halted.