flash-loan
यह क्या करती है
यह प्लेबुक बताती है कि flash loans कमज़ोरियाँ सीधे पैदा नहीं करते, बल्कि मौजूदा कमज़ोरियों का असर बढ़ाते हैं। यह उन ऑडिटरों के लिए है जो flash loan callbacks या price data इस्तेमाल करने वाले DeFi कॉन्ट्रैक्ट की समीक्षा करते हैं।
कब इस्तेमाल करें
- ✓जब कोई DeFi कॉन्ट्रैक्ट flash loan callbacks स्वीकार करता है और उनकी समीक्षा करनी है।
- ✓जब किसी प्रोटोकॉल की price या voting ऐसे balances पर निर्भर है जिन्हें एक loan अस्थायी रूप से बदल सकता है।
- ✓जब जाँचना हो कि क्या callback को बिना असली loan के बुलाया जा सकता है।
Skill का लिंक
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/flash-loan/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“हमारा lending कॉन्ट्रैक्ट flash loan callbacks संभालता है। क्या आप जाँच सकते हैं कि इसका दुरुपयोग हो सकता है?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट callback सत्यापन जाँचता है, ऐसे price या balance reads खोजता है जिन्हें loan बदल सकता है, और परिणाम की टेस्ट से पुष्टि करता है।
तकनीकी सामग्री (मूल 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 खुद बग है?
नहीं। प्लेबुक कहती है कि flash loans मौजूदा बग के लिए एक force multiplier हैं।
callback की आम गलती क्या है?
यह जाँचना भूल जाना कि caller lending pool है और initiator मान्य है।
टीमें इससे कैसे बचती हैं?
callers को मान्य करके, और spot balances या prices पर आधारित महत्वपूर्ण फ़ैसले न लेकर।
जानकारी
लेखक का मूल विवरण
Flash-loan exploit patterns — callback reentrancy, oracle amplification, governance attacks, unauthenticated callback handlers.
लोकप्रियता
- GitHub स्टार
- 6.5k
- रैंकिंग में स्थान
- #14007
- लाइसेंस
- Apache-2.0
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
detector-overview
6.5kयह आपके एजेंट को स्कैनर से चिह्नित कोड पढ़ने और तय करने में मदद करती है कि कौन सी जगहें असली सुरक्षा बग हैं और कौन सी गलत चेतावनी।
exploiter-overview
6.5kयह आपके एजेंट को कई पक्की सुरक्षा कमज़ोरियों को एक परीक्षण श्रृंखला में जोड़ने और जाँचने में मदद करती है कि वह श्रृंखला कितनी दूर तक पहुँच सकती है।
llm-redteam-overview
6.5kयह आपके एजेंट को परीक्षण के लिए सही AI रेड-टीम गाइड खोजने में मदद करती है, प्रॉम्प्ट इंजेक्शन से लेकर मॉडल के दुरुपयोग तक 15 रणनीति समूहों में।
aatmf-t01-prompt-injection
6.5kसमझाती है कि प्रॉम्प्ट इंजेक्शन क्या है, जिसमें छिपे निर्देश AI सिस्टम के नियम बदलने की कोशिश करते हैं, ताकि सुरक्षा परीक्षक उसकी जाँच कर सकें।
मिलती-जुलती skills
reverse-engineer-anything
422kयह आपके एजेंट को REA टूल से शिप हुई ऐप्स और पैकेज को अंदर से समझने, वर्ज़न की तुलना करने या दोबारा बनाने में मदद करती है।
1password
394kयह आपके एजेंट को 1Password CLI सेट करने, साइन इन करने और सीक्रेट्स की वैल्यू चैट में छापे बिना उन्हें पढ़ने या इस्तेमाल करने में मदद करती है।
healthcheck
394kयह आपके एजेंट को उस कंप्यूटर या सर्वर का सुरक्षा ऑडिट करने देती है जिस पर OpenClaw चलता है, जिसमें SSH, firewall, अपडेट और बैकअप शामिल हैं, और फिर सुरक्षित सुधार सुझाती है।