What is a Flash Loan?
Simply put, a flash loan in the DeFi space is the equivalent of an unsecured or un-collateralized loan.
In traditional finance, loans require the borrower to submit some form of collateral that secures the loan guaranteeing that the borrower will pay back the loan. The lender takes time to approve the loan after checking the borrower’s credit history or assessing the collateral submitted by the borrower.
However, in the DeFi universe, flash loans bring about a new concept where a borrower can instantly borrow Ethereum’s ETH or other ERC20 tokens to take advantage of arbitrage opportunities in the DeFi ecosystem without collateral.
The entire operation runs on smart contracts that are designed to execute an arbitrary code right after the borrower gets the loan thus ensuring that the loan is funded within the same transaction. The design of a flash loan might seem simple on the surface but requires complex and sophisticated algorithms that allow developers and crypto traders to take advantage of arbitrage opportunities on decentralized exchanges.
How Do Flash Loans Work?
The concept of flash loans was first introduced into the world of DeFi in 2018 by Marble (a forerunner of the DeFi space as well as an open-source bank). Aave and Chainlink picked up the concept soon after and brought it to the Ethereum ecosystem.
The entire process takes place in one fell swoop transaction where funds are instantly borrowed with no requirement for collateral. Therefore, if the borrower defaults on paying back the loan within the stipulated period, the transaction is automatically reversed by the smart contract.
For example, given the fact that multiple decentralized exchanges (DeX) now exist on the Ethereum ecosystem, an arbitrage trader can search through the many market pairs on those DeXs and identify arbitrage opportunities.
Thereafter, that trader can go to a platform such as Aave and get a flash loan for ETH and buy an ERC 20 token from one DeX, selling it on a second DeX for a higher price pocketing the arbitrage profit. With smart contracts, this entire process can be executed in a single transaction.
Why are Flash Loans Necessary?
Even though DeXs have become a huge part of the DeFi movement, the reality is that they only account for a small percentage of the overall trading volume of crypto assets.
A majority of the trading volume and price discovery is happening on centralized exchanges. Flash loans create liquidity and improve price discovery on decentralized exchanges thereby advancing the DeFi movement in general. With a flash loan, a trader can gain arbitrage profit without putting their capital at risk.
Flash loans can also be used to swap collateral on DeFi lending and borrowing protocols thereby increasing the quality of APY earned by crypto traders. For instance, a trader can swap collateral on a DeFi platform such as Compound from one underlying collateral (in this case an under-performing ERC20 token) to a high-quality collateral asset such as ETH (especially when its price is going up).
Flash loans make it possible for the trader to execute such a transaction without having to first pay back their outstanding loan on Compound and paying exorbitant transactional fees. Swapping collateral will help the trader prevent the liquidation of their collateral position on Compound as well.
One Danger of a Flash Loan? Flash Loan Attack
The adage about your greatest strengths sometimes becoming your greatest weakness is true for flash loans in that the smart contracts that make them a reality are also their main point of vulnerability.
A flash loan’s smart contract can be attacked by malicious actors to game the loaning mechanism. This incident is called a ‘flash loan attack’ and it works through a combination of tactics that take advantage of flash loan smart contracts whose code has loopholes.
For instance, a malicious actor can borrow from a lending protocol and use those funds in conjunction with various types of market manipulative tactics to control the price of crypto assets in a short time thereby making profits. The attacker can work with several smart contracts from different DeFi protocols to achieve their goal.