A collection of Foundry tests reproducing exploits, bug bounty reports, and theoretical vulnerabilities on EVM chains. Diagrams and context links accompany each attack reproduction to make it more helpful as a reference or study material for anyone trying to learn more about vulnerabilities in smart contract systems.
Want to take a quick look? Just go to a vulnerability folder (say, MBCToken). Read the README or jump ahead to running the reproduction in your computer! You only need Foundry installed.
$ git clone https://github.com/coinspect/learn-evm-attacks
$ forge install
$ forge test --match-contract Exploit_MBCToken -vvv
We now have 31 reproduced exploits. Of those 31, we have chosen a few in case you want to start studying up with some of the most interesting ones.
- Furucombo is an excellent way to show the dangers of
DELEGATECALL
. - MBC Token is a primer on how sandwich attacks can be made with an interesting backstory on suspicious tokenomics.
- Uranium is a great excuse to study up on the actual code that guards the famouse AMM constant product
x*y=k
.
To run an specific exploit, you can just use:
forge test --match-contract Exploit_MBCToken -vvv
Vary the amount of verbosity (-v
, -vv
...) according to the data you want. -vvvv
includes traces!
The full list is below:
- TempleDAO, Oct 2022 - (~$2.3MM) - Unchecked ownership on token migration
- Rikkei, Apr 2022 - ($1MM) - Public Oracle Setter
- DAOMaker, Sept 2021 - (~$4MM) - Public Init
- Sandbox, Feb 2022 - (1 NFT, possibly more) - Public Burn
- Punk Protocol, Aug 2021 - (~$8MM) - Non initialized contract
- MBC Token, Nov 2022 - (~$8MM) - External function
- Olympus DAO Bond, Oct 2022 - (~$300,000) - Arbitrary Tokens / Unchecked transfers
- Bad Guys NFT, Sept 2022 - (400 NFTs) - Unchecked Mint Amount
- Multichain a.k.a AnySwap, Jan 2022 - (~$960,000) - Arbitrary Tokens / Unchecked Permit
- Superfluid, Jan 2022 - (~$8.7MM) - Calldata crafting / CTX not verified
- TeamFinance - Oct 2022 - (~$15MM / $7MM returned) - Arbitrary Input Parameters / Migrate Authentication Bypass
- EarningFarm, Oct 2022 - (200 ETH) - Unchecked Flashloan reception
- BVaults, Oct 2022 - ($35,000) - DEX Pair Manipulation
- Fantasm Finance, Mar 2022 - ($2.4MM) - Unchecked Payments While Minting
- Compound - Mar 2022 - ($0) - Side Entrance on cToken
- OneRing Finance - Mar 2022 - (~$2MM) - Price Feed Manipulation
- Vesper Rari Pool - Nov 2021 - (~$3MM) - Price Feed Manipulation
- Uranium - Apr 2021 - (~$50MM) - Wrong Constant Product AMM checks
- Furucombo - Feb 2021 - ($15MM) - DELEGATECALL to proxy
- Seaman - Nov 2022 - ($7K) - Sandwich attack
- Qi Dao / Curve Pool - Nov 2022 - (~$156K) - Read Only Reentrancy
- DFX Finance - Nov 2022 - (~$6MM) - Reentrancy / Side Entrance
- Fei Protocol, Apr 2022 - (~$80MM) - Cross Function Reentrancy / FlashLoan Attack
- Revest Protocol, Mar 2022 - (~$2MM) - ERC1155 Reentrancy / Flashswap Attack
- Hundred Finance - Mar 2022 - (~$6MM) - Reentrancy / ERC667 Transfer Hook
- Paraluni - Mar 2022 - (~$1.7MM) - Reentrancy / Arbitrary tokens
- Cream Finance - Aug 2021 - (~$18MM) - Reentrancy / ERC777 Transfer Hook
- Read Only Reentrancy - N/A - N/A - Read Only Reentrancy
- Nomad Bridge, Aug 2022 - (~$190MM) - Invalid Root Hash Commitment / Poor Root Validation
- Ronin Bridge, Mar 2022 - (~$624MM) - Compromised Keys
- Wormhole Bridge, Feb 2022 - (~$10MM, bounty) - Uninitialized bridge
- PolyNetwork Bridge, Aug 2021 - (~$611MM) - Arbitrary External Calls, Access Control Bypass
- Arbitrum Inbox (REPORTED), Sep 2022 - (400K ETH BUG BOUNTY) - Uninitialized Implementation
To contribute, create a new file inside the most appropriate category. Use the template.txt
file in the test
folder including the information related to the attack.
Utils that perform flashloans and swaps are provided in test/utils
to ease the job of reproducing future attacks. Also, modules that provide enhanced features to Foundry are included in the test/modules
folder.
The tests should pass
if the attacker succeeded, for examples: your requires should show that the attacker has more balance after the attack than before.
- DefiHackLabs has a similar repository with more exploits and more focus on the test reproductions alone, with no context or further explanations. It is nevertheless great if you only care about the attack reproductions! Go check it out.
If a reproduction is failing (ie: it reverts), try to:
- Clean Forge's cache:
forge cache clean
- Update Foundry:
foundryup