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: 0x1c Introduced: Constantinople (EIP-145) SHR performs logical (unsigned) shift right on a 256-bit value, shifting bits toward the least significant position. Vacated bits (on the left) are filled with zeros. This operation efficiently divides by powers of 2 and extracts high-order bits. Before EIP-145, right shifts required expensive DIV + EXP operations (15-60+ gas). SHR reduces this to 3 gas. Note: SHR is for unsigned values. For signed division, use SAR (0x1d).

Specification

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

Behavior

SHR pops two values from the stack:
  1. shift - number of bit positions to shift right (0-255)
  2. value - 256-bit value to be shifted
Result is value shifted right by shift positions, with zeros filling vacated high-order bits (logical shift). If shift >= 256, result is 0. Difference from SAR: SHR always fills with zeros (unsigned), while SAR preserves the sign bit (signed).

Examples

Basic Right Shift

Divide by Power of 2

Zero Shift (Identity)

Maximum Shift (Underflow)

Extract High Bytes

Logical vs Arithmetic (Negative Number)

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 (Halve)

Shift by 255 (Extract MSB)

Shift by 256+ (Complete Underflow)

MSB Set (Unsigned Interpretation)

Truncation

Hardfork Check (Pre-Constantinople)

Stack Underflow

Out of Gas

Common Usage

Divide by Power of 2

Unpack Data Fields

Extract High Bits

Check MSB (Sign Bit)

Bitmap Operations

Extract Nibble (4 bits)

Implementation

Testing

Test Coverage

Edge Cases Tested

  • Basic shift operations
  • Division by powers of 2
  • Zero shift (identity)
  • Shift >= 256 (underflow to zero)
  • MSB extraction
  • Logical shift (zero-fill) vs arithmetic
  • Bit truncation
  • High bit extraction
  • Zero value shifts
  • Hardfork compatibility
  • Stack underflow
  • Out of gas

Security

Signed vs Unsigned Confusion

Truncation Assumptions

Unchecked Shift Amount

Incorrect Division

Endianness in Byte Extraction

Benchmarks

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

References