EIPs Explained

EIP-7745 · Draft · Core · 2024-07-17

EIP-7745: Trustless log and transaction index

Replaces the per-block 2048-bit logs bloom with a log index root in the header, a Merkle-ized structure of filter maps and index entries that makes log, transaction and block-hash lookups efficient and provable to light clients.

What problem does it solve?

Every block header carries a logs_bloom: a fixed 2048-bit filter where each log address and topic sets 3 bits. That was fine when blocks were small. Today blocks add over 1000 addresses and topics on average, so the filter is mostly ones and almost every query "matches". Searching logs over a long range ends up downloading huge numbers of receipts, and even with a working bloom you would still need to scan every header.

Full nodes and RPC providers build their own indexes, but those cannot be verified remotely. Applications therefore trust their RPC provider for eth_getLogs results. EIP-7745 puts a verifiable search index into consensus so that a node or light client can check log query results, transaction lookups and canonical block hashes with Merkle proofs.

How it works

  • From the fork, the header field logs_bloom is replaced by log_index_root, the SSZ root of a LogIndex structure.
  • Every indexed item gets a position in one global, ever-growing map value index space:
    • a transaction entry (one transaction value),
    • each log entry (one address value plus 0 to 4 topic values),
    • a block entry (one block value; block N's entry appears at the start of block N+1's index state, because its hash is not yet known while it is built).
  • The full entries are hashed into an index_entries tree keyed by position.
  • For every 2^16 values there is a filter map: a 2^24 by 2^16 sparse bit map. Each value marks one bit; the row is derived from the value's hash, the column from its position plus a hash-based check part. Rows from 1024 consecutive maps (an epoch) sit next to each other in the tree so they can be proven together.
  • Very common values (e.g. a popular token's Transfer topic) would overfill rows, so mapping layers move overflow to other rows with larger limits.
  • To search, you read the rows for your address/topics, keep only columns whose check part matches, and get exact candidate positions. Then you fetch and prove just those entries.

With the proposed constants, the spec estimates roughly 0.0044 false positives per map for a single-value search, and pattern searches (address plus topics at consecutive positions) are far lower.

Sample code

Checking a candidate match from a filter row (simplified from the spec):

MAP_WIDTH = 2**24
VALUES_PER_MAP = 2**16

def get_map_value_index(map_index, column_index):
    map_value_width = MAP_WIDTH // VALUES_PER_MAP
    return map_index * VALUES_PER_MAP + column_index // map_value_width

def is_potential_match(map_index, column_index, map_value_hash):
    idx = get_map_value_index(map_index, column_index)
    return get_column_index(idx, map_value_hash) == column_index

# map value hashes per the spec:
#   sha2(address), sha2(topic), sha2(tx_hash + b"\x01"), sha2(block_hash + b"\x02")

Existing RPC calls stay the same for applications:

const logs = await provider.getLogs({ address: TOKEN, topics: [TRANSFER_TOPIC], fromBlock: 0n, toBlock: "latest" });

Things to know

  • Status: Draft. It changes the block header, so it requires a hard fork and would affect any tool that reads logsBloom.
  • eth_getLogs and filter APIs keep working; the gain is speed and verifiability, not a new API. A wire-protocol extension for fetching log index proofs is described in the EIP's assets.
  • Validators that do not serve logs can keep only a small, hard-capped "minimal state"; the spec estimates about 21 MB to initialize it.
  • Extra storage is estimated at roughly 15 to 20 % of the size of the logs themselves.
  • It relies on SSZ ProgressiveList from EIP-7916. A simpler alternative, EIP-7668, proposes just removing bloom filters.
  • Block builders could deliberately mine values that collide with an important event's rows to raise its false-positive rate; the design makes this harder but cannot rule it out.

#logs #bloom #light-clients #ssz #core

Details

Authors
Zsolt Felföldi (@zsfelfoldi)
Status
Draft
Type
Standards Track / Core
Created
2024-07-17
Requires
Required by

Machine-readable: Markdown · JSON