A Uniswap v4 hook that runs four independent instruments on the pool: two that catch toxic swaps, one that taxes drive-by liquidity, and two that make sure the oracle underneath all of it can be trusted.
A sandwich attacker's front-run pushes the pool's price away from the truth. A JIT bot's liquidity shows up and leaves inside one block. Neither has to say what it's doing — the shape of the trade already gives it away, if something is watching for it.
Compares the pool's own price against a trusted Chainlink reading. A swap that widens the gap is taxed. A swap that closes it is discounted.
Compares this swap's price impact against a running average of what's normal for this specific pool — no fixed threshold, self-calibrating.
An earlier version averaged the two scores — and testing found a real bug: it diluted a maximally-confident signal by half. Fixed to noisy-OR, verified with exact numbers before and after.
Remove any one of these and a real, distinct MEV vector goes uncovered. Here's exactly what each does, with a real live-state mockup for each.
Same-block, oracle-aware, self-calibrating. Runs on every swap. Neither signal alone catches everything; combined via noisy-OR, they do.
A bot adds liquidity, captures a swap's fee, leaves within one block. Fees earned are taxed 80%, decaying to 0% by block 10 — no cliff to dodge.
Signal 1 only matters if the oracle is trustworthy. A Reactive contract on another chain watches for suspicious changes and pauses autonomously.
Doesn't trust Chainlink alone. A zkTLS-proven price from an independent source is checked against it before anything is trusted.
The three oracle-safety layers exist for one reason: to protect Signal 1's one real dependency. Signal 2 and JIT don't depend on the oracle at all — they run independently, alongside it.
Rings = trust protecting the oracle. Right = detection combining into a fee. Bottom = JIT, entirely separate, since liquidity events never touch a swap at all.
OracleGuardian's automated cross-chain trigger worked once with hard, verified proof. On repeat attempts across multiple deployments, Reactive's Lasna testnet has shown inconsistent processing — a documented testnet characteristic, not a fault in our contract logic. Sandwich-attack and reentrancy defenses are deliberately verified via adversarial Foundry tests rather than live mempool manipulation, since reliably reproducing same-block multi-actor ordering on a public testnet isn't a meaningful improvement over a controlled, repeatable test.
| Mechanism | Live proof | Status |
|---|
Connect a Sepolia wallet to swap. Everything else on this screen reads the live contract state.
Need Sepolia test ETH? Try the Alchemy Sepolia faucet or Infura's faucet. Full source, test suite, and every real transaction referenced on this page are in the GitHub repository.
Plain English first, then the real math, the real bugs, and every real address — nothing summarized away.
A liquidity provider deposits into a pool expecting to earn fees. What isn't obvious is how much of that fee income is quietly handed straight back out to two kinds of traders who never had to reveal what they were doing. The first is the sandwich attacker, who pushes the pool's price away from the true market price on purpose, trades against the LP at the distorted price, then lets an honest arbitrageur correct it back — collecting the difference. The second is the JIT (just-in-time) liquidity bot, which adds a large, precisely-ranged position moments before a known large swap, captures a disproportionate share of that single swap's fee, and withdraws immediately after — inside one block, with almost no price risk taken on at all.
Neither attacker has to announce their intent. A sandwich attack looks, on the surface, like three ordinary swaps. A JIT position looks like ordinary liquidity provision. What gives both away is the shape of the activity — if something is actually watching for it.
Signal 1 asks a simple question: does this swap push the pool's price further from, or closer to, a trusted outside reading? It compares the pool's own price against Chainlink's ETH/USD feed. A swap that widens that gap is charged more; a swap that closes it is charged less.
Signal 2 asks a different question: is this swap unusually large for this specific pool, right now? Rather than a fixed size threshold — which would need constant recalibration as a pool's real volume changes — it compares the swap's actual price impact against a running exponential moving average of what's structurally normal for that pool.
A real bug, found and fixed: the original design averaged the two scores together. Real testing showed this quietly diluted a maximally-confident single signal by roughly half — a swap that Signal 1 alone would have flagged at full severity got cut down simply because Signal 2 had nothing to add. Replaced with a noisy-OR combination, which correctly treats either signal alone as sufficient grounds for a full response.
Theoretical grounding: both signals independently correspond to recognized loss-versus-rebalancing (LVR) mitigation strategies described in the academic literature (Milionis, Moallemi, Roughgarden, Zhang, 2022) — arrived at through iteration and testing, not derived from the papers, but genuinely validated by them after the fact. Full derivation and citation in the repository's MATH.md.
Neither signal above ever sees a JIT attack, because neither one watches liquidity events at all — they only run during a swap. JIT liquidity needs its own, entirely separate defense.
The mechanism tracks the exact block a position was added, keyed to the specific pool, owner, tick range, and salt. When that same position is removed, it checks how many blocks it was actually held for. If liquidity was added and removed within the same block — the textbook JIT signature — 80% of the fees that position earned (never its deposited principal) are redirected to the pool's honest, long-term LPs instead. That penalty decays linearly, reaching 0% by the 10th block held.
Why a decay, not a hard cutoff: an earlier version simply checked "same block, yes or no." That has a real, exploitable weakness — a bot patient enough to wait exactly one extra block pays nothing at all. A smooth decay removes that cliff entirely.
Verified exact, not approximate: a position removed at precisely the halfway point (5 of 10 blocks) produced a penalty of exactly half the same-block value — 11,999,999,999,999,999 wei versus 23,999,999,999,999,999 wei. Verified live on Sepolia: a real position held for 2 real blocks produced a real, correctly-scaled, nonzero penalty, confirmed both by the emitted event and by a persisting on-chain reserve balance afterward.
Signal 1's entire value depends on one assumption: that the oracle it reads from is telling the truth. Three separate, layered defenses protect that single dependency, so that no one of them failing is catastrophic on its own.
A 24-hour delay on every oracle and guardian change. Always on, with no dependency on any external system — the simplest, most reliable layer, by design.
A Reactive Smart Contract, deployed on Reactive Network's Lasna testnet, subscribes to oracle-change events emitted on Sepolia. When one fires, the contract reacts entirely autonomously — no off-chain bot, no server, no keeper — and triggers a cross-chain callback that pauses the pool. Proven live: a real, queued oracle change produced a real, confirmed pause in a single block, roughly 12 seconds end to end.
Even a real, honest Chainlink feed is still one single source. ZKPriceGuardian checks it against an independent, cryptographically-verified reading obtained via Reclaim Protocol's zkTLS — proving a real HTTPS response actually occurred, without needing to trust whoever relays that proof. If the two sources diverge by 5% or more, the pool pauses. Proven live: a real proof attesting $2422.80 was generated, submitted on-chain, and checked directly against Chainlink's own live reading in the same transaction.
The guardian-swap timelock vulnerability. On a final, deliberate review of every externally-callable function, we found that changing an already-active guardian had no timelock at all — the only trust-affecting change in the entire contract without one. A compromised configurer could have instantly disabled both OracleGuardian and ZKPriceGuardian, silently, before ever attempting a malicious oracle change — meaning neither safety layer would ever get a chance to fire. We wrote a test that first demonstrated this exact exploit and confirmed it passed, proving the vulnerability was real, then applied the same 24-hour timelock pattern already proven for oracle changes, and confirmed the identical test then correctly failed — direct, before-and-after evidence that the fix genuinely works, not just an assertion that it should.
The missing receive() for native ETH. Every one of this project's 100+ local tests used two ERC20 tokens for its pool currencies — never native ETH. That meant a real, production-breaking bug went completely undetected: the hook had no way to accept an incoming ETH transfer at all, so any skim (whether from the swap fee mechanism or the JIT penalty) that needed to deliver native ETH to the contract would simply revert. This was only found because we insisted on a real, live JIT demonstration against a real currency0=ETH pool on Sepolia, and it reverted. Fixed with a minimal receive() external payable {}, then closed permanently with three new, dedicated native-ETH tests, and confirmed working with a successful live re-run immediately after.
Static analysis (Slither) returns 0 High or Medium findings in first-party code. Every Low/Informational finding was individually investigated rather than dismissed — including one that initially looked like a real gap (a deprecated Chainlink field, answeredInRound) and turned out, on research, to already match current best practice. Full triage in STATIC-ANALYSIS.md.
Reentrancy is tested adversarially with a real malicious token attempting a nested call during the exact window a static analyzer would flag as risky — confirmed blocked by Uniswap v4's own protocol-level lock, not just assumed safe.
| BallastHook | 0xC321e31f42c9630Cdc54bcd304Cbb70B8B1769C5 |
| PoolManager | 0x9008B62b056A7F15C7cdd48561cfbc32e0F818DD |
| Demo token | 0x11aFe39b01189774a5D11f041BB55dfc888098B0 |
| MultiGuardian | 0xed58A0D946eBBEC2A732d1Aeef66d39f93e619Ed |
| ZKPriceGuardian | 0x300c0da3d1B85fAac02eEfd6186eDC2B34f2BF55 |
| OracleGuardianCallback | 0x9D8A1CB49D24C90C739f9F8986d207b7E71348bB |
| OracleGuardianReactive (Lasna) | 0x38F87873Db0292F04D201E9A7f4C2b654974Adb1 |
114 named tests across every mechanism, 384,000 invariant operations across 3 suites with zero violations, 512 fuzz runs, and 0 High/Medium static-analysis findings. This includes dedicated pool-isolation tests (proving toxic activity in one pool never leaks into another sharing the same hook), a direct comparison suite benchmarking Ballast against volatility-only and size-only fee designs, and gas benchmarks for every new JIT liquidity hook. Full breakdown and instructions to run every test yourself are in the repository README.
Milionis, Moallemi, Roughgarden, Zhang (2022). Automated Market Making and Loss-Versus-Rebalancing. The foundational LVR framework both signals independently correspond to.
"Optimal Dynamic Fees for Automated Market Makers" (2026). A formal stochastic-control model describing an oracle-deviation fee term matching Signal 1's structure, arrived at independently.