Flash Loans

Aditi Shastri
The Polygon Blog
Published in
6 min readJun 15, 2022

Flash loans are bigger, better, and faster versions of traditional loans. They are typically used to finance a short-term investment or speculation. However, they have certain limitations and are more vulnerable to attack. Let’s take a review of flash loans in DeFi.

What is a Flash Loan?

Flash loans are a new type of uncollateralized loan.

DeFi users benefit from flash loans since they allow for immediate borrowing without the need for collateral, as long as the liquidity is returned to the pool within one transaction block. Flash loans eliminate the need for intermediaries. Typically, when you take out a normal loan, you are required to go through another individual or a bank to receive that loan. However, with flash loans, the use of smart contracts does away with the need for all these intermediate steps and makes the process of using a flash loan instantaneous and secure.

Flash loans have become popular and beneficial because they allow users to arbitrage and trade in ways that were previously impossible.

How do Flash Loans Work?

The large majority of people understand how a normal loan works. Personal loans are issued as a lump sum which is then deposited into the borrower’s bank account. The borrower is required to pay back that loan over a certain period of time at typically, a fixed interest rate.

Flash loans can be thought of as similar to normal loans, with a few exceptions:

  • Flash loans make use of smart contracts, programs that execute when preset criteria are satisfied and are recorded on a blockchain. In this case, funds will not be given to the borrower unless the condition that the borrower pays back the loan before the end of a transaction is met. If the borrower does not pay back the loan before the end of the transaction, the transaction is undone and the lender receives the money that was lent to the borrower. In essence, a reversal of the transaction acts as if the loan was never awarded to the borrower. It is worth noting that fees for flash loans are relatively low. Aave, for example, charges 0.09, owing to the fact that there is effectively zero risk for lenders due to the smart contract reversal component of these loans.
Flash Loan Process: Complete Transaction vs. Reversal
Flash Loan Process: Complete Transaction vs. Reversal (Source: Killer Whale Crypto)
  • When you think of the process of taking out a normal loan some of the words that might come to mind are tedious, long, and wearisome. The good news is: flash loans are instant. The smart contract with the loan information must be fulfilled within the same translation that the money is lent to the borrower. But how is this possible? Well, the borrower typically has to make use of other smart contracts to complete the necessary actions with the money that has been lent out before the initial transaction has ended.
  • When you want to take out a normal loan you must decide between two options: secured or unsecured loan. Secured loans are loans in which you offer a possession of yours as collateral in the case that you can’t pay back the loan. Unsecured loans let you borrow the money with any collateral. Flash loans don’t have such options; all flash loans are unsecured loans. In the case of flash loans, although collateral does not need to be offered, the money must still be paid back in a different method if the borrower cannot pay the loan back. This different method comes in the form of the borrower paying the money back instantly rather than offering up a possession as collateral.

Use Cases

When should you take out a flash loan instead of a normal loan?

There are three major uses for flash loans:

  • Collateral Swaps: By using flash loans you can rapidly swap the collateral that initially backs the borrower’s loan for a different type of collateral. This ties into the instant nature of flash loans mentioned earlier.
  • Arbitrage: Let’s start by defining arbitrage. Cryptocurrency arbitrage is a method in which investors purchase a cryptocurrency on one exchange and rapidly sell it for a greater price on another market. By using flash loans, traders can increase profits as they observe the differences in prices between various exchanges. Let’s consider an example. Suppose that BTC is valued at $2 on the first exchange and at $4 on the second exchange. You make use of a flash loan and call a different smart contract (remember, we mentioned this earlier!) to buy 100 coins for $200 on the first exchange and sell those 100 coins for $400 on the second exchange. By doing this, you make a $200 profit!
Arbitrage Cycle
Arbitrage Cycle (Source: Reddit)
  • Transaction Fees: Flash loans offer lower transaction fees. As mentioned, flash loans are instant. What could possibly be multiple transactions in a standard loan become a single transaction in the flash loan process. (Reminder: This is because the smart contract with the loan information must be fulfilled within the same translation that the money is lent to the borrower). Because each transaction has an additional fee associated with it, the fewer the amount of transactions, the lower the total transaction fee.

Future of Flash Loans

Flash loans have many benefits but the drawbacks have not yet been considered.

How secure are flash loans?

The stories of flash loan attacks have frequented the news. Flash loan attacks have led to multiple problems, the most substantial being the loss of millions of dollars. For example, an attacker took out a 10,000 ETH flash loan in April 2020 and was able to influence the price of the USDC stablecoin. The attacker then made a profit of nearly $6 million by selling their USDC. There was even an attack on MakerDAO. An attacker took out a 500 ETH flash loan in November 2019 and made a profit of nearly $4 million by selling their DAI and manipulating the price of DAI stablecoin. Each attack included an attacker borrowing hundreds of thousands of dollars in ETH, threading it through a series of flawed on-chain protocols, extracting hundreds of thousands of dollars in stolen assets, and then repaying their enormous ETH debts.

The frequency of flash loan attacks points to a larger issue in the DeFi space. The primary concern with flash loans is that smart contracts that back them can be manipulated if they aren’t written in extensive detail to ensure that all the actions detailed in the contract are executed or if the data they receive is faulty or vulnerable. However, it is worth noting that this technology is relatively new. As DeFi evolves and grows, many of the issues surrounding flash loans have the possibility to be resolved as technology improves. However, they may continue to be a problem.

Regardless of the potentially negative consequences of flash loans, they are here to stay. In the future, as more developers become familiar with this technology, we should expect to see more applications for flash loans and an increase in the security, making these loans more accessible.

Sources:

  1. https://www.coindesk.com/learn/2021/02/17/what-is-a-flash-loan/
  2. https://opentezos.com/defi/lending/
  3. https://www.coinspeaker.com/guides/what-is-flash-loan-attack-and-how-to-prevent-it/
  4. https://www.machow.ski/posts/flash_loans_finance_on_steroids/
  5. https://10clouds.com/blog/defi/understanding-flash-loans-in-defi/
  6. https://www.coindesk.com/tech/2020/02/27/the-defi-flash-loan-attack-that-changed-everything/

Author is a Decentralized Finance (DeFi) software engineer intern at Polygon interested in the intersection of Blockchain and Artificial Intelligence and its applicability to the real world. They’re a student at Georgia Tech, studying Computer Science. Outside of this, other interests include watching ice hockey and sketching.

--

--