Files
nexus/wiki/concepts/FlashLoanAttack.md
2026-05-03 05:42:12 +08:00

44 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "FlashLoanAttack"
type: concept
tags: []
last_updated: 2026-05-01
---
## Definition
Flash Loan闪电贷是 DeFi 中的一种无抵押借贷模式,允许用户在单笔交易内借入任意数量的资产,条件是在同一交易的结尾必须归还借款 + 利息。Flash Loan Attack闪电贷攻击则是利用闪电贷的特性在单笔交易中操纵价格、状态或协议逻辑来获取非法收益的攻击方式。
## How Flash Loans Work
```solidity
// 用户通过闪电贷借出 1000 ETH
// 在同一交易内:执行各种操作(交易、借贷、套利)
// 必须归还 1000 ETH + 手续费,否则整笔交易 revert
```
关键特性:**无需抵押**(因为资金在同一交易内流转),但这也意味着**协议无法在交易中途检查清算状态**。
## Attack Patterns
### 1. 价格操纵Price Manipulation
- 在借贷协议中:先借出大量资产 → 操纵预言机价格 → 以超低抵押率借出更多资产 → 归还闪电贷
- 案例:[[Euler Finance]]2023、Cream Finance多次
### 2. 治理攻击Governance Attack
- 通过闪电贷获得大量治理代币
- 在单笔交易内发起并通过恶意提案
- 案例Beanstalk2022
### 3. 重入攻击(通过闪电贷)
- 与 reentrancy 结合,放大攻击规模
## Defense Mechanisms
1. **TWAP时间加权平均价格预言机**:使用时间窗口内的平均价格,而非即时价格
2. **借贷健康度实时检查**:在每笔清算操作前验证抵押率
3. **闪电贷攻击监控**:链上监控异常大额闪电贷 + 后续清算模式
4. **最小清算门槛**:设置合理的清算参数,防止微小偏差导致清算
## Sources
- [[engineering-solidity-smart-contract-engineer]]
- [[Euler-Finance]]
- [[blockchain-security-auditor]]