DeFi Protocol Analysis
DeFi Protocols: Risk and Security Analysis
Decentralized finance (DeFi) reached a total value locked (TVL) of $150 billion by 2024, with a peak of $180 billion in November 2021. Behind these impressive figures lies a complex ecosystem of smart contracts that carries specific security risks, from technical vulnerabilities to economic exploits.
Categorization of DeFi Protocols
Lending Protocols
Aave, Compound, MakerDAO, and Morpho allow users to deposit collateral and borrow other tokens. Key risks:
- Oracle manipulation: If an attacker can manipulate the price of collateral, they can borrow more than the real value or avoid liquidation
- Bad debt: During extremely volatile market conditions, liquidators may not be able to react fast enough, leaving the protocol with bad debt (e.g., Aave bad debt incident with CRV, 2023)
- Flash loan attacks on collateral: Short-term price manipulation used to extract more than the actual value
Decentralized Exchanges (DEX)
Uniswap, Curve, Balancer, and dYdX manage huge volumes. Risks include:
- Sandwich attacks: MEV bots see transactions in the mempool and “sandwich” the user’s transaction with their own, manipulating the price
- Price oracle risk: Protocols that use spot DEX price as an oracle are vulnerable to flash loan manipulation
- Impermanent loss: Not a hack, but a financial risk that LP providers must understand
Yield Aggregators
Yearn Finance, Convex, and Beefy automatically move funds between protocols for maximum yield. The risk is multiplied because they are exposed to the vulnerabilities of every protocol they interact with.
TVL as a Risk Metric
Total Value Locked (TVL) is an indicator of protocol size, but it is also a proxy for the potential “reward for the attacker.” Protocols with high TVL and a weak security profile are particularly attractive targets.
TVL analysis should take into account:
- Concentration of TVL in a few addresses (whale risk)
- Proportion of TVL in a single token (correlation risk)
- Lockup periods, whether a large amount of TVL can exit in a short period
Flash Loan Attacks: Anatomy
Flash loan attacks are specific to DeFi and do not exist in traditional finance. Here is a typical scenario:
- The attacker borrows $100 million USDC from Aave (no collateral, must be repaid in the same transaction)
- Uses $50M to buy token X on Uniswap, which raises the price
- On a protocol that uses the spot Uniswap price as an oracle, the value of X is now high, the attacker uses X as collateral to borrow USDC
- Sells X back on Uniswap (price drops), repays the flash loan
- Profit remains from the borrowed USDC at inflated prices
All this happens within a single atomic transaction that lasts seconds. Beanstalk Farms lost $182 million this way in April 2022.
Our Criteria for Protocol Analysis
When we analyze a DeFi protocol, we evaluate:
- Audit history: Number of audits, reputation of firms, age of the last audit
- Bug bounty program: Does it exist? What is the maximum payout?
- Oracle solution: Which oracle do they use? TWAP, Chainlink, or a vulnerable spot oracle?
- Admin privileges: Does the team have unrestricted access to funds? Is there a timelock?
- Incident history: Has the protocol already been exploited? How did they respond?
- Code complexity: More complex code equals a larger attack surface
- Governance decentralization: Is governance centralized or distributed?
Top DeFi Exploits and Lessons
The history of DeFi exploits is a textbook for understanding security risks. Each attack carries a lesson: Ronin ($625M), compromised validator keys; Poly Network ($611M), access control error; Wormhole ($320M), signature verification flaw; Nomad ($190M), fake root hashes; Beanstalk ($182M), flash loan governance attack.
Common denominator: speed of launch without adequate audit, and too many privileges for administrators. The DeFi community is slowly learning these lessons, but at a high price.