What is a Flash Loan?
If you have been engaging with DeFi or just reading up on it, you have probably come across flash loans. While many find flash loans a useful innovation, others consider them a means to exploit vulnerable protocols. With this article’s deep dive into all things to do with flash loans, you will be well-positioned to decide which side is correct. Or maybe, like many things in life, the truth lies somewhere in between.
Understanding Flash Loans
Flash loans are unsecured (or uncollateralized) loans available on some decentralized finance (DeFi) protocols based on the Ethereum blockchain network. These loans differ from traditional centralized finance (CeFi) loans in some significant ways.
We are all familiar with traditional loans, where the lender lends to the borrower based on collateral (secured loans) or the borrower’s creditworthiness (unsecured loans). The borrower pays interest over time and, eventually, the full amount, with the lender making some or no profit.
Flash loans are also loans in that a lender lends money to a borrower and expects to get it back. The difference comes from the following three properties:
In brief, smart contracts are transaction protocols that automatically execute an action according to the terms of the contract. In the case of flash loans, smart contracts are blockchain-enabled tools that prevent funds from changing hands until a specific rule is met.
The rule is that the borrower needs to pay back the loan before a transaction ends. If the rule isn’t satisfied, the smart contract reverses the transaction. Thus, it’s as if the loan never originated in the first place. Note that unlike at least two different transactions (lending and repayment) in a traditional loan, flash loans have the entire exchange covered in a single transaction.
Flash loans are unsecured as there are no collaterals involved. However, unlike traditional lending, there’s no way to check the borrower’s creditworthiness. Here, the loan’s repayment is ensured by necessitating, through a smart contract, that the borrower pays the money back right away.
In conventional lending, both the approval and the repayment take place over a certain period. Flash loans are instantaneous, as the smart contract for the loan has to be fulfilled in the same transaction. The flash loan transaction lasts for a few seconds. So, the borrower borrows the money, uses it for a specific purpose by running other smart contracts, and repays the money before the transaction ends.
How does a Flash Loan Work
Thanks to our years of familiarity with traditional (or centralized finance) loans, it can be a bit difficult initially to wrap our minds around the concept of instantaneous lending transactions. However, it can be broken down into simple steps for clarity.
First, understand that flash loans are not available on all DeFi platforms. Among the handful where they are, the most well-known include Aave, dYdX, and Uniswap. For this explanation, we’ll call these platforms lenders, while a user seeking a loan is a borrower. Broadly speaking, the following three steps make up the flash loan workflow:
Loan transfer: The borrower applies for a flash loan on the lender platform. The lender transfers the assets to the borrower.
Execution of operations: The borrower interacts with different smart contracts to execute operations, trying to make a profit using the borrowed assets. These operations could be trades, sales, DEX purchases, and so on.
Loan repayment: On completing the operations, the borrower returns the borrowed assets to the lender along with a certain fee (usually 0.09% of the borrowed amount). The lender checks the balance before closing the transaction. If the repayment is incomplete, the transaction is reversed immediately, and all borrowed assets return to the lender.
Uses of Flash Loans
Flash loans can be utilized for various purposes, including trading and paying off debts. Let’s look at the most common uses of flash loans.
Arbitrage is a common strategy to make money by exploiting differences in the pricing of the same asset in different markets. In crypto trading, if two markets price the same cryptocurrency differently, a trader can use separate smart contracts to buy from the lower-priced market and sell in the higher-priced market.
With the help of flash loans, the trades made can be much bigger than would be possible with one’s own money. Consequently, the profits can also be much greater.
A collateral swap, or a liquidity swap, occurs when the borrower replaces one asset placed as collateral with another asset. The recovered asset may then be used for a profitable market action, such as a trade.
Normally, this is done by paying back the loan and then swapping the collateral, which takes some time and could be affected by market volatility. However, with flash loans, the borrower can close the collateral position with borrowed assets and immediately open a new collateral position with a new asset.
Slightly similar to the above process is debt refinancing or an interest rate swap. Here, say, a borrower has taken a loan from lending platform A for a specific asset as collateral. The borrower notes that lending platform B is offering a better interest rate on the same asset. To pay back the loan on platform A and deposit the collateral on platform B, the borrower can take out a flash loan from a DeFi protocol, close the loan on A, open it on B, and return the flash loan in a single transaction.
Pros and Cons of Flash Loans
The most significant advantage of flash loans is that they are instantaneous and unsecured. Thus, funds can become available to market participants and put to various uses at short notice without the need to own assets for collateralization. Moreover, flash loans are designed to prevent defaults. Therefore, in theory, they are a low-risk tool for both borrowers and lenders.
However, for potential borrowers, we recommend a proper understanding of smart contracts and the Ethereum network before using flash loans. Moreover, flash loans were originally designed for people with programming knowledge. While flash loans for less tech-savvy users are also available now through apps like Furucombo, some programming knowledge is an advantage.
On the negative side, flash loans are still a developing product. Hence, complete understanding is not yet widespread. As flash loans get used more, new issues may crop up. Flash loans are also not widely available on DeFi systems. With time, and depending on the demand for such loans, more DeFi protocols may begin offering them.
A more significant issue is the potential for exploitation. Malicious users can try to game the system, which is where flash loan attacks come in.
Flash Loan Attacks
Some of the positives of flash loans—no need for collateral, both borrowing and repayment in one quick transaction—can also be misused by people with malicious intent. In a flash loan attack, a borrower tricks the lending platform into believing that the flash loan has been repaid in full. However, the loan is used to manipulate the market and exploit vulnerable smart contracts.
Mechanism of a Flash Loan Attack
Here’s a simple example to make the above clearer. Suppose a borrower borrows a large amount of token A from a flash loan provider. The borrower then uses a decentralized exchange (DEX) to trade token A for token B. As a result, the price of A on the DEX comes down while that of B goes up.
Now, he finds a DeFi protocol that relies solely on this DEX for its pricing data. On this protocol, he uses the amount of B with him to borrow A. Note that since B’s value has gone up on the DEX and hence the DeFi protocol, the person will get a higher amount of A than he would in the general market.
Finally, some of this token A is used to repay the original flash loan with the first provider. The person keeps the remaining A as profit. In some time, the values of A and B will move back to the actual market price. However, the DeFi protocol ended up offering a higher debt than the collateral was worth. This undercollateralized position harms other users.
In the above example, the borrower manipulated the market while theoretically adhering to the rules. Since flash loans are unsecured, large sums can be borrowed to exploit such arbitrage opportunities, resulting in a significant impact, sometimes worth millions of dollars. In fact, in the short period of their existence, flash loans have been in the news for several high-profile attacks.
This information on flash loan attacks doesn’t aim to scare you from trying out flash loans. As the use of flash loans grows, measures will be put in place to minimize such attacks. Already, security protocols are being developed to detect smart contract exploitation and take fast action against any unusual activity. Top DeFi protocols are also beginning to rely on a decentralized network for price data instead of one. So, the information above is only to ensure users don’t treat flash loans as a completely no-risk tool for making money.
There’s enough evidence to prove that flash loans represent a tool with several potential benefits, with more use cases likely to be unearthed over time. The associated risks of attacks should also come down as robust measures are adopted. Many users may still prefer to engage with crypto in simpler ways, which is a perfectly valid strategy. However, if you intend to give flash loans a try, this article should get you started on your path to deeper research.