CS Hack
What happened
On May 23, 2023, an attacker drained the PancakeSwap pool of the newly launched CS token on BNB Smart Chain in one flash-loan transaction. Reported losses range from nearly $700,000 (Web3 Is Going Great) to about $710,000 (Beosin). The bug was in the token's own transfer logic, not in PancakeSwap.
CS stored the size of the last sale in a global sellAmount variable and used it to compute a burn amount. The variable was out of date when later transfers read it, so a transfer could trigger a burn sized from an earlier sale. By selling CS and then sending a tiny amount of CS to itself again and again, the attacker set off these stale burns, cut the pool's CS balance and pushed the CS price up against BSC-USD.
The attacker borrowed 80,000,000 BSC-USD, bought CS in 99 small swaps, sold it back into the manipulated pool, repaid 80,240,000 BSC-USD including the 240,000 fee, and kept the difference. Web3 Is Going Great reports the profit was converted to about 383 ETH and sent through Tornado Cash.
Exploit transaction: 0x906394b2ee093720955a7d55bff1666f6cf6239e46bea8af99d6352b9687baa4
How it happened
- The attack contract flash-borrowed 80,000,000 BSC-USD from a PancakeSwap pair.
- It bought CS with BSC-USD in 99
swapTokensForExactTokenscalls of 5,000 CS each. - It then looped while it held at least 3,000 CS: sell 3,000 CS into the pool, which updated
sellAmount, then callCS.transfer(address(this), 2), a self-transfer of 2 base units (wei) of CS. The self-transfer triggered a burn sized from the stalesellAmount, shrinking the pool's CS and raising the CS price. - After selling its CS back for BSC-USD, it repaid 80,240,000 BSC-USD to the pair and kept the rest.
- The profit was later converted to about 383 ETH and sent through Tornado Cash.
Protocol details
Evidence
- report @DeDotFiSecurity incident report twitter.com
- transaction bscscan.com transaction 0x9063…nbsp bscscan.com
- address bscscan.com address 0x2cde…nbsp bscscan.com
- address bscscan.com address 0x90fa…nbsp bscscan.com
- analysis DeFiHackLabs CS_exp.sol proof of concept (2023-05) raw.githubusercontent.com
- analysis Brand new $CS token exploited for almost $700,000 web3isgoinggreat.com
- analysis BscScan block 28466976 bscscan.com
- analysis Blockchain Security Monthly Recap of May: $19.69M lost in total beosin.com
Understand the attack patterns
Build your security review skills
Work through hands-on labs covering real exploit mechanics, review techniques, and defensive patterns.