Skip to main content
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

Overview

Opcode: 0x1a Introduced: Frontier (EVM genesis) BYTE extracts a single byte from a 256-bit value at a specified index, using big-endian byte ordering where byte 0 is the most significant byte (leftmost). Returns 0 if the index is out of range (>= 32). Primary uses: extracting individual bytes from packed data, parsing structured data, endianness conversions.

Specification

Stack Input:
Stack Output:
Gas Cost: 3 (GasFastestStep) Byte Ordering (Big-Endian):

Behavior

BYTE pops two values from the stack:
  1. i - byte index (0 = MSB, 31 = LSB)
  2. x - 256-bit value to extract from
Returns the byte at position i, or 0 if i >= 32. Algorithm:

Examples

Extract MSB (Most Significant Byte)

Extract LSB (Least Significant Byte)

Extract Middle Byte

Out of Range Index

Extract Address Byte

Iterate Through Bytes

Gas Cost

Cost: 3 gas (GasFastestStep) BYTE shares the lowest gas tier with:
  • AND (0x16), OR (0x17), XOR (0x18), NOT (0x19)
  • SHL (0x1b), SHR (0x1c), SAR (0x1d)
  • ADD (0x01), SUB (0x03)
  • Comparison operations

Edge Cases

Index Zero (MSB)

Index 31 (LSB)

Index Out of Range

Zero Value

Maximum Value

Stack Underflow

Out of Gas

Common Usage

Parse Function Selector

Extract Nibble (4 bits)

Validate Address Encoding

Extract Packed Timestamp

Check UTF-8 Encoding

Implementation

Testing

Test Coverage

Edge Cases Tested

  • MSB extraction (byte 0)
  • LSB extraction (byte 31)
  • Middle byte extraction
  • Out of range indices (>= 32)
  • Large indices (1000+)
  • Zero value
  • Maximum value (all bytes 0xFF)
  • All 32 byte positions
  • Stack underflow
  • Out of gas

Security

Endianness Confusion

Index Validation

Off-by-One Errors

Packed Data Alignment

Benchmarks

BYTE is one of the fastest EVM operations: Execution time (relative):
  • BYTE: 1.0x (baseline, fastest tier)
  • SHR/SHL: 1.0x (same tier, can be used as alternative)
  • AND: 1.0x (same tier)
  • DIV: 2.5x
Gas efficiency:
  • 3 gas per byte extraction
  • ~333,333 BYTE operations per million gas
Comparison with alternatives:
  • BYTE: 3 gas (direct extraction)
  • SHR + AND: 6 gas (shift + mask)
  • DIV + MOD: 10 gas (arithmetic extraction)

References