Introduction

EIP-1599 (for more details see here or here) is an improvement of an existing auction-based fee market in Ethereum network that introduces a basefee and a tip. The basefee will be paid by the user and afterward burned by the protocol, while the tip will be paid by the user directly to the block producer.

The goal of this research is to examine if the manipulation of the basefee is possible and what the cost of such manipulation is. We analyze two cases:

1. A lone wolf submitting crafted transactions to manipulate the basefee

How the basefee works

The value of the basefee is calculated according to the following formula:

delta = gas_used - TARGET_GAS_USED
new_basefee = basefee + basefee * delta // TARGET_GAS_USED // 8

It means that after an empty block (gas_used = 0) the basefee will be equal to:

new_basefee = basefee + basefee * (0 - TARGET_GAS_USED) // TARGET_GAS_USED // 8
new_basefee = basefee - basefee * TARGET_GAS_USED // TARGET_GAS_USED // 8
new_basefee = basefee - basefee // 8
new_basefee = basefee - 0.125 * basefee
new_basefee = 0.875 * basefee

Analogically for a full block (please note that EIP-1559 allows for the extension of blocks), the basefee will be equal to:

new_basefee = basefee + basefee * (2 * TARGET_GAS_USED - TARGET_GAS_USED) // TARGET_GAS_USED // 8
new_basefee = basefee + basefee * TARGET_GAS_USED // TARGET_GAS_USED // 8
new_basefee = basefee + basefee // 8
new_basefee = basefee + 0.125 * basefee
new_basefee = 1.125 * basefee

To sum up, the full block increases the basefee by 12.5% and the empty block decreases the basefee by 12.5%. It means that if somebody wants to increase the basefee to some value, they should generate some number of full blocks. Analogically if somebody wants to decrease the basefee then empty blocks should be generated.

Here it is also worth pointing out that empty blocks will drop the basefee faster than full blocks. For example, let’s assume that we have 10 empty blocks generated one after another. In this case the final basefee will be equal to:

new_basefee = basefee * 0.875 * 0.875 ... * 0.875
new_basefee = 0.2631 * basefee

After 10 full blocks it will be:

new_basefee = basefee * 1.125 * 1.125 ... * 1.125
new_basefee = 3,2473 * basefee

In other words after 10 empty blocks the basefee drops 3.8 times and after 10 full blocks it increases “only” 3.25 times. So after 10 empty blocks and 10 full blocks, the basefee will not come back to its original value and will be equal to 0.2631 * 3.2473 * basefee = 0.8543 * basefee.

Simulation 1 — a lone wolf

In this simulation, we consider a lone wolf (or a wolf pack) who only submits crafted transactions and does not mine blocks. By doing that, the lone wolf wants to increase the basefee to a specific value. We also assumed that the lone wolf will not start the manipulation if the basefee is dynamically changing (in one direction or another) because we want to estimate the manipulation cost in isolation from other factors. The simulation takes this into account and it waits until the basefee stabilizes before trying to manipulate it. Additionally, we assume that the lone wolf wants to increase the basefee as fast as possible so in this simulation it submits as many fake transactions as needed to fully fill the next block and that it always pays the gas premium = 1 gwei (for more details see also the appendix).

While running the simulation, we calculate the cost of the manipulation as the sum of costs for each individual block. The cost per block is equal to:

cost_of_manipulation_for_current_block = gas_used_by_crafted_transactions  * current_gas_price

After starting the simulation, the basefee stabilized on the level of around 187 gwei and the target basefee for the manipulation was set to 10 x 187 = 1870 gwei. Later on, we also use the term manipulation ratio which should be understood as a ratio between the target and the initial basefee. In our case, the manipulation ratio is equal 10.

It turns out that this kind of manipulation finishes after only 20 blocks and the total cost is ~277 Eth. What is also very important is, it is always successful while the network does not play against this kind of manipulation (compare with the next simulation).

The number of blocks needed to perform this kind of manipulation can be calculated as:

