What is Bytecode?
EVM bytecode is a sequence of hexadecimal bytes representing instructions (opcodes) and their data. Each opcode is 1 byte, and some opcodes are followed by additional data bytes.Bytecode Structure
- Pushes
0x03onto the stack - Pushes
0x02onto the stack - Adds the top two stack values
Reading Bytecode
Bytecode is read left to right, two characters at a time (one byte):Opcode Format
Fixed-Length Opcodes
Most opcodes are just 1 byte with no additional data:Variable-Length Opcodes (PUSH)
PUSH opcodes are followed by 1-32 bytes of data:| Opcode | Hex | Data Bytes | Example |
|---|---|---|---|
| PUSH1 | 0x60 | 1 byte | 60 0a pushes 10 |
| PUSH2 | 0x61 | 2 bytes | 61 01 2c pushes 300 |
| PUSH3 | 0x62 | 3 bytes | 62 0f 42 40 |
| … | … | … | … |
| PUSH32 | 0x7f | 32 bytes | Full 256-bit value |
PUSH0 (0x5f) pushes zero without any data bytes - it’s the only PUSH that doesn’t need data.
Examples from Tests
Simple Arithmetic
60 0a- PUSH1 1060 14- PUSH1 2003- SUB
Memory Operations
60 20- PUSH1 32 (value to store)60 80- PUSH1 128 (memory address)52- MSTORE
Storage Operations
64 68656c6c6f- PUSH5 “hello” in hex60 01- PUSH1 1 (storage slot)55- SSTORE
Common Patterns
Pushing Small Numbers
For values 0-32, use PUSH1:Pushing Zero
PUSH0 is more efficient:Multiple Operations
Chain operations together:60 02- PUSH1 260 14- PUSH1 2060 14- PUSH1 2001- ADD (20 + 20 = 40)02- MUL (40 * 2 = 80… wait, this is wrong!)
- PUSH1 32 →
[32] - PUSH1 10 →
[32, 10] - ADD →
[42](32 + 10) - PUSH1 2 →
[42, 2] - MUL →
[84](42 * 2)
Bytecode Validation
Cubipods validates bytecode when parsing:Valid Formats
Invalid Formats
Building Bytecode
Manual Construction
Calculate opcodes and data manually:- Look up opcode hex values in Opcodes Overview
- Convert data to hex
- Concatenate bytes
62004869620
Using Tests
The test suite shows many examples:Next Steps
Execution Model
See how bytecode is executed step by step
Opcodes Reference
Complete list of supported opcodes
CLI Examples
More bytecode examples to try
Try It Out
Execute bytecode yourself