Previous Module
Security Best Practices Game

🔍 Decode Reverts: Understand Error Messages

Learn how to decode revert reasons from transaction data

Debug failed transactions and trace execution

🔍 Decoding Revert Reasons

Revert messages are your best debugging tool. When a transaction fails with "execution reverted", the contract explicitly rejected it with a reason. Pre-Solidity 0.8.4, contracts used string messages like "Insufficient balance". Post-0.8.4, custom errors save gas: revert InsufficientBalance(balance, amount). Your job: decode these messages from transaction data, understand what went wrong, and fix the root cause. Etherscan shows decoded reverts for verified contracts, but unverified contracts require manual decoding. This section teaches you to read revert data, match error selectors, extract parameters, and trace back to the failing require() statement.

🎮 Interactive: Revert Examples

Explore common revert scenarios. Each shows the error message, contract code, debugging steps, and how to fix it.

💸

ERC20 Transfer Fail

User balance insufficient

❌ Error Message
execution reverted: ERC20: transfer amount exceeds balance
Transaction Hash
0xabc...failed
Function Called
transfer(address to, uint256 amount)
💻 Contract Code
// Contract code that failed
function transfer(address to, uint256 amount) public returns (bool) {
  require(balanceOf(msg.sender) >= amount, "ERC20: transfer amount exceeds balance");
  _balances[msg.sender] -= amount;
  _balances[to] += amount;
  emit Transfer(msg.sender, to, amount);
  return true;
}

// User tried: transfer(bob, 1000 tokens) with only 500 tokens balance
// Result: Transaction reverted at require() check
🔍 Debugging Steps

Look at transaction input data → decode function call → check msg.sender balance at block → compare with transfer amount

✅ How to Fix
  • Check sender balance before transfer: balanceOf(msg.sender)
  • Add require(balance >= amount, "Insufficient balance")
  • Frontend: Query balance, disable button if insufficient
  • Consider using transferFrom with approval flow

🎮 Interactive: Input Data Decoder

Paste transaction input data to decode the function call and parameters. This helps understand what the transaction was trying to do.

🛠️ Manual Decoding Steps

1. Get Revert Data

Etherscan → Transaction Details → Click "Click to see More" → Find "Revert Reason" or "Input Data"

2. Identify Error Type

String message starts with 0x08c379a0. Custom error starts with 4-byte selector. Panic code starts with 0x4e487b71.

3. Decode Parameters

Use ABI decoder (Etherscan, Tenderly) or manually: Extract bytes after selector, decode based on parameter types.

4. Find Source Code

Match error to contract source. Search for revert string or error definition. Understand the require() condition.