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: 0x13
Introduced: Frontier (EVM genesis)
SGT performs signed greater than comparison on two 256-bit integers interpreted as two’s complement signed values. Returns 1 if the first value is strictly greater than the second, 0 otherwise. Values are in the range -2^255 to 2^255 - 1.
This operation complements SLT for implementing signed conditional logic and range checks.
Specification
Stack Input:
Stack Output:
Gas Cost: 3 (GasFastestStep)
Operation:
Behavior
SGT 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
Positive Greater Than Negative
Negative Less Than Positive
Negative Value Comparison
Zero Boundary
Minimum and Maximum
Contrast with Unsigned GT
Gas Cost
Cost: 3 gas (GasFastestStep)
SGT shares the lowest gas tier with all comparison operations:
- LT, GT, SLT, SGT, EQ (comparisons)
- ISZERO, NOT
- ADD, SUB
Comparison:
- SGT/SLT/GT/LT: 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
Positive Value Check
Signed Upper Bounds
Maximum of Signed Values
Signed Range Validation
Non-Negative Check
Implementation
Testing
Test Coverage
Edge Cases Tested
- Positive value comparisons
- Positive greater than negative
- Negative less than positive
- Negative value comparisons (-5 > -10)
- Zero boundary (0 > -1, 1 > 0)
- MAX_INT256 and MIN_INT256
- Equal values
- Stack underflow
- Out of gas
- Stack preservation
Security
Critical: Signed vs Unsigned Confusion
COMMON VULNERABILITY: Using GT instead of SGT for signed values:
Type Safety Issues
Overflow in Signed Operations
Sign Extension Errors
Optimizations
Relationship to SLT
Positive Check Optimization
Inversion Pattern
Benchmarks
SGT performance matches other comparison operations:
Execution time (relative):
- SGT: 1.05x (slightly slower due to sign conversion)
- SLT: 1.05x
- GT/LT/EQ: 1.0x
- ISZERO: 0.95x
Gas efficiency:
- 3 gas per signed comparison
- ~333,333 comparisons per million gas
- Sign conversion adds negligible overhead
References
- SLT - Signed less than
- GT - Unsigned greater than
- LT - Unsigned less than
- SDIV - Signed division
- SMOD - Signed modulo