Kaoya Swap Hack

Reported loss $118K
BNB Chain
Flash Loan Attack

What happened

KaoyaSwap, a DEX on BNB Smart Chain, was exploited on August 24, 2022. The attacker profited about 37,294 BUSD and 271.2 WBNB, roughly $118,000.

Unlike Uniswap V2, where each pair contract holds its own reserves, KaoyaSwap's router held the tokens for all pools. Its swapExactTokensForETHSupportingFeeOnTransferTokens function paid the user the drop in the last pair's WBNB balance, measured before and after the whole swap. That works when the last pair appears once in the path. If the path passes through the last pair twice, the measured difference no longer matches what the final hop actually produced, and the router pays out WBNB that belongs to other pools.

The attacker used a flash loan of 1,800 WBNB and two self-made tokens to route a swap through the same TokenA/WBNB pair twice. KaoyaSwap did not publish an official statement at the time.

**Block data**

  • Exploit tx: 0xc8db3b620656408a5004844703aa92d895eb3527da057153f0b09f0b58208d74
  • Attack contract: 0xa722ca7bf032de8f7a675da75dfec661bc89ace9
  • Vulnerable router: 0x879ead67c92ec2bfa70fa9d157f500b7b31b64ab

How it happened

  1. The attacker flash-borrowed 1,800 WBNB and swapped part of it for KaoyaSwap's KY token and for BUSD.
  2. It deployed two tokens, TokenA and TokenB, and created three pools it controlled on KaoyaSwap: TokenA/WBNB (seeded with about 1,026 WBNB), TokenB/WBNB and TokenA/TokenB.
  3. It called swapExactTokensForETHSupportingFeeOnTransferTokens with the path [TokenA, WBNB, TokenB, TokenA, WBNB], so the TokenA/WBNB pair was both the first and the last hop.
  4. The router measured the last pair's WBNB balance before and after the whole path and paid that difference as amountOut, which counted WBNB from the first hop again.
  5. The attacker removed liquidity from its three pools to recover its seed funds, sold the KY tokens through KaoyaSwap and PancakeSwap, repaid the flash loan and kept about 37,294 BUSD and 271.2 WBNB.

Protocol details

Classification Exchange (DEX) / Protocol Logic
Protocol Type Exploit/Flash Loan Attack
Affected asset / contract KALP
Implementation language Solidity
Protocol links @Kaoyaswap

Understand the attack patterns

Build your security review skills

Work through hands-on labs covering real exploit mechanics, review techniques, and defensive patterns.