Skip to main content

Try it Live

Run Bytecode examples in the interactive playground
Conceptual Guide - For API reference and method documentation, see Bytecode API.
EVM bytecode is the low-level machine code that smart contracts compile to and execute on the Ethereum Virtual Machine. This guide teaches bytecode fundamentals using Tevm.

Structure

Bytecode is a sequence of bytes where each byte (or sequence of bytes) represents either:
  • An opcode - Instruction telling the EVM what to do (ADD, PUSH1, JUMP, etc.)
  • Data - Constant values embedded after PUSH opcodes

Parsing Bytecode

The main challenge: PUSH1-PUSH32 opcodes (0x60-0x7f) are followed by 1-32 bytes of data that are NOT opcodes.

Analyzing Structure

Use analyze() for complete bytecode analysis:

What analyze() Returns

Jump Destinations

JUMPDEST (0x5b) markers indicate valid jump targets. The EVM validates that JUMP/JUMPI only target JUMPDEST opcodes:

Disassembly

Use formatInstructions() to disassemble bytecode to human-readable strings:

Complete Example: ADD Operation

Here’s bytecode that adds 5 + 3 and returns the result:

Execution Flow

Parsing Individual Instructions

Use parseInstructions() for detailed instruction data:

Metadata Detection

Solidity compilers append metadata (typically 50-100 bytes) containing compiler version and IPFS hash:
See hasMetadata() and stripMetadata().

Extracting Runtime Code

Deployment bytecode includes initialization code that runs once. Extract just the runtime portion:
See extractRuntime().

EVM Instructions

The EVM has ~140 single-byte opcodes organized by category:
  • Arithmetic & Logic - ADD, MUL, SUB, DIV, AND, OR, XOR
  • Storage - SLOAD, SSTORE (persistent contract storage)
  • Memory - MLOAD, MSTORE (temporary execution data)
  • Control Flow - JUMP, JUMPI, JUMPDEST (loops, conditionals)
  • Contract Calls - CALL, DELEGATECALL, STATICCALL
  • Contract Creation - CREATE, CREATE2
  • System - SELFDESTRUCT, REVERT

PUSH Instructions

PUSH1-PUSH32 (0x60-0x7f) embed 1-32 bytes of immediate data:

Validation

Use validate() to check bytecode structure:

Resources

Next Steps