β Master Transaction Debugging
Understand revert decoding, execution tracing, and gas profiling
Debug failed transactions and trace execution
Your Progress
0 / 5 completedπ 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
π― Knowledge Check
Test your understanding of transaction debugging with this 5-question quiz. Each question includes detailed explanations.