Liquidity providers and swappers lose over $1B annually to MEV sandwich attacks. Most Uniswap v4 MEV defenses try to prevent extraction inside beforeSwap by adding dynamic fee spikes, delays, or swap reverts—which adds gas overhead to every normal trade and breaks aggregator routing when natural volatility looks like an attack. Meanwhile, MEV analytics dashboards visualize historical extraction after the fact but never return a single cent to the victim.
DarkTrace decouples MEV attribution from swap execution to provide post-trade forensics and automated USDC restitution:
-
Passive On-Chain Detection (Base Sepolia): Our Uniswap v4 hook (DarkTraceHook v1 & v2) never blocks, delays, or taxes a swap. Instead, it tracks intra-block tick movements and BalanceDelta round-trip profitability across swaps. When a searcher frontruns a victim and backruns in the opposite direction for a positive net token delta within the same block, the hook emits ExtractionDetected. For split-contract sandwiches where the frontrun and backrun use two different contracts signed by the same EOA, our indexer's off-chain linked-origin scanner catches the evasion from PoolManager Swap logs.
-
Counterfactual Slippage Decomposition: Our deterministic simulator reconstructs the pool's pre-attack reserves from PoolManager events and prices the victim's swap twice using the constant-product formula—once against pre-attack reserves and once after the frontrun—isolating normal liquidity slippage (e.g., 90 bps) from injected MEV slippage (e.g., +35 bps, or $3.54 USDC lost).
-
Tamper-Evident Proof Ledger (Arkiv Rabdi): Every ExtractionReceipt, SearcherProfile, and LPClaim is sealed on Arkiv Rabdi (chain 7794095) signed by our verified writer wallet. Every page in the web app queries Arkiv live with zero mock fallbacks.
-
Beneficiary-Gated USDC Restitution (Arc Testnet): Losses are attested in SimulationRegistry on Arc Testnet, and victims claim native 6-decimal USDC rebates from RebateVault. Only the victim wallet (beneficiary) can claim—we proved on-chain in Verified Run #2 that an unauthorized claim reverts with NotBeneficiary before the separate Victim EOA successfully claimed $3.54 USDC.
DarkTrace is built as a TypeScript/Solidity monorepo (pnpm workspaces, Foundry, Solc 0.8.26 with Cancun EVM, Next.js 14, wagmi v2, viem, and @arkiv-network/sdk) spanning three testnets: Base Sepolia (84532), Arkiv Rabdi (7794095), and Arc Testnet (5042002).
- Uniswap v4 Hook (Base Sepolia — 0xCeF7…c0c0 & 0xBCC9…80c0):
We mined CREATE2 salts (0x139d for v1, 0x180d for v2) against Foundry's canonical deployer so the hook address bits match BEFORE_SWAP_FLAG | AFTER_SWAP_FLAG (0x00C0).
- Notable hacky detail #1 (EIP-1153 tstore vs. multi-tx sandwiches): We initially used EIP-1153 transient storage (tstore/tload) for all hook state, then discovered that while a single-bundle sandwich works in tstore, a real 3-transaction sandwich wipes tstore at the end of tx1! In Hook v2, beforeSwap uses pure tstore (since beforeSwap and afterSwap of a single swap share one transaction frame), while cross-swap state in afterSwap uses a packed 2-slot tload-to-sload fallback keyed by uint48(block.number). Sub-threshold clean swaps execute zero sstore operations, cutting hook gas overhead by 53.7% (58,522 -> 27,085 gas).
- Notable hacky detail #2 (Eliminating false positives & router batching): Hook v2 consumes PoolManager's BalanceDelta in afterSwap to require strictly positive searcher round-trip profit (frontrunAmount0 + backrunAmount0 > 0), and supports opt-in hookData (0x01 || abi.encode(trader)) so shared aggregator routers can attribute end-user victims without tx.origin.
- Arkiv Rabdi Proof Ledger (Chain 7794095 — Namespace darktrace.v1):
We built a strict fail-loud wrapper around @arkiv-network/sdk defining three schemas: ExtractionReceipt, SearcherProfile, and LPClaim. Every UI route (/dashboard, /receipt/[hash], /pool/[id], /searcher/[address], /lp/[address]) runs live server-side select().where().ownedBy(writerWallet) queries on every request and displays the exact query in a "Live from Arkiv Rabdi" provenance bar.
- Deliberate TTL engineering: Standard receipts are written with a 30-day TTL, but our indexer uses Arkiv's extendEntity API to extend receipts with open, unclaimed rebates to a 90-day TTL (verified on Rabdi in tx 0x03512e4f…8744 to block #4,172,852) so forensic evidence never expires while a victim can still claim.
- Arc Testnet & Arc Studio (Chain 5042002 — Native 6-Decimal USDC at 0x3600…0000):
We generated and validated SimulationRegistry.sol and RebateVault.sol in Arc Studio (60/60 unit, fuzz, invariant, and reentrancy tests passing at 0x5279…2983 / 0x6760…c1de). Because Arc Studio's cloud deployer key is non-exportable and cannot call transferOwnership to our live indexer wallet, we deployed our evolved v2 beneficiary-gated settlement contracts (0xd501…61a2 / 0x238d…4d5b) and v2 Escrow + Claim Expiry contracts (0x31d5…0E77 / 0x0897…E104) via Foundry.
- Advanced stablecoin guardrails: RebateVault v2 enforces beneficiary-only claims (NotBeneficiary), replay nullifiers (AlreadyClaimed), an escrow dispute window (flagDispute / resolveDispute) where challengers can freeze wash-traded or self-sandwiched claims, and on-chain claim expiry recycling (expireUnclaimedRebate) that returns unclaimed USDC liabilities back into active vault reserves.