Reproduce DeFi hack incidents using Foundry.
541 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 | Spanish )
- Lesson 3: Write Your Own PoC (Price Oracle Manipulation) ( English | ä¸ć–‡ | Korean | Spanish )
- Lesson 4: Write Your Own PoC (MEV Bot) ( English | ä¸ć–‡ | Korean | Spanish )
- Lesson 5: Rugpull Analysis ( English | ä¸ć–‡ | Spanish )
- Lesson 6: Write Your Own PoC (Reentrancy) ( English | ä¸ć–‡ | Spanish )
- Lesson 7: Hack Analysis: Nomad Bridge, August 2022 ( English | ä¸ć–‡ | Spanish )
If you appreciate our work, please consider donating. Even a small amount helps us continue developing and improving our projects, and promoting web3 security.
- Gitcoin - Donate DeFiHackLabs
- EVM Chains - 0xD7d6215b4EF4b9B5f40baea48F41047Eb67a11D5
- Giveth
20240703 UnverifiedContr_0x452E25
20240417 UnverifiedContr_0x00C409
2023
20231201 UnverifiedContr_0x431abb
20230715 USDTStakingContract28
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/2024-11/PolterFinance_exploit.sol -vvv
https://twitter.com/Bcpaintball26/status/1857865758551805976
forge test --contracts ./src/test/2024-11/DeltaPrime_exp.sol -vvv
https://x.com/peckshield/status/1855910524460159197
forge test --contracts ./src/test/2024-10/CompoundFork_exploit.sol -vvv --evm-version shanghai
https://x.com/Phalcon_xyz/status/1849636437349527725 https://app.blocksec.com/explorer/tx/base/0x6ab5b7b51f780e8c6c5ddaf65e9badb868811a95c1fd64e86435283074d3149e
forge test --contracts ./src/test/2024-10/Erc20transfer_exp.sol -vvv
https://x.com/d23e_AG/status/1849064161017225645
forge test --contracts ./src/test/2024-10/VISTA_exp.sol -vvv --evm-version cancun
https://x.com/TenArmorAlert/status/1848403791881900130
forge test --contracts ./src/test/2024-10/MorphoBlue_exp.sol -vvv --evm-version shanghai
https://x.com/omeragoldberg/status/1845515843787960661
forge test --match-contract P719Token_exp -vvv
https://x.com/TenArmorAlert/status/1844753750386426182
forge test --match-contract SASHAToken_exp -vvv
https://x.com/0xNickLFranklin/status/1842864840265883833
forge test --contracts ./src/test/2024-10/HYDT_exp.sol -vvv --evm-version cancun
https://x.com/TenArmorAlert/status/1844241843518951451
forge test --match-contract AIZPTToken_exp -vvv
https://x.com/0xNickLFranklin/status/1842576732047700077
forge test --contracts ./src/test/2024-10/FireToken_exp.sol -vvv
https://twitter.com/0xNickLFranklin/status/1841305965750350089
forge test --match-contract LavaLending_exp -vvv
https://x.com/0xNickLFranklin/status/1841823216425435308
forge test --match-contract OnyxDAO_exp -vvv
https://x.com/peckshield/status/1839302663680438342
forge test --match-contract Bedrock_DeFi_exp -vvv
https://x.com/certikalert/status/1839403126694326374
forge test --match-contract MARA_exp -vvv
https://bscscan.com/tx/0x0fe3716431f8c2e43217c3ca6d25eed87e14d0fbfa9c9ee8ce4cef2e5ec4583c
forge test --match-contract Bankroll_exp -vvv
https://x.com/Phalcon_xyz/status/1838042368018137547
forge test --match-contract OTSeaStaking_exp -vvv
Nick Franklin: https://nickfranklin.site/2024/09/13/otsea-staking-hacked/
forge test --match-contract Caterpillar_Coin_CUT_exp -vvv --evm-version shanghai
https://www.certik.com/zh-CN/resources/blog/caterpillar-coin-cut-token-incident-analysis
forge test --match-contract Penpiexyzio_exp -vvv --evm-version shanghai
https://x.com/peckshield/status/1831072098669953388
https://x.com/AnciliaInc/status/1831080555292856476
https://x.com/hackenclub/status/1831383106554573099
post-morten: https://x.com/Penpiexyz_io/status/1831462760787452240
forge test --match-contract AAVE_Repay_Adapter -vvv
https://www.vibraniumaudits.com/post/aave-hacked-via-periphery-contract-56kstolenfromtipjar
forge test --match-contract Zenterest_exp -vvvv --evm-version shanghai
https://x.com/0xNickLFranklin/status/1824579761383018564
forge test --match-contract OMPxContract_exp -vvv
https://x.com/0xNickLFranklin/status/1820816386551357448
forge test --match-contract YodlRouter_exp -vvv
https://x.com/0xNickLFranklin/status/1823601087011807636
forge test --match-contract VOW_exp -vvv
https://x.com/Vowcurrency/status/1823407231658025300
forge test --match-contract IvestDao_exp -vvv
https://x.com/AnciliaInc/status/1822870201698050064
forge test --match-contract NovaXM2E_exp -vvv
https://x.com/EXVULSEC/status/1820676684410147276
forge test --match-contract Convergence_exp -vvvv --evm-version cancun
https://x.com/DecurityHQ/status/1819030089012527510
forge test --match-contract Spectra_finance_exp -vvv
https://x.com/shoucccc/status/1815981585637990899
forge test --match-contract -vvv --evm-version cancun
https://x.com/SlowMist_Team/status/1815656653100077532
forge test --match-contract Lifiprotocol_exp -vvv
https://x.com/danielvf/status/1505689981385334784
forge test --match-contract Minterest_exp -vvv
https://x.com/0xNickLFranklin/status/1813122959219040323
forge test --match-contract DoughFina_exp -vvv
https://x.com/CertiKAlert/status/1811668992882307478
forge test --match-contract SBT_exp -vvv
https://x.com/0xNickLFranklin/status/1811401263969673654
forge test --match-contract GAX_exp -vvv
https://x.com/EXVULSEC/status/1811348160851378333
forge test --match-contract LW_exp -vvv
https://x.com/0xNickLFranklin/status/1810245893490368820
forge test --match-contract DeFiPlaza_exp -vvv
https://x.com/DecurityHQ/status/1809222922998808760
forge test --match-contract UnverifiedContr_0x452E25_exp -vvv --evm-version "cancun"
UnverifiedContr_0x452E25_exp.sol
https://x.com/SlowMist_Team/status/1808334870650970514
forge test --match-contract MRP_exp -vvv
https://x.com/0xNickLFranklin/status/1808309614443733005
forge test --match-contract Will_exp -vvv --evm-version "shanghai"
https://x.com/0xNickLFranklin/status/1806704287252394238
forge test --match-contract APEMAGA_exp -vvv --evm-version "shanghai"
https://x.com/ChainAegis/status/1806297556852601282
forge test --match-contract INcufi_exp -vvv
https://x.com/0xNickLFranklin/status/1803317022513832301
forge test --match-contract Dyson_money_exp -vvv
https://x.com/0xNickLFranklin/status/1802634237667054052
forge test --match-contract WIFCOIN_ETH_exp -vvv --evm-version "shanghai"
https://x.com/ChainAegis/status/1802550962977964139
forge test --match-contract Crb2_exp -vvv --evm-version shanghai
forge test --match-contract JokInTheBox_exp -vvv --evm-version cancun
https://x.com/0xNickLFranklin/status/1800355604692910571
forge test --match-contract Bazaar_exp -vvv
https://x.com/shoucccc/status/1800353122159833195
forge test --match-contract YYS_exp -vv
https://x.com/0xNickLFranklin/status/1799610045589831833
forge test --match-contract SteamSwap_exp -vvv --evm-version shanghai
https://x.com/SlowMist_Team/status/1798905797440897386
forge test --match-contract MineSTM_exp -vv
https://x.com/0xNickLFranklin/status/1798920774511898862
forge test --match-contract NCD_exp -vv
https://x.com/SlowMist_Team/status/1797821034319765604
forge test --match-contract Velocore_exp -vv
https://x.com/BeosinAlert/status/1797247874528645333
forge test --match-contract Liquiditytokens_exp -vvv
https://x.com/EXVULSEC/status/1796499069583724638
forge test --match-contract MixedSwapRouter_exp -vvv
https://x.com/ChainAegis/status/1796484286738227579
forge test --match-contract SCROLL_exp -vvv
https://x.com/0xNickLFranklin/status/1795650745448169741
forge test --match-contract MetaDragon_exp -vvvvv --evm-version shanghai
https://x.com/Phalcon_xyz/status/1795746828064854497
forge test --match-contract Tradeonorion_exp -vvv
https://x.com/MetaSec_xyz/status/1796008961302258001
forge test --match-contract EXcommunity_exp -vvv
https://x.com/SlowMist_Team/status/1795648617530995130
forge test --match-contract RedKeysCoin_exp -vvv --evm-version shanghai
forge test --match-contract NORMIE_exp -vv
https://x.com/lookonchain/status/1794680612399542672
forge test --match-contract Burner_exp -vv
https://x.com/0xNickLFranklin/status/1792925754243625311
forge test --match-contract TCH_exp -vvv
https://x.com/DecurityHQ/status/1791180322882629713
forge test --match-contract Sonne_exp -vvv
https://neptunemutual.com/blog/taking-a-closer-look-at-sonne-finance-exploit/
forge test --match-contract PredyFinance_exp -vvv
https://twitter.com/Phalcon_xyz/status/1790307019590680851
forge test --match-contract TGC_exp -vvv
https://x.com/ChainAegis/status/1789490986588205529
forge test --match-contract GFOX_exp -vvv --evm-version shanghai
https://twitter.com/CertiKAlert/status/1788751142144401886
forge test --match-contract TSURU_exp -vvv --evm-version shanghai
https://base.tsuru.wtf/usdtsuru-exploit-incident-report
forge test --match-contract GPU_exp -vvv
https://twitter.com/PeckShieldAlert/status/1788153869987611113
forge test --match-contract OSN_exp -vvv
https://twitter.com/ChainAegis/status/1787667253435195841
forge test --match-contract OSN_exp -vvv --evm-version shanghai
https://twitter.com/SlowMist_Team/status/1787330586857861564
forge test --match-contract Yield_exp -vvv
https://twitter.com/peckshield/status/1785121607192817692
https://medium.com/immunefi/yield-protocol-logic-error-bugfix-review-7b86741e6f50
forge test --match-contract PikeFinance_exp -vvv
https://twitter.com/Phalcon_xyz/status/1785508900093194591
forge test --match-contract BNBX_exp -vvv --evm-version shanghai
https://x.com/ChainAegis/status/1784431544557514896
forge test --match-contract NGFS_exp -vvv --evm-version shanghai
https://twitter.com/CertiKAlert/status/1783476515331616847
forge test --match-contract XBridge_exp -vvv
forge test --match-contract YIEDL_exp -vvv
forge test --match-contract Z123_exp -vvv
https://twitter.com/PeckShieldAlert/status/1782322484911784385
forge test --match-contract Rico_exp -vvv
https://twitter.com/ricocreditsys/status/1781803698940781009
forge test --match-contract HedgeyFinance_exp -vvv
https://twitter.com/Cube3AI/status/1781294512716820918
forge test --match-contract UnverifiedContr_0x00C409_exp -vvv
UnverifiedContr_0x00C409_exp.sol
https://x.com/CyversAlerts/status/1780593407871635538
forge test --match-contract SATX_exp -vvv
https://x.com/bbbb/status/1780341239801393479
forge test --match-contract MARS_exp -vv
https://twitter.com/Phalcon_xyz/status/1780150315603701933
forge test --match-contract GFA_exp -vvv
https://x.com/ChainAegis/status/1779809931962827055
forge test --match-contract ChaingeFinance_exp -vvv
https://twitter.com/CyversAlerts/status/1779875922381860920
forge test --match-contract Hackathon_exp -vvv
https://x.com/EXVULSEC/status/1779519508375613827
forge test --match-contract FIL314_exp -vvv
forge test --match-contract SumerMoney_exp -vvv
https://twitter.com/0xNickLFranklin/status/1778986926705672698
forge test --match-contract GROKD_exp -vvv
https://x.com/hipalex921/status/1778482890705416323?t=KvvG83s7SXr9I55aftOc6w&s=05
forge test --match-contract BigBangSwap_exp -vvv
https://x.com/ChainAegis/status/1778254222288621912
forge test --match-contract UPS_exp -vvv
https://twitter.com/0xNickLFranklin/status/1777589021058728214
forge test --match-contract SQUID_exp -vvv
https://twitter.com/bbbb/status/1777228277415039304
forge test --match-contract WSM_exp -vvv
https://hacked.slowmist.io/#:~:text=Hacked%20target%3A%20Wall%20Street%20Memes
forge test --match-contract HoppyFrogERC_exp -vvv --evm-version shanghai
https://x.com/ChainAegis/status/1775351437410918420
forge test --match-contract ATM_exp -vvv
https://twitter.com/0xNickLFranklin/status/1775008489569718508
forge test --match-contract OpenLeverage2_exp -vvv
https://twitter.com/0xNickLFranklin/status/1774727539975672136
forge test --match-contract ETHFIN_exp -vvv --evm-version shanghai
forge test --match-contract Prisma_exp -vvv
https://twitter.com/EXVULSEC/status/1773371049951797485
forge test --match-contract LavaLending_exp -vvv
https://twitter.com/0xNickLFranklin/status/1774727539975672136
https://twitter.com/Phalcon_xyz/status/1773546399713345965
https://hackmd.io/@LavaSecurity/03282024
forge test --match-contract ZongZi_exp -vvv
https://twitter.com/0xNickLFranklin/status/1772195949638775262
forge test --match-contract CGT_exp -vvv
https://x.com/AnciliaInc/status/1771598968448745536
forge test --match-contract SSS_exp -vvv
https://twitter.com/dot_pengun/status/1770989208125272481
forge test --match-contract ARK_exp -vvv
https://twitter.com/Phalcon_xyz/status/1771728823534375249
forge test --match-contract Paraswap_exp -vvv --evm-version shanghai
https://medium.com/neptune-mutual/analysis-of-the-paraswap-exploit-1f97c604b4fe
forge test --match-contract MO_exp -vvv
https://twitter.com/0xNickLFranklin/status/1768184024483430523
forge test --via-ir ---match-contract IT_exp -vvv
https://twitter.com/0xNickLFranklin/status/1768171595561046489
forge test --match-contract BBT_exp -vvv
https://x.com/8olidity/status/1767470002566058088
forge test --match-contract Binemon_exp -vvv
forge test --match-contract Juice_exp -vvv --evm-version shanghai
https://medium.com/@juicebotapp/juice-staking-exploit-next-steps-95e218b3ec71
forge test --match-contract UnizenIO_exp -vvvv
UnizenIO_exp.sol | UnizenIO2_exp.sol
https://twitter.com/Phalcon_xyz/status/1766274000534004187
https://twitter.com/AnciliaInc/status/1766261463025684707
forge test --match-contract GHT_exp -vvv
Testing
forge test --match-contract ALP_exp -vvv
https://twitter.com/0xNickLFranklin/status/1765296663667875880
forge test --match-contract TGBS_exp -vvv
https://twitter.com/0xNickLFranklin/status/1765290290083144095
https://twitter.com/Phalcon_xyz/status/1765285257949974747
forge test --match-contract Woofi_exp -vvv
https://twitter.com/spreekaway/status/1765046559832764886 https://twitter.com/PeckShieldAlert/status/1765054155478175943
forge test --match-contract Seneca_exp -vvv
https://twitter.com/Phalcon_xyz/status/1763045563040411876
forge test --match-contract SMOOFSStaking_exp -vvv
https://twitter.com/AnciliaInc/status/1762893563103428783
https://twitter.com/0xNickLFranklin/status/1762895774311178251
forge test --match-contract Zoomer_exp -vvv --evm-version "shanghai"
https://x.com/ChainAegis/status/1761246415488225668
forge test --match-contract CompoundUni_exp -vvv
https://twitter.com/0xLEVI104/status/1762092203894276481
forge test --match-contract BlueberryProtocol_exp -vvv
https://twitter.com/blueberryFDN/status/1760865357236211964
forge test --match-contract SwarmMarkets_exp -vvv
forge test --match-contract DeezNutz404_exp -vvv
https://twitter.com/0xNickLFranklin/status/1760481343161700523
forge test --match-contract GAIN_exp -vvv
https://twitter.com/0xNickLFranklin/status/1760559768241160679
forge test --match-contract EGGX_exp -vvv
https://x.com/PeiQi_0/status/1759826303044497726
forge test --match-contract RuggedArt_exp -vvv
https://twitter.com/EXVULSEC/status/1759822545875025953
forge test --match-contract ParticleTrade_exp -vvv
https://twitter.com/Phalcon_xyz/status/1758028270770250134
forge test --match-contract DualPools_exp -vvvv
https://medium.com/@lunaray/dualpools-hack-analysis-5209233801fa
forge test --match-contract Babyloogn_exp -vvvv
forge test --match-contract Miner_exp -vvv --evm-version shanghai
https://twitter.com/Phalcon_xyz/status/1757777340002681326
forge test --match-contract MINER_bsc_exp -vvv --evm-version shanghai
forge test --match-contract Game_exp -vvv
https://twitter.com/AnciliaInc/status/1757533144033739116
forge test --match-contract DN404_exp -vvv
forge test --match-contract PANDORA_exp -vvv
https://twitter.com/pennysplayer/status/1766479470058406174
forge test --match-contract BurnsDefi_exp -vvv
https://twitter.com/pennysplayer/status/1754342573815238946
https://medium.com/neptune-mutual/how-was-citadel-finance-exploited-a5f9acd0b408 (similar incident)
forge test --match-contract ADC_exp -vvv
https://x.com/EXVULSEC/status/1753294675971313790
forge test --match-contract AffineDeFi_exp -vvv
https://twitter.com/Phalcon_xyz/status/1753020812284809440
https://twitter.com/CyversAlerts/status/1753040754287513655
forge test --match-contract XSIJ_exp -vvv
https://x.com/CertiKAlert/status/1752384801535918264
forge test --match-contract MIMSpell2_exp -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 --match-contract PeapodsFinance_exp -vvv
forge test --match-contract BarleyFinance_exp -vvv
https://phalcon.blocksec.com/explorer/security-incidents
https://www.bitget.com/news/detail/12560603890246
https://twitter.com/Phalcon_xyz/status/1751788389139992824
forge test --match-contract CitadelFinance_exp -vvv
https://medium.com/neptune-mutual/how-was-citadel-finance-exploited-a5f9acd0b408
forge test --match-contract NBLGAME_exp -vvv
https://twitter.com/SlowMist_Team/status/1750526097106915453
https://twitter.com/AnciliaInc/status/1750558426382635036
forge test --match-contract DAO_SoulMate_exp -vvv --evm-version 'shanghai'
https://twitter.com/MetaSec_xyz/status/1749743245599617282
forge test --match-contract Bmizapper_exp -vvv
https://x.com/0xmstore/status/1747756898172952725
forge test --match-contract Shell_MEV_0xa898_exp -vvv
forge test --match-contract SocketGateway_exp -vvv --evm-version shanghai
https://twitter.com/BeosinAlert/status/1747450173675196674
https://twitter.com/peckshield/status/1747353782004900274
forge test --match-contract WiseLending02_exp -vvv --evm-version shanghai
https://twitter.com/danielvf/status/1746303616778981402
forge test --match-contract Freedom_exp -vvv
forge test --match-contract LQDX_alert_exp -vvv
https://twitter.com/SlowMist_Team/status/1744972012865671452
forge test --match-contract Gamma_exp -vvv
https://twitter.com/officer_cia/status/1742772207997050899
https://twitter.com/shoucccc/status/1742765618984829326
forge test --match-contract MIC_exp -vvv
https://x.com/MetaSec_xyz/status/1742484748239536173
forge test --match-contract RadiantCapital_exp -vvv
https://neptunemutual.com/blog/how-was-radiant-capital-exploited/
https://twitter.com/BeosinAlert/status/1742389285926678784
forge test --match-contract OrbitChain_exp -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