Lightning loan: what can an Ethereum transaction do?

Translator & Author: A Jian

Source: Ethereum enthusiasts

Flashloans, the new invention of magical internet currency

The chain has always claimed to change the financial industry, and recently it has finally begun to show signs because young bankers have formed alliances with technical staff.

The latest method is called "flash loan", that is, you can use code to specify a series of operations. As long as your operation can guarantee the repayment in a transaction, you can loan unconditionally .

There are many things that can be done in a "transaction" on the blockchain; not only can you transfer the account once, you can even complete 50 funds transfers in one transaction. Because a smart contract is just like a computer program, when you send a transaction, it is equivalent to "calling a certain function in a smart contract"; in a transaction, you can call many functions, and naturally you can complete many operations.

What Lightning Loan requires is that all operations must be completed within one transaction (you cannot lend funds if you cannot repay within one transaction). So you have to program all the steps into a transaction sent to a smart contract, and include "borrowing, transfer (execution), repayment".

If you cannot repay at the end of the transaction, the transaction will fail, as if nothing had happened.

Suppose, at the beginning, the lightning loan contract gave you 10,000 ETH. If you did not pay 10,000 ETH at the end of the transaction, it means that you have never lent 10,000 ETH, because when the node is executing the transaction, as long as the transaction fails , All operations in this transaction will be rolled back as if nothing happened.

Very counter-intuitive, right? If not all operations are performed and sufficient funds are successfully returned, the ETH will be the same as if it had not been moved.

Well, we also think this is magic. This magic is the latest invention on a Turing-complete network (Turing-complete programming language + auto-executable "accounts" or smart contracts).

All computer nodes running Ethereum software run this Lightning Loan smart contract. When this program (smart contract) is activated by an on-chain transaction, it is equivalent to the contract performing the operation specified by the transaction. If it can be completed at the end If the payment is repaid, the contract sends "execution successful", and the status of the entire network is completed. If the payment cannot be completed, the contract sends "failure", and the status of other contracts affected by the transaction fails. Only the Lightning loan contract is changed. status.

If you hear the clouds and fog, that's normal, because this is a brand new field. You need to understand programming to use this kind of contract because you need to specify each step in a coherent manner. However, if you are willing to spend a few weeks learning Solidity tutorials, you can also get free funds for arbitrage to capture everything that can be profitable in a coherent series of steps.

For example, one guy made $ 360,000 in one transaction! This incident also made Lightning loan catch everyone's attention.

But this is not the only invention in the field of decentralization. For example, Fulcrum has super liquidity; dYdX smart contracts support free flash borrowing, which is the same as flash loan. A new DeFi project, Aave, is also providing such functionality under the name of flash loan.

