The Physics of Execution: EVM & Opcodes
Why the Ethereum Virtual Machine is slower than native code. The physics of Stack Machines, Gas Metering, and I/O Bottlenecks.
🎯 What You'll Learn
- Deconstruct the EVM as a Stack-Based Machine
- Analyze Opcode Gas Cost (why `SSTORE` costs more than `ADD`)
- Trace a Transaction Execution Step-by-Step
- Calculate the throughput limit of Sequential Execution
- Understand why parallel EVM execution is hard
Introduction
The EVM is Turing Complete, but it is Resource Constrained. It is designed for Determinism, not Speed. It sacrifices raw performance to ensure that a 50,000 server in Tokyo.
This lesson explores the physics of the World Computer and why it is, by design, slow.
The Physics: Stack Machines (EVM)
Your CPU (x86/ARM) is a Register Machine. It operates on fast, internal registers (rax, rbx).
The EVM is a Stack Machine. It has no registers.
It operates on a single Stack of 256-bit words.
The Physics: To add two numbers:
PUSH1 0x05(Stack: [5])PUSH1 0x03(Stack: [3, 5])ADD(Pops 3 and 5, pushes 8. Stack: [8])
Stack machines are easier to implement (simple VM), but slower because every operation requires memory access (Push/Pop) rather than register access.
Deep Dive: Gas Physics (Opcode Cost)
Why does ADD cost 3 gas, but SSTORE costs so much more?
The cost reflects real resource consumption.
ADD: Pure CPU math. Cost is negligible.SSTORE: Disk write to the state trie. A cold slot write costs 20,000 gas (EIP-2929). Warm slot writes (same slot touched earlier in the tx) cost 2,900 gas.
Gas is not arbitrary money. Gas is a proxy for Time.
If SSTORE were cheap, an attacker could fill every node’s hard drive in 1 block, stopping the network. Gas limits enforce resource quotas.
Architecture: Sequential Execution
The EVM processes transactions Sequentially.
Tx1 -> Tx2 -> Tx3.
Even if Tx1 affects Account A and Tx2 affects Account B (unrelated), they cannot run in parallel.
Physics:
This is because State Root N depends on State Root N-1.
If you parallelize, you risk Non-Determinism (Race Conditions).
Modern chains (Solana, Aptos) use Parallel Execution (Block-STM) by pre-declaring memory access dependencies.
Code: Simulating the EVM Stack
class TinyEVM:
def __init__(self, code):
self.code = code
self.pc = 0
self.stack = []
def run(self):
while self.pc < len(self.code):
opcode = self.code[self.pc]
if opcode == "PUSH":
value = self.code[self.pc + 1]
self.stack.append(value)
self.pc += 2
elif opcode == "ADD":
b = self.stack.pop()
a = self.stack.pop()
self.stack.append(a + b)
self.pc += 1
elif opcode == "STOP":
break
return self.stack[-1]
# Execution: 5 + 3
# Code: PUSH 5, PUSH 3, ADD, STOP
vm = TinyEVM(["PUSH", 5, "PUSH", 3, "ADD", "STOP"])
result = vm.run() # Returns 8
Practice Exercises
Exercise 1: The Infinite Loop (Beginner)
Scenario: Smart Contract has while(true) {}.
Result: It consumes all provided Gas. The transaction fails with “Out of Gas”. The validator keeps the fee. The node stops executing when Gas Remaining == 0.
Exercise 2: Storage Cost (Intermediate)
Scenario: You change a variable from 0 to 1.
Task: Calculate cost. Cold SSTORE = 20,000 gas.
Scenario 2: You change it back to 0.
Result: You get a Gas Refund (currently capped at 20% of total gas used in the tx, per EIP-3529) for freeing up storage space.
Exercise 3: Parallelism (Advanced)
Task: Why can’t Ethereum add threads? (Answer: Read/Write conflicts on the Global State Trie. If Tx1 reads Balance A, and Tx2 writes Balance A, the order matters absolutely).
Knowledge Check
- What is a Stack Machine?
- Why is
SSTOREexpensive? - Why is the EVM single-threaded?
- What happens when a transaction runs out of gas?
- How does Parallel Execution (like Solana) work?
Answers
- LIFO. A VM that operates on a Last-In-First-Out data structure instead of registers.
- Disk I/O. Writing to the state trie (persistent storage) is orders of magnitude slower than CPU math.
- Determinism. To ensure every node reaches the exact same state root after every block.
- Revert. State changes are undone, but the fee is paid to the validator for the work done so far.
- Access Lists. Transactions declare which accounts they touch beforehand, allowing non-overlapping txs to run on different cores.
Summary
- EVM: Stack-based, deterministic, intentionally slow.
- Gas: A proxy for compute time and storage I/O.
- Execution: Sequential by design — parallelism requires knowing dependencies in advance.
Full article: Blockchain Node Execution Infrastructure
Want to go deeper?
Weekly infrastructure insights for engineers who build trading systems.
Free forever. Unsubscribe anytime.
You're in. Check your inbox.
Questions about this lesson? Working on related infrastructure?
Let's discuss