All vulnerabilities
CRITICALWeb3exploited in the wild

WEB3-URANIUM-2021

Web3 · BNB Chain · Uranium Finance

Summary

On 28 April 2021 Uranium Finance, a Uniswap-V2-style AMM on BNB Chain, lost about $50 million across 26 pairs during its v2 migration. The forked pair contract's swap() ended with a constant-product sanity check, but a copy-paste error left mismatched scaling constants: the post-swap invariant compared balance-adjusted reserves multiplied by 10000 against the old reserves multiplied by 1000*1000 (1,000,000). Because the adjusted-balance side used 10000 instead of 1000, the check was 100x too loose, so require(balance0Adjusted * balance1Adjusted >= reserve0 * reserve1 * 1000000) passed while the attacker removed nearly all output reserves for a negligible input. This is an incorrect AMM-invariant / constant-product math bug, not a logic-flow flaw, and it was exploited shortly before the patched build was deployed.

How to avoid it in your code

  • Never derive AMM invariants from hand-edited constants; unit-test the k-invariant against Uniswap reference values after any fork
  • Assert that fee/scaling multipliers on both sides of the constant-product check use identical, named constants
  • Add invariant tests proving reserve0*reserve1 never decreases across swap() for all input amounts
  • Gate migrated/forked AMM code behind a full re-audit and a timelock; deploy the audited version, not the pre-fix build

References

Related vulnerabilities

All Web3 →