
Defi Attack Patterns
Analyze DeFi protocols for flash-loan, oracle, MEV, governance, and bridge attack paths during smart-contract security reviews with an agent.
Overview
DeFi Attack Patterns is an agent skill most often used in Ship (also Validate, Build) that catalogs flash-loan, oracle, MEV, governance, and bridge exploits for DeFi security analysis.
Install
npx skills add https://github.com/yaklang/hack-skills --skill defi-attack-patternsWhat is this skill?
- Flash loan section covers atomic borrow-use-repay with Aave V3 and dYdX fee constraints
- Explains spot versus TWAP oracle manipulation and why models confuse them
- Documents MEV sandwich, JIT liquidity, and liquidation extraction patterns
- Spans governance exploits, bridge vulnerabilities, precision loss, and token-standard edge cases
- Routes to smart-contract-vulnerabilities for Solidity primitives and deserialization for off-chain relayers
- Flash loan fee table cites Aave V3 at 0.05% with possible zero fee for approved borrowers
- Dedicated sections for flash loans, oracle manipulation, MEV, governance, bridges, and token standards
Adoption & trust: 1k installs on skills.sh; 980 GitHub stars; 1/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are shipping a DeFi protocol but lack a structured map of atomic flash-loan chains, oracle types, and MEV surfaces your agent can apply in review.
Who is it for?
Indie protocol developers and security-minded solo builders auditing lending, AMM, bridge, or governance contracts before launch.
Skip if: Teams with no on-chain component, or builders seeking step-by-step mainnet exploit execution without a formal audit mindset.
When should I use this skill?
Analyzing flash loan attacks, price oracle manipulation, MEV sandwich attacks, governance exploits, bridge vulnerabilities, and token standard edge cases in decentralized finance protocols.
What do I get? / Deliverables
You produce a categorized exploit checklist tied to Solidity primitives and optional off-chain relayer risks before deployment.
- Attack-surface memo organized by flash loan, oracle, MEV, governance, and bridge categories
- Prioritized findings linked to underlying Solidity vulnerability patterns
- Review notes on off-chain relayer or indexer risks when bridges are in scope
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
DeFi attack pattern analysis is cataloged under Ship → Security as the primary shelf for pre-launch exploit review of on-chain products. Content targets exploit mechanics (flash loans, oracles, MEV, bridges)—the same subphase as contract audits and adversarial testing before mainnet.
Where it fits
Scope whether a new lending market is flash-loan viable before committing to oracle architecture.
Implement TWAP oracles while cross-checking spot-manipulation paths the skill documents.
Run a pre-mainnet pass over bridge and governance modules using the playbook’s exploit categories.
How it compares
Complements generic Solidity lint skills with DeFi-specific economic attack models flash loans and oracles require.
Common Questions / FAQ
Who is defi-attack-patterns for?
Solo and indie builders working on DeFi smart contracts who want agent-guided adversarial pattern lists during design and security review.
When should I use defi-attack-patterns?
Use it in Validate when scoping protocol risk, in Build while implementing oracles and governance, and in Ship → Security before mainnet to walk flash loan, MEV, bridge, and token-standard attack paths.
Is defi-attack-patterns safe to install?
It is educational security content for authorized review of your own contracts. Check the Security Audits panel on this Prism page and treat exploit details as sensitive in shared agent logs.
Workflow Chain
Requires first: smart contract vulnerabilities
SKILL.md
READMESKILL.md - Defi Attack Patterns
# 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 - [smart-contract-vulnerabilities](../smart-contract-vulnerabilities/SKILL.md) for underlying Solidity vulnerability patterns (reentrancy, integer overflow, delegatecall) - [deserialization-insecure](../deserialization-insecure/SKILL.md) when targeting off-chain bridge relayer or indexer infrastructure --- ## 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. | Provider | Max Amount | Fee | |---|---|---| | Aave V3 | Pool liquidity per asset | 0.05% (can be 0 for approved borrowers) | | dYdX | Pool liquidity | 0 (uses internal balance manipulation) | | Uniswap V3 | Pool liquidity per pair | 0.3% (swap fee tier) | | Balancer | Pool liquidity | Protocol-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). ### 1.3 Liquidity Pool Drain via Reentrancy Flash borrow → deposit into pool → trigger reentrancy during callback → withdraw more than deposited → repay loan. Exploits the combination of flash loan capital with reentrancy in pool accounting logic. ### 1.4 Governance Flash Borrow ``` 1. Flash borrow governance tokens 2. Create/vote on malicious proposal (if no snapshot or timelock) 3. Proposal passes instantly 4. Execute proposal (drain treasury, change admin, etc.) 5. Return governance tokens ``` Defense: snapshot-based voting (Compound Governor Bravo), timelocks, minimum proposal period. --- ## 2. PRICE ORACLE MANIPULATION ### 2.1 Spot Price vs TWAP | Oracle Type | Manipulation Cost | Time Window | |---|---|---| | Spot price (`getReserves()`) | Single large swap (flash loanable) | Same transaction | | TWAP (Time-Weighted Average) | Sustained multi-block manipulation | Multiple blocks (expensive) | | Chainlink aggregator | Compromise ≥ majority of oracle nodes | Practically infeasible | ### 2.2 AMM Manipulation Flow ``` Normal state: Pool has 1000 ETH + 1,000,000 USDC → price = 1000 USDC/ETH Attack: ├── Swap 9000 ETH into pool │ Pool now: 10000 ETH + 100,000 USDC (constant product) │ Spot price: 10 USDC/ETH (crashed 100x) ├── Dependent contract reads this price │ → Liquidates positions at wrong price │ → Or allows cheap borrowing against ETH collateral ├── Swap back: buy ETH with USDC │ Price restores to ~1000 USDC/ETH └── Net profit = value extracted from dependent contract - swap slippage - fees ``` ### 2.3 Chainlink Oracle Staleness ```solidity (, int price, , uint updatedAt, ) = priceFeed.latestRoundData(); // Missing checks: // 1. price > 0 // 2. updatedAt != 0