Flash loans are a relatively new type of unsecured lending in the decentralized finance world. Originally pioneered by Aave in early 2020, it has since grown in popularity and is available on many lending protocols.
Many crypto industry experts have become ardent advocates of flash loans, as they offer innovative ways to arbitrage, execute fast transactions, and offer many other novel features that were previously unavailable in traditional finance.
Most of us are familiar with traditional loans, where a lender lends money to a borrower and pays it back over a fixed period of time at a fixed premium or interest on top of the principal. Flash loans share the same fundamentals, but include several unique characteristics:
This is an unsecured loan, which means that the borrower does not need to use any assets or deposits to obtain the loan. Also, unlike traditional unsecured loans, there is no credit check process.
All flash loans are done through smart contracts on the blockchain, and stipulates that if the borrower does not return the funds in a single blockchain transaction, the loan process will be reversed as if it never happened. This key distinction is why borrowers are able to secure fast loans without any collateral or credit checks, as it removes any risk for the lender.
The loan process is instant, so once the loan is extended, the borrower must invoke other smart contracts to attempt to execute a near-instant transaction using flash loans, and then return the funds before the end of the single block transaction, usually within seconds.
Given that lenders have zero capital risk and borrowers have no collateral or credit check obligations, it’s no surprise that flash loans have grown so rapidly across DeFi since last year.
Let's look at a few flash loan use cases. In the first case, assume the user has borrowed DAI, using ETH holdings as collateral. If the price of ETH starts to drop, the value of the collateral will drop and the user will face the threat of the loan being liquidated at some point.
To solve this situation, users can take advantage of flash loans. Through this flash loan function, borrowers can exchange volatile ETH for stablecoins. The value of the collateral becomes immediately stable, eliminating any scope for liquidation.
While this use case falls into the collateral swap category, you can also use flash loans to swap out your debt. Consider the previous example where you borrowed funds in DAI.
Flash loan attack
Flash loan attack
In principle, flash loans allow users to borrow as much as they want without any collateral. As a result, borrowers can take thousands or even hundreds of thousands of dollars worth of Ether as a loan without any collateral or KYC process.
This has led to the rise of flash loan attacks, where malicious agents take out large flash loans and then use these funds to manipulate the market and leverage various DeFi protocols for tidy profits, often at the expense of ordinary investors and platform users .
The attackers strung together borrowed flash loan amounts through a series of vulnerable on-chain protocols to obtain hundreds of thousands of dollars in stolen assets before the loans were repaid.
There have been multiple flash loan attacks over the past year, and the frequency of these attacks appears to be increasing.
secondary title
Examples of Flash Loan Attacks
The first flash loan attack occurred in 2020, when borrowers obtained ETH flash loans using the DeFi lending protocol dYdX. They then split the loan in two and send it to the lending platforms Compound and Fulcrum.
On Fulcrum, some flash loans were used to short ETH against WBTC. Fulcrum went on to acquire WBTC from popular decentralized exchange Uniswap via another DeFi protocol called Kyber.
As Uniswap's WBTC has low liquidity, the asset price rises. As a result, Fulcrum paid a higher price than usual to acquire WBTC.
At the same time, the borrower also took a WBTC loan from Compound and traded it on Uniswap, and the price of WBTC has risen.
By manipulating multiple protocols and artificially increasing the price of WBTC, the borrower made a tidy profit - not only repaying his ETH loan, but also earning excess ETH profit.
While borrowers made significant gains, Fulcrum was tricked into acquiring WBTC at a price well above the market price.
In a separate flashloan attack, the attackers again leveraged and manipulated the bZX protocol upon which Fulcrum was built. First, the borrower takes a portion of his ETH loan and places a large order on Kyber to buy sUSD.
Smart contracts recognize currencies and their prices, but they don't understand that stablecoins are pegged to the dollar. Large orders caused the price of sUSD to skyrocket to $2 each, which goes against the very foundation of what a stablecoin should be able to do.
Since the purchasing power of sUSD doubled, the borrower used it to take out more ETH loans than he had previously taken out. He then paid off his first ETH loan and ran away with the rest of the money.
secondary title
How to prevent these flash loan attacks?
Since these attacks exploit DEXs to believe their own or single price feed, which can be manipulated by placing large orders for currencies, it is prudent to utilize decentralized pricing oracles to determine the correct price of an asset.
There are a number of ways dApps can protect themselves against flash loan attacks, some of the most common are:
Decentralized Oracle —— The safest option is undoubtedly to use a decentralized oracle, using multiple sources to find out the "true price". Some decentralized oracles, such as our own Umbrella Network, go a step further by committing data to the blockchain to ensure data reliability.
This means that if bad actors attempt a quick attack on a dapp that gets its feed from a decentralized oracle, the price manipulation will fail, the transaction time will pass, and the entire transaction will be reversed — unprocessed.
Frequent Pricing Updates- This is an easy fix on paper, but can be more expensive in practice. Here we are simply increasing the frequency of how often the liquidity pool queries the oracle for new prices. The logic is that as the number of updates increases, the prices of the tokens in the pool update faster and make price manipulation ineffective.
Time Weighted Average Pricing- It is common practice to use the average (or the nearest median) to calculate prices in liquidity pools. However, TWAP recommends using an average price across multiple blocks.
This helps counteract flash loan attacks, as the entire attack transaction sequence needs to be processed within the same block, but TWAP cannot be manipulated without manipulating the entire blockchain.
Another strategic recommendation to prevent such attacks is to use two transaction blocks instead of one in the transaction cycle.
As you can imagine, this complicates the process and is dissuasive to attackers. However, it also has the risk of causing damage to the DeFi UI.
in conclusion
in conclusion
DeFi is still an emerging field. The way it works is undergoing many innovations and rapid fundamental shifts. Rapid change, even innovative ones, often leads to neglect of extremely vulnerable groups.
Attackers will continue to explore the vulnerabilities that exist, but with each incident, prevention mechanisms will grow stronger as the entire ecosystem evolves.
While there are ways to help reduce risk, such as the use of decentralized oracles, more frequent pricing updates, or TWAP strategies, as the entire DeFi industry adopts more effective methods, flash loans will no longer be a potential exploitation tool. Some time to fight it.