Another view is that you can turn a CDP (a stable coin bond for users in the MakerDAO single collateral stablecoin system), which is somewhat similar to a permanent loan, into a token like a promissory note. (Translator's Note: Before the MakerDAO system upgrade (November 2019), as long as you provide pledges, you can loan DAI. Interest will not be repaid in real time, only when you repay, so as long as your pledges Enough, you can borrow money to borrow forever, so it is similar to perpetual debt.) … Original address: https://www.trustnodes.com/2020/02/15/flashloans-the-crazy-new-invention- of-magic-internet-money

Lightning boy

The so-called arbitrage is the use of price differences in different markets to make money. Arbitrage opportunities exist in all financial markets, and digital assets are no exception. Arbitrage activities can help reduce the price difference of an asset in different markets, because arbitrage activities can also increase liquidity

The design of Lightning Loan is designed to allow developers to borrow freely without providing collateral. The entire loan and repayment process will be completed in one transaction! Developers can borrow funds from the savings fund pool of the Aave agreement, provided that the liquidity borrowed from the fund pool will be returned to the pool as it is after the transaction is over. If it cannot return so much liquidity, the transaction will fail and roll back, ensuring that the funds in the savings fund pool are not lost.

There are many interesting uses of Lightning Loans, including:

-Arbitrage between decentralized exchanges

-Close positions on multiple lending platforms (Compound, dYdX, etc.)

-Rebalancing, for example: loan DAI from Aave agreement, close your MakerDAO pledged debt warehouse and get your pledge, deposit these pledges in Compound, lend DAI, and then return DAI and some fees to Aave

As a result, more people can participate in arbitrage and liquidation because there is no initial capital requirement. Arbitrage generally has no capital requirements (from $ 100 to $ 10,000), but liquidation requires a large amount of capital to close the debtor's position. Closing positions in Compoud and single collateral DAI (ie, SAI) often requires ETH or DAI worth more than $ 1 million.

To show the limitless potential of Lightning Loan, we did an arbitrage, but in fact it can be used in many other places. You can look up this transaction we issued: <https://etherscan.io/tx/0x4555a69b40fa465b60406c4d23e2eb98d8aee51def21faa28bb7d2b4a73ab1a9>

1 2

(Translator's Note: As can be seen from the two pictures above, the operations involved in the exchange are coherent, transferring funds from the A address to the B address, and then from the B address to the C address, and finally back to the contract address)

Original address: https://medium.com/@bneiluj/flash-boys-arbitrage-dao-c0b96d094f93

On February 15, a hacker mobilized a large amount of funds borrowed, used the Compound protocol to replace assets, interfered with asset prices in the Uniswap market, affected Kyber's quotes, and finally made profits through the leveraged trading function provided by bZx. Everything is done in one block. To be more precise, this is done in one transaction, using exactly the lightning loan function provided by the dYdX protocol mentioned above.

The specific process is not shown here. You can see the detailed analysis provided by the PeckShield and Hydro communities: "Hardcore Technology Analysis, bZx Protocol Attacked by Hacker Vulnerabilities",

DeFi Low Key Sharing | How to Empty Gloves White Wolf 51 BTC

From these detailed analysis, we can know that the key part of this hacker's profit is that he used the borrowed funds to manipulate the price of assets on Uniswap and Kyber, and the bZx protocol uses Kyber as its price information providing mechanism (Also known as the "predictor"), and finally gave the hackers a lot of tokens in the leverage function. After the hackers got these assets and sold them, they could repay the initial loan of Lightning Loan. Of course, the hackers did not even out their leverage in the bZx protocol, that is, they did not pay back.

After the incident, the bZx team used the management key to freeze the hacker's earnings.

This has sparked much discussion throughout the circle, including but not limited to: Is the bZx approach reasonable? Should the DeFi protocol leave an administrator key? Is the decentralized oracle machine safe? The emergence of lightning loans is a good thing or a bad thing.

We don't want to review these discussions here. We just want to discuss a simple question, which may be the question that everyone is most interested in: What does lightning loan mean?

There is a term in computer science called "atomicization", which refers to the ability to ensure that related operations always succeed and fail at the same time when processing transactions, and never fall into a situation where some operations succeed and some operations fail; If it can, it guarantees "atomicity".

If you use a specific example, you will find this concept is no stranger: you want to travel somewhere, you always want transportation and accommodation to be determined at the same time, for example, if you grab a high-speed rail ticket, you want to pick a high-speed rail Stand closer to Hotel A; but if you can't grab a high-speed rail ticket, you will want to pick another Hotel B, and you may even consider changing to a tourist location.

At this time you will find that if you have to determine each item separately, you can only install a lot of apps and switch between them constantly, which is very troublesome. For example, if you do n’t book A, and you ’re afraid you wo n’t be able to book a hotel; if you book A, if you ca n’t get your ticket, you will have to cancel your booking.

But if the processing of these two things is atomic, you can do one operation directly to grab tickets and book the hotel at the same time. If the time fails, the hotel will be automatically cancelled. This can bring great convenience.

By the same token, when you need to transfer to reach your destination, you will also want to buy multiple tickets on the journey or buy them all at once, so as to avoid manual refunds.

It's simple to say and it fits everyone's wishes, but this kind of thing is still extremely rare in our lives. We still have to download many apps and pay attention to many public accounts and applets.

But Ethereum is not the case. Think of Ethereum as a computer and smart contracts as programs. User-initiated transactions are like you are operating a computer. Operations that can be included in a transaction are naturally atomic. The number of programs is the same, but-you can really use these programs all at once, and once an operation does not get the expected results, you can undo all of your operations, as if nothing happened.

Beautiful and powerful to be a bit unreal.

When it comes to DeFi, many people will mention composability. At the beginning, everyone thought that (for example) with MakerDAO, we have stable currency DAI; with DAI, we can do the lending market, and we can also do margin trading (providing leverage). Everyone has two imaginations. One is that these products can be freely combined and there are no access measures to each other. This way, of course, the functions will be more powerful and of course create value. The other is that this means that DeFi The potential of creativity, in the long run, will definitely become more and more prosperous, because the combination of each other will always give birth to more powerful functions.

But neither of these ideas specifies the specific appearance of different protocols when they are combined, nor does it specify the time concept when such a combination occurs. In other words, they are more imagined and elaborated from the perspective of complementary functions, not from the perspective of computers.

However, the concept of atomicity (lightning loan) means that any number of contracts can work together or remain indifferent together in one transaction. Either they really combined in an instant, or when everything happened together.

I can't help but want to say that Lightning Loan is the most extreme form of "combinability", so extreme that everything happens only in a flash.

People have finally discovered that the most authentic aspect of an agreement is to think from the "transaction instant" dimension, just like the example given by the ethical teacher of the founder of the dForce project, borrowing with lightning can instantly transform into the liquidity of Uniswap. After completing the transaction you want, you can quickly withdraw your capital, which can reduce the handling fee from 0.3% to 0.05%. The security of the protocol must also be designed from the "instantaneous" granularity, otherwise the situation of bZx will occur. , Directly penetrated by lightning.

Now people know that the seamless flow of value is both wine and poison, and the DeFi protocol either strengthens the body under the wine or breaks the heart.

Two more interesting things.

First, many friends have felt the destructive power of Lightning Loan, thinking that a large amount of Lightning Loan is like a loaded weapon thrown on the street. However, some friends believe that this is a good thing, because the best way to improve is to directly eliminate the things that do not work; because early detection of problems can avoid accumulating systemic risks.

That's right, now there is a cannon that everyone can actively try to aim at the city formed by the DeFi protocol. Any agreement that cannot be combined into an iron wall defense will be penetrated by the cannon. You do n’t have a good time, weird money blocks, you have a hard time. However, it is believed that the rest are copper and iron walls.

Second, the concept of Lightning Loan should be the earliest proposed by the Marble project, which was mid-2018. But because this project is not profitable, the founding team has been included by other projects (thanks to Tina @ Yellow Hat DAO for the clue). A year later, the concept began to work.

So be patient.

We will continue to update Blocking; if you have any questions or suggestions, please contact us!

Share:

Was this article helpful?

93 out of 132 found this helpful

Discover more

Blockchain

I left the project side and went to the exchange.

In the first article of "Industry Reflection", we briefly reviewed the secondary market conditions of the f...

Blockchain

Will NOVA be the next Pepe? Analysis from the perspective of trading techniques.

"Ten years of speculation in cryptocurrency can all be in vain, but a successful gamble on meme can make you live in ...

Blockchain

EN: Binance has requested "Binance Nigeria Limited" to cease operations.

CEO of Binance, CZ, announced on Twitter that Binance has issued a notice to the scam entity "Binance Nigeria Limited...

News

Inventory of Seven Bills that Could Determine the Future of Cryptocurrency in the United States

Author | DL NEWS compilation | Garyma Wu said the original link of the blockchain https//www.dlnews.com/articles/defi...

Market

Wu's Weekly Picks CoinEX attacked, FTX's coin selling rules, Binance US layoffs, and Top 10 news (September 9-15)

Author | Wu's Top 10 Blockchain News This Week. US August Unadjusted CPI Annual Rate 3.7% Core...

Blockchain

Coinbase becomes Tezos' largest verification node, will it be a new trend for exchanges?

Original: Cryptopotato , original author: Jordan Lyanchev Source: Odaily Planet Daily, Translator: Yu Shunsui Accordi...