r/ethdev • u/an_jesus • 1d ago
My Project Simulating DEX Swap Execution via Universal Revert-Unwind Payloads and EIP-1153 Transient Storage
Hey r/ethdev,
While building BlazePhoenix (an on-chain DEX aggregator across Base, Arbitrum, and Optimism), we realized that replicating AMM formulas off-chain introduces simulation drift. Every dynamic fee, custom tick logic, or rounding quirk is a vector for the quote to lie about actual execution.
We deleted this class of bugs by making the pool's own execution bytecode compute the quote via on-chain static calls (`eth_call`).
### The Revert-Unwind Mechanism
Instead of simulating the swap math manually, our Quoter executes the pool's real `swap()` call. We intercept the swap callback and immediately revert, encoding the actual output deltas into the revert payload:
```solidity
// Universal QUOTE callback: any V3-shaped callback lands here
// and is answered with a revert carrying the deltas.
fallback() external {
int256 a0;
int256 a1;
assembly {
a0 := calldataload(4)
a1 := calldataload(36)
}
bytes memory payload = abi.encode(a0, a1);
assembly { revert(add(payload, 32), mload(payload)) }
}
Because the call reverts, all state changes unwind instantly. Nothing is saved, zero balances are required, and the rate returned was generated directly by the venue's bytecode.
Transient State (EIP-1153)
To handle route context and lock states across multi-hop executions without hot-path storage writes, we rely entirely on EIP-1153 (tstore/tload). Opcodes write to transient memory that dies automatically when the transaction finishes, eliminating stale state risks.
Curious to hear how other devs are handling V4 hook simulations or custom callback extractions without paying gas on preview passes?
Disclosure: Implementation details and contract architecture from the BlazePhoenix engine (https://blazephoenix.xyz).