In this guide we’re exploring flash loans and how are they used in DeFi and crypto
When it comes to cryptocurrency and digital assets, there are a lot of choices. You can choose between different types of cryptocurrencies, use an exchange or a wallet service provider, and even look into other DeFi protocols like Aave and Compound. However, one thing that has been missing until recently is a way to borrow money against your crypto holdings. Sure you could go through your normal bank or credit card provider but that defeats the whole purpose of using the blockchain. Now, what if you could take a loan and repay it in just a few seconds? Sounds crazy, but flash loans allow you to do just that.
What Is a Flash Loan?
Flash loans are short-term unsecured loans that are issued by a Defi (Decentralised Finance) organisation in the form of a smart contract. Flash loans allow you to borrow any available amount of assets without putting up any collateral, as long as the borrowed amount is returned to the DeFi within the same transaction.
Flash loans, or flash lending, were first introduced by the Marble Protocol in 2019, on the Ethereum blockchain. The innovation was described as a “smart bank” that allows users to take out zero-risk loans through a smart contract. Flash loans became popular with Aave protocol that made it easy for developers to use flash loans in their smart contracts.
By removing the need to hold any capital, we aim to democratize the liquidation market and enable faster and easier liquidations. The safety of the whole ecosystem will be better and the risk of “bad debts” much lower.
Marc Zeller from Aave.
Why Do We Need Flash Loans in DeFi?
You are probably wondering what is the point of flash loans if you have to repay your loan instantly and pay for all the gas transactions as well. One of the most popular uses for Flash Loans are for arbitrage.
Arbitrage is the practice of buying a product at a price that is lower than the seller’s cost, then selling it at a higher price. In trading, arbitrage involves taking advantage of differences in prices for the same asset between different markets. Arbitrage opportunities exist when an asset can be bought in one market and sold in another for a profit without any risk. In DeFi that means that you can buy a crypto asset on a Decentralised Exchange (DEX) like PancakeSwap and sell it on another DEX (like UniSwap) for a higher amount. Arbitrage with Flash Loans is (almost) a riskless trading strategy because all transactions are carried out simultaneously.
Another interesting use case of flash loans is reduced transaction fees. Since a flash loan combines several transactions into one within the same smart contract, the transaction fees are reduced. The cost of the transaction is then charged on the loan amount so the borrower suffers lower fees.
How Do Flash Loans Work?
To help you understand how flash loans work even better, let’s look at a hypothetical arbitrage example. Let’s say a crypto asset (or token) trades for $0.50 on one exchange and for $1 on another. This presents a great opportunity for savvy traders, who can take out a flash loan of $50 worth of tokens on the first exchange and sell it for $100 on the second exchange, repay the loan, and be left with an extra $50 in profit minus all the gas fees used in the transaction. Now assuming you took a loan worth $50 million instead of $50, that would leave you with $50 million profit in the previous example.
As you can imagine if you find opportunity flash loans can present you with tremendous gains assuming you know what you are doing. However as with every new blockchain invention there are always malicious actors out there trying to exploit potential vulnerabilities. Flash loans have been the focus of hackers trying to exploit new exchanges often resulting in hundreds of millions in loses.
Flash Loans Attacks
The biggest flash loan attack recorded (at the time of this writing) was at the stablecoin protocol known as Beanstalk Farms. The hack resulted in $182 millions in total loses. The Beanstalk attacker managed to get away with $80 million in illicit crypto funds in this way and the BEAN token plummeted from $1 to 11 cents in value overnight. The attacker took a flash loan on the liquidity protocol Aeve and acquired a large enough amount of the Stalk native governance token to have the power to pass a malicious proposal. This attack gave the ability to the hacker to pass a proposal (by exploiting Beanstalk’s majority vote governance system) that allowed the attacker to siphon money directly from the protocol’s wallet.
Flash loans are a relatively new innovation in a highly experimental field like DeFi. When there are millions at stake and no regulations that means that these new innovations can be exploited by hackers or scammers. On the other hand, flash loans can also give opportunities for professional traders to make extra profit at a lesser risk.
To make sure your funds are safe if you are using a DEX always make sure that all the smart contracts are properly audited by a reputable company like Cyberscope.