A flash loan is a type of transaction that borrows a certain amount of liquidity and pays it back within the same transaction or block. No time elapses between borrowing and paying back the funds, as it is all settled together at once, atomically. Atomic composability is therefore necessary for flash loans to work as everything has to either settle together or fail together.
As per the diagram above, all transactions within the block are settled together, guaranteeing that any funds borrowed as part of a flash loan are paid back.
Because of this, there is no credit or counterparty risk, and so flash loans do not need to be collateralized. This makes flash loans hyper capital-efficient, as they provide extreme levels of leverage. This degree of capital efficiency is not possible in traditional financial markets and is only possible in DeFi.
The liquidity for flash loans typically comes from lending protocols such as Aave or CREAM, which offer single-transaction loans as a feature to allow them to be composed with other dApps such as Uniswap or Sushiswap.
So why have flash loans at all?
The main use case for flash loans is for individuals or bots to take advantage of arbitrage opportunities, such as the same asset being priced differently across two different exchanges.
To illustrate, if the price of ETH on Uniswap is $2,000, and the price of ETH on Sushiswap is $2,005, there is a difference of $5 in the price of ETH between the two. Without a flash loan, an arbitrageur would only be able to arbitrage the difference in price using their available liquidity. So for example, if they had $1,000, they would only be able to make a profit of $2.5. However, with a flash loan, the arbitrageur could borrow $1,000,000, arbitrage the price difference, pay back the $1,000,000, and gain a profit of $2,500 instead. The price of ETH on Uniswap and Sushiswap would move closer together as a result of the arbitrageur with the flash loan, than without.
Flash loans enhance the efficiency of markets in DeFi, as they allow individuals with strong information but limited capital to have a greater impact in resolving market inefficiencies.
Are there any issues with flash loans?
Flash loans sometimes have a bad reputation as they often appear alongside DeFi hacks, bugs, and exploits. However, in nearly all of these cases, flash loans are not the root cause of the issue. Instead, the flash loan allows the attacker to leverage up significantly and take advantage of the underlying flaw in the DeFi protocol with much more liquidity than an unleveraged position would allow. In a way, this is in itself an arbitrage opportunity, but one that takes advantage of smart contract vulnerabilities, rather than inefficient markets.
Flash loans are therefore not the culprit in the vast majority of hacks. They are merely a tool that amplifies an attackers’ ability to take advantage of a vulnerability.
How to get the benefit without the downside
So, flash loans are great at making DeFi markets more efficient, but because of this, they amplify attackers’ ability to take advantage of hacks, bugs and exploits. How do we get the best of both worlds?
Then, you address the root cause of DeFi hacks, bugs and exploits through a safer and more predictable application execution environment. At Radix, we’ve spent years developing Radix Engine to solve just these problems.
You can learn more about how Radix Engine does this here: