--- eip: 7814 title: Introspection opcodes description: Introspection opcodes that expose the current block context to the EVM author: Brecht Devos (@Brechtpd) discussions-to: https://ethereum-magicians.org/t/eip-7814-introspection-precompiles/21872 status: Draft type: Standards Track category: Core created: 2024-11-09 --- ## Abstract This EIP proposes to add an opcode that enables introspection of the chain state at arbitrary points within a block in the EVM. Currently, the EVM only has access to the state of previous blocks. No block data is currently exposed to the EVM for the block it's executing in. ## Motivation The new opcode aims to enhance introspection capabilities within the EVM, enabling the calculation of the latest chain state offchain at any point in an Ethereum block. This is important to allow general and efficient synchronous composability with L1. Otherwise, to ensure having the latest L1 state, the state would have to be read on L1 and passed in as a separate input. This is expensive and there may be limitations on who can read the state without something like [EIP-2330](./eip-2330). This proposal allows computing the latest state from the state root of the previous block and the transactions that are in the current block. This data can then be passed into any system requiring the latest chain state where the partial block can be re-executed to compute the latest state before the start of the current transaction in a provable way. The state can be computed at arbitrary points inside the transaction as well by enforcing things inside the current transaction, this requires no additional EVM functionality. ## Specification - `TXROOT`: This opcode returns the transaction trie root of all transactions in the current block, excluding the transaction that is currently executing (which could introduce a circular dependency between the merkle tree proof and the transactions hash and thus the merkle trie root). The tx trie is already calculated for the block header. This EIP just enforces that the trie is constructed incrementally per transaction and exposes the root to the EVM. ### Gas Cost The gas cost for `TXROOT` is a fixed fee of `2`. ## Rationale Simple and efficient access to the latest state of a chain is critical for composability. For synchronous composability, we need to be able to immediately prove all offchain work inside the same block. This makes it impossible to delay the proving to a later block where more information about the current block is available. Onchain functionality to verify arbitrary state like [EIP-2330](./eip-2330) is great, but still expensive because it still requires onchain logic. This EIP makes it possible to move all verfication logic offchain without any limitations or edge cases (we need to be able to make sure ALL state is as expected, which is easy if you can simply re-execute). It also supersedes [EIP-7793](./eip-7793.md) which only exposes the current transaction index for use in the context of encrypted mempools. After [EIP-7793](./eip-7825.md) the transaction size will be limited. This EIP makes it possible to chain transactions that are block position dependent (i.e. multiple transactions that need to be top of block after each other). ### Gas Price The precompiles are priced to match similar opcodes in the `W_base` set. ## Backwards Compatibility Further discussion required. ## Test Cases N/A ## Security Considerations Needs discussion. This EIP might impact MEV. ## Copyright Copyright and related rights waived via [CC0](../LICENSE.md).