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

Opcode: 0x12 Introduced: Frontier (EVM genesis) SLT performs signed less than comparison on two 256-bit integers interpreted as two’s complement signed values. Returns 1 if the first value is strictly less than the second, 0 otherwise. Values are in the range -2^255 to 2^255 - 1. This operation is critical for signed integer arithmetic and conditions involving negative values.

Specification

Stack Input:
Stack Output:
Gas Cost: 3 (GasFastestStep) Operation:

Behavior

SLT pops two values from the stack, interprets them as signed 256-bit two’s complement integers, compares them, and pushes 1 if signed(a) < signed(b), otherwise 0:
  • If signed(a) < signed(b): Result is 1 (true)
  • If signed(a) >= signed(b): Result is 0 (false)
Two’s complement interpretation:
  • Bit 255 = 0: Positive (0 to 2^255 - 1)
  • Bit 255 = 1: Negative (-2^255 to -1)

Examples

Positive Values

Negative Less Than Positive

Positive Greater Than Negative

Negative Value Comparison

Zero Boundary

Minimum and Maximum

Contrast with Unsigned LT

Gas Cost

Cost: 3 gas (GasFastestStep) SLT shares the lowest gas tier with all comparison operations:
  • LT, GT, SLT, SGT, EQ (comparisons)
  • ISZERO, NOT
  • ADD, SUB
Comparison:
  • SLT/SGT/LT/GT: 3 gas
  • MUL/DIV: 5 gas
  • SDIV/SMOD: 5 gas

Edge Cases

Signed Boundary Values

Equal Values

Sign Bit Boundary

Stack Underflow

Out of Gas

Common Usage

Signed Bounds Checking

Negative Value Check

Signed Range Validation

Absolute Value

Sign Function

Implementation

Testing

Test Coverage

Edge Cases Tested

  • Positive value comparisons
  • Negative less than positive
  • Positive greater than negative
  • Negative value comparisons (-10 < -5)
  • Zero boundary (-1 < 0, 0 < 1)
  • MIN_INT256 and MAX_INT256
  • Equal values
  • Stack underflow
  • Out of gas
  • Stack preservation

Security

Critical: Signed vs Unsigned Confusion

MOST COMMON VULNERABILITY: Using LT instead of SLT for signed values:

Integer Type Casting

Overflow in Signed Arithmetic

Sign Extension Issues

Optimizations

Two’s Complement Implementation

The implementation efficiently converts to signed for comparison:

Comparison Patterns

Benchmarks

SLT performance matches other comparison operations: Execution time (relative):
  • SLT: 1.05x (slightly slower due to sign conversion)
  • LT/GT/EQ: 1.0x
  • SGT: 1.05x
  • ISZERO: 0.95x
Gas efficiency:
  • 3 gas per signed comparison
  • ~333,333 comparisons per million gas
  • Sign conversion adds negligible overhead

References

  • SGT - Signed greater than
  • LT - Unsigned less than
  • GT - Unsigned greater than
  • SDIV - Signed division
  • SMOD - Signed modulo