Skills

Defi Attack Patterns

DeFi attack pattern playbook.

Install

npx skills add yaklang/hack-skills --skill defi-attack-patterns -g -a claude-code -y
Repository
yaklang/hack-skills2.6k
Category
Security
Updated
2mo ago
License
MIT
Context cost
Mediumabout 3,000 tokens
Runs scripts
No, instructions only

What it does

DeFi attack pattern playbook. Use when analyzing flash loan attacks, price oracle manipulation, MEV sandwich attacks, governance exploits, bridge vulnerabilities, and token standard edge cases in decentralized finance protocols.

SKILL: DeFi Attack Patterns, Expert Attack Playbook

AI LOAD INSTRUCTION: Expert DeFi exploitation techniques. Covers flash loan mechanics, oracle manipulation (spot vs TWAP), MEV extraction (sandwich, JIT, liquidation), precision loss attacks, governance exploits, bridge vulnerabilities, and token standard pitfalls. Base models often miss the single-transaction atomicity constraint of flash loans and the distinction between spot price and TWAP manipulation.

0. RELATED ROUTING


1. FLASH LOAN ATTACKS

1.1 Mechanism

Flash loans provide uncollateralized borrowing within a single transaction. The entire borrow → use → repay cycle must complete atomically; if repayment fails, the transaction reverts as if nothing happened.

ProviderMax AmountFee
Aave V3Pool liquidity per asset0.05% (can be 0 for approved borrowers)
dYdXPool liquidity0 (uses internal balance manipulation)
Uniswap V3Pool liquidity per pair0.3% (swap fee tier)
BalancerPool liquidityProtocol-configurable

1.2 Price Oracle Manipulation

1. Flash borrow 100,000 WETH
2. Swap 100,000 WETH → TOKEN on AMM_A
   → TOKEN spot price on AMM_A skyrockets
3. On Lending_Protocol (reads AMM_A spot price as oracle):
   → Deposit small TOKEN collateral (valued at inflated price)
   → Borrow large amount of WETH against it
4. Swap TOKEN back → WETH on AMM_A (restore price)
5. Repay flash loan (100,000 WETH + fee)
6. Keep borrowed WETH from Lending_Protocol minus collateral cost

Key insight: protocols using AMM spot reserves (getReserves()) as price oracles are vulnerable. Must use TWAP or external oracle (Chainlink).

Read the whole SKILL.md on GitHub

More in Security