What Are Flash Loans? » Meaning and Definition | Chainlink (2024)

A flash loan is a type of uncollateralized loan that lets a user borrow assets with no upfront collateral as long as the borrowed assets are paid back within the same blockchain transaction.

The decentralized finance (DeFi) ecosystem started out by recreating traditional financial services, such as lending and borrowing, exchanges, futures and options markets, for blockchains. As the ecosystem developed, fundamentally new services were created that are only possible thanks to the inherent properties of blockchain technology and the permissionless composability enabled by smart contract applications.

Like the concept of yield farming, flash loans are an exciting new financial primitive. Flash loans enable users to borrow assets from an on-chain liquidity pool with no upfront collateral as long as the borrowed amount of liquidity, plus a small fee, is returned to the pool within the same transaction. If the borrower does not pay back the loan in the same transaction, then the entire transaction is reverted, including the initial borrow and any actions taken afterward. This innovative mechanism increases access to capital for users across a variety of use cases while ensuring the continued solvency of the underlying on-chain liquidity pool.

In this article, we outline how flash loans work, what they are used for, and what DeFi protocols can do to mitigate the potential attack vectors created by this new financial primitive.

How Do Flash Loans Work?

In the case of collateralized lending, borrowers need to put up capital (collateral) to borrow funds. If the borrower fails to meet the terms of the loan, the lender can still cover the loan using the borrower’s collateral. Flash loans don’t have this requirement; the loan can only exist if the borrower pays it back within the same transaction. As a result, defaulting on a flash loan is not possible, since the entire transaction would simply revert.

For a short period of time—the span of a single transaction—a flash loan can turn anyone into a very well-capitalized actor. The hundreds of millions of dollars of liquidity provided by flash loans creates unique opportunities for arbitrage, liquidations, collateral swapping, and the creation of leveraged positions. It also creates certain risks, especially for a nascent ecosystem of financial protocols with varying degrees of decentralization and security. These risks should be understood by smart contract developers so more robust applications can be built for users.

What Are Flash Loans Used For?

The most common usage of flash loans is for arbitrage. By harnessing a large amount of capital to fill an inefficiency in the market, where an asset has differing exchange rates on different markets, arbitrageurs can generate a profit by bringing the market to an equilibrium and improving liquidity for everyone in the DeFi market.

Another use case for flash loans is liquidations. Many lending protocols incentivize third-party liquidators that can earn a reward for liquidating loans that fail to meet a certain collateralization ratio requirement. Access to large amounts of capital through flash loans can help ensure that undercollateralized loans are liquidated on time and the underlying protocol remains solvent.

Flash loans can also be used for collateral swaps—a technique where a user closes their loan with borrowed funds to immediately open a new loan with a different asset as collateral. Flash loans can also simplify the process of creating a leveraged position or allow loans to be seamlessly transferred across protocols.

Flash Loans and Price Oracle Attacks

Flash loans have a controversial reputation as, in addition to the use cases above, they can also be used to fund various types of attacks on DeFi protocols. Once a vulnerability is uncovered by a malicious actor, the attacker can manipulate certain functions of the protocol using capital acquired via a flash loan and make a profit while potentially draining funds from its smart contracts. In addition, since flash loan transactions revert on failure, hackers don’t have to put a large amount of their own capital at risk to fund an attack.

It’s important to note a key distinction here—flash loans aren’t inherently the problem, since all they do is provide a source of capital. The real issue at hand is existing vulnerabilities in a protocol that may be revealed through a flash loan-funded attack. Over the long-term, flash loans may even be beneficial for the security of the DeFi ecosystem, as protocol engineers have to consider the potential attack vectors flash loans may uncover by providing instant access to a large amount of liquidity.

While attacks often differ in methodology and scope, an attack commonly attributed to flash loans involves manipulating protocols that use a spot price from a decentralized exchange (DEX) as their sole price oracle. As explained in The Importance of Data Quality for DeFi Smart Contracts, protocols that fetch prices from a single centralized source are easily exploitable by well-capitalized malicious actors who can manipulate the market with one large trade. DeFi protocols are typically looking to maximize their decentralization and censorship resistance—centralized price oracles undermine this objective by acting as a single point of failure.

