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:Behavior
SHR pops two values from the stack:- shift - number of bit positions to shift right (0-255)
- value - 256-bit value to be shifted
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: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
- TypeScript
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 savings: 2-1612 gas per shift vs pre-EIP-145 methods.
References
- EIP-145 - Bitwise shifting instructions in EVM
- Yellow Paper - Section 9.4.1
- EVM Codes - SHR
Related Documentation
- SHL (0x1b) - Shift left
- SAR (0x1d) - Arithmetic shift right (signed)
- DIV (0x04) - Unsigned division
- Hardfork - Constantinople

