skills/references/exploit-reference/SKILL.md
Reference guide to major DeFi exploits and reproducible Foundry workflows from DeFiHackLabs
npx skillsauth add apegurus/solidity-argus exploit-referenceInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Curated quick-reference table of major DeFi exploit reproductions from DeFiHackLabs.
| Exploit | Primary Pattern | Foundry PoC | |--------|------------------|-------------| | The DAO (2016) | Reentrancy | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/TheDAO_exp.sol | | Parity Wallet (2017) | Access Control | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/Parity_exp.sol | | bZx (2020) | Flash Loan + Oracle Manipulation | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/bZx_exp.sol | | Harvest Finance (2020) | Flash Loan + Oracle Manipulation | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/Harvest_exp.sol | | Compound (2021) | Logic Error | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/Compound_exp.sol | | Cream Finance (2021) | Reentrancy | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/Cream_exp.sol | | Poly Network (2021) | Access Control / Cross-chain Validation | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/PolyNetwork_exp.sol | | Wormhole (2022) | Signature Verification | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/Wormhole_exp.sol | | Ronin Bridge (2022) | Access Control | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/Ronin_exp.sol | | Beanstalk (2022) | Flash Loan + Governance | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/Beanstalk_exp.sol | | Nomad Bridge (2022) | Logic Error | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/Nomad_exp.sol | | Mango Markets (2022) | Flash Loan + Oracle Manipulation | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/MangoMarkets_exp.sol | | Euler Finance (2023) | Flash Loan + Logic Error | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/Euler_exp.sol | | Wintermute (2022) | Access Control / Key Compromise | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/Wintermute_exp.sol | | BadgerDAO (2021) | Access Control / Frontend Compromise | https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/BadgerDAO_exp.sol |
Step-by-step guide for setting up DeFiHackLabs and running Foundry proof-of-concept exploit reproductions locally.
Before cloning, ensure you have the following installed:
# Install Foundry (includes forge, cast, anvil)
curl -L https://foundry.paradigm.xyz | bash
foundryup
# Verify installation
forge --version
Most exploits require forking Ethereum mainnet at a specific block. You need an RPC endpoint:
Set your RPC URL as an environment variable:
export ETH_RPC_URL="https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY"
For BSC exploits:
export BSC_RPC_URL="https://bsc-dataseed.binance.org"
git clone https://github.com/SunWeb3Sec/DeFiHackLabs
cd DeFiHackLabs
# Install Foundry dependencies (forge-std, etc.)
forge install
Create a .env file in the project root (or export variables directly):
# .env
ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY
BSC_RPC_URL=https://bsc-dataseed.binance.org
Note: DeFiHackLabs uses
vm.createSelectFork()inside each test to fork at the exact exploit block. The RPC URL is read from the environment.
forge test --match-contract TheDAO_exp -vvv --fork-url $ETH_RPC_URL
| Flag | Output |
|------|--------|
| -v | Test pass/fail only |
| -vv | Logs and events |
| -vvv | Call traces (recommended) |
| -vvvv | Full traces including reverts |
| -vvvvv | Maximum detail (very verbose) |
# The DAO (2016) — Reentrancy
forge test --match-contract TheDAO_exp -vvv --fork-url $ETH_RPC_URL
# Euler Finance (2023) — Flash Loan + Logic
forge test --match-contract Euler_exp -vvv --fork-url $ETH_RPC_URL
# Beanstalk (2022) — Flash Loan + Governance
forge test --match-contract Beanstalk_exp -vvv --fork-url $ETH_RPC_URL
# Ronin Bridge (2022) — Access Control
forge test --match-contract Ronin_exp -vvv --fork-url $ETH_RPC_URL
# Nomad Bridge (2022) — Logic Error
forge test --match-contract Nomad_exp -vvv --fork-url $ETH_RPC_URL
A typical trace looks like:
[PASS] testExploit() (gas: 1234567)
Traces:
[1234567] TheDAO_exp::testExploit()
├─ [0] VM::createSelectFork(...)
├─ [50000] TheDAO::withdraw(1 ether)
│ ├─ [40000] Attacker::receive() ← REENTRANCY HERE
│ │ └─ [30000] TheDAO::withdraw(1 ether)
│ └─ ← ()
└─ ← ()
vm.createSelectFork() pins the fork to the exploit blockflashLoan() or borrow() calls early in the traceMost PoCs log the attacker's profit:
[console.log] Attacker profit: 197,000,000 USDC
If you see this, the exploit reproduced successfully.
Use DeFiHackLabs PoCs as templates when auditing similar protocols.
TheDAO_exp.sol) to your audit project// Template structure of a DeFiHackLabs PoC
contract MyAudit_exp is Test {
// Target contract interface
IVulnerableProtocol target;
function setUp() public {
// Fork at a specific block
vm.createSelectFork("mainnet", BLOCK_NUMBER);
target = IVulnerableProtocol(TARGET_ADDRESS);
}
function testExploit() public {
uint256 balanceBefore = address(this).balance;
// Step 1: Acquire flash loan or initial capital
// Step 2: Execute the attack
// Step 3: Repay flash loan
uint256 profit = address(this).balance - balanceBefore;
console.log("Profit:", profit);
assertGt(profit, 0, "Exploit failed");
}
// Callback for reentrancy or flash loan repayment
receive() external payable {
// Re-enter if conditions met
}
}
cast block --rpc-url $ETH_RPC_URL latest to get the current blockvm.label() — label addresses for readable traces: vm.label(address(target), "VulnerableProtocol")console.log checkpoints — log balances before/after each step to trace the attack flowvm.expectRevert() — verify that the fix (if applied) causes the exploit to revert| Problem | Solution |
|---------|----------|
| RPC rate limit exceeded | Use a paid RPC tier or add --slow flag |
| Block not found | The fork block may be too old for your RPC provider; try Alchemy Archive |
| Contract not deployed at block | Adjust the fork block to after the contract deployment |
| Out of gas | Increase gas limit: --gas-limit 30000000 |
| Compilation error | Run forge build first to check for syntax errors |
| Test not found | Verify the contract name matches exactly with --match-contract |
exploit-reference skill for the full list of 15 exploits with GitHub URLstesting
Specialist profile for mechanically applying the attack-vector deck and classifying vectors as skip, drop, or investigate.
tools
Specialist profile for libraries, helpers, base contracts, adapters, encoders, wrappers, and integration glue.
testing
Specialist profile for rounding, scale, decimal, downcast, and arithmetic accounting edge cases.
testing
Specialist profile for extracting conservation laws and state couplings, then searching for violating paths.