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:Behavior
SHL pops two values from the stack:- shift - number of bit positions to shift left (0-255)
- value - 256-bit value to be shifted
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: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
- TypeScript
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 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 - SHL
Related Documentation
- SHR (0x1c) - Logical shift right
- SAR (0x1d) - Arithmetic shift right
- MUL (0x02) - Multiplication
- Hardfork - Constantinople

