flash-loan
できること
この手順書は、フラッシュローンが他の弱点を直接引き起こすのではなく、それらを増幅する仕組みを説明します。フラッシュローンのコールバックや価格データを使うDeFiのコントラクトを確認する監査人向けです。
使う場面
- ✓DeFiのコントラクトがフラッシュローンのコールバックを受け付けていて、それをレビューする必要があるとき。
- ✓プロトコルの価格や投票が、ローンで一時的に変えられる残高に依存しているとき。
- ✓本物のローンなしにコールバックを呼べないかを確認したいとき。
スキルのリンク
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/flash-loan/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“当社のレンディングのコントラクトはフラッシュローンのコールバックを扱っています。悪用されうるかを確認してもらえますか。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、コールバックの検証を確認し、ローンで動かせる価格や残高の読み取りを探し、テストで結果を確かめます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Flash Loan Attack Playbook
Flash loans give the attacker uncollateralized capital for a single transaction. They're not vulnerabilities themselves — they're a force multiplier for existing bugs. Sources: Aave, Balancer, Uniswap V2/V3, Maker, dYdX (deprecated).
Common attack patterns
1. Oracle amplification (most common)
Use loan to push a price, then trigger price-dependent action.
Cross-reference: see oracle-manipulation/SKILL.md.
2. Unauthenticated callback handler
function executeOperation(
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata premiums,
address initiator, // ← UNVALIDATED in many contracts
bytes calldata params
) external returns (bool) {
// Anyone can call this with fake `initiator`
// and have the contract do whatever the params say
}
Bug: initiator and msg.sender == pool checks are missing.
Attack: call executeOperation directly with no actual loan, malicious params → contract does the operation anyway.
3. Governance attack via flash loan
// Vulnerable governance:
function propose() external {
require(getVotes(msg.sender) > THRESHOLD);
// ...
}
function getVotes(address user) public view returns (uint256) {
return token.balanceOf(user); // ← reads SPOT balance, not snapshot
}
Attack: flash-loan governance tokens, propose malicious change (e.g., upgrade contract to drain), vote with the loaned tokens, execute, repay loan. MakerDAO had this pattern; mitigated by checkpoint-based voting.
4. Liquidity manipulation
Pool that uses totalSupply() or balanceOf(pool) for share math:
function deposit(uint256 amt) external {
uint256 shares = (amt * totalSupply()) / underlying.balanceOf(address(this));
_mint(msg.sender, shares);
underlying.transferFrom(msg.sender, address(this), amt);
}
Attacker:
- Flash-loan and deposit (becomes 99% of pool)
- Donate underlying to inflate
underlying.balanceOfartificially - Next depositor's shares =
amt * totalSupply / inflatedBalance≈ 0 - Withdraw → drain
This is the ERC4626 inflation attack (also covered in
reentrancy/overlap).
5. Liquidation arbitrage gone wrong
A liquidator that uses flash loans to repay debt before claiming collateral — usually benign. The bug: liquidation health check happens before the seizure, but the seizure happens via callback into a manipulable function. Reentrancy + oracle dependent.
Audit steps
1. Locate flash-loan integrations
grep -rn 'executeOperation\|flashLoan\|onFlashLoan\|flashCallback\|aaveFlashLoan' src/
2. For each handler
Check:
msg.sender == known_pool(whitelist callback origin)initiator == address(this)(only respond to your own loans)- ReentrancyGuard on the public function that takes the loan
- The fee is correctly accounted (
amounts[i] + premiums[i]is repaid)
3. For each price-reading function
See oracle-manipulation/SKILL.md.
4. For each share-mint / share-burn function
Check ERC4626 virtual-shares mitigation:
// OpenZeppelin ERC4626 v4.7+
function _convertToShares(uint256 assets, MathUpgradeable.Rounding rounding) internal view virtual override returns (uint256) {
return _initialConvertToShares(assets, rounding); // adds 10**18 to total supply for share calc
}
If using legacy ERC4626 or custom vault math, write a Foundry test that:
- Attacker deposits 1 wei → gets 1 share
- Attacker direct-transfers 1e18 underlying to vault
- Victim deposits 1e18 → gets 0 shares (rounding)
- Attacker withdraws 1 share → gets 100% of pool
foundry_inflation_test(vault_address="...", underlying="...", target_path="src/Vault.sol")
Severity calibration
| Pattern | Severity if confirmed |
|---|---|
| Unauth callback handler → arbitrary execution | Critical 10.0 |
| Flash-loan oracle manipulation drains protocol | Critical 9-10 |
| Governance attack possible | Critical 9-10 (if exec results in fund loss) |
| ERC4626 inflation attack on live vault | Critical 9 |
| Liquidation reentrancy via callback | High 8 |
| Theoretical (low liquidity, manipulation cost > attack profit) | Medium-Low |
PoC template (Foundry)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "forge-std/Test.sol";
import "@aave-v3/interfaces/IPool.sol";
contract Test_FlashAttack is Test {
IPool constant AAVE = IPool(0x87870Bca3F3fD63
よくある質問
フラッシュローンそのものはバグですか?
いいえ。フラッシュローンは既存のバグの増幅装置だと手順書は述べています。
よくあるコールバックの誤りは何ですか?
呼び出し元がレンディングのプールであること、また開始者が正当であることを確認しないことです。
チームはどう防ぎますか?
呼び出し元を検証し、スポットの残高や価格に基づいて重大な判断をしないことです。
詳細
作者による元の説明
Flash-loan exploit patterns — callback reentrancy, oracle amplification, governance attacks, unauthenticated callback handlers.
人気
- GitHubのスター
- 6.5k
- ランキング
- #14007
- ライセンス
- Apache-2.0
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
detector-overview
6.5kエージェントが、スキャナーが指摘したコードを読み、本物のセキュリティバグと誤検知を見分けられるよう支援します。
exploiter-overview
6.5kエージェントが、確認済みの複数のセキュリティ上の弱点を一つのテストの連鎖にまとめ、その影響がどこまで及ぶかを確認できるよう支援します。
llm-redteam-overview
6.5kエージェントが、プロンプトインジェクションからモデルの悪用まで、15の戦術グループの中から適切なAIレッドチーム用ガイドを見つけられるよう支援します。
aatmf-t01-prompt-injection
6.5kプロンプトインジェクションを説明します。隠された指示でAIシステムを乗っ取ろうとする手口を、セキュリティテスターが確認できるようにします。
似ているスキル
reverse-engineer-anything
422kREAツールを使って、出荷済みのアプリやパッケージの中身を調べ、機能の説明、版の比較、再構築の手順をエージェントが支援します。
1password
394k1Password CLIをセットアップし、サインインして、秘密情報の値を会話に表示せずに読み取ったり注入したりするようエージェントを支援します。
healthcheck
394kOpenClawを動かすコンピューターやサーバーを、SSH、ファイアウォール、更新、バックアップなどのセキュリティリスクについて監査し、安全な修正案を提案するようエージェントを支援します。