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
Component
Description
Stack
Temporary storage for operations. Supports 256-bit words, max depth = 1024.
Memory
Volatile RAM-like space. Cleared after execution.
Storage
Persistent blockchain storage. Key-value pairs of 256-bit. Only accessible by the contract itself.
Program Counter (PC)
Points to the current instruction being executed.
Gas
Measures execution cost and prevents DoS. Reduced per instruction.
Opcode Set
EVM 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
CODECOPY copies the bytecode to memory.
PC (Program Counter) starts from 0 and reads instructions sequentially.
Stack is used for computation — values are pushed/popped here.