What is the EVM?
The Ethereum Virtual Machine (EVM) is a computation engine that executes smart contracts on the Ethereum blockchain. It’s a stack-based virtual machine that processes bytecode instructions (opcodes) to perform operations on data.Cubipods implements a minimal but functional subset of the EVM, focusing on core operations needed to understand and test EVM bytecode.
Stack-Based Architecture
The EVM uses a stack-based architecture rather than a register-based one. This means:- Operations work with values on a stack (Last-In-First-Out data structure)
- Most opcodes pop operands from the stack and push results back
- The stack has a maximum depth of 1024 elements
Stack Example
Core Components
Cubipods implements the essential EVM components:Stack
1024-element stack for temporary values and computation
Memory
Volatile byte-addressable memory that expands as needed
Storage
Persistent key-value storage using 32-byte slots
Bytecode
Hexadecimal sequence of opcodes and their operands
How Cubipods Implements the EVM
1. Lexical Analysis
TheLexer tokenizes bytecode into individual bytes:
2. Instruction Decoding
Each byte pair is converted to anInstructionType:
3. Execution Loop
The VM executes instructions sequentially:Key Differences from Full EVM
Cubipods is a minimal implementation for learning and testing:| Feature | Full EVM | Cubipods |
|---|---|---|
| Opcodes | 140+ | 40+ core opcodes |
| Gas | Full gas metering | No gas tracking |
| Context | Account state, block info | Standalone execution |
| Precompiles | 9 precompiled contracts | None |
| Purpose | Production blockchain | Education & testing |
Cubipods focuses on correctness of core operations rather than production features like gas optimization or account management.
Word Size
The EVM uses 256-bit (32-byte) words for all stack operations:- All integers are 256 bits
- Memory is byte-addressable but operations work with 32-byte chunks
- Storage slots are 32-byte keys and values
Bytes32 type:
Next Steps
Bytecode Format
Learn how to read and write EVM bytecode
Execution Model
Understand how bytecode is executed
Supported Opcodes
Explore all supported operations
Try It Out
Execute your first bytecode