Explaining DeFi: Crypto Primitives and Flash Loans

The first uses of new technology are often adapting old products to a new distribution channel. Modern tech giant Amazon started as an online book-seller in 1995, and it took twenty years for that business to evolve and take advantage of capabilities such as real-time communication (Alexa) and cloud computing (AWS) enabled by the internet.

As technologies mature, novel business models emerge that weren’t possible before. Uber and Lyft, for example, couldn’t exist without the innovation and mass adoption of the smartphone. These native applications take a first-principles approach to fully leverage the capabilities provided by the new underlying technological platform.

In the current era, much of our existing financial infrastructure feels outdated, with cumbersome payment systems, high fees, and convoluted structures that can require several different institutions to clear your debit-card coffee purchase. That means that even “modern” fintech applications are often constrained by last century’s technology. Meanwhile, blockchains and cryptocurrencies are re-inventing money as profoundly as the internet revolutionized communication.

This is an opportunity to bring finance into the 21st century. With “decentralized finance” (DeFi), developers can leverage the inherent capabilities of blockchains to build new financial primitives. These primitives enable a whole new class of financial products that will allow us to interact in ways that weren’t possible or even imaginable before. Each is a building block, and collectively they enable a huge number of powerful combinations. The next generation of developers will use these "Money Legos" to create the native applications of Finance 2.0.

To date, the novel financial primitives enabled by blockchains are largely being explored and used by developers and others with significant technical skills. Over time, however, these new primitives figure to work their way into the mainstream and create new use cases for everyday consumers. Already, investors and other non-developers are borrowing, lending, and trading cryptocurrencies on emerging exchanges. Meanwhile, new models are popping up to create more opportunities for innovation.

Among the newer financial primitives enabled by blockchains are flash loans, in which the owner of an asset lends it to someone else for a fee (or rate of interest). The "flash" part -- and this is where the blockchain comes in -- means that the duration of this loan is extremely short, like 15 seconds short. So short, in fact, that by just looking at the ledger balances in each block, it would appear that the asset never changed hands at all.

Though it seems like the financial equivalent of quantum superposition, it’s not magic. Rather, it’s a consequence of the way state updates and transactions work on a smart contract blockchain like Ethereum.

Fifteen-Second Loans

