# What is a flash loan in smart contracts?

URL: https://shield.quillaudits.com/learn/glossary/flash-loan/

A flash loan is a loan with no collateral that must be repaid, with any fee, before the transaction that took it ends. If the borrower doesn't repay, the check at the end of the loan fails and the whole transaction reverts as if the loan never happened, so the lender takes no credit risk.

Last updated 3 December 2026. 2 minute read. By the QuillAudits Team.

## How does a lender enforce repayment?

The lender sends the tokens, calls a function on the borrower and then checks its own balance. [ERC-3156](https://eips.ethereum.org/EIPS/eip-3156) standardizes the shape: the lender calls `onFlashLoan` on the borrower, checks the value it returns and pulls back the amount plus the fee.

**A minimal flash lender that enforces repayment (illustrative, not audited code)** `SimpleFlashLender.sol`

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

interface IERC20 {
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 amount) external returns (bool);
}

interface IFlashBorrower {
    function onFlashLoan(uint256 amount, uint256 fee) external;
}

contract SimpleFlashLender {
    IERC20 public immutable token;
    uint256 public constant FEE_BPS = 5; // illustrative fee: 0.05%

    constructor(IERC20 token_) {
        token = token_;
    }

    function flashLoan(uint256 amount) external {
        uint256 fee = (amount * FEE_BPS) / 10_000;
        uint256 before = token.balanceOf(address(this));
        require(token.transfer(msg.sender, amount), "transfer failed");
        IFlashBorrower(msg.sender).onFlashLoan(amount, fee); // borrower uses the funds
        require(token.balanceOf(address(this)) >= before + fee, "not repaid");
    }
}
```

## Why do flash loans show up in exploit reports?

For one transaction, anyone can borrow as much as the lending pools hold. Any number a contract reads from balances that capital can move, such as the spot price of a pool, the share price of an [ERC-4626](https://shield.quillaudits.com/learn/glossary/erc-4626/) vault or a token-weighted vote, can be pushed and used before the loan is repaid. The [oracle price manipulation](https://shield.quillaudits.com/learn/vulnerabilities/oracle-price-manipulation/) page shows the price read that fails.

The loan only supplies the funding. The Inverse Finance write-up of its April 2022 oracle manipulation says it was not a flash loan attack: the attacker used 901 ETH withdrawn from Tornado Cash ([Inverse Finance](https://www.inverse.finance/blog/posts/en-US/inv-price-manipulation-incident)).

## What should a reviewer check?

- Can a price, share rate or vote weight move with one large deposit, swap or donation?
- Does each flash loan callback check that the caller is a lender it trusts and that it started the loan, as ERC-3156 advises?
- Does the lender check the return value of the callback and its own final balance?
- Are votes counted from balances at an earlier block, not the current one?

## FAQ

### Can a flash loan be repaid in a later block?

No, it has to be repaid inside the same transaction, and that is why the lender needs no collateral: if the funds don't come back, the whole transaction is undone.

## Sources

- [ERC-3156: Flash Loans, Ethereum Improvement Proposals](https://eips.ethereum.org/EIPS/eip-3156) · checked 3 December 2026
- [INV price manipulation incident, Inverse Finance](https://www.inverse.finance/blog/posts/en-US/inv-price-manipulation-incident) · checked 3 December 2026
