flash-loan
What it does
This playbook explains how flash loans amplify other weaknesses rather than causing them directly. It is for auditors reviewing DeFi contracts that use flash loan callbacks or price data.
When to use it
- βWhen a DeFi contract accepts flash loan callbacks and you need to review them.
- βWhen a protocol's price or voting depends on balances that a loan could temporarily change.
- βWhen you want to check whether a callback could be called without a real loan.
Skill link
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/flash-loan/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βOur lending contract handles flash loan callbacks. Can you check whether it could be abused?β
5 new skills a week. 1 minute to read.
How it works
The agent checks callback validation, looks for price or balance reads that a loan could move, and confirms the result with a test.
Technical content (original SKILL.md)
Original text by the author, straight from 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
FAQ
Is a flash loan itself a bug?
No. The playbook says flash loans are a force multiplier for existing bugs.
What is a common callback mistake?
Not checking that the caller is the lending pool and that the initiator is valid.
How do teams guard against it?
By validating callers and avoiding critical decisions based on spot balances or prices.
Details
Original description by the author
Flash-loan exploit patterns β callback reentrancy, oracle amplification, governance attacks, unauthenticated callback handlers.
Popularity
- GitHub stars
- 6.5k
- Ranking position
- #14007
- License
- Apache-2.0
- Updated
- 11/1/2026
Comments
- β¦
More skills from this repository
detector-overview
6.5kHelps your agent read code that a scanner flagged and decide which flagged spots are real security bugs and which are false alarms.
exploiter-overview
6.5kHelps your agent join several confirmed security weaknesses into one test chain and check how far that chain could reach.
llm-redteam-overview
6.5kHelps your agent find the right AI red-team guide for a test, covering 15 tactic groups from prompt injection to model abuse.
aatmf-t01-prompt-injection
6.5kExplains prompt injection, where hidden instructions try to override an AI system, so security testers can check for it.
Similar skills
reverse-engineer-anything
422kHelps your agent look inside shipped apps and packages to explain features, compare versions, or guide a rebuild, using the REA tool.
1password
394kHelps your agent set up the 1Password CLI, sign in, and read or inject secrets without printing their values into chat.
healthcheck
394kHelps your agent audit the computer or server that runs OpenClaw for security risks, such as SSH, firewall, updates, and backups, then suggest safe fixes.