Front Running: The Achilles heel of decentralized trading

Written by: Li Hua

Source: Chain News

Acknowledgements: Guo Yu, Sun Zhipeng, Wu Weilong, Anxiety Research Institute

In "Edge of Tomorrow", various human tactics are ineffective against invading aliens, because once this tactic takes effect, after the aliens are killed, the time will be returned to the time before the battle. Do it again. In this new time, aliens know what will happen, and of course they know how to respond.

1

Slogan for Edge of Tomorrow: Reincarnation

In the blockchain, there are also people who know what will happen. Not only do they know what will happen in the future, they can also use this information to act like aliens in Edge of Tomorrow to generate a future that is good for them.

Where does all this start? Let's start with the recent lightning storm incident.

The beginning and end of the lightning loan incident

The method of making money by hackers in the Lightning Loan incident is no different from that of you and me: buy low and sell high. The only difference is that the hacker knows where the low point is and where the high point is. Why does he know? Because the person who is about to raise the price is himself.

A simulated attack process just to illustrate the principle is this: 60 ETH is borrowed through dYdX's flash loan function, then 40 ETH is loaned at Compound to lend 1 BTC, and the remaining 20 ETH is bought at bZx plus 5 times leverage BTC, the liquidity of this leveraged transaction is provided by Uniswap, causing the price of BTC on ETH on Uniswap to skyrocket. At this time, 1 BTC is sold to Uniswap. Assuming the average selling price doubles, you can sell 80 ETH. Drop the first 60 ETH borrowed and make a profit of 20 ETH. (For the actual process, please refer to the reference materials 1 and 2 at the end of the article.)

2

Picture from CryptoLaboratory

It can be considered that the hacker has two avatars, one avatar (20 ETH × 5 = 100 ETH), and two avatars (40 ETH). In this process, the money made by avatar two and the money made by Uniswap market maker are added. It should be equal to the money lost by the split, that is, the hacker loses money overall, but because bZx has a contract loophole, and the split position has not been exploded in time, the bZx saver also took the loss together, and this is exactly Why hacking can be established. The role of Lightning Loan in the whole incident is only to provide initial funding, so that hackers can complete the attack without cost and risk.

However, the attack itself is not the focus of this article. This example is described because it clearly shows one thing: if you know that someone will buy a lot in the future (the market will have large price fluctuations), "Ambush" before buying to achieve profitability. Visually, if A plans to buy a large amount of ETH, and B knows A's purchase intention, he can rush to buy ETH at the current price before A, and then sell it at a higher price to earn the difference.

In traditional financial markets, this behavior is Front Running. Front Running means: if you know in advance from large-scale transactions that will affect the price of assets, you can buy and sell in advance to make a profit.

It mainly contains two cases:

Before executing the client's buying and selling order, the dealer believed that the client's buying and selling would change the market price, so he bought and sold his account first; the broker's buying and selling of stocks before the research report published by him was widely distributed.

In the decentralized transaction market on the chain, Front Running is similar to the first case described above. After learning about the other party's purchase intention, it is the first to complete its own transaction. This behavior is illegal in traditional financial markets because it uses non-public information, but it is difficult to identify it as illegal on the blockchain because it uses "public" information.

Due to the special nature of blockchain time, the future on the blockchain can be "seen" before it happens, that is, we know that a transaction will happen before a transaction occurs, just like executing a customer sale The commissioned dealer knows that buying and selling will happen the same.

Time specificity of blockchain

Blockchain is a distributed system. One of its biggest problems is that participants cannot reach consensus on physical time. But in order to determine the order of transactions and avoid double spending, it is also very important for network participants to reach a consensus on time. Therefore, Satoshi Nakamoto combined the proof of work with the longest chain principle to implement the time stamp service: using the sequence of blocks Representing the order of time, participants only need to agree on the order of the blocks. You can think of a block as the basic unit of time on the blockchain.

So, how to convert the unit of minute time of a transaction into the unit of block time?

After the transaction is submitted, it will enter a place called the transaction pool, and there are many other transactions. The mining union selects transactions from the transaction pool and packs them into the next block. These transactions have a default priority. Physical time is a factor that determines the order, but it is not the most important factor. For example, miner fees are far more important than physical time. Only transactions that are selected to enter the next block will be converted from minute-to-second time units to block time units, and only after this conversion is completed can the transaction truly occur on the blockchain.

It is not difficult to find that transactions must first occur in physical time, then wait in the transaction pool, and finally occur on the blockchain. This indeterminate waiting process can lead to exposure of transaction intent, making Front Running prone to happen.

Who can see exposed trading intent? The most typical are miners. Miners are people who package transactions.They can not only see the transactions, they even know which transactions will enter the next block, and the order of these transactions in the same block. From a technical point of view, miners can insert their transactions into appropriate positions through intervention in the transaction order. No one has an advantage over miners in Front Running.

In addition to the miners, each of us can also see the transaction intent. Because the transaction is first broadcast to the network and then enters the transaction pool, and everyone can listen to the transaction broadcast. For traders and trading robots on DEX, they only need to monitor the transaction situation on DEX. After discovering the transaction intent, they can increase their transaction fees to make their transactions come to the front, thus completing Front Running and achieving risk-free profit. .

But Front Running is obviously unfair. It destroys the trading strategies of normal traders and damages their trading interests. An inaccurate but illustrative example: you plan to buy 100 ETH from the market, the average possible price is 270 USD / ETH; but the trading robot first buys when it finds your transaction intention, it is bought at 270 USD / ETH , And you may have to buy it at the increased price of 280 USD / ETH, which costs an additional 1,000 USD.

In this case, how is it possible for people to make large-scale transactions on DEX? Every transaction has the potential to be "oiled." As long as Front Running exists, DEX will be difficult to scale.

Flash Boys on DEX

In 2019, Philip Diane, an active Cornell University blockchain researcher, and his colleagues published a paper entitled "Flash Boys 2.0: Preemptive Transactions in Decentralized Transactions, Rearrangement of Transactions, and Unstable Consensus" , Analyze the situation that the trading robots on the blockchain perform preemptive transactions by increasing transaction fees and reducing network delays.

Flash Boys is derived from the book "Flash Boys: A Wall Street Uprising" by Michael Lewis, author of "Big Shorts", and refers to a group of high-frequency traders on Wall Street.

3

Flash Boys: A Wall Street Uprising by Michael Lewis

Front Running on the blockchain will be compared with High Frequency Trading because they have certain similarities.

High-frequency trading puts "bait" orders on all exchanges. These small orders provide the lowest selling price and the highest buying price. When a large transaction is split into multiple transactions and completed on multiple exchanges, they These bait are always encountered first, so that their trading intentions may be exposed (there are other ways to predict the situation of the transaction together); at the same time, high-frequency trading uses better technology and more "straight" Online, buy and sell related stocks on various exchanges before the rest of this big deal is completed, and then make money through price differences.

How profitable is high-frequency trading? We can find an interesting way to push back: Lewis once talked about a person who works for Citadel Securities. His salary is $ 90 million per year, but he later left in anger because he felt that the company did not pay him enough.

Both high-frequency trading and Front Running on the blockchain include two basic components: discovering the transaction intent and completing the transaction first. It is just that the former discovers the transaction intention through "bait", and the latter discovers the transaction intention through monitoring; the former advances its own transaction through better technology, and the latter advances its transaction through higher transaction fees.

The difference between the two is that the time window for high-frequency transactions is very small, and everyone races in nanoseconds. This has extremely high requirements for high-frequency trading systems; while Front Running on the blockchain is basically Affected only by transaction fees, the more money you make, the more you can get ahead.

Overall, in terms of transaction methods, Front Running on the blockchain is closer to high-frequency transactions in traditional financial markets, but it has replaced higher "straight" network cables with higher transaction fees. From the nature, the degree of unfairness, and the damage to the market, it is closer to Front Running in the traditional financial market. However, this transaction behavior on the blockchain is not illegal, so it cannot be banned. .

Solution

To avoid the problem of Front Running in decentralized transactions, you need to start with the design of the DEX itself. Different characteristics of the DEX protocol may develop different methods.

Front Running in the Dutch auction mode is difficult to occur. Typical representative is DutchX. The competition between transactions is mainly based on price rather than "time", and these transactions are executed at the same price. Front Running is not profitable. However, due to the long time it takes for Dutch auctions to complete, time-sensitive trading needs cannot be met with DutchX.

The DEX protocol in the automated market-making mode is more difficult to block Front Running, such as Uniswap, which automatically adjusts the price according to the available liquidity. The size of the transaction has a large impact on the quote, and the order of transactions determines the price of the transaction. In order to reduce the damage caused by Front Running, Uniswap's approach is to allow users to specify the maximum price of the transaction, so that the user may not be able to complete the transaction, but will not complete the transaction at an unacceptably high price. But this is an expedient, and the real solution to the problem needs to be further explored.

The most widely used DEX protocol based on the order book model is currently based on the difficulty of combating Front Running between the first two types of protocols. The impact of Front Running can be reduced through the design of the DEX: the method that has been applied is to introduce some centralization, such as the completion of order matching by the administrator off-chain, and restricting the administrator to only submit to the chain for settlement; The developing method is to use zero-knowledge proof to hide the trade intention of the trader. According to the existing experience, it seems that using cryptography to solve the problems on the blockchain is the ideal way.

Front Running is a common problem faced by DEX and an important reason preventing DEX from becoming a mainstream choice. But with the development of technology, we may circumvent or control Front Running. This article discusses the problems of DEX, but these problems cannot be used to prove that DEX is not a good choice. We discuss it precisely because it is worth discussing.

References

"Arbitrage logic Bzx Lightning credit events, the break-even analysis and sensitivity testing" by: natural; "PeckShield: hardcore technical analysis, bZx agreement by hackers exploit the whole story," Author: PeckShield; "Lightning Credit: sum Ethernet Square What can transactions do? "Author: A sword;" when talking about the issue to the center of the Exchange Front-Running of, what are we talking about? "Author: Crowe said; https: //bihu.com/article/1695326980

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

Hackers are getting smarter, with the largest number of exchange attacks ever in 2019

Source | bitcoinmagazine Translation | Huohuo Sauce Production | Blockchain Camp (ID: blockchain_camp) Currently, maj...

Blockchain

DeSpread Research Data Analysis of Centralized Exchanges and Investor Behavior in South Korea

According to a survey by the Korea Financial Intelligence Unit (KoFIU), it is expected that the number of cryptocurre...

Blockchain

Interpretation of wallet data: The exchange holds more than 12.4 billion mainstream currencies, who is the largest Holder?

QUICK TAKE The cryptocurrency exchange currently holds at least $12.4 billion in Bitcoin, Ethereum and USDT (Tether) ...

Blockchain

Market Weekly | The market is in a consolidation period, and the exchange has picked up

Weekly summary Last week, the average daily market value of global digital currency assets was 326.973 billion US dol...

Blockchain

Long text: the change of the encrypted asset exchange and the risk challenge

Encrypted asset exchanges, like traditional exchanges, are products that develop to a certain period of time. With th...

Blockchain

Interview with Justin Sun: Web3 Yu'ebao stUSDT, Tron's Ambition to Connect DeFi and TradFi

stUSDT allows users to access low-risk and stable investment opportunities in national bonds, and supports flexible w...