EVM Deep Dive (Part 4): Understanding Ethereum's "World State"

·

This article explores the Geth codebase to demystify Ethereum's "world state" and its architectural components.

Introduction

This is Part 4 of the "EVM Deep Dive" series. In Part 3, we examined contract storage mechanics. Here, we’ll explore how individual contract storage integrates into Ethereum’s broader "world state." We’ll dissect Ethereum’s architecture, data structures, and the internal workings of the Go Ethereum (Geth) client.


Ethereum Architecture Overview

Ethereum’s architecture comprises layered data structures, starting with block headers and cascading down to contract storage slots. Below is a simplified breakdown:

Block Header Components

Each block header includes critical fields that anchor Ethereum’s state:

👉 Explore Ethereum block anatomy


State Root: The Gateway to World State

The State Root is a Merkle root hash derived from a Merkle Patricia Trie (MPT) that maps Ethereum addresses to account states. Key points:

Ethereum Account Structure

Each account (e.g., 0x...) stores:

  1. Nonce: Transaction count (EOA) or contract creations (CA).
  2. Balance: Wei held by the address.
  3. CodeHash: Hash of contract bytecode (empty for EOAs).
  4. StorageRoot: Merkle root of contract storage (details below).

StorageRoot: Contract Storage Trie

The StorageRoot is another MPT, but it maps:

How SSTORE & SLOAD Work

  1. SSTORE (Write):

    • Pops key and value from the stack.
    • Updates dirtyStorage in the stateObject (intermediate state).
    • Finalized via StateDB.Commit() (updates StorageRoot).
  2. SLOAD (Read):

    • Pops key from the stack.
    • Checks dirtyStoragependingStorageoriginStorage (in order).
    • Returns the latest value for the slot.

👉 Dive into Geth’s state transitions


Geth Implementation Deep Dive

Key Structures

Initializing a New Account

  1. StateDB.createObject() generates a stateObject with an empty StateAccount.
  2. SSTORE writes propagate through dirtyStoragependingStorageoriginStorage.
  3. StorageRoot updates occur during StateDB.Commit().

FAQs

1. What is the State Root?

The State Root is a Merkle root representing the entire Ethereum state (all accounts) after executing a block’s transactions.

2. How does contract storage connect to the State Root?

3. Why does SLOAD check dirtyStorage first?

dirtyStorage holds the most recent slot values during transaction execution, ensuring reads reflect uncommitted changes.

4. What triggers a StorageRoot update?

StateDB.Commit() finalizes writes by updating the trie database, recalculating the StorageRoot and State Root.


Conclusion

Ethereum’s "world state" is a hierarchical data structure anchored by the State Root and StorageRoot. Understanding these components clarifies how contract storage integrates into the broader blockchain state. Stay tuned for Part 5, where we’ll explore CALL and DELEGATECALL opcodes!

Further Reading:


### SEO Notes:
- **Keywords**: EVM, Geth, World State, State Root, StorageRoot, SSTORE, SLOAD, Merkle Patricia Trie.