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: 0x17
Introduced: Frontier (EVM genesis)
OR performs bitwise OR on two 256-bit unsigned integers. Each bit in the result is 1 if either (or both) corresponding bits in the operands are 1. This operation is fundamental for combining flags, setting specific bits, and data packing.
Primary uses: enabling multiple flags, setting bits in bitmaps, combining packed data fields.
Specification
Stack Input:
Stack Output:
Gas Cost: 3 (GasFastestStep)
Truth Table (per bit):
Behavior
OR pops two values from the stack, performs bitwise OR on each corresponding bit pair, and pushes the result. The operation is:
- Commutative: a | b = b | a
- Associative: (a | b) | c = a | (b | c)
- Identity element: a | 0 = a
- Null element: a | MAX_UINT256 = MAX_UINT256
Examples
Set Multiple Flags
Combine Two Bitmaps
Pack Data Fields
Set Specific Bit
Commutative Property
Gas Cost
Cost: 3 gas (GasFastestStep)
OR shares the lowest gas tier with:
- AND (0x16), XOR (0x18), NOT (0x19)
- BYTE (0x1a)
- SHL (0x1b), SHR (0x1c), SAR (0x1d)
- ADD (0x01), SUB (0x03)
- Comparison operations
Edge Cases
Identity Element
Null Element
Self OR
Alternating Bits
Stack Underflow
Out of Gas
Common Usage
Enable Multiple Permissions
Set Bits in Bitmap
Pack Multiple Values
Combine Selectors
Set Color Channels
Implementation
Testing
Test Coverage
Edge Cases Tested
- Basic OR operations (truth table)
- Identity element (OR with 0)
- Null element (OR with MAX_UINT256)
- Flag combining
- Idempotent property (a | a = a)
- Commutative property
- Complementary patterns (0xAAAA… | 0x5555… = MAX)
- Stack underflow
- Out of gas
Security
Flag Mismanagement
Overlapping Bit Positions
Unintended Side Effects
Packed Data Corruption
Benchmarks
OR is one of the fastest EVM operations:
Execution time (relative):
- OR: 1.0x (baseline, fastest tier)
- AND/XOR: 1.0x (same tier)
- ADD: 1.0x (same tier)
- MUL: 1.2x
- DIV: 2.5x
Gas efficiency:
- 3 gas per 256-bit OR operation
- ~333,333 OR operations per million gas
- Native hardware instruction on all platforms
References