114 tests passing 384,000 invariant operations, 0 violations a real vulnerability found and fixed: guardian-swap timelock a real bug found live: native ETH receive() sandwich attacker profit: 0.258 ETH → $0 JIT penalty proven live, 2 blocks held zkTLS proof verified on-chain: $2422.80 cross-chain detection confirmed: block 11590977 114 tests passing 384,000 invariant operations, 0 violations a real vulnerability found and fixed: guardian-swap timelock a real bug found live: native ETH receive() sandwich attacker profit: 0.258 ETH → $0 JIT penalty proven live, 2 blocks held zkTLS proof verified on-chain: $2422.80 cross-chain detection confirmed: block 11590977
Ballast TOXIC-FLOW PROTECTED LIQUIDITY
Uniswap Hookathon · UHI10 · fair-flow track

Two readings.
When they disagree, that's the alarm.

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.

SIGNAL READOUT● live
Signal 10.04
Signal 20.02
combined divergence score
0.06
JIT PENALTY, LIVE● proven
Held2 blocks
Captured2.4e12 wei
Signal 1 — oracle deviation
Signal 2 — structural impact
live trace, real swap sequence
DIVERGENCE FLAGGEDSandwich attacker's real profit fell from 0.258 ETH to exactly 0 on this pool.
Why this exists

MEV bots don't announce themselves. Their trades just look wrong.

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.

Signal 1 — is this trade honest with the outside world?

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.

deviationBps = |pool − oracle| / oracle
score = min(deviationBps, cap) / cap

Signal 2 — is this trade honest with this pool's own history?

Compares this swap's price impact against a running average of what's normal for this specific pool — no fixed threshold, self-calibrating.

excessRatio = impact / baseline(EMA)
score = min(excessRatio / mult, 1)

Combined — a noisy-OR, not an average

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.

combined = 1 − (1 − s1)(1 − s2) fee = BASE + combined × (MAX − BASE)
One hook, four protocols

Every integration is load-bearing.

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.

Via Signal 1 + 2

Same-block, oracle-aware, self-calibrating. Runs on every swap. Neither signal alone catches everything; combined via noisy-OR, they do.

sandwich attacker profit0.258 ETH
on Ballast, same attack$0

Via JIT decay

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.

held 2 blocks, livereal penalty
captured2,399,999,999,999 wei

Via OracleGuardian

Signal 1 only matters if the oracle is trustworthy. A Reactive contract on another chain watches for suspicious changes and pauses autonomously.

trigger → detection, block 11590977confirmed
bot or keeper requirednone

Via ZKPriceGuardian

Doesn't trust Chainlink alone. A zkTLS-proven price from an independent source is checked against it before anything is trusted.

attested price$2422.80
divergence from Chainlink0.55%
The whole system, in one view

Four layers, one hook — how they actually fit together.

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.

Signal 1 oracle read Layer 3 — ZKPriceGuardian independent zkTLS price check Layer 2 — OracleGuardian cross-chain, autonomous pause Layer 1 — Timelock 24h delay, always on, no dependency Signal 2 structural impact — independent FEE 0.15–1.50% Liquidity event add / remove — separate path JIT check same-block? PENALTY 80% → 0%, 10 blocks

Rings = trust protecting the oracle. Right = detection combining into a fee. Bottom = JIT, entirely separate, since liquidity events never touch a swap at all.

The real mechanism, step by step

Not just Signal 1 and Signal 2 — all four, in full.

