Until recently most projects in decentralized finance (DeFi) have focused on implementing conventional financial processes on the blockchain, whether that be lending, borrowing or saving. Projects such as Compound and Maker Protocol have for example established the logic of decentralized credits.
Indeed, since credit scores are not yet available in crypto, the only way to borrow on-chain is to provide collateral for your borrowing. To offset the risks of the loan not being repaid, users are required to secure their borrowing by locking in some capital at a certain collateralization ratio. For instance, to borrow $100 worth of DAI users will have to send $150 worth of ETH to a smart contract that releases the loan. For a while the industry was limited by the logic of secured loans, which arguably creates massive capital inefficiencies.
The concept of flash loans was introduced by Aave as a way to override capital inefficiencies by means of unsecured loans. It is one of the first experiments within the DeFi space that cannot be replicated in a traditional financial system, since it's based on the programmable nature of blockchain transactions.
How Crypto Flash Loans Work
The programmable nature of blockchain allows users to submit complex transaction “programs” that can consist of multiple steps. In the case of flash loans the three steps are:
1) Receive the loan
2) Use the loan received to do something
3) Repay the loan
It all happens in a very short period of time until the next block is verified. If the funds are not returned within this “flash”, meaning that if the borrower does not repay the loan by the end of the current block time, the transaction that was intended to lend the funds will be reversed. In the context of blockchain and programmable contracts, users can lend funds through flash loans and be repaid instantly — as if the funds never left the lender.
Therefore, flash loans do not require collateral as the funds are being borrowed and returned within the same block.
Use Cases for Crypto Flash Loans in DeFi
The two most common use cases of flash loans are arbitrage and collateral swaps.
Crypto Arbitrage is the act of buying an asset on one market and simultaneously selling it on another market at a higher price. In crypto it is common to arbitrage prices between exchanges. For instance, assuming Injective (INJ) is currently trading at $15 on Uniswap and at $17 on Sushi, the borrower can use a flash loan of $150 to swap it for 10 INJ on Uniswap, sell 10 INJ for $170 on Sushi and return $150 back to the lender. This way the borrower makes a profit of $20 with 0 initial capital. The trick is to accomplish it all within one transaction.
Collateral Swaps in DeFi
Collateral swaps allow users to switch the underlying collateral asset they used to take on a secured loan in DeFi on a lending application like Aave. Assume that a user initially locked ETH to create DAI, but wants to switch to Chainlink (LINK) as collateral. The user could then take a flash loan in DAI of the same value as the original loan. The borrower would then use the flash loan funds to repay the original loan, withdraw the staked ETH and trade it for LINK on a DEX. Then, they would use LINK to collateralize the creation of a new regular loan in DAI, which would in turn repay the flash loan. Again, the catch is that all of these steps must be completed in one transaction.
Crypto Flash Loan Attacks
Flash loans as a nascent concept have been used as a tool to conduct several attacks which have led to millions of dollars in losses
In May 2021, the yield-farming aggregator PancakeBunny suffered an attack from a flash loan which caused the token value to crash by 95%. The attacker used PancakeSwap to borrow a huge amount of BNB and then manipulated its price against the BUSD stablecoin and Bunny tokens. The Bunny tokens acquired by the attacker were dumped on the market causing its price to drop from around $146 to $6 - a crash of over 95%. This was one of the biggest attacks using flash loans and blockchain data suggests that the attacker profited close to $3 million.
Even though flash loans have introduced a new attack vector, they are not the root cause of attacks such as the one illustrated above. Flash loans were used only as a tool that exploited the vulnerabilities present in the protocol.
Flash loans are one of the first innovations in DeFi that could not exist in traditional finance. By introducing the concept of uncollateralized loans powered by smart contracts, this technology helps achieve higher capital efficiencies and presents immense possibilities in the realm of DeFi. Even though they are still in a nascent stage, flash loans have paved the way for industry experts to explore new innovative applications that can soon become more mainstream.
Injective is a lightning fast interoperable layer one blockchain optimized for building the premier Web3 finance applications. Injective provides developers with powerful plug-and-play modules for creating unmatched dApps. INJ is the native asset that powers Injective and its rapidly growing ecosystem. Injective is incubated by Binance and is backed by prominent investors such as Jump Crypto, Pantera and Mark Cuban.