Overview
Opcode:0xfd
Introduced: Byzantium (EIP-140)
REVERT halts execution, reverts all state changes in the current execution context, and returns error data to the caller. Unlike pre-Byzantium failures, REVERT refunds remaining gas and provides error information.
This enables graceful failure handling with gas efficiency and informative error messages.
Specification
Stack Input:Behavior
REVERT terminates execution with error:- Pops offset from stack (top)
- Pops length from stack (second)
- Validates offset and length fit in u32
- Charges gas for memory expansion to offset+length
- Copies length bytes from memory[offset] to output buffer
- Reverts all state changes (storage, logs, balance transfers)
- Sets execution state to reverted
- Returns control to caller with failure status
- Refunds remaining gas to transaction
- All state changes reverted in current call context
- Error data available to caller
- Remaining gas refunded (not consumed like INVALID)
- Execution marked as failed
- Byzantium or later: REVERT available
- Pre-Byzantium: REVERT triggers InvalidOpcode error
Examples
Basic Revert
Require Statement
Custom Error (Solidity 0.8.4+)
Empty Revert
Pre-Byzantium Error
Gas Cost
Cost: Memory expansion cost (dynamic) + remaining gas refunded Memory Expansion Formula:- REVERT: Refunds remaining gas
- INVALID (0xfe): Consumes all gas
Edge Cases
Zero Length Revert
Large Error Data
Out of Bounds
Stack Underflow
State Reversion
Common Usage
Input Validation
require compiles to conditional REVERT.
Access Control
Business Logic Checks
Custom Errors (Gas Efficient)
- String: ~50 gas per character
- Custom error: ~4 gas (function selector) + parameter encoding
Implementation
- TypeScript
Testing
Test Coverage
Security
REVERT vs INVALID
REVERT (0xfd):- Refunds remaining gas
- Returns error data
- Graceful failure
- Use for: validation, business logic, access control
- Consumes all gas
- No error data
- Hard failure
- Use for: should-never-happen, invariant violations
Gas Refund Implications
REVERT refunds gas - important for: Nested calls:Error Data Validation
Caller must validate error data:State Reversion Scope
REVERT only reverts current call context:Reentrancy
REVERT doesn’t prevent reentrancy:Compiler Behavior
Require Statements
Custom Errors
Try-Catch
Hardfork History
Pre-Byzantium (Frontier, Homestead, Tangerine Whistle, Spurious Dragon)
No REVERT opcode:- Only INVALID (0xfe) for reverting
- Consumed all gas
- No error data
- Poor UX
Byzantium (EIP-140)
REVERT introduced:- Opcode 0xfd
- Refunds remaining gas
- Returns error data
- Graceful failure handling
- Better error messages
- Gas efficiency
- Improved debugging
- Custom errors possible
Post-Byzantium (Constantinople → Cancun)
No changes to REVERT:- Behavior stable since Byzantium
- Foundation for Solidity 0.8.4+ custom errors
- Essential for modern error handling
References
- Yellow Paper - Section 9.4.4 (REVERT instruction)
- EIP-140: REVERT instruction
- EVM Codes - REVERT
- Solidity Docs - Error Handling
- Solidity Docs - Custom Errors

