All vulnerabilities
CRITICALWeb3exploited in the wild

WEB3-KYBERSWAP-2023

Web3 · Ethereum · KyberSwap Elastic

Summary

On November 23, 2023 KyberSwap Elastic was exploited across six chains for over $48M (>$20M Arbitrum, $15M Optimism, $7.5M Ethereum, $3M Polygon, $2M Base, ~$23K Avalanche). The root cause was a rounding-direction bug in the concentrated-liquidity math: estimateIncrementalLiquidity should have rounded delta liquidity up so the final price rounded down, but it used mulDivFloor and rounded delta liquidity down, pushing the computed sqrt price slightly past a tick boundary without legitimately crossing it. Using Aave flash loans, the attacker first swapped to park the price in a liquidity-empty region, calibrated a tight position, then performed extremely precise swaps so the price landed exactly on a tick's sqrt price. This forced _updateLiquidityAndCrossTick to register a crossing in computeSwapStep twice, double-counting the tick's liquidity on the reverse swap and paying out far more output than backed, draining the pools. The attacker later opened negotiations; most funds were not promptly recovered.

How to avoid it in your code

  • Use correct rounding directions in AMM math so price always rounds against the trader, never past a tick.
  • Guard tick-crossing logic against double-counting liquidity at exact boundary equality.
  • Add invariant tests asserting pool reserves back all redeemable liquidity after every swap step.
  • Fuzz swap math with adversarially precise, boundary-targeting inputs.
  • Cross-check pool solvency invariants on-chain after liquidity-mutating operations.

References

Related vulnerabilities

All Web3 →