How do flash loans work? Recall that blockchain transactions are sequences of computation performed by nodes on a distributed network according to some predefined rules. The simplest and most common sequence is an asset transfer, say where Alice pays Bob. In that case, the transaction would consist of two steps: 1) reduce Alice's balance, and 2) increase Bob's by a corresponding amount. Note that if any individual step fails (e.g. reducing Alice's balance results in a negative number), then the entire transaction is invalid.

Smart-contract blockchains like Ethereum can support much more complex transactions than simple asset transfers, such as lending which consists of the following:

  1. Alice borrows an asset from Bob

  2. Alice does something with the asset

  3. Alice returns the asset to Bob

Flash loans compress this sequence into a single transaction, where the intermediate step can be expanded to several or even dozens of steps on its own. But because each part of the transaction must succeed or the entire operation will fail, the lender can guarantee that they will be repaid. In fact, if you look at the blockchain ledger as recorded in individual blocks, it would seem the lender never even relinquished custody of the asset in question.

Practical Advantages of Flash Loans

What use could there be for a fifteen-second loan? First, unlike traditional loans, flash loans are fully permissionless, meaning that they do not require approval or authentication by anyone. So they can potentially help democratize the financial system and level the playing field between individuals and large institutions, because anyone with a computer and an internet connection can access capital as readily as a bank or professional trader. Though most users of flash loans today are quite technical, models like this will become more accessible over time as developers explore ways to integrate them into user interfaces and applications.

Besides being permissionless, flash loans offer the following advantages for users:

(1) Enabling risk-free lending. In a traditional loan, a borrower of an asset might not be able to pay it back. This is called default risk. However, the nature of a flash loan guarantees that it will be repaid because the repayment is part of the same atomic transaction as the loan. The fact that the loan is risk-free means that anyone holding assets is incentivized to lend, allocating capital to productive uses that would have otherwise sat idle.

Today, the closest thing to risk-free lending in the traditional financial system is the overnight repo market, where banks lend their reserves to each other to meet a threshold set by the central bank. The central bank itself serves as the “lender of last resort” in this market. Because the central bank can print money, in theory, there should be no default risk. Yet this market has faced liquidity crises in recent years, with larger banks often preferring to hold their reserves instead of lending them out.

Figure 1 - 2019 Overnight Repo Markets
Figure 1 - 2019 Overnight Repo Markets

A flash loan is insured against default not by a legal guarantee, but a technological one. That guarantee is as strong as the security of the underlying blockchain on which the asset is issued. With no risk to lending, there should always be adequate liquidity since anyone holding capital is incentivized to flash-lend it and earn risk-free yield.

(2) Increasing capital efficiency by reducing/removing loan collateralization requirements. Taking out a loan in the traditional financial system requires depositing some collateral. For example, people pay a cash deposit as a down payment on a house or a car. Even most DeFi protocols require borrowers to deposit collateral that exceeds the value of their loan.

Obviously, this limits most consumer lending use cases. It also limits the size of an opportunity a borrower can take advantage of. But flash loans theoretically eliminate default risk and therefore no collateral should be required to guarantee them. This means that any smart trader (or automated bot) can take advantage of a market opportunity that arises without the need for upfront capital.

In the real world, market opportunities arise all the time, but most people are unable to take advantage of them. Imagine it’s Christmas and everyone wants the latest video game console. The local Best Buy is selling them for $500, but you’re a bargain shopping sleuth and have found an online seller that sells for $400. To maximize the opportunity, you should buy as many $400 systems as you can and resell them for $499 in town. But there’s a problem. You’re short on cash from buying other presents and can only afford one. So the most you can earn is $99.

In finance, this is called arbitrage. It describes an opportunity to profit from price discrepancies in otherwise identical assets. It shows up all over the place in financial markets, and traders at banks and hedge funds regularly take advantage of them. In the example above, you can see the problem — it takes money to make money. But a flash loan enables you to obtain the money you need to make the money. Using our retail scenario, it would allow you to effectively borrow money to buy the $400 game consoles, sell them for $499, and pay back the loan all at the same time.

This isn’t just good for profit-seekers. A fundamental premise of capitalism is that collective buying and selling decisions of individuals result in a price that reflects the underlying value of the asset. But many markets are limited to those with significant starting capital, restricting participation and causing asset prices to reflect the market inefficiency rather than underlying value. By making arbitrage opportunities more accessible, flash loans can open up these markets to anyone, increasing their efficiency and leading to fairer prices.

(3) Improving user experience by combining multiple transactions into one. Refinancing a collateralized debt position (CDP) on MakerDAO is normally a two-step process. First, a user needs to acquire stablecoin DAI. Second, they use the DAI to pay back the loan and redeem their collateral. Each step beyond the first adds friction and fees, which compound with more complicated transactions.

Flash loans directly address this problem by allowing multiple transactions to be aggregated into one. For example, Uniswap lets users swap for an asset that they receive up front, which they only pay for at the end of the transaction. They can use the asset for whatever they want in-between. So in the above example, a CDP owner could swap for DAI, pay the loan and unlock their collateral, and then settle the swap in a single transaction. This aggregation delivers a better user experience and lower fees for the user.

As the number and type of loans originated on a blockchain increases, flash loans could be applied even more broadly. For example, a “smart mortgage” issued on-chain could integrate flash loans to allow borrowers to automatically refinance every time the rate dipped by a couple of basis points. Primitives like flash loans are a consequence of the fact that money on a blockchain is fully programmable. As a result, transactions can be aggregated and simplified to a greater degree than even many modern fintech apps which still operate within the limitations of the existing financial system.

More Innovation Needed

Despite the advantages listed above, flash loans have their drawbacks. An obvious one is their limited duration. So they are not a panacea or drop-in replacement for many existing use cases on their own. And like any new technology, flash loans introduce new challenges as well as benefits. Existing systems in both traditional and decentralized finance aren’t built with flash loans in mind, and therefore may have structural weaknesses that can be exploited by a clever individual leveraging a flash loan to give themselves effectively unlimited capital. There have already been a few cases where flash loans have been used to drain liquidity from Ethereum smart contracts that weren’t designed to account for their existence.

But grappling with tradeoffs is part of human advancement. Users and developers can evolve this technology in a way that mitigates the greatest risk of abuse while retaining the key benefit of removing much of the financial friction and inequality that exists in markets today.

Just as it took the second generation of internet entrepreneurs to show what was truly possible with the internet, the second generation of crypto entrepreneurs will use new primitives enabled by blockchains such as flash loans to create a new financial paradigm that is more open, more capable, and more accessible to all.

Thanks to Spencer Noon, Jesse Walden, Alex Evans, Richard Chen, Santiago Roel Santos, and Anish Acharaya for their input/feedback on this post.

Subscribe to Amor Fati
Receive the latest updates directly to your inbox.
Verification
This entry has been permanently stored onchain and signed by its creator.
Author Address
0x605ACc13c07CB2d…315857fDE7d5C5c
Content Digest
7ce066c04a6562a…fe44269a572956c