Here’s an example of a flash loan-funded attack on a DeFi lending protocol using a DEX-based spot price feed as its sole price oracle:

  1. Attacker borrows a large amount of token A from a protocol supporting flash loans.
  2. Attacker swaps token A for token B on a DEX (lowering the spot price of token A and increasing the spot price of token B on the DEX).
  3. Attacker deposits the purchased token B as collateral on a DeFi protocol that uses the spot price from the above DEX as its sole price feed, and uses the manipulated spot price to borrow a larger amount of token A than should normally be possible.
  4. Attacker uses a portion of borrowed token A to fully pay back the original flash loan and keep the remaining tokens, generating a profit using the protocol’s manipulated price feed.
  5. As the spot prices of token A and B on the DEX are arbitraged back to the true market-wide price, the DeFi protocol is left with an undercollateralized position.

What Are Flash Loans? » Meaning and Definition | Chainlink (1)

Because the attacker was able to open a flash loan and manipulate the exchange that the DeFi protocol used as its sole spot price oracle, the attacker was able to raise the reported value of the token used as collateral and lower the reported value of the token used as debt. This allowed the attacker to borrow more funds than they should have been able to, creating a position that cannot be fully liquidated, as the collateral became worth less than the debt. This attack can occur within a single transaction but can be repeated many times across multiple transactions, furthering the damage.

Furthermore, when used as price feeds, single on-chain exchanges also provide extremely limited market coverage, as they represent the trading activity of only one exchange. This leaves protocols relying on the spot price from that DEX vulnerable to manipulated price points if volume shifts to different exchanges or a well-capitalized actor temporarily manipulates the price on that exchange. It’s especially risky for lower liquidity assets, which are increasingly being used as collateral within DeFi lending protocols.

With that in mind, this style of attack is entirely preventable with a decentralized oracle solution with proper market coverage.

How Chainlink Oracles Prevent Flash Loan Attacks

In order to generate full market coverage, Chainlink Price Feeds are powered by decentralized networks of nodes that aggregate price data not from a single source but from multiple independent data aggregation firms. These data aggregators track all liquid trading environments—including both centralized and decentralized exchanges—to generate volume-weighted average pricing that reflects the market-wide price of assets. Such data aggregators also commonly take into account various differences between exchanges and actively filter market outliers such as flash crashes and wash trading.

If you’d like a deep dive into the advantages of using Chainlink Price Feeds in DeFi protocols, read How Chainlink Price Feeds Secure the DeFi Ecosystem.

Since flash loans only exist within the timeframe of a single on-chain transaction, any manipulation that occurs is reverted by the end of the transaction. Because Chainlink Price Feeds aggregate price data off-chain from a wide collection of sources and publish data on-chain asynchronously, flash loans have no effect on the aggregated values within oracle reports.

To prevent flash loan-related price oracle attacks, it is strongly recommended that smart contract developers avoid manipulatable DEX spot prices and instead utilize Chainlink Price Feeds as their source of validated market data. This helps ensure that DeFi protocols always receive an aggregated price point that is reflective of market-wide trading activity and untouchable by flash loans, mitigating an entire category of price oracle attack vectors.

What Are Flash Loans? » Meaning and Definition | Chainlink (2)

Conclusion

Flash loans are a sophisticated financial primitive in DeFi that unlock complex financial applications and lower the barrier to entry for a new wave of market participants. While flash loans have been utilized to fund attacks on DeFi protocols, they are simply a financial tool available to developers and users—they do not create vulnerabilities, but reveal vulnerabilities that may already exist in a protocol, with the most common being faulty price oracle designs.

Chainlink is a decentralized oracle network that helps DeFi protocols become more tamper resistant, particularly regarding the critical function of sourcing real-time market data that will trigger a cascade of other transactions across other Web3 applications. Only through a security-first approach can DeFi protocols adapt to new risks, maintain trust, and sustainably scale to attract billions of users and trillions of dollars of value.

If you’re a developer and want to quickly get your application connected toChainlink Price Feeds, visit thedeveloper documentationand join the technical discussion inDiscord. If you want to discuss the integration more in-depth, reach out here.

What Are Flash Loans? » Meaning and Definition | Chainlink (2024)

FAQs

What Are Flash Loans? » Meaning and Definition | Chainlink? ›

A flash loan is a type of uncollateralized loan that lets a user borrow assets with no upfront collateral as long as the borrowed assets are paid back within the same blockchain transaction.

Why do people use flash loans? ›

