Alchblockquoteix Incident Analysis: The Longest Road Took Was Its Own Way
Source: Slow Fog Technology
Originally written by Yudan
On June 16, 2021, Ethereum Defi project AlchBlockquoteix suffered a suspected security issue with the Aleth contract. On the 17th, AlchBlockQuoteix released the accident analysis report. The slow fog security team quickly intervened and analyzed the whole context and core points of the incident based on the official analysis report for your reference.

Too long not to look at the series
This is a long analysis. Here is the conclusion, so that you can have a general understanding. The main reason for this accident is that AlchBlockQuoteix added VAPT three times through Transmuter, resulting in the revenue information being recorded on a wrong element. However, when calling Transmuter's harvest function, the correct index value was not passed in, resulting in the wrong income from the wrong element, and the wrong 4300 ETH income was sent to the Adapter contract to help the user repay the loan of Aleth. The problems that lead to increased revenue lead to tragedy.

According to the accident analysis report released by the authorities, the cause of the accident was that the official Aleth deployment script accidentally created additional VAPTs, causing AlchBlockQuoteix to use the wrong index in the VAPTS array and calculate the wrong reward. As a result, Transmuter used all of its rewards to pay off all of its users' debts. I know this brief analysis is a bit confusing, so we'll have to look at the official deals and see if we can find the truth.
According to the official transaction, we analyze it with ethtx.info. It is not difficult to find that this transaction calls the harvest function of the AlchBlockQuoteisteth contract and passes the parameter _vaptId=0, which finally returns
"4308144937764982868765" and "4308144937764982866415".

To better understand what the Harvest function does, we need to examine the entire function:

As you can see, the Harvest function actually contains two important operations: harvesting the reward and distributing the reward to the Transmuter contract. Where VAPT is a pbrary library contract, where the Harvest logic is implemented as follows:

Through code analysis, it is easy to find that the harvest function of the VAPT repository contract actually checks the total amount of money in the external Adapter, and then calculates the part of the income according to the amount of money in the Adapter minus the amount of recharge by the user.
Here we can think of the Adapter as a pool of policies to manage the user's money and revenue. Then we go back to the Harvest function in the AlchBlockQuoteisteth contract where the user started and find that "4308144937764982868765" and are returned
The two values of "4308144937764982866415" actually correspond to the number of tokens to be withdrawn as calculated by the harvest function of the VAPT repository contract and the number of tokens to be retrieved from the Adapter (policy pool). Since the payoff token corresponding to this Adapter is WETH with an accuracy of 18 bits, then the value "4308144937764982866415" is converted to "4308.144937764982866415" WETH.
In other words, this harvest operation generated over 4300 ETH revenue, which was then distributed to the transmuter contract in the next step through _distributeToTransmuter function. Let's see how the logic of distribution process works:

The logic of the _distributeToTransmuter function is only a simple three lines long, and we focus on the last external call, the LowerHashMinted function. The xToken to which this function corresponds refers here to alETH itself. Because Aleth itself is borrowed by the user, what LowerHashMinted does is use Harvest's proceeds to reduce the total amount of Aleth lent, thereby reducing the amount of Aleth lent per user. In summary, the harvest 4300 ETH proceeds are used to repay the user's Aleth loan.

Just a quick summary
AlchBlockQuoteisteth contract obtains 4300 ETH revenue through harvest function, and distributes this revenue to repay the user's Aleth loan. This led to a situation where users who had lent alETH could get their ETH back without having to pay it back. So why, exactly, is there a profit of 4300 ETH? How does this extra 4300 ETH income come from? In view of this problem, we begin the next round of analysis.
To understand why 4300 ETH is added, it is necessary to understand the fund stored procedure of AlchBlockQuoteisteth. In the AlchBlockQuoteisteth contract, the total top up of the contract is recorded using the Data structure of the Vapt Pbrary library, and then the corresponding top up amount is updated via the FlushActivEvapt function.


The depositAll function inserts the totalValue of the adapter into the corresponding policy pool, so that the user's principal is added to the totalValue of the policy pool at the next harvest. In order to calculate the principal part in the revenue process, we debug the transaction given by the government and find that the principal is only 9000 ETH, and the revenue obtained from the adapter plus the principal is 13000 ETH, that is to say, the principal of 9000 ETH generates 4300 ETH.

However, according to the logic of the above analysis, the user's principal does not generate that much revenue. The problem must be that the Adapter gets the totalValue. In other words, AlchBlockQuoteisteth is not only a recharging token for Adapter, but also has other revenue channels. To test our idea, the Slow Fog Security team analyzed all of the Adapter's token revenue, and sure enough, they found an abnormal transfer behavior that matched the additional 4300 ETH revenue. In other words, that's the problem.

By looking at the transaction data, we find that this is a transaction called Harvest operation, and the contract called is Transmuter:

In other words, the problem is with the harvest function. The logic of the harvest function is as follows:

Vapt's harvest function is also invoked, familiar recipe, familiar taste. When we debug again, we find a surprising fact that the VAPT's totalDeposit was 0 during the revenue process, resulting in the 4300 ETH's revenue being directly distributed to the Adapter, resulting in the wrong totalValue obtained by the Adapter. 4300 more ETH, and that's why.

So at this point, we're pretty close to the truth, and all that remains to be done is why is totalDeposit equal to 0? We queried where the Transmuter contract could change the totalDeposit and found that only the _plantorRecallExcessFunds function could change the value, and that the upper part of that function called distribute function. The distribute function of the transmuter contract is called by the alchBlockQuoteisteth contract at the time of the gain. In other words, the process itself should be:
The AlchBlockQuoteisteth contract calls harvest for revenue
The alchBlockQuoteisteth contract calls the distribute function of the transmuter contract to record the profit and distribute it to the Adapter
Adapter receives Transmuter's revenue and reimburses the user's Aleth loan based on the revenue
But the problem is in the _plantorRecallExcessFunds function. Since _vapts.last() was used to get the latest vapt when recording the recharge information, the recharge information was actually superimposed on the last element. However, the project calls the setactivt three times, so the top up information is actually overlaid on element 3 of the _vapts array, which is the vapt element with an index of 2. However, the _vaptId passed in by the transmuter contract at harvest is 0, element 0 does not have any reload record, so the transmuter contract mistakenly gave all the profits to the adapter. This led to the tragedy.


At this point, it became clear that the AlchBlockQuoteix project party had for some reason added VAPT three times through Transmuter, resulting in revenue information being recorded on the wrong element. The call to Transmuter's harvest function did not pass in the correct index value, resulting in the wrong payoff from the wrong element, which was sent to the Adapter contract, resulting in increased payoff, resulting in tragedy.
Slow fog security team here to remind, DEFI is a complex system, in the operation of DEFI, remember to check every process in the business logic, to prevent accidents, when necessary, you can contact professional security team for professional security audit, to prevent accidents.
Reference link:
Official accident analysis report:
https://forum.alchblockquoteix.fi/pubpc/d/137-incident-report-06162021
Earnings are miscalculated trades
https://etherscan.io/tx/0x3cc071f9f40294bb250fc7b9aa6b2d7e6ca5707ce4d6d222157d7a0feef618b3
The original link
Welcome to join the official BlockBeats community:
Telegram Subscription Group: https://t.me/theblockbeats
Telegram Discussion Group: https://t.me/BlockBeats_App
Official Twitter Account: https://twitter.com/BlockBeatsAsia