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

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.

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: See BENCHMARKING.md for detailed benchmarks.

References