the toll
JIT liquidity defense
1
beforeAddLiquidity records the blockEvery position's exact add-block is tracked, keyed to (pool, owner, range, salt).
2
afterRemoveLiquidity checks how long it was heldblocksHeld = block.number − addedAtBlock.
3
a decaying penalty applies to fees earned, never principal80% at same-block, linearly to 0% by block 10.
live: real position, 2 blocks held, real penalty event on-chain, no revert
penalty decay, verified exact80% → 0%, 10 blocks
the relay
OracleGuardian
1
A queued oracle change fires a real event on SepoliaOracleChangeQueued, watched by a Reactive Smart Contract on Lasna.
2
The Reactive contract reacts autonomouslyNo off-chain bot, no server — the reaction is itself an on-chain contract.
3
A cross-chain callback pauses the pool on SepoliaReal detection confirmed at block 11590977, on the original OracleGuardianCallback deployment.
live: real detection, block 11590977, address 0x800f4b1B...05CD4 (original deployment) — decodes to "OracleChangeQueued detected"
real cross-chain sequence~12 seconds, one block
Lasna Sepolia ~12s
the witness
ZKPriceGuardian
1
A zkTLS proof is generated off-chain, from a live sourceReclaim Protocol proves a real HTTPS response without a trusted intermediary.
2
The proof is verified and submitted on-chainZKPriceAttestor checks the cryptographic proof itself, not just a signed number.
3
The two independent prices are comparedA divergence ≥5% from Chainlink pauses the pool.
live: real proof, $2422.80, submitted and checked on-chain
real proof, decodedsubmitted live
Attested price$2422.80
Chainlink price, same block$2436.21
Divergence0.55% — well within bound
The stack

What Ballast is actually built on.

the hook
Uniswap v4
the relay
Reactive Network
the witness
Reclaim zkTLS
price feed
Chainlink
build + fuzz
Foundry
network
Sepolia
Deployed and verifiable

Every address, real and checkable.

Exactly what passes locally

Numbers from the real suite, nothing claimed that hasn't run.

114
named tests, all passing
384,000
invariant operations, 0 violations
512
fuzz runs
0
High/Medium static-analysis findings
WHAT'S NOT YET PROVEN LIVE

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.

The evidence — click any row to verify

Nothing here is asserted without its receipt.

MechanismLive proofStatus

Read the math, or just launch it.

Live dashboard

Ballast, on the pool, right now.

Connect a Sepolia wallet to swap. Everything else on this screen reads the live contract state.

Swapnot connected
ETH
↓
DEMO
this swap's live fee reading: 0.30%

Signal readout

Signal 1 (oracle deviation)0.04
Signal 2 (structural impact)0.02
Combined score0.06
Resulting fee0.30%

Pool state

PoolETH / DEMO
Statusunpaused
Chainlink ETH/USD$2,468.18
Hook0xC321…9C5

Guardian status

Timelock
24h delay, always on
OracleGuardian
0x9D8A…8bB — Reactive-armed
ZKPriceGuardian
0x300c…F55 — last check $2422.80

JIT decay, if you remove now

Network & contracts

Everything this app talks to.

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.

Documentation

How Ballast works, in full.

Plain English first, then the real math, the real bugs, and every real address — nothing summarized away.

The problem: value that leaves without asking

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.

The two signals

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.

deviationBps = |pool − oracle| / oracle score1 = min(deviationBps, cap) / cap

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.

excessRatio = impact / baseline(EMA) score2 = min(excessRatio / mult, 1)

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.

combined = 1 − (1 − s1)(1 − s2) fee = BASE + combined × (MAX_SURCHARGE − BASE)

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.

JIT liquidity defense: taxing the drive-by

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.

blocksHeld = block.number − liquidityAddedAtBlock[positionKey] penaltyBps = JIT_MAX_PENALTY_BPS × (JIT_DECAY_BLOCKS − blocksHeld) / JIT_DECAY_BLOCKS

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.

Oracle safety: three independent layers

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.

Layer 1 — Timelock

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.

Layer 2 — OracleGuardian

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.

Layer 3 — ZKPriceGuardian

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.

Real bugs found, not hypothetical ones

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.

Security posture

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.

Contract addresses (Sepolia)

BallastHook0xC321e31f42c9630Cdc54bcd304Cbb70B8B1769C5
PoolManager0x9008B62b056A7F15C7cdd48561cfbc32e0F818DD
Demo token0x11aFe39b01189774a5D11f041BB55dfc888098B0
MultiGuardian0xed58A0D946eBBEC2A732d1Aeef66d39f93e619Ed
ZKPriceGuardian0x300c0da3d1B85fAac02eEfd6186eDC2B34f2BF55
OracleGuardianCallback0x9D8A1CB49D24C90C739f9F8986d207b7E71348bB
OracleGuardianReactive (Lasna)0x38F87873Db0292F04D201E9A7f4C2b654974Adb1

Test coverage

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.

References

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.