The Physics of Execution: EVM & Opcodes

Why the Ethereum Virtual Machine is 100x slower than Native Code. The physics of Stack Machines, Gas Metering, and I/O Bottlenecks.

Intermediate 45 min read Expert Version →

🎯 What You'll Learn

  • Deconstruct the EVM as a Stack-Based Machine
  • Analyze Opcode Gas Cost (Why `SSTORE` is 20,000 gas)
  • Trace a Transaction Execution Step-by-Step
  • Calculate the throughput limit of Sequential Execution
  • Audit the overhead of JIT Compilation vs Interpreter

📚 Prerequisites

Before this lesson, you should understand:

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 500laptopinPerucomputestheexactsameresultasa500 laptop in Peru computes the exact same result as a 50,000 server in Tokyo.

This lesson explores the physics of the World Computer and why it is, by design, slow.


Pro Version: See the full research: Blockchain Node Execution

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:

  1. PUSH1 0x05 (Stack: [5])
  2. PUSH1 0x03 (Stack: [3, 5])
  3. ADD (Popper 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.


Pro Version: See the full research: Blockchain Node Execution

Deep Dive: Gas Physics (Opcode Cost)

Why does ADD cost 3 gas, but SSTORE costs 20,000 gas? Physics relative to Real World Resources.

  • ADD: CPU Cycle (~0.3ns). Cost is negligible.
  • SSTORE: Disk Write (~100 microseconds). Cost is massive.

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.


Pro Version: See the full research: Blockchain Node Execution

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.


Pro Version: See the full research: Blockchain Node Execution

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":
                a = self.stack.pop()
                b = 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

Pro Version: See the full research: Blockchain Node Execution

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 miner 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. SSTORE (Dirty Slot) = 20,000 gas. Scenario 2: You change it back to 0. Result: You get a Gas Refund (up to a limit) 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).


Pro Version: See the full research: Blockchain Node Execution

Knowledge Check

  1. What is a Stack Machine?
  2. Why is SSTORE the most expensive opcode?
  3. Why is the EVM single-threaded?
  4. What happens when a transaction runs out of gas?
  5. How does Parallel Execution (like Solana) work?
Answers
  1. LIFO. A VM that operates on a Last-In-First-Out data structure instead of registers.
  2. Disk I/O. Writing to physical storage is orders of magnitude slower than CPU math.
  3. Determinism. To ensure every node reaches the exact same state root after every block.
  4. Revert. State changes are undone, but the fee is paid to the miner for the work done so far.
  5. Access Lists. Transactions declare which accounts they touch beforehand, allowing non-overlapping txs to run on different cores.

Pro Version: See the full research: Blockchain Node Execution

Summary

  • EVM: Stack-based, Slow, Deterministic.
  • Gas: Metrics for Time & Storage.
  • Execution: Sequential bottleneck.

Pro Version: See the full research: Blockchain Node Execution

Questions about this lesson? Working on related infrastructure?

Let's discuss