Levyathan Hack

Reported loss $1.5M
BNB Chain
Private Key Compromised (Stored Publicly)

What happened

On July 30, 2021, an attacker took over the Levyathan yield farm on BNB Smart Chain and minted a vast amount of LEV. Levyathan developers had left the private key of the deployer wallet, which could queue actions on the protocol's timelock, in the project's public GitHub. It sat there for about four months before it was used.

The attacker used that key to queue a MasterChef ownership transfer through the timelock, which enforced a 48-hour delay (DeFiHackLabs indexes the incident under July 28, 2021). Once the delay passed they executed it, took ownership of the MasterChef and the LEV token, minted LEV, sold part of it and bridged the proceeds to Ethereum. The first bridged ETH arrived on Ethereum at 11:50 UTC on July 30. LEV fell from about $0.15 to about $0.00000147.

A second bug made things worse. emergencyWithdraw() paid out rewardDebt instead of user.amount, so early users could withdraw more than they had staked and drained the pools before others got out. The farm's TVL of about $1.5 million was lost. Levyathan had been audited by CertiK.

Attacker: 0x7507f84610f6d656a70eb8cdec044674799265d3 Timelock schedule: 0xfd30def124c1345606598ae4817ae184fc1918fc638111c6e71bc9752361fd87 Timelock execute: 0xe6e504208ba90d121c3212a4f2547ae28e69790ab541d459c080ec8b1f3efab2 Mint: 0x86ddfd9864199ea78c1e6dc2a83c033f5900e00d3826cd39044a0ef7fcd2135e Sales: 0xe3faf5bfab37bf335b7850dab966a448d8e41bc06f56d5b6185ac6f3af068230, 0x06498e85588bb0e6083ca01ff7f9e9393bd0944697540c523aec5c7f43ddca3f Remaining tokens burned: 0x2893474012d4438260e757679544af58027b9ba84ce6bfc44c0cc78c6a5710b0 Swaps to ETH: 0xfba3cd6046ac669fdb5d9217f2ca6cb2c735ac4009ab1def2a0b84511f87bf2e, 0x692d4a6a1f074b2c082202d56b4d88a8f8f57f1b7f04d10fad8b0bf39debf3a8 Bridge to Ethereum: 0x7643893ee149277fe6dc08881f329ac03cbd012719dfd40907a2570211949166, 0x6ee8444d2436eff636ce64d42f74dc12766f38bd25c3dbd439d7401ac032877b Tornado Cash deposits: 0x50a243cf3bc2024f9231dd0976f232f991d5f66f8b16d4d6536f1c744ba0fcca, 0xffbabbe3f484a025f27ecd343171abfa30c63ecac245aa487207d03232d53c3f, 0xcd715f0148706f89decbbc7294a0862825f52bc3dce7ed69853847a667b4f9cb

How it happened

  1. The private key of the Levyathan deployer, which could propose timelock transactions, was committed to the project's public GitHub repository.
  2. The key was used to schedule() a timelock transaction transferring MasterChef ownership (tx 0xfd30def1...fd87).
  3. After the 172,800-second (two-day) delay, the transaction was execute()d (tx 0xe6e50420...efab2). The new owner called recoverLevOwnership() to take the LEV token back from the MasterChef.
  4. As token owner, the attacker minted a large amount of LEV, sold part of it, swapped the proceeds to ETH and bridged them to Ethereum on July 30.
  5. Normal withdraw() and leaveStaking() calls reverted, while the buggy emergencyWithdraw() paid out rewardDebt and could be called repeatedly, so the remaining stake went to whoever withdrew first.

Protocol details

Classification Infrastructure / Other / Frontend & Infrastructure
Protocol Type Exploit/Other
Affected asset / contract LEV
Implementation language Solidity

Security review history

  • CertiK 2021-05-25 No public report

Understand the attack patterns

Build your security review skills

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