Overview
Comparison operations provide boolean logic for 256-bit integers. All comparisons return 1 (true) or 0 (false) and consume minimal gas. These operations enable conditional logic, bounds checking, and control flow in smart contracts. 6 opcodes enable:- Unsigned comparison: LT, GT
- Signed comparison: SLT, SGT
- Equality: EQ
- Zero check: ISZERO
Opcodes
Signed vs Unsigned Comparison
Unsigned (LT, GT)
Standard unsigned integer comparison treating all 256-bit values as positive:Signed (SLT, SGT)
Two’s complement signed integer comparison:Two’s Complement Representation
Signed operations interpret bit 255 as the sign bit:Gas Costs
All comparison operations cost 3 gas (GasFastestStep), making them the cheapest operations in the EVM.| Operation | Gas | Category |
|---|---|---|
| LT, GT, SLT, SGT | 3 | Fastest |
| EQ, ISZERO | 3 | Fastest |
| ADD, SUB | 3 | Fastest (same tier) |
| MUL, DIV | 5 | Fast |
| ADDMOD, MULMOD | 8 | Mid |
Common Patterns
Conditional Logic
Bounds Checking
Range Validation
Zero Address Check
Signed Integer Logic
Boolean Operations
Comparison results (0 or 1) compose with bitwise operations for complex logic:Edge Cases
Maximum Values
Sign Bit Boundary
Implementation
TypeScript
Zig
Security Considerations
Signed Integer Confusion
Mixing signed and unsigned comparisons can cause vulnerabilities:Integer Overflow in Comparisons
Comparisons happen after arithmetic wrapping:Off-by-One Errors
Zero Address Checks
Always validate addresses:Optimizations
Gas-Efficient Patterns
Comparison Inversion
Benchmarks
Comparison operations are among the fastest EVM operations:| Operation | Gas | Execution Time (relative) |
|---|---|---|
| LT/GT/SLT/SGT | 3 | 1.0x (baseline) |
| EQ | 3 | 1.0x |
| ISZERO | 3 | 0.9x (slightly faster) |
| ADD/SUB | 3 | 1.0x |
| MUL | 5 | 1.5x |
References
- Yellow Paper - Section 9.4.1 (Comparison Operations)
- evm.codes - Interactive reference
- EIP-145 - Bitwise shifts (related operations)
- Solidity Docs - Type system and comparison semantics
Related Documentation
- Arithmetic Operations - ADD, SUB, MUL, DIV, signed arithmetic
- Bitwise Operations - AND, OR, XOR, NOT
- Control Flow - JUMP, JUMPI (use comparison results)
- Gas Constants - Gas cost definitions