N = ceiling(log1.125(manipulation_ratio)) = ceiling(log10(manipulation_ratio) / log10(1.125)).

In the formula above 1.125 is a base of a logarithm because the basefee increases by 12.5% after each full block = 1.125 times. This formula gives the upper limit while it assumes that the manipulator will need to fill N blocks on his/her own. In practice, it may be less.

The total cost of the manipulation is equal to:

cost_for_block_1 + cost_for_block_2 + ... cost_for_block_N

In the formula above, we start counting blocks from the first block with crafted transactions. cost_for_block_n can be replaced with:

cost_for_block_n = gas_used_by_crafted_transactions * gas_price_for_block_n

We know that each block is fully filled with transactions that gives us:

cost_for_block_n = 0.02 * 10^9 * (basefee_for_block_n + gas_premium)

Now we know that:

basefee_for_block_2 = initial_basefee * 1.125
basefee_for_block_3 = initial_basefee * 1.125 * 1.125
...

What is a geometric series and it’s sum can be calculate as:

a1 * (1 - q^N) / (1 - q)

Where a1 = initial_basefee and q = 1.125 what finnaly gives us:

0.02 * 10^9 * gas_premium * N + 0.02 * 10^9 * initial_basefee *  (1 - 1.125^N) / (1 - 1.125)
0.02 * 10^9 * (gas_premium * N + initial_basefee * (1 - 1.125^N) / (1 - 1.125))
0.02 * 10^9 * (gas_premium * N + initial_basefee * (1.125^N - 1) / 0.125)
0.02 * (gas_premium * N + initial_basefee * (1.125^N - 1) / 0.125) gwei

Simulation 2 — the miners cartel

A lone wolf can manipulate the basefee only by increasing it. A cartel being in possession of a specific amount of the hashpower can manipulate the basefee in two ways. Firstly, it can produce empty blocks which will decrease the baseefee. Secondly, it can theoretically produce full blocks that will increase the basefee. In the previous section, we showed that this kind of manipulation is relatively easy to be performed by a lone wolf and requires no cartel. To add depth to the analysis, we consider here a theoretical scenario when the network does not play alongside the cartel (no artificially created transactions are included in the blocks created outside of the cartel). Such scenario is unlikely to happen in practice since miners do not have tools nor incentives to exclude artificially generated transactions.

While running this simulation we also calculate the cost of the manipulation. Generating empty blocks and full blocks implies different costs to the cartel. For empty blocks the cost is equal to:

cost_for_cartel_for_current_block = lost_tip

And in the second case it is:

cost_for_cartel_for_current_block = gas_used_by_crafted_transactions  * current_basefee

In this case, the manipulation also started when the basefee was stabilized at the level of around 185 gwei. The target basefee was set either to 185 / 10 = 18.5 gwei or 10 x 185 = 1850 gwei.

Let’s analyze the results. The general observation is that the network plays against the cartel. If the cartel wants to decrease the basefee, then other users are more and more willing to submit transactions which fills blocks and increases the basefee. It works in an analogical way in the opposite scenario. If the cartel wants to increase the basefee, then other users are less and less willing to submit transactions which leads to more and more empty blocks and decreases the basefee.

The first diagram shows the percentage of successful manipulations depending on the hashpower controlled by the cartel. Firstly, it must be pointed out that, in order to perform a successful manipulation, the cartel needs to control a significant percentage of the network, i.e. around 35%. Nonetheless, in this case the chance of a successful manipulation is negligible, i.e. 0.1%. To have a 25% chance of a successful manipulation, more hashpower is needed, 47% for the manipulation ratio = 0.1 and around 50% for the manipulation ratio = 10 respectively.

It is also worth pointing out an anomaly here for the manipulation ratio = 10. We can notice that, one manipulation out of 1000 succeeded for the hashpower = 35% but, zero manipulations succeeded for the hashpower = 40%. The reason for this anomaly is a random nature of this simulation and it can be ignored as an outlier.

