Reproduce DeFi hack incidents using Foundry.
379 incidents included.
Let's make Web3 secure! Join Discord
Notion: 101 root cause analysis of past DeFi hacked incidents
Disclaimer: This content serves solely as a proof of concept showcasing past DeFi hacking incidents. It is strictly intended for educational purposes and should not be interpreted as encouraging or endorsing any form of illegal activities or actual hacking attempts. The provided information is for informational and learning purposes only, and any actions taken based on this content are solely the responsibility of the individual. The usage of this information should adhere to applicable laws, regulations, and ethical standards.
-
Follow the instructions to install Foundry.
-
Clone and install dependencies:
git submodule update --init --recursive
All articles are also published on Substack.
- Lesson 1: Tools ( English | ä¸ć–‡ | Vietnamese | Korean | Spanish )
- Lesson 2: Warm up ( English | ä¸ć–‡ | Korean )
- Lesson 3: Write Your Own PoC (Price Oracle Manipulation) ( English | ä¸ć–‡ | Korean )
- Lesson 4: Write Your Own PoC (MEV Bot) ( English | ä¸ć–‡ | Korean )
- Lesson 5: Rugpull Analysis ( English | ä¸ć–‡ )
- Lesson 6: Write Your Own PoC (Reentrancy) ( English | ä¸ć–‡ )
- Lesson 7: Hack Analysis: Nomad Bridge, August 2022 ( English | ä¸ć–‡ )
2022
20221024 MulticallWithoutCheck
20221011 Rabby Wallet SwapRouter
20220908 Ragnarok Online Invasion
20220701 Quixotic - Optimism NFT Marketplace
20220624 Harmony's Horizon Bridge
20220608 Optimism - Wintermute
20220430 Rari Capital/Fei Protocol
2021
Before 2020
Phalcon | Tx tracer | Cruise | Ethtx | Tenderly | eigenphi
ABI to interface | Get ABI for unverified contracts | ETH Calldata Decoder | ETHCMD - Guess ABI | Abi tools
Slowmist | Defillama | De.Fi | Rekt | Cryptosec
forge test --contracts ./src/test/ATM_exp.sol -vvv
forge test --contracts ./src/test/Prisma_exp.sol -vvv
https://twitter.com/EXVULSEC/status/1773371049951797485
forge test --contracts src/test/ZongZi_exp.sol -vvv
https://twitter.com/0xNickLFranklin/status/1772195949638775262
forge test --contracts ./src/test/SSS_exp.sol -vvv
https://twitter.com/dot_pengun/status/1770989208125272481
forge test --contracts src/test/ARK_exp.sol -vvv
https://twitter.com/Phalcon_xyz/status/1771728823534375249
forge test --contracts src/test/Paraswap_exp.sol -vvv --evm-version shanghai
https://medium.com/neptune-mutual/analysis-of-the-paraswap-exploit-1f97c604b4fe
forge test --contracts src/test/MO_exp.sol -vvv
https://twitter.com/0xNickLFranklin/status/1768184024483430523
forge test --via-ir --contracts src/test/IT_exp.sol -vvv
https://twitter.com/0xNickLFranklin/status/1768171595561046489
forge test --contracts ./src/test/Juice_exp.sol -vvv
https://medium.com/@juicebotapp/juice-staking-exploit-next-steps-95e218b3ec71
forge test --contracts src/test/UnizenIO_exp.sol -vvvv
UnizenIO_exp.sol | UnizenIO2_exp.sol
https://twitter.com/Phalcon_xyz/status/1766274000534004187
https://twitter.com/AnciliaInc/status/1766261463025684707
forge test --contracts ./src/test/GHT_exp.sol -vvv
Testing
forge test --contracts ./src/test/ALP_exp.sol -vvv
https://twitter.com/0xNickLFranklin/status/1765296663667875880
forge test --contracts ./src/test/TGBS_exp.sol -vvv
https://twitter.com/0xNickLFranklin/status/1765290290083144095
https://twitter.com/Phalcon_xyz/status/1765285257949974747
forge test --contracts ./src/test/Woofi_exp.sol -vvv
https://twitter.com/spreekaway/status/1765046559832764886 https://twitter.com/PeckShieldAlert/status/1765054155478175943
forge test --contracts ./src/test/Seneca_exp.sol -vvv
https://twitter.com/Phalcon_xyz/status/1763045563040411876
forge test --contracts ./src/test/SMOOFSStaking_exp.sol -vvv
https://twitter.com/AnciliaInc/status/1762893563103428783
https://twitter.com/0xNickLFranklin/status/1762895774311178251
forge test --contracts ./src/test/CompoundUni_exp.sol -vvv
https://twitter.com/0xLEVI104/status/1762092203894276481
forge test --contracts ./src/test/BlueberryProtocol_exp.sol -vvv
https://twitter.com/blueberryFDN/status/1760865357236211964
forge test --contracts ./src/test/DeezNutz404_exp.sol -vvv
https://twitter.com/0xNickLFranklin/status/1760481343161700523
forge test --contracts ./src/test/GAIN_exp.sol -vvv
https://twitter.com/0xNickLFranklin/status/1760559768241160679
forge test --contracts ./src/test/RuggedArte_exp.sol -vvv
https://twitter.com/EXVULSEC/status/1759822545875025953
forge test --contracts ./src/test/ParticleTrade_exp.sol -vvv
https://twitter.com/Phalcon_xyz/status/1758028270770250134
forge test --contracts ./src/test/DualPools_exp.sol -vvvv
https://medium.com/@lunaray/dualpools-hack-analysis-5209233801fa
forge test --contracts ./src/test/Miner_exp.sol -vvv --evm-version shanghai
https://twitter.com/Phalcon_xyz/status/1757777340002681326
forge test --contracts ./src/test/Game_exp.sol -vvv
https://twitter.com/AnciliaInc/status/1757533144033739116
forge test --contracts ./src/test/PANDORA_exp.sol -vvv
https://twitter.com/pennysplayer/status/1766479470058406174
forge test --contracts ./src/test/BurnsDefi_exp.sol -vvv
https://twitter.com/pennysplayer/status/1754342573815238946
https://medium.com/neptune-mutual/how-was-citadel-finance-exploited-a5f9acd0b408 (similar incident)
forge test --contracts ./src/test/AffineDeFi_exp.sol -vvv
https://twitter.com/Phalcon_xyz/status/1753020812284809440
https://twitter.com/CyversAlerts/status/1753040754287513655
forge test --contracts ./src/test/MIMSpell2_exp.sol -vvv
https://twitter.com/kankodu/status/1752581744803680680
https://twitter.com/Phalcon_xyz/status/1752278614551216494
https://twitter.com/peckshield/status/1752279373779194011
https://phalcon.blocksec.com/explorer/security-incidents
forge test --contracts ./src/test/BarleyFinance_exp.sol -vvv
https://phalcon.blocksec.com/explorer/security-incidents
https://www.bitget.com/news/detail/12560603890246
https://twitter.com/Phalcon_xyz/status/1751788389139992824
forge test --contracts ./src/test/CitadelFinance_exp.sol -vvv
https://medium.com/neptune-mutual/how-was-citadel-finance-exploited-a5f9acd0b408
forge test --contracts ./src/test/NBLGAME_exp.sol -vvv
https://twitter.com/SlowMist_Team/status/1750526097106915453
https://twitter.com/AnciliaInc/status/1750558426382635036
forge test --contracts ./src/test/Bmizapper_exp.sol -vvv
https://x.com/0xmstore/status/1747756898172952725
forge test --contracts ./src/test/SocketGateway_exp.sol -vvv --evm-version shanghai
https://twitter.com/BeosinAlert/status/1747450173675196674
https://twitter.com/peckshield/status/1747353782004900274
forge test --contracts ./src/test/WiseLending02_exp.sol -vvv --evm-version shanghai
https://twitter.com/EXVULSEC/status/1746829519334650018
https://twitter.com/peckshield/status/1745907642118123774
forge test --contracts src/test/LQDX_alert_exp.sol -vvv
https://twitter.com/SlowMist_Team/status/1744972012865671452
forge test --contracts ./src/test/Gamma_exp.sol -vvv
https://twitter.com/officer_cia/status/1742772207997050899
https://twitter.com/shoucccc/status/1742765618984829326
forge test --contracts ./src/test/RadiantCapital_exp.sol -vvv
https://neptunemutual.com/blog/how-was-radiant-capital-exploited/
https://twitter.com/BeosinAlert/status/1742389285926678784
forge test --contracts ./src/test/OrbitChain_exp.sol -vvv
https://blog.solidityscan.com/orbit-chain-hack-analysis-b71c36a54a69
Foundry also has the ability to report the gas
used per function call which mimics the behavior of hardhat-gas-reporter. Generally speaking if gas costs per function call is very high, then the likelihood of its success is reduced. Gas optimization is an important activity done by smart contract developers.
Every poc in this repository can produce a gas report like this:
forge test --gas-report --contracts <contract> -vvv
For Example: Let us find out the gas used in the Audius poc
Execution
forge test --gas-report --contracts ./src/test/Audius.exp.sol -vvv
Demo
Moved to DeFiVulnLabs
Moved to DeFiLabs