βœ… Master Transaction Debugging

Understand revert decoding, execution tracing, and gas profiling

Debug failed transactions and trace execution

πŸŽ“ Module Summary

πŸ› What You Learned

1. Transaction Failure Types

Reverts (explicit require/revert), Out of Gas (insufficient gas limit), Invalid Opcode (assert/overflow), and Underflow/Overflow (pre-0.8.0 arithmetic). Each has distinct symptoms, debugging approach, and gas consumption pattern.

2. Decoding Revert Reasons

String messages (0x08c379a0 prefix), Custom errors (4-byte selector + ABI-encoded params), and Panic codes (0x4e487b71 + error code). Etherscan auto-decodes for verified contracts; unverified requires manual ABI matching.

3. Execution Tracing

Follow call hierarchy (external β†’ internal β†’ nested calls). Etherscan shows tree view, Tenderly provides step-through debugger with opcodes and state diffs. Identify deepest failing call, trace back to understand invalid inputs.

4. Gas Profiling

Storage writes (SSTORE) cost 20,000 gasβ€”100x more than memory. Unbounded loops over dynamic arrays are gas bombs. Use Tenderly Gas Profiler (per-line costs) and Hardhat gas reporter (test benchmarks) to identify hotspots.

5. Optimization Strategies

Storage packing (pack variables into 256-bit slots), memory over storage (temporary data), batch operations (amortize base cost), short-circuit logic (cheap checks first), events over storage (historical data).

πŸ’‘ Key Debugging Principles

  • β€’
    Start with the error message: 80% of failures have descriptive messages. Read carefully before diving into code.
  • β€’
    Reproduce locally: Fork mainnet state at failing block, replay transaction in Hardhat, get full stack trace + console.log.
  • β€’
    Check inputs first: Invalid address, insufficient approval, expired deadlineβ€”input validation failures before logic errors.
  • β€’
    Use binary search: Comment out half the code, retry. Narrows down failing statement in O(log n) attempts.
  • β€’
    Read the contract source: Etherscan verified contracts show exact require() conditions. Understand the logic, don't just patch.

πŸ› οΈ Essential Tools Recap

Etherscan: View tx details, internal txs, decode input/output, check state changes. Free, public, works for all verified contracts.
Tenderly: Visual debugger, step-through execution, gas profiler, state diffs. Best for deep dive analysis.
Hardhat Console: Local debugging with console.log(), fork mainnet, run tests with full traces. Development environment.
Gas Reporter: Hardhat plugin showing gas per function. Benchmark during tests, catch regressions early.

🎯 Knowledge Check

Test your understanding of transaction debugging with this 5-question quiz. Each question includes detailed explanations.

Question 1 of 520% Complete

A transaction fails with "execution reverted: Insufficient balance". What should you check first?

0 / 1 correct
Complete the quiz to finish this module and move to the next one.