Kaoya Swap Hack
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
- The attacker flash-borrowed 1,800 WBNB and swapped part of it for KaoyaSwap's KY token and for BUSD.
- 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.
- It called
swapExactTokensForETHSupportingFeeOnTransferTokenswith the path[TokenA, WBNB, TokenB, TokenA, WBNB], so the TokenA/WBNB pair was both the first and the last hop. - 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. - 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
Evidence
- report KaoyaSwap Logic Exploit Analysis by QuillAudits Team medium.com
- transaction bscscan.com transaction 0xc8db…8d74 bscscan.com
- address etherscan.io address 0x236b…91e5 etherscan.io
- address etherscan.io address 0x50fc…4d28 etherscan.io
- address etherscan.io address 0x8df3…9ca1 etherscan.io
- address etherscan.io address 0xb77e…8589 etherscan.io
- address etherscan.io address 0xe946…df09 etherscan.io
- code HackerAnalysis: kaoya.md (KaoyaSwap attack analysis) github.com
- analysis DeFiLlama defillama.com
Understand the attack patterns
Build your security review skills
Work through hands-on labs covering real exploit mechanics, review techniques, and defensive patterns.