Within the DeFi ecosystem, flash loans are used for arbitrage, liquidations, and collateral swaps. Arbitrage. The borrower purchases crypto assets at a lower price on one market and sells them at a higher price on another market.

Do you have to pay back a flash loan? ›

The Flash Loan leverages atomicity to allow a user to borrow without posting collateral. There are two caveats to mention. First of all, whenever you borrow an asset in a Flash Loan you have to pay a fee of 0.09% of the amount loaned. Secondly, you must pay back the loan in the same transaction in which you borrowed.

What is the difference between flash loan and traditional loan? ›

These loans differ from traditional loans mainly in their collateral requirement and transaction speed. The loans do not require collateral and must be repaid within the same blockchain transaction block. They enable quick, short-term borrowing for instant trading opportunities.

Are flash loans risky? ›

Flash loans may be a profit-making tool for attackers. However, the crypto community, in general, incurs losses due to such attacks. Investors who believe their assets will appreciate lose money once attackers sell tokens and coins and move out of the market.

What is the main advantage of flash loans? ›

Flash loans offer multiple advantages over traditional loans! No collateral required: With flash loans, there is no need to post any collateral for your transaction! Low cost: Because flash loans are typically less expensive than traditional loans because they don't require middlemen like underwriters and loan agents!

Are flash loans illegal? ›

No. Flash loans are unsecured and uncollateralized, meaning anyone can borrow funds to make profits.

Is Flash loans legit? ›

There is no risk using a flash loan. Either you will have a successful arbitrage happen, or the money goes right back to wherever you borrowed it from, Aave in my example. Are Flash Loans and Flash Loan Arbitrage Bots Legal and Legit? Yes, 100% legal and Legit.

How much can you borrow with a flash loan? ›

Flash Loans allow you to borrow any available amount of assets without putting up any collateral, as long as the liquidity is returned to the protocol within one block transaction.

What is the limit of a flash loan? ›

Provided there's enough liquidity in the pool(s) to conduct your transaction, there's no limit to the amount you can loan in a flash loan.

What is the flash loan strategy? ›

One such strategy that has gained significant traction is flash loan arbitrage. By leveraging flash loans, smart traders can exploit price discrepancies across various decentralized exchanges (DEXs) in a matter of seconds, generating profits without the need for substantial capital upfront.

How fast is a flash loan? ›

A flash loan, however, is instantaneous. The smart contract for the loan must be fulfilled in the same transaction that it is lent out. This means the borrower has to call on other smart contracts to perform instant trades with the loaned capital before the transaction ends, which is usually a few seconds.

Is Flash Cash a loan? ›

Flash cash (also known as transactional funding or same-day funding) refers to money borrowed for a short timeframe, usually 24 to 48 hours, to conduct a double closing.

What is an example of a flash loan? ›

The attacker repays the flash loan of 1000 ETH, plus any fees and interest, and keeps the remaining 100 ETH profit. This is an example of a flash loan arbitrage attack. This attack takes advantage of price discrepancies between different exchanges to generate profit.

Do flash loans require collateral? ›

While flash loans don't need collateral and income proof, they're essentially risk-free for lenders. If the borrower fails to repay, the smart contract automatically cancels the transaction, effectively erasing the loan. Therefore, we're speaking about a very short time frame here.

How to lend flash loans? ›

How To Create a Flash Loan on Aave
  1. Step 1: Setup the Development Environment. ...
  2. Step 2: Install MetaMask Extension. ...
  3. Step 3: Create a Smart Contract. ...
  4. Step 4: Fund the Wallet. ...
  5. Step 5: Deploy the Contract. ...
  6. Step 6: Fund the Flash Loan. ...
  7. Step 7: Execute Flash Loan Contract.
Jan 21, 2023

Has anyone made money with flash loans? ›

An arbitrage bot flash loaned $200 million worth of the dai stablecoin (DAI) from MakerDAO on Wednesday, making a $3.24 profit after transaction fees.

What are the use cases of flash loan? ›

Borrowers specify loan details in a smart contract. They receive funds, use them (e.g., for trades), and repay within the same transaction, often with a fee. Flash loans are used for arbitrage, collateral swaps, and debt refinancing.

Are flash loans still profitable? ›

While flash loan arbitrage bot development strategies offer significant opportunities for profit, they also come with inherent risks, including smart contract vulnerabilities, market volatility, and regulatory uncertainty.

Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 5911

Rating: 4 / 5 (51 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.