CS Hack

Reported loss $714K
Stale accounting and liquidity-pair burn manipulation using flash-loan funding

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

  1. The attack contract flash-borrowed 80,000,000 BSC-USD from a PancakeSwap pair.
  2. It bought CS with BSC-USD in 99 swapTokensForExactTokens calls of 5,000 CS each.
  3. It then looped while it held at least 3,000 CS: sell 3,000 CS into the pool, which updated sellAmount, then call CS.transfer(address(this), 2), a self-transfer of 2 base units (wei) of CS. The self-transfer triggered a burn sized from the stale sellAmount, shrinking the pool's CS and raising the CS price.
  4. After selling its CS back for BSC-USD, it repaid 80,240,000 BSC-USD to the pair and kept the rest.
  5. The profit was later converted to about 383 ETH and sent through Tornado Cash.

Protocol details

Classification Token
Protocol Type Exploit/Flash Loan Attack
Affected asset / contract CS

Understand the attack patterns

Build your security review skills

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