To sum up, it is much easier to perform a manipulation if the manipulation ratio = 0.1, than when the manipulation ratio is equal to 10. It happens because the basefee drops faster after empty blocks than it increases after full blocks.

The next diagram shows the cost of the manipulations. In the case of the manipulation ratio = 0.1 it is very low. It is only the cost of lost profits. The situation is totally different if we want to increase the basefee. In this case, the cost reaches > 800 Eth, and at the same time, the probability that the manipulation succeeds is only 25.9%. The cost is so high because the bigger the basefee, the smaller number of users are willing to pay it. It means that at some point, the cartel needs to fill blocks only with fake transactions and pay for that. The “strange” peak of the cost for the manipulation ratio = 10 and for the hashpower = 35%, is due to the anomaly mentioned before.

The last diagram shows the number of blocks that were needed to perform manipulations. Here we can observe that both kinds of manipulations require a similar number of blocks to be performed. Nonetheless, the differences are not significant. The “strange” peak of the number of blocks, for the manipulation ratio = 10 and for the hashpower = 35%, is again due to the anomaly mentioned before.

Summary

1. If somebody wants to increase the basefee, it is enough to produce fully filled blocks by submitting fake transactions. In other words, to perform this kind of manipulation one does not need to have any hashpower — this kind of manipulation will not be performed by cartels.

Appendix — how simulations work under the hood

Both simulations (for a lone wolf and for the miners cartel) were created based on abm1559 library and have the following parameters:

1. The number of iterations. All the results are averaged across all the iterations

1. The value of each transaction is drawn from the normal distribution with the mean = 50 and the standard deviation = 150. While for these parameters negative values can be generated, the absolute value is taken

A lone wolf

The simplified flow of the simulation for a lone wolf are as follows:

1. Initially, the simulation is run in order to reach the basefee stabilization

I. First, it analyzes the current state of the transaction pool to figure out which transactions will be included in the next block

II. Then, it looks at the last found transaction to see the max fee it pays

III. In the next step, it is calculated how much space will be left in the next block

IV. The manipulator submits as many fake transactions as it is needed to fully fill the next block. All these transactions have the gas premium set to 1 gwei and the max fee is set to the max fee found in the previous step

V. Finally, the basefee is updated and it is checked if the target basefee was reached. If not, the simulation is continued

This simulation was run for the following parameters:

1. The number of iterations = 10

The miners cartel

The simplified flow of the simulation for a cartel are as follows:

1. Initially, the simulation is run in order to reach the basefee stabilization

I. It is decided if a block is mined by a cartel or a network. It is done by randomly selecting a number X from 0 to 100%. If X < Y (Y is the percentage of the network controlled by the cartel) then the block is mined by the cartel

II. If a block is mined by the network then it is filled by transactions from the transaction pool and added to the chain. The lower the basefee, the more the block is filled by the network

III. If a block is mined by the cartel and the cartel wants to increase the basefee then it generates the full block by -

a) Adding to the block transactions from the transaction pool

b) Adding as many fake transactions as it is needed in order to fully fill the block

IV. If a block is mined by the cartel and the cartel wants to decrease the basefee then it simply generates the empty block

V. Finally, the basefee is updated and it is checked if the target basefee was reached. If not, the simulation is continued.

The simulation was run for the following parameters:

1. The number of iterations = 1000

WRITTEN BY @mkomorowski / michalkomorowski.com

We look forward bringing you even more exciting content in the near future. In the meantime, be sure to follow along on socials to keep updated with all the latest news and announcements, and sign up for our newsletter if you’d like to get it all straight to your inbox.

Nethermind.eth

From out of the Ether and into reality

Various technical tutorials and blog posts on #ethereum, #ethereum2 #eth2 and DecentralizedFinance #DeFi Nethermind.eth

Various technical tutorials and blog posts on #ethereum, #ethereum2 #eth2 and DecentralizedFinance #DeFi