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: 0x1b Introduced: Constantinople (EIP-145) SHL performs logical shift left on a 256-bit value, shifting bits toward the most significant position. Vacated bits (on the right) are filled with zeros. This operation efficiently multiplies by powers of 2 and is critical for bit manipulation and data packing. Before EIP-145, left shifts required expensive MUL + EXP operations (5-60+ gas). SHL reduces this to 3 gas.

Specification

Stack Input:
Stack Output:
Gas Cost: 3 (GasFastestStep) Hardfork: Constantinople (EIP-145) or later Shift Behavior:

Behavior

SHL pops two values from the stack:
  1. shift - number of bit positions to shift left (0-255)
  2. value - 256-bit value to be shifted
Result is value shifted left by shift positions, with zeros filling vacated bits. If shift >= 256, result is 0 (all bits shifted out). Overflow: High-order bits are discarded (wraps at 256 bits).

Examples

Basic Left Shift

Multiply by Power of 2

Zero Shift (Identity)

Maximum Shift (Overflow)

Partial Overflow

Pack Address into uint256

Gas Cost

Cost: 3 gas (GasFastestStep) Pre-EIP-145 equivalent:
Savings: 12-1612 gas per shift operation.

Edge Cases

Zero Value

Zero Shift

Shift by 1 (Double)

Shift by 255 (Near Max)

Shift by 256+ (Complete Overflow)

Large Value, Small Shift

Hardfork Check (Pre-Constantinople)

Stack Underflow

Out of Gas

Common Usage

Multiply by Power of 2

Pack Data Fields

Align to Byte Boundary

Create Bit Mask

Scale Fixed-Point Numbers

Efficient Array Indexing

Implementation

Testing

Test Coverage

Edge Cases Tested

  • Basic shift operations
  • Multiplication by powers of 2
  • Zero shift (identity)
  • Shift >= 256 (overflow to zero)
  • Partial overflow
  • Maximum value shifts
  • Shift to MSB position
  • Zero value shifts
  • Hardfork compatibility
  • Stack underflow
  • Out of gas

Security

Unchecked Shift Amount

Overflow Assumptions

Data Loss from Overflow

Incorrect Multiplication

Benchmarks

SHL is one of the fastest EVM operations: Execution time (relative):
  • SHL: 1.0x (baseline, fastest tier)
  • SHR/SAR: 1.0x (same tier)
  • MUL: 1.2x
  • DIV: 2.5x
Gas comparison (left shift by 8): Gas savings: 2-1612 gas per shift vs pre-EIP-145 methods.

References