Flash Loans
Published on April 9, 2026 • 6 min read
Introduction
A flash loan is an uncollateralized loan that exists only within a single blockchain transaction. A lender contract hands over the assets to a borrower contract, gives the borrower “temporary control” via a callback, and then enforces repayment (principal plus fee, if any) before the transaction ends. If the borrower contract is unable to pay back the lender, the call reverts and all state changes are undone. This system makes flash loans a very unique tool in finance. A user can access a massive amount of capital for trading, refinancing, or a range of other on-chain actions.
Motivation
I find this concept fascinating as anyone can borrow a large sum of money (100s of millions!) without putting up any collateral. Furthermore, the lender can never lose that loan as, if the borrower fails to repay, the blockchain reverts the whole thing like it never happened! I wanted to write a short article on flash loans to explore how they work and how they can be used.
How Flash Loans Work
The first question I asked when I stumbled across this financial tool was, how is this even possible? Flash loans work because blockchain transactions are atomic. An atomic transaction is one that has a binary state. Either the transaction executes completely or does not execute at all. If any step within the transaction fails, the entire thing reverts to the original state. This property is enforced at the protocol level. This means the blockchain's execution environment (such as EVM for Ethereum) guarantees atomicity.
There are two contracts involved in the execution of a flash loan: the lender and the borrower. At a high level, the execution flow looks like this:
- The borrower contract asks for a loan from the lender contract
- The lender contract (after some sanity checks) transfers the requested amount of tokens to the borrower
- The lender calls the borrower's callback function
- The borrower does some operation
- The lender checks the repayment
- If the repayment fails, everything reverts
Assuming the borrower is willing and able to repay, the repayment formula would look something like: $$\text{repayment} = \text{principal} + \text{fee} = A*(1 + f)$$If you borrow $A$ tokens and the fee rate is $f$, that is what you owe at the end of the transaction. The value of the fee is set by the protocol, and in some cases can be changed through governance. Knowing this, it may seem like a trader who is using flash loans to amplify capital (let's say for cross exchange arbitrage) just has to make more than the fee to be profitable. It is unfortunately not that simple. The profit can be given as: $$\text{net profit} = \text{gross trading profit} - (\text{fee} + \text{gas} + \text{slippage} + \text{trading losses})$$This is why flash loans aren't free money. Even with a fixed fee, a trade still has to overcome gas costs, slippage, and execution risk to be profitable. In practice, that can be difficult even when the underlying idea looks profitable on paper, such as a cross exchange arbitrage.
Use Cases
As mentioned in the previous section, a very popular use case for flash loans is capital-free arbitrage. A user can borrow an asset, trade it on a different exchange where the price is better, repay the borrowed funds, and keep the spread. Unlike traditional arbitrage, a user is not locked behind needing to have sufficient capital. This use case, to me, is the simplest to understand.
Another, more complex, use case for flash loans is debt switching. Debt switching is a way to keep the same position while swapping the asset you owe. For example, let's say you have a position where you are using ETH as collateral and owe some amount of token X. You might want to switch your debt in token X to another token Y. A debt switch is a one transaction tool that swaps these two assets while keeping the collateral the same. The important idea here is that you are not closing the position and opening another one from scratch. You are replacing one liability with another. At a high level, the transaction works like this:
- Flash loan the new debt asset
- Swap this for the old debt asset
- Repay the old debt
- Borrow the new debt from the position
- Use that new borrowing to repay the flash loan
The flash loan is useful in this case as it lets you eliminate the old debt without needing external funding. A user could want to perform a debt switch if the new debt asset is more attractive than the old one.
There are other use cases like liquidations or getting instant leverage but I will not go into them in this article.
Misconceptions
First, flash loans are not a tool that is easily accessible to retail traders and are not a normal borrow product. To use one, you would either write a smart contract that requests the loan and uses the callback correctly, or use an app that wraps that complexity for a specific purpose (e.g. debt switching).
Second, flash loans are not inherently an exploit, but rather a legitimate tool in decentralized finance. Flash loans have been used in exploits in the past as they do give attackers massive amounts of capital within a single transaction which they can use to amplify other weaknesses in an attack.
Third, flash loans are not unlimited. The amount a person can borrow is bounded by the amount of liquidity available.
Exploits
It should not be surprising that a tool that allows a user to borrow millions of dollars of capital instantly can be used to exploit vulnerable protocols. In fact, the first thought I had when hearing about this concept was if it was possible to exploit. However, I initially fell into the misconception that a flash loan itself could be exploited and the borrowed amount could be stolen. A flash loan, rather, can be used to exploit a weak point in a protocol. A recurring pattern in many exploits that use flash loans is:
- Borrow a huge amount of capital
- Use that capital to distort some on-chain condition
- Trigger a vulnerable protocol action based on the distorted state
- Extract value
- Repay the flash loan
- Keep the leftover extracted value as profit
A vulnerable target can be governance mechanisms, pricing logic, or any setup that assumes a user cannot temporarily control very large balances. The key idea behind an attack is that the protocol being attacked has usually made some bad assumption. For example, a vulnerable protocol could assume that "nobody can move the price that much in a single transaction" or "nobody can get that much voting power instantly".
Final Notes
I got interested in the concept of a flash loan last year when I randomly stumbled onto the idea when learning more about a crypto exploit that had happened with Claude (not sure what it was but it wasn't even relevant to flash loans). I remember starting to rabbit hole into the topic, but I quickly realized it was very technically advanced and I lacked a lot of domain knowledge. I also realized that I was probably never going to actually use a flash loan so I eventually lost interest. However, in the last few months, I have wanted to try to write an article about something somewhat niche that I also have found intriguing. I felt that flash loans were the perfect topic to cover. My end goal with this article was to explain a cool topic while also improving my writing.