Decoding a Failed Uniswap V3 Swap From the Mempool to Revert
Bottom line: A failed Uniswap V3 swap is almost always reconstructible from three things: the exact block state, the transaction’s gas parameters, and the pool’s tick state at the moment of execution. Replaying with debug_traceTransaction and a pinned eth_call tells you which of slippage, gas, or a sandwich actually killed it.
Not investment advice. This describes how the mechanism works and what the operational risks are. It does not tell you what to buy. See the editorial policy.
A swap that reverts on-chain still costs gas. The user pays for the computation, the state changes are rolled back, and the mempool ordering that produced the failure is gone by the time anyone looks. What survives is the transaction receipt, the block, and — if you run an archive node or have access to one — the ability to re-execute the transaction against the state it actually saw. That is enough to distinguish the three common failure modes: the price moved past the slippage bound, the gas limit was too low for the route, or an attacker reordered the pool state around the victim’s transaction.
What a Uniswap V3 swap actually touches
Uniswap V3 is a binary contract system: a factory, the pools it deploys, and a periphery layer that users call. The pool itself (UniswapV3Pool.sol) is the AMM. It holds the liquidity, exposes the oracle, and delegates nearly all arithmetic to libraries — TickMath for sqrt-price/tick conversion at tick spacing 1.0001, SqrtPriceMath and SwapMath for the amount math within a tick, FullMath for 512-bit multiply-divide, TickBitmap for the packed set of initialized ticks.
The periphery is what your wallet usually calls. SwapRouter.sol handles single-hop (x to y) and multihop (x to y to z) trades. Multihop matters for debugging because a revert can originate in the second or third pool, not the first. The router also enforces the deadline and the amountOutMinimum you signed.
A V3 swap moves the pool’s sqrt price along the tick range, consuming liquidity in each initialized tick it crosses. If the price impact of your size exceeds the liquidity available before your sqrtPriceLimit, or if the output falls below amountOutMinimum, the pool or router reverts. The revert reason is usually Too little received from the router or a slippage check inside the pool callback.
Getting the transaction and its context
Start with the hash and pull the receipt plus the block. You need the block number, the block’s baseFeePerGas, and the transaction’s maxFeePerGas / maxPriorityFeePerGas because EIP-1559 changed what “gas failure” means. Under EIP-1559 (type 0x02 transactions), the sender pays baseFeePerGas of the inclusion block plus the priority fee, capped at maxFeePerGas. A transaction can be included and still fail if its gas_limit is below what the route needs — inclusion is not success.
1 | # Receipt: status, gasUsed, effectiveGasPrice, logs |
If status is 0, the transaction reverted. Note gasUsed against the transaction’s gas_limit. If gasUsed is within a few percent of the limit, gas exhaustion is a strong candidate; if it is far below, the revert came from a require/revert, not from running out.
Replaying with debug_traceTransaction
debug_traceTransaction re-executes the transaction against the state of its parent block and returns the full call trace. Geth exposes it under the debug namespace; you need an RPC endpoint with debug enabled (most public endpoints disable it, so use your own node or a provider that offers it). The callTracer gives a compact nested call tree; prestateTracer gives the accounts and storage slots the transaction touched, which is what you want when you need to know exactly which pool state was read.
1 | # Full call tree with revert reasons |
Read the trace from the outside in. The outermost frame is the router call. The next frame is the pool’s swap. If the revert is inside a uniswapV3SwapCallback frame, the router’s slippage check fired — the pool delivered less than amountOutMinimum. If the revert is a bare execution reverted with no reason and gasUsed is near the limit, suspect gas. If the trace shows the pool’s slot0 sqrt price already displaced before your swap’s first frame, something else in the block moved the price first.
Pinning state with eth_call
debug_traceTransaction replays the original transaction with the original gas. To test counterfactuals — “would this have succeeded with a 1% higher slippage bound?” — you need eth_call against the exact block, with the exact pre-state. Use the block number of the failed transaction minus one, or use the block itself with stateOverride if your provider supports it.
1 | # Re-run the same calldata against the parent block state |
If the call succeeds at block N-1 but the on-chain transaction at block N reverted, the state changed between the two — either another transaction in block N moved the pool, or the block’s ordering placed an attacker’s swap immediately before yours. That is the signature of a sandwich.
Slippage, gas, or sandwich: the decision table
| Symptom in trace | gasUsed vs limit |
eth_call at N-1 |
Most likely cause |
|---|---|---|---|
Revert in uniswapV3SwapCallback, reason Too little received |
Well below limit | Succeeds | Slippage bound too tight for the price move |
| Bare revert, no reason, deep in pool math | Within ~2% of limit | Succeeds | Gas limit too low for the route (multihop or tick crossings) |
Revert in callback, slot0 already moved at tx start |
Below limit | Succeeds | Sandwich: attacker swap before, reverse swap after |
| Revert in router before pool call | Below limit | Fails identically | Deadline expired or malformed calldata |
| Revert in second pool of a multihop | Below limit | Succeeds at N-1 | Price moved in the intermediate pool |
The sandwich case deserves a note. A sandwich is two transactions around yours: a buy that pushes the price, your swap executing at the worse price, and a sell that captures the difference. The tell is in the block’s transaction list. Pull the block, find your transaction’s index, and inspect the transactions immediately before and after from the same sender or to the same pool. If the pre-transaction is a swap in the same direction as yours and the post-transaction reverses it, and the from addresses are related (same EOA, or a contract that pays the EOA), you have the pattern.
1 | # List transactions in the block with sender and target |
Pitfalls and how to diagnose them
Tracing against the wrong block. debug_traceTransaction replays against the parent block’s state by default. If you instead eth_call against the failed block’s post-state, the pool has already absorbed the failed transaction’s (rolled-back) effects and any later transactions in the same block. Always pin to blockNumber - 1 for a clean replay.
Ignoring the base fee. A transaction with maxFeePerGas below the inclusion block’s baseFeePerGas cannot be included at all — it will sit in the mempool. If it was included, the base fee was satisfied. Gas failures on EIP-1559 chains are about gas_limit, not price, unless the transaction was a legacy type with a too-low gasPrice.
Assuming the router is the revert site. The router wraps the pool call. Reverts bubble up from the pool’s callback. The trace’s innermost frame is where the actual require lives; read that one.
Missing the tick crossings. A large swap crosses many initialized ticks, each costing gas. A route that succeeded at small size can run out of gas at larger size even with identical calldata shape. Compare gasUsed across sizes, not just against the limit.
Treating a revert as a loss of principal. A reverted swap returns the input tokens (minus gas). The loss is the gas paid, not the swap amount. Confirm by checking the input token balance before and after in the trace’s prestate.
Confusing amountOutMinimum with sqrtPriceLimitX96. The router enforces amountOutMinimum; the pool enforces sqrtPriceLimitX96. A revert in the pool’s swap before the callback suggests the price limit was hit; a revert in the callback suggests the output minimum was missed.
FAQ
Why does a failed swap still cost gas?
The EVM charges for computation as it executes. A revert unwinds state changes but does not refund the gas already consumed up to the revert point. Under EIP-1559 the base fee portion is burned and the priority fee goes to the block producer, so the sender pays both for a reverted transaction.
Can I tell from the receipt alone whether a sandwich caused the revert?
No. The receipt gives status, gas used, and logs. It does not show the pool’s state at the start of your transaction or the ordering of other transactions in the block. You need the trace and the block’s transaction list to see whether the price was displaced before your swap executed.
What is the difference between debug_traceTransaction and eth_call for this?
debug_traceTransaction replays the exact transaction with its original gas and returns the full call tree, including revert reasons and internal calls. eth_call executes arbitrary calldata against a chosen block’s state without persisting anything, which is what you use to test counterfactuals like a different slippage bound.
Does a higher gas limit prevent slippage reverts?
No. A higher gas limit only helps if the revert was gas exhaustion. A slippage revert is a deliberate require failure — the pool or router decided the output was too low. Raising the limit does nothing; widening amountOutMinimum or reducing trade size does.
How do I know which pool in a multihop route failed?
The call trace nests one swap frame per pool. The innermost frame that reverts is the failing pool. If the revert is in the second pool’s callback, the price in the intermediate token moved between the first and second hop, which is common when the intermediate pool is thin.
Is replaying a failed transaction against the parent block always accurate?
It is accurate for the state at the end of the parent block. It does not reproduce intra-block ordering, so it cannot tell you what would have happened if your transaction had landed at a different index in the same block. For ordering questions you need the block’s full transaction list and, ideally, a trace of the transactions around yours.









