Skip to main content

ErrorSignature

An ErrorSignature is a 4-byte identifier used for Solidity custom errors in revert data. It’s computed as the first 4 bytes of the Keccak-256 hash of the error signature, similar to function selectors.

Type Definition

Creating Error Signatures

From Signature String

From Hex String

From Bytes

Operations

Convert to Hex

Compare Signatures

Standard Error Signatures

Built-in Errors

Solidity has two built-in error signatures:

Panic Codes

When using assert() or encountering specific errors, Solidity reverts with Panic(uint256) and a code:
  • 0x00 - Generic panic
  • 0x01 - Assert failed
  • 0x11 - Arithmetic overflow/underflow
  • 0x12 - Division by zero
  • 0x21 - Invalid enum value
  • 0x22 - Invalid storage byte array access
  • 0x31 - Pop on empty array
  • 0x32 - Array out of bounds
  • 0x41 - Out of memory
  • 0x51 - Invalid internal function call

Custom Errors

Custom errors are more gas-efficient than require() with strings:

Common Custom Errors

Access Control

Token Operations

DeFi

Revert Data Structure

When a custom error is thrown, the revert data contains:
Example for InsufficientBalance(1000, 2000):

Decoding Errors

Use error signatures to decode revert data:

Signature Format

Error signatures must use canonical type names: ✅ Correct:
  • InsufficientBalance(uint256,uint256)
  • Unauthorized()
  • InvalidSwap(address,uint256,bytes)
❌ Incorrect:
  • InsufficientBalance(uint, uint) (should be uint256)
  • InsufficientBalance(uint256, uint256) (has spaces)
  • insufficientBalance(uint256,uint256) (wrong capitalization)
Note: Error names conventionally start with uppercase.

How Error Signatures Work

  1. Error Signature: Start with the canonical error signature
  2. Hash: Compute keccak256(signature)
  3. Truncate: Take the first 4 bytes

Gas Efficiency

Custom errors are significantly more gas-efficient than require() with strings:

Handling Errors

API Reference

Constructors

  • from(value: ErrorSignatureLike): ErrorSignatureType - Create from various inputs
  • fromHex(hex: string): ErrorSignatureType - Create from hex string
  • fromSignature(signature: string): ErrorSignatureType - Compute from error signature

Operations

  • toHex(sig: ErrorSignatureType): string - Convert to hex string
  • equals(a: ErrorSignatureType, b: ErrorSignatureType): boolean - Compare signatures

See Also