DKP Token Hack
What happened
DKP, a BEP-20 token traded on PancakeSwap, was drained for roughly $80,000 on March 8, 2023 (about 79,233 USDT by the reported profit figure). A separate DKP exchange contract let users buy DKP with USDT, but priced DKP from the live balance ratio of the USDT-DKP PancakeSwap pair. The attacker flash-borrowed almost all of the pair's USDT, which made DKP look nearly worthless to the exchange, bought 17,029 DKP for 100 USDT, and sold it back into the pool for USDT.
The exchange contract (0x89257A52Ad585Aacb1137fCc8abbD03a963B9683) was closed source, so the analysis rests on the observed transactions.
**Block data**
- Attacker:
0xf38b677fa6e9e51338d0c32fd21afe43406e06df - Attack contract:
0xf34ad6cea329f62f4516ffe00317ab09d934fba3 - Exploit transaction:
0x0c850f54c1b497c077109b3d2ef13c042bb70f7f697201bcf2a4d0cb95e74271 - Sell transaction:
0x2d31e45dce58572a99c51357164dc5283ff0c02d609250df1e6f4248bd62ee01 - DKP token:
0xd06fa1BA7c80F8e113c2dc669A23A9524775cF19 - USDT-DKP pair:
0xBE654FA75bAD4Fd82D3611391fDa6628bB000CC7
How it happened
- The attacker flash-swapped about 259,390 USDT (BSC-USD) out of the USDT-DKP PancakeSwap pair, draining almost all of its USDT side.
- Inside the
pancakeCallcallback, a helper contract calledexchange()on the DKP exchange contract with 100 USDT. Because the exchange priced DKP from the pair's current USDT/DKP balance ratio, the near-empty USDT side made DKP look extremely cheap, and the call returned 17,029 DKP. - The borrowed USDT plus the swap fee was returned to the pair in the same callback, restoring the pool's USDT balance and DKP's price.
- In a second transaction the attacker sold the 17,029 DKP to the pair through
swapExactTokensForTokensSupportingFeeOnTransferTokens, taking out roughly 79,233 USDT.
Protocol details
Evidence
- report @CertiKAlert incident report twitter.com
- transaction bscscan.com transaction 0x0c85…4271 bscscan.com
- transaction bscscan.com transaction 0x2d31…ee01 bscscan.com
- address bscscan.com address 0xf34a…fba3 bscscan.com
- address bscscan.com address 0xf38b…06df bscscan.com
- code DeFiHackLabs DKP_exp.sol PoC github.com
- code DeFiHackLabs 2023 index: 20230308 - DKP - FlashLoan price manipulation github.com
- analysis DeFiLlama defillama.com
- analysis DKP Hack Analysis - Improper Token-Pair Ratio Calculation blog.solidityscan.com
- analysis Reproducing the DKP Token Exploit using Foundry gist.github.com
Understand the attack patterns
Build your security review skills
Work through hands-on labs covering real exploit mechanics, review techniques, and defensive patterns.