Curriculum·J302 Swap Execution: AMMs, MEV, and DEX Architectures·about 41 min

Constant product math

By the end of this lesson you can

  • Derive an AMM's price from its reserves and compute the effect of a trade of any size
  • Calculate the capital required to move a pool price by a given factor
  • Explain why an AMM price is a reserve ratio rather than a valuation
  • Identify systems that treat a pool price as an oracle, and why that is exploitable

Junior · enrolled learners

This lesson opens with bZx, February 2020.

What happened
bZx used Kyber as the sole price source for its feeds, and Kyber routed to on-chain pools. On 14 and 15 February an attacker took a flash loan of about $10M in ETH from dYdX, used roughly $5M of it to open a five times leveraged short on the ETH and wBTC book at bZx, and the resulting order was routed and filled on Uniswap, driving the wBTC price there to around three times its starting level. The attacker profited by about $370,000 and bZx lost about $620,000. On 18 February a second attacker used 900 ETH to buy sUSD on Kyber and Uniswap, pushing the price above two and a half times the market rate, then posted the inflated sUSD as collateral to borrow 6,796 ETH from bZx, taking about $665,000. Combined losses were roughly $954,000.
The decision point
No contract was broken and no key was stolen. The attacker used the pricing formula exactly as designed. A constant product pool reports a price that is a function of its two reserve balances and nothing else, so anybody willing to move the balances can set the reported price to any value they choose, and a flash loan supplies the capital to do it inside a single transaction at no cost. The failure was that a system treated a reserve ratio as if it were a valuation.
Recorded loss
$954,000

What you will be able to answer

  • What determines the price in a constant product pool?
  • What does the invariant say?
  • How much capital moves a pool price by a factor f?
  • Why is a pool price not a valuation?

Orientation and Year One are open: anyone can read them without an account. From Year Two onward the lessons are for enrolled learners, because progress through the later years only means anything if it is tracked against a record.

It is free. We do not sell the list and there is nothing to buy at the end of it.

Sources and review

Confidence high·Volatility low·Reviewed 2026-08-06·Owner unassigned

Contested

This course has two halves since the 2026-09-09 merge. Lessons 1 to 5 cover the mechanics of a single swap and do not compare venues. Lessons 6 to 12, formerly the separate course J309, own venue selection: the four architectures, AMM generations, on-chain order books, aggregators, intents, perp DEXs and launch venues. The split between the halves is kept; material should not move across it without moving in both directions.

Reported bZx losses vary between about $918,000 and $954,000 depending on valuation date and on whether both incidents are combined. The mechanism is identical in both and is the durable part.