# Flash loan parameter and repayment validation gaps

Flash loan entrypoints trusting caller params or skipping balance-delta repayment checks after the callback

_Area: DeFi oracles, liquidations and flash loans. Seen in 3 disclosed reports; latest 2024-07-12. Updated 2026-10-24._

## How it works
A flash loan is only safe if two assumptions hold: the caller-supplied parameters describe a legitimate operation, and the borrowed funds are actually returned before the transaction ends. This pattern breaks when either assumption is left unchecked. Either the entrypoint executes attacker-controlled parameters (debt tokens, amounts, swap calldata) without validating them, or repayment is inferred from a transfer call's return value instead of a measured balance delta. In both cases the contract trusts an input it should verify.

## Where it shows up
- Flash loan or callback functions taking `swapData`, token lists, or amounts straight from the caller and passing them to low-level calls.
- Repayment checked only via `safeTransferFrom` success, with no before/after balance comparison.
- Callback invoked before the outbound transfer, so the borrower never holds the funds.
- Connector/strategy contracts that let caller calldata reach `transferFrom` or similar sensitive functions on other users' behalf.

## How to review
Identify the invariant: pool balance after the callback must be at least balance before plus fee, measured as a delta, not inferred from a return value. Check that every caller-supplied parameter is constrained (allowlisted tokens, bounded amounts, validated targets) before use. For ordering, confirm the outbound transfer precedes the callback so the callee actually holds borrowed funds. Treat any path where user calldata reaches a sensitive function as unsafe unless explicitly gated.

## Variants seen
- Unvalidated flashloanReq parameters allowing arbitrary debt/collateral manipulation [E1](https://bugbountylibrary.com/r/dhl%3A20240712-doughfina.md).
- Repayment relying on transfer return value with no balance-delta check, exploitable by tokens reporting false success [E2](https://bugbountylibrary.com/r/sherlock%3A2023-01-ajna%3AM-13.md).
- Callback fired before token transfer, breaking the flash-swap invariant [E3](https://bugbountylibrary.com/r/c4%3A2021-09-sushitrident%3AH-01.md).

## Impact and severity
Led to a ~$1.8M drain [E1](https://bugbountylibrary.com/r/dhl%3A20240712-doughfina.md) and a pool-draining path via false-success tokens [E2](https://bugbountylibrary.com/r/sherlock%3A2023-01-ajna%3AM-13.md); ordering bugs silently break the feature [E3](https://bugbountylibrary.com/r/c4%3A2021-09-sushitrident%3AH-01.md). Severity is high where funds move; worse when exotic or upgradable tokens later change transfer semantics [E2](https://bugbountylibrary.com/r/sherlock%3A2023-01-ajna%3AM-13.md).

## Evidence
- E1: https://bugbountylibrary.com/r/dhl%3A20240712-doughfina.md
- E2: https://bugbountylibrary.com/r/sherlock%3A2023-01-ajna%3AM-13.md
- E3: https://bugbountylibrary.com/r/c4%3A2021-09-sushitrident%3AH-01.md
