Briefly discuss about the operation of Ethereum Virtual Machine (EVM) with the help of a neat diagram.

The Ethereum Virtual Machine (EVM) is the heart of Ethereum’s smart contract system.
It is a stack-based, Turing-complete virtual machine that executes smart contracts and transforms the system’s global state with every transaction.


Features of EVM

  • Stack-Based: Uses a Last-In-First-Out (LIFO) stack with max 1024 elements.
  • Word Size: 256-bit (32 bytes), ideal for cryptographic operations.
  • Turing-Complete: Can perform any computation, but gas limits prevent infinite loops.
  • Isolated: Sandbox environment — no access to filesystem or internet.
  • Deterministic: Same input will always produce the same output on all nodes.

Main Components of EVM

ComponentDescription
StackTemporary storage for operations. Supports 256-bit words, max depth = 1024.
MemoryVolatile RAM-like space. Cleared after execution.
StoragePersistent blockchain storage. Key-value pairs of 256-bit. Only accessible by the contract itself.
Program Counter (PC)Points to the current instruction being executed.
GasMeasures execution cost and prevents DoS. Reduced per instruction.
Opcode SetEVM instructions like ADD, MUL, CALL, etc.
Code (ROM)Read-only area where contract bytecode is stored. Copied to memory via CODECOPY.

Neat Diagram of EVM Operation

Execution Flow of EVM

  1. CODECOPY copies the bytecode to memory.
  2. PC (Program Counter) starts from 0 and reads instructions sequentially.
  3. Stack is used for computation — values are pushed/popped here.
  4. Opcodes (e.g., ADD, MSTORE) manipulate stack/memory/storage.
  5. Gas is consumed per instruction. If it runs out → exception & halt.
  6. Execution halts with STOP, RETURN, REVERT, or errors.

Memory vs Storage vs Stack

TypeNatureScopeExample Use
StackTemporaryPer operationImmediate calculations
MemoryVolatilePer executionStore function variables
StoragePersistentPer contractStore contract state/data

Leave a Reply

Your email address will not be published. Required fields are marked *