Disrupt - The FinTech Initiative · Follow
11 min read · Jan 29, 2024
Written by Anderson Lo and Aidan O’Brien
When people try to borrow money, it is usually collateralized. For example, if someone wants to borrow money from the bank, they may put their car or house up as collateral. Therefore, if they are not able to pay back the loan, the bank can take the borrower’s assets and liquidate them to get their money back.
However, now with the rise of decentralized finance (DeFi), a new way of loaning money is being brought into the spotlight. In 2020, flash loans were popularized by Aave, an open-source liquidity protocol. Unfortunately, since this technology allows users to borrow large amounts of capital in a short period of time, there have been many bad actors that have exploited flash loans to their advantage.
For instance, an attacker utilized a flash loan to increase their voting power significantly and pass a malicious proposal. This proposal allowed the hacker to steal assets from the Beanstalk Protocol, resulting in an $80 million profit. Nevertheless, many people are quick to defend flash loans from becoming the scapegoat of these attacks. Instead, flash loan attacks are only possible due to vulnerabilities within the protocols themselves.
Context
In 2018, the Marble Protocol released an article that described their “open-source bank on the Ethereum blockchain.” Marble’s most significant innovation was the concept of a flash loan, a risk-free, uncollateralized loan where users can borrow and return large amounts of funds within the same blockchain transaction.
Max Wolff, one of the co-founders of the protocol, wrote, “Flash lending lets anyone borrow Ether and ERC20 tokens to take advantage of arbitrage opportunities on Ethereum.” Marble’s founders hoped that the effects of arbitrage, creating “liquidity and improv[ing] price discovery,” would promote decentralized exchanges by making them “more usable.”
In addition, flash loans became largely popularized by Aave after its official launch in January 2020. According to aave.com, “Aave is a decentralized non-custodial liquidity market protocol where users can participate as suppliers or borrowers.” Thus, people can put their capital into a liquidity pool and earn passive income on their money, or they can utilize some of Aave’s technologies, like flash loans, to take advantage of the large liquidity pool to make a large amount of profit through arbitrage or other avenues.
Infrastructure
To complete a flash loan transaction, two entities, lenders and borrowers, are required. Before requesting a flash loan, a borrower should have their intended operations planned and designed. To approach a lender, a borrower must have a smart contract that complies with lenders’ conditions and access for lenders to receive the payback amount plus premiums. Once a smart contract is developed, the transaction officially begins with the lenders transferring the assets borrowed to the borrower.
The borrower then performs their intended operations via smart contracts with their borrowed assets. After the operation is completed, the borrower either immediately pays back the borrowed assets plus a flash loan fee (0.09% of the borrowed amount if using Aave) or incurs a debt approved by the lender.
Finally, the lender can check if assets are fully paid back and have the right to immediately void the transaction if insufficient funds are received. According to BSC news, the leading platform for Defi news, an average flash loan transaction process in the ETH blockchain takes a mere 16 seconds to complete, which makes it an attractive option for borrowers interested in quick, uncollateralized loans.
Flash Loans
Flash loans are important because they solve the issues involved in both centralized and decentralized lending. Within most centralized lending systems, borrowers provide collateral and may have to wait from a couple of weeks to months to get approved for a loan. Thus, flash loans were created to make borrowing money fast and accessible.
In addition, flash loans remove risk for traditional lenders. For instance, if a traditional borrower defaults on their loan, the lender will have to spend money to try to recollect the loan (i.e., through a debt collection agency). The lender may also decide to cut their losses and stop trying to recollect the money that was loaned out. Another risk that lenders face is illiquidity. If a lender lends out too much money or does not receive payments from their borrowers in time, they could become illiquid and not be able to pay their current liabilities.
Flash loans have risen in an environment where technology and finance are working together more than ever before. The financial barriers that have been built up for decades by traditional finance institutions are being broken due to innovations in DeFi.
Santiago Palladino, author of Ethereum for Web Developers, explained the significance of flash loans in a Twitter thread from February 2020. Palladino wrote, “[F]or the first time ever, you don’t need money to make more money… anyone can become a whale (owning a large number of crypto assets) for an instant…” Flash loans enable people to take on an enormous amount of capital for a fraction of what they are borrowing.
There are also entire communities forming around the DeFi innovation. For example, a group of people have gathered together to create a decentralized autonomous organization, known as ArbitrageDAO. They can utilize flash loans to take advantage of arbitrage opportunities.
While flash loans have created opportunities for people to make more money than ever before, they also create unethical opportunities for hackers to exploit systems and profit quickly and easily
Risk and Limitations
Although flash loans are meant to make borrowing more accessible by removing the need for collateral, they still require a smart contract to be developed. To create a smart contract, developers need to be proficient in Solidity and its inheritance techniques.
Furthermore, even though the barrier to borrowing money may be lower, it is arguable that the technical knowledge required (i.e., smart contracts) is an even greater barrier than the previous. Since there is no current real-world analogy to flash loans, it is a concept that requires an understanding of Ethereum, smart contracts, and programming background to execute.
Flash Loan also provides an opportunity for people with bad intentions to borrow large amounts of assets with no collateral and is commonly used as a tool for launching attacks. The most common method of attack using flash loans is to abuse smart contract security by borrowing a large number of funds. Such attacks allow users to modify and prevent transactions within the network, as well as manipulate the cryptocurrency market in general.
In the next section, we will be highlighting some key flash loan events and attacks, and how the crypto and DeFi markets are affected.
Effects on the Crypto Market
On March 13th, 2023, Euler Finance, an Ethuerum-based lending protocol similar to Aave, suffered a loss of approximately 197 million from a series of flash loan attacks initiated by a hacker. The event signifies the biggest known instance of a flash loan attack and the blockchain was able to record a comprehensive overview of the losses from the attack.
The attacker was able to utilize flash loans to borrow around 30 million worth of DAI from Aave after creating a smart contract. 20 million of those DAI was then used as a deposit to exchange for 19.6 million eDAI tokens on Euler. Since Eular allowed depositors to borrow up to 10 times their deposit, the attacker mined approximately 195.7 million eDAI tokens.
The attacker later repaid the initial remainder of 10 million DAI to clear parts of the acquired debt (dDAI) and minted even more eDAI tokens. Exploiting the inconsistencies in the exchange rate between DAI and eDAI, the attacker was able to profit approximately 8.9 million. To get a more comprehensive overview of the attack, feel free to read this article written by Cointelegraph.
The same process was then used for many other stablecoins, resulting in a whopping 197 million acquired. As seen from the breakdown, the attacker targeted various types of stablecoins ranging from USDC (US Dollar Coin), WBTC (Wrapped Bitcoin), and stETH (Stacked Ether).
Following the original attack on March 13, Euler initially offered a bounty of 1 million for anyone who was able to provide information that would help identify and eventually arrest the attacker. In a surprising turn of events, the attacker, who self-identifies as Jacob, sent a message through an Ethereum address linked to Euler a week after the attack, offering to negotiate with the platform.
In April, Jacob eventually took to blockchain public messages to apologize to Euler and the community affected, promising to return all assets acquired through the attack. Jacob eventually returned all recoverable funds to Euler Finance on April 3rd through 8 different transactions, following successful negotiations with Euler. As a result, Euler commented that the attacker did the right thing by returning all assets and would no longer accept new information from their 1 million bounty campaign that would lead to an arrest.
bZx Flash Loans attack
In February 2020, BzX, the 8th largest DeFi project at the time, suffered two flash loans in one weekend, resulting in a loss of around $1 million worth of Ethereum. The first attack exploited the price of Uniswap, a wrapped bitcoin (WBTC) by tripling up the conversion rate between WBTC and ETH by using flash loans and borrowing 10,000 ETH. The attacker was able to profit roughly $355,880 through the attack after repaying their loans. The second attack took advantage of the pricing system of DeFi networks by targeting Synthetix USD (sUSD) and borrowing 7,500 ETH.
Utilizing the common pump and dump scheme through Kyber, a decentralized crypto exchange that bZx bases their pricing data on, the attacker was able to manipulate the ETH/sUSD price to 2.5 times the average exchange rate. The attack then exchanged the rest of their ETH with a synthetic depot contract, which ensures a fair ETH/sUSD exchange rate. The attacker finally borrowed ETH using the inflated sUSD price and was able to come out with roughly $665,840 in profit after repaying their loans.
Even though a total of around $1 million loss may seem low in the cryptocurrency world. The bZx attacks were one of the earliest known instances of flash loan attacks, which happened around 1 month after flash loans were first launched by Aave. The two attacks highlight the problem of how flash loans can exploit the bad programming and pricing data of DeFi projects and would eventually bring the concept of flash loan attacks to the attention of market manipulators and thieves.
BAYC Flash Loans attack
In March of 2022, Yuga Labs, the creators of Bored Ape Yacht Club (BAYC) and Mutant Ape Yacht Club (MAYC) NFTs, airdropped (free tokens provided to community members) their newly released ApeCoin, a token that aims to support the development of web3, and gain token holders access to the ApeCoin DAO (Decentralized Autonomous Organization). The token airdrop is originally reserved for BAYC and MAYC holders only, which could range from $80,000 to $200,000 USD in value. However, someone who initially did not own the NFTs was able to claim $1.1 million worth of ApeCoin airdrops with the help of flash loans.
How it works: Instead of tracking ownership of BAYC and MAYC holders and handing out airdrops, ApeCoin is claimable for holders with ownership of the tokens at the time of the airdrop. The individual took advantage of unclaimed Ape Coins and initialized flash loans that allowed them to purchase 5 BAYC tokens that haven’t claimed ownership to their ApeCoins airdrop, claimed a total of 60,564 ApeCoins, returned the asset to the lender, then sold the Ape Coins for a total of 399 ETH ($1.1 million). By utilizing flash loans, the individual was able to complete the whole process under one transaction.
The event sparked a huge debate in flash loans within the Defi space on whether such transactions are classified as fair arbitrage trading or an attack, as the transaction that the user abides with their smart contracts and returns the asset to the lender. However, according to blockchain security firm BlockSec, the incident has been classified as an attack due to the user understanding the potential vulnerability of a token airdrop, thus taking advantage of the loophole.
Beanstalk Attack
In April of 2022, Beanstalk, an Ethereum DeFi platform, lost $182 million due to a flash loan attack, which marked the largest theft attack for a DeFi platform in history at the time. The attacker was able to utilize flash loans to borrow large amounts of stalk, Beanstalk’s main governance token through Aave. Since stalk token holders are granted voting powers, the attacker can now pass through a governance proposal that grants all funds within the platform to their personal Ethereum wallet due to Beanstalk’s governance system being a majority vote. After the attack, the attacker was able to profit from $80 million worth of crypto funds, and the total value lost was up to $182 million due to the drastic price drop of Beanstalk’s stablecoin Bean. The total attack process was estimated to be completed in 13 seconds.
The funds are now unlikely to be traced and returned due to the attacker transporting funds through Tornado Cash, a cryptocurrency tumbler service that is commonly used to disrupt the traceability of funds. As a result, the event has not only led to many Beanstalk project investors claiming to lose tens of thousands of dollars but also Publius, the backer for Bean, announcing that the project would be ending due to a lack of VC funding. The Beanstalk attack highlights the issue of Defi platforms struggling to defend against flash loans due to its majority vote structure and proof of state security measures.
Implications: The Future of Flash Loans
While flash loans currently offer accessibility to quick capital, efficiency in transaction time, and the potential to eliminate risks associated with traditional lending, it is evident that the current state of flash loans has its shortcomings. The occurrences of events like the ApeCoin airdrop and the Euler attack highlight the existing issues and vulnerabilities within flash loans. Flash loan attacks will continue to remain a potential concern until decentralized platforms universally adopt stricter security measures.
Nevertheless, as a concept that is still in its early stages of development, the potential of flash loans continues to excite people within the DeFi space. If utilized properly, these decentralized loans could offer benefits such as improved transaction speed, no traditional collateral, and higher transaction volume, making flash loans a tool worth considering for traditional banking.
With the evolution of flash loans over time, more security protocols will hopefully be implemented to not only reduce the risk of flash loan attacks but to make flash loans and DeFi the gold standard for financially secured transactions.
Works Cited:
https://www.moonpay.com/blog/defi-flash-loans-explained
https://docs.aave.com/developers/guides/flash-loans
https://www.bsc.news/post/cryptonomics-flash-loans-explained
https://learn.bybit.com/defi/what-is-a-flash-loan-attack/
https://docs.aave.com/developers/v/1.0/tutorials/performing-a-flash-loan
https://docs.aave.com/developers/v/1.0/tutorials/performing-a-flash-loan/...-in-your-project
https://peckshield.medium.com/bzx-hack-full-disclosure-with-detailed-profit-analysis-e6b1fa9b18fc
https://peckshield.medium.com/bzx-hack-ii-full-disclosure-with-detailed-profit-analysis-8126eecc1360
https://www.coindesk.com/tech/2022/04/17/attacker-drains-182m-from-beanstalk-stablecoin-protocol/
https://www.coindesk.com/tech/2022/04/17/attacker-drains-182m-from-beanstalk-stablecoin-protocol/
https://sensoriumxr.com/articles/what-are-flash-loans
https://decrypt.co/resources/what-are-flash-loans-the-defi-lending-phenomenon-explained
https://www.yahoo.com/now/defi-flash-loans-become-standard-232453417.html
https://www.chainalysis.com/blog/euler-finance-flash-loan-attack/