Arbitrage logic, profit and loss analysis and sensitivity test of Bzx flash loan event
星球君的朋友们
2020-02-20 06:19
本文约3118字,阅读全文需要约12分钟
An unprecedented form of attack.

Editor's Note: This article comes fromEditor's Note: This article comes from, Author: Zhang Tianran, reproduced by Odaily with authorization.

image description

Five Arbitrage Steps for Bzx Events, PC: Peckshield

There are quite a few blockchain technical analyzes of the Bzx flash loan incident this time, but the data and business logic analysis is still lacking in addition to some basic factual data, so try it here

If you want to have a clearer understanding of the events and technical analysis, please refer to these links (in English)

Bzx official review

Analysis of Peckshield

secondary title

background and logic

Here is some background. Bzx is a leveraged trading platform, so it is naturally divided into two parts, lending and trading. The borrowing is Bzx’s own, and the trading is connected to Kyber. Kyber has many liquidity pools, one of which is Uniswap, Kyber The price system is to choose the best price in its pool. In this incident, Uniswap has been used for the best price, so Kyber has basically not played a role. In addition, leveraged transactions can be completed on a platform like Bzx, or you can go to a third-party platform to borrow money and trade. Just like another part of this incident is to borrow money from Compound to trade on Uniswap. In a brief summary, the main players in this event are two lending platforms, Bzx and Compound, and a trading platform, Uniswap.

As for the nature of financial arbitrage here, there is an analogy to a traditional financial case. Before Google’s financial report, it opened a hundred times more and opened short at the same time. For example, if the price rises by 5%, then the short position will be liquidated, and the double will be gone immediately. The long side makes money, earns five times, and the two ends offset, the trader earns four times, and the platform loses four times. This set of logic has been corrupted and banned in the traditional market.

In this defi incident, the two platforms for borrowing money and increasing leverage are different. One end is Bzx borrowing money to trade and liquidate the position, and the other end is to make money by trading Compound. But since the trading platform is Uniswap without a counterparty, the logic is not exactly the same. Here, it is assumed that everyone understands Uniswap's basic product logic and price trend rules.

It doesn't matter if you talk about Oracle, and Kyber doesn't blame it. If you want to take the blame, Bzx will take part, and Uniswap will take part.

secondary title

Analysis of Profit and Loss Analysis and Sensitivity Test

Starting from the beginning, first borrowed 6,800 eth from Dydx with flashloan, and obtained the operating principal, of which 1,300 went to Bzx, and 5,500 went to Compound. Then Bzx’s 5x leverage (mortgaging 1300eth to borrow 5637eth) went long, and Compound’s side borrowed coupons (mortgaging 5500eth, borrowing 112btc, equivalent to 4400eth) to short. The effect is that 5637eth on the Bzx side was replaced by 51 btc, and then 112 btc on the Compound side was replaced by 6871 eth.

In terms of price fluctuations, the original normal price of btc/eth was about 39. On the Uniswap curve, the average price of the Bzx pull was 108, which means that the price may be 200 at the end of the pull. The same curve is reversed, and after offsetting, the average price of the excess is about 20 [(6871-5637)/(112-51)=20], so the lowest price may be 10.

Compound’s normal 1.25 times over-mortgage, took out double the equivalent of BTC, forced to go back and forth twice through the Uniswap curve, and sold 1.56 times of eth, exceeding the mortgage amount. (From here onwards, 1 times refers to 112btc or 4400eth)

The result of the final profit and loss data is that the transaction of Compound earned 0.56 times (the deposit of 5500eth, took out 4400eth equivalent btc, and sold it as 6871eth=2471eth). The loss on the Bzx transaction itself should be 0.83 times (5637-2000=3637eth), but Bzx’s collateral is only 0.3 times (1300eth), so the net loss is about 0.53 times (2337eth), which is borne by Bzx depositors, who are the losses principal. The problem reflected here is that the large Uniswap transaction on the side of Bzx will obviously lead to insufficient collateral and liquidation, but it has not been suspended.

For the hacker, adding up the two ends, Compound earns 0.56 times (2471eth), and the cost of Bzx needs to be deducted 1300eth, leaving 1171eth, and the profit is about 0.26 times

If you calculate the general ledger, Bzx has a loss of 0.83 times and Compound has a profit of 0.56 times. Where does the remaining 0.27 times go? This is due to the slippage of Uniswap. As mentioned earlier, after going back and forth on Uniswap twice, the average price of the excess is about 20 [(6871-5637)/(112-51)=20], so here is a loss-making shipment, which is about 61 btc on Uniswap. Selling at 50% off the average price. It is the market-making pool on Uniswap that takes advantage.

Question 1: The Uniswap curve goes back and forth twice, can it cancel each other out, can it only take the remaining part after the offset?

The answer is no. If we only discuss the part that offsets each other, we can see that originally there were 5637 eth on the Bzx side, and 51 btc on the Compound side. After the first step is completed (the Bzx side sells eth for btc), there are 51 btc left on the Bzx side . After the second step was completed (the Compound side sold btc for eth), there were 5637 eth left on the Compound side. It can be said that the transfer of wealth from the Bzx side to the Compound side is completed by pulling and smashing. This is a unique phenomenon of Uniswap. There is no benchmark in the traditional world. This is also the core logic of this financial arbitrage. Therefore, in order to create 0.56 times the profit of the Compound side, it is necessary to walk the Uniswap curve twice. The Bzx side must be pulled to the top first, and then the Compound side must be pulled down, and then the extra unoffset part is counted to sell 6871eth , profit 0.56 times (2471eth).

Question 2: If there is no problem with the risk control on Bzx and the warehouse is not broken, that is, only 1300eth of collateral is spent and depositors have no losses, can hackers make money?

The answer is not sure. If you earn, it will definitely be less than the current one, and you may also lose money, because the Uniswap curve has not reached such an extreme position. After that, 1 times the funds will not be able to pull out the effect of 1.56 times. If 1.3 times If it is not pulled out, it will not be able to cover the cost of 1300eth on Bzx, and it will lose money. Even if it is covered, it will still earn less than before.

Question 3: If Bzx borrowed 2800eth (the original was 1300eth), and then only opened 2 times the leverage to go long (the total loan amount remains 5637eth, is it okay?

Bzx will still be liquidated, because the loss is 3637eth, and the collateral is only 2800eth. On the other side, Compound made 2471eth, less than the collateral 2800eth lost here, so hackers lost 329eth, and Bzx depositors lost 837eth. This will create an n-lose situation...only Uniswap's liquidity providers will profit. Of course, this is the case for executing transactions. If the hacker finds that the transaction is not profitable, the transaction will not be executed.

When 5637 eth were used to pull the disk, the price has reached about 200, and the price will only get worse after that, so assuming that the extra 4763 eth is only exchanged for 15 btc, a total of 10400 eth is exchanged for 66 btc. The 112 btc on the other end can certainly buy back all 10,400 eth, but there will be 46 more btc, which is less than the previous 61 more btc. The average price of these 46 btc should be slightly higher than the average price of 20 of the 61, such as 22, then a total of 112 btc were sold to obtain 11412 eth. Compared with the principal of 4400eth, the profit was 1.6 times, and the deduction was 0.3 times (1300 eth). The hacker made 1.3 times the profit, 5700 eth, much higher than the previous 1171 eth. Bzx depositors will lose more than before

Note:

  • Note:

  • All btc in this article refers to wbtc;

星球君的朋友们
作者文库