Introduction to EVM
The Ethereum Virtual Machine (EVM) is a stack-based virtual machine designed for executing smart contracts on the Ethereum blockchain. With a maximum stack depth of 1024, each element is 256 bits (32 bytes) wide. During execution, it maintains transient memory (volatile storage) and processes operations via an instruction set where each opcode is 8 bits long.
Key Features of EVM:
- Stack Architecture: No registers; relies on a Last-In-First-Out (LIFO) stack.
- 256-bit Precision: All operations handle 32-byte data chunks.
- Ephemeral Memory: Temporary data storage during contract execution.
EVM Bytecode and Instruction Set
Explore the full EVM opcode reference at ethervm.io. Below are categorized instructions:
1. Arithmetic and Logical Operations
Performed modulo 2²⁵⁶ unless specified otherwise.
| Opcode | Name | Input Stack | Output Stack | Description |
|--------|---------------|------------------|-----------------|--------------------------------------|
| 0x01 | ADD | a, b | a + b | Addition |
| 0x02 | MUL | a, b | a * b | Multiplication |
| 0x03 | SUB | a, b | a - b | Subtraction |
| 0x10 | LT | a, b | a < b | Unsigned comparison |
| 0x16 | AND | a, b | a & b | Bitwise AND |
👉 Master EVM opcodes with this interactive tool
2. Storage and Memory Operations
EVM uses three storage types:
- Stack: Accessed via
PUSH/POPinstructions. - Memory: Volatile; modified via
MLOAD/MSTORE. - Storage: Persistent; managed with
SLOAD/SSTORE.
| Opcode | Name | Function |
|--------|---------------|-------------------------------------------|
| 0x51 | MLOAD | Load 32 bytes from memory |
| 0x55 | SSTORE | Write to persistent storage |
3. Control Flow Instructions
Jumps: Restricted to
JUMPDESTmarkers.JUMP(unconditional)JUMPI(conditional)
4. Contract Interaction
- CREATE/CREATE2: Deploy new contracts.
CALL/DELEGATECALL: Execute external calls.
DELEGATECALLpreserves the originalmsg.sender.
EVM Reverse Engineering Tools
When source code is unavailable, use these resources to decompile bytecode:
👉 Explore advanced EVM analysis techniques
FAQs
Q1: What distinguishes EVM from traditional VMs?
A: EVM is purpose-built for blockchain, featuring deterministic execution, gas metering, and persistent storage.
Q2: How does DELEGATECALL differ from CALL?
A: DELEGATECALL runs the external code in the context of the caller’s state, whereas CALL modifies the callee’s state.
Q3: Can EVM handle floating-point operations?
A: No—all arithmetic is integer-based modulo 2²⁵⁶.
This guide covers EVM’s core mechanics, instruction set, and practical tools for developers. For further reading, consult Ethereum’s official documentation.
Last updated: November 2022