Instead of a rotating 3D block ring, this companion draws the AMM's own x·y=k curve directly in a 2D reserve plane and a real 2D price-history chart, both computed independently from the same constant-product economics:
Pool point (x, y) always sits on x·y = k
Spot price p = y/x = |slope of the tangent to the curve at (x, y)|
since y = k/x ⇒ dy/dx = −k/x² = −y/x = −p
Flash loan: dump dx of token A in (moves the point
along the curve to x' = x+dx, y' = k/x'), read the
manipulated tangent slope p' = y'/x' as "price", then
atomically repay dx — the point snaps back to (x, y)
before the next block, only that block's spot reading
was ever manipulated.
TWAP over N blocks: TWAP = (1/N) · Σ p_i
- The top panel is the literal reserve curve: the white dot is the pool's current (reserveX, reserveY); the dashed red segment is the tangent line whose slope magnitude is the spot price — you can watch the tangent steepen exactly as the dot slides down the curve during an attack.
- The bottom panel is a real price-vs-block-number chart: red bars are the per-block spot price, the blue line is the rolling TWAP over the chosen window, and the dashed bands mark the ±12% naive-liquidation threshold.
- Flash-loan size sets how large a fraction of reserveX is dumped into the pool in the attacked block. That oversupplies token A, pushing the point along the curve toward larger x / smaller y — a bigger fraction moves it further, dropping the tangent slope (the spot price) further below 1.0; the deviation-from-1.0 magnitude is what a naive oracle checks, so a bigger flash loan means a bigger false-liquidation swing either way the price moves.
- TWAP window — how many past blocks the defensive oracle averages; a wider window dilutes one manipulated block into a much smaller move in the blue line.
- Unlike the 3D version's background-noise routine (which mean-reverted price with an ad-hoc reserve nudge), this 2D model drives ordinary blocks with a genuine partial-arbitrage rule: each block, an arbitrageur trades a fraction of the gap between the current price and the external reference price of 1.0, exactly the way real arbitrage bots close AMM mispricing against the wider market — plus small independent noise trades.