Try it Live
Run Opcode examples in the interactive playground
Opcode
EVM opcode utilities for bytecode parsing, disassembly, and instruction analysis.Overview
Opcode provides comprehensive utilities for working with EVM opcodes (0x00-0xFF). Supports opcode validation, instruction parsing, bytecode disassembly, jump destination analysis, and opcode categorization (PUSH, DUP, SWAP, LOG, etc.).Quick Start
- Functional API
- Bytecode Parsing
- Disassembly
Type Definition
Core Methods
info()
Get complete opcode metadata.name()
Get opcode mnemonic name.isValid()
Check if byte is valid opcode.isPush()
Check if opcode is PUSH1-PUSH32.pushBytes()
Get number of immediate bytes for PUSH opcode.pushOpcode()
Get PUSH opcode for given byte count.isDup()
Check if opcode is DUP1-DUP16.dupPosition()
Get stack position for DUP opcode (1-16).isSwap()
Check if opcode is SWAP1-SWAP16.swapPosition()
Get stack position for SWAP opcode (1-16).isLog()
Check if opcode is LOG0-LOG4.logTopics()
Get number of topics for LOG opcode (0-4).isTerminating()
Check if opcode terminates execution (STOP, RETURN, REVERT, INVALID, SELFDESTRUCT).isJump()
Check if opcode is JUMP or JUMPI.parse()
Parse bytecode into instructions.format()
Format instruction as human-readable string.disassemble()
Disassemble bytecode into array of formatted strings.jumpDests()
Find all valid JUMPDEST positions in bytecode.isValidJumpDest()
Check if offset is valid JUMPDEST in bytecode.Opcode Constants
All EVM opcodes are exported as constants:Use Cases
Bytecode Analysis
Jump Validation
Disassembler
Stack Depth Analysis
Code Coverage
Tree-Shaking
Import only what you need for optimal bundle size:parse without disassemble or jump analysis).
Opcode Categories
Stack Operations
- PUSH1-PUSH32 (0x60-0x7F): Push 1-32 bytes onto stack
- DUP1-DUP16 (0x80-0x8F): Duplicate stack item at position 1-16
- SWAP1-SWAP16 (0x90-0x9F): Swap top stack item with item at position 1-16
- POP (0x50): Remove top stack item
Arithmetic
- ADD, MUL, SUB, DIV, MOD (0x01-0x05)
- ADDMOD, MULMOD (0x08-0x09)
- EXP (0x0A)
- SIGNEXTEND (0x0B)
Comparison & Logic
- LT, GT, SLT, SGT, EQ (0x10-0x14)
- ISZERO, AND, OR, XOR, NOT (0x15-0x19)
- BYTE, SHL, SHR, SAR (0x1A-0x1D)
Memory & Storage
- MLOAD, MSTORE, MSTORE8 (0x51-0x53)
- SLOAD, SSTORE (0x54-0x55)
- MSIZE (0x59)
Flow Control
- JUMP, JUMPI, JUMPDEST (0x56-0x5B)
- PC (0x58)
- STOP, RETURN, REVERT (0x00, 0xF3, 0xFD)
Logging
- LOG0-LOG4 (0xA0-0xA4): Emit log with 0-4 topics
System Operations
- CREATE, CREATE2 (0xF0, 0xF5)
- CALL, CALLCODE, DELEGATECALL, STATICCALL (0xF1-0xF4, 0xFA)
- SELFDESTRUCT (0xFF)
API Reference
Core
- info - Get complete opcode metadata (gas cost, stack effects, name)
- name - Get opcode mnemonic name (PUSH1, ADD, etc.)
- isValid - Check if byte is valid opcode
- parse - Parse bytecode into instructions
- disassemble - Disassemble bytecode to human-readable strings
- format - Format instruction as human-readable string
Categorization
- isPush - Check if opcode is PUSH1-PUSH32
- pushBytes - Get number of immediate bytes for PUSH opcode
- pushOpcode - Get PUSH opcode for given byte count
- isDup - Check if opcode is DUP1-DUP16
- dupPosition - Get stack position for DUP opcode (1-16)
- isSwap - Check if opcode is SWAP1-SWAP16
- swapPosition - Get stack position for SWAP opcode (1-16)
Jump Analysis
- jumpDests - Find all valid JUMPDEST positions in bytecode
- isValidJumpDest - Check if offset is valid JUMPDEST
Documentation
- Reference Guide - Complete opcode reference with execution traces and stack diagrams
- Fundamentals - Learn stack machine architecture, gas costs, and patterns
- Usage Patterns - Real-world bytecode analysis and gas estimation
- Constructors - Opcode constants and construction utilities
- Validation - Opcode validation and category checks
- Utilities - Metadata, stack effects, and gas cost utilities
- WASM Implementation - Performance analysis (pure TS is faster)
Related Types
- Opcode (Effect) - Effect.ts integration with Schema validation
- Bytecode - Contract bytecode representation and manipulation
- Transaction - Transactions that deploy and execute bytecode
- State - EVM state operations accessed by opcodes
- GasConstants - Gas costs for EVM operations
Opcode Reference Tables
Complete Opcode Listing
- Arithmetic
- Comparison & Bitwise
- Cryptographic
- Environmental
- Block Info
- Stack & Memory
- Push & Dup
- Swap & Log
- System
- Gas: Base gas cost (dynamic marked with *)
- EIP: Ethereum Improvement Proposal adding the opcode
- Warm/Cold: Access list (EIP-2929) affects gas
Stack Effect Diagrams
Common stack patterns: Binary Operations (ADD, MUL, SUB, etc)Gas Cost Variations
Specification References
- EVM Opcodes - Interactive opcode reference
- Ethereum Yellow Paper - Formal EVM specification
- Solidity Assembly - Inline assembly documentation
- EIP-3198 - BASEFEE opcode
- EIP-3855 - PUSH0 instruction
- EIP-2929 - Access lists (warm/cold gas)

