or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
Path-dependence problem with EIP-1559 and a possible solution to this problem
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →alidarvishi14@gmail.com
with help from https://github.com/barnabemonnot/abm1559
Introduction
EIP 1559 is an upgrade to the economic model of Ethereum gas fee. Proposed by Vitalik Buterin in his Blockchain Resource Pricing paper, this mechanism is going to replace the first-price auction model governing the current fee market for transaction inclusion.
The basefee and EIP-1559
As discussed in EIP-1559, users have to pay a basefee that will be burned for each transaction. Basefee is updated with a multiplicative rule derived from the size of the last block. If the last block size is more than the target size, basefee will increase, and if the last block is not full enough, basefee will decrease.
In this proposal basefee is updated according to the following formula:
\[delta=gas\ used-target\ gas\ used\]
\[new\ basefee=basefee+basefee\times\ \frac{delta}{target\ gas\ used}\times\frac{1}{basefee\ max\ change\ denominator}\]
Here we declare and proof a statement:
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →So assuming that the cumulative deviation of the sum of gas cost from the sum of target gas cost is bounded (has a finite upper bound which can be arbitrary large enough), then gas price converges to zero unless the gas used in each block converges to the constant function equal to the target gas (which will never happen in reality). Therefore for a large enough sequence of blocks, we would expect that difference between the sum of gas used and the sum of the gas target is going to grow.
In this part we are gathering data to show that this has happened after the London upgrade.
Finally, we compare the histogram of gas used in each block before and after the London hard fork. As one can see, the target which is the full block size is achieved most of the time pre-fork. However as a result of the predicted oscillations, we observe a bimodal density post-fork where the target which is the half block size is rarely achieved.
The simulation of permanent loss
We will simulate the basefee parameter in EIP-1559 and show in a world where only 5% of users are rational enough to optimize for paying less fee if possible, the basefee will eventually decrease to 0.
Later, we are going to show that an additive equation for updating basefee would solve this problem.
First, we implement a class for transactions. In this class we store important data. Users specify these parameters:
Then, we import some libraries.
We declare some constants.
Here, we declare a demand function that generates new transactions for each block. Gas premium and fee cap are generated randomly.
In this simulation, we assume that only 5% of the transactions are not an emergency and can wait for at most 10 blocks, and the other transactions will be sent immediately after creation.
We can simply see that a rational choice for a user is that if the user thinks basefee will increase, he should send the transaction immediately, and if basefee is going to decrease, he should wait for at least one block. If sent orders fill 50% or more of the block, patient users will wait.
Declaring a block and a function to check the validity of transactions.
This function is going to include valid transactions in the next block.
Update basefee after each block as mentioned in EIP-1559.
Save last block in results.
Run simulation and save the results in a data frame.
In this plot we show basefee as time passes. We can see basefee is not stable and decreases with time.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →An unintentional uncoordinated attack
Now assume a percentage of users with a considerable number of transactions (like the users of a wallet client designed to have this optimization as a built-in feature) want to pay less basefee, even though, they do not intend to manipulate it. They can simply do so by sending all of their transactions in a more-than-target full block and not sending any transactions in blocks with a size considerably below the target size. This action would make basefee decrease over time and eventually converge to zero. We have to incentivize such honest but rational users to smoothly send their transactions instead of sending them in bulk.
A possible solution to this attack
The problem of sending a large number of transactions is equivalent to the problem of liquidating a large portfolio as discussed in "Optimal Execution of Portfolio Transactions". It is shown in this paper that with an additive cost function, the trader's optimal execution of transaction strategy is to distribute the transactions across time. Therefore, if we update basefee with an additive rule, users are incentivised to gradually send transactions during a long period of time and spread them across different blocks which in turn helps to avoid network congestion.
In this section, we change
update_basefee
function with an additive fucntion which is convex in basefee and gas_used jointly.Run simulation with the new update rule.
And finally plot the two plots together.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Relation to constant function market makers
This is interestingly related to the concept of path independence in automated market makers (see section 2.3 in here). Consider a hypothetical automated market maker as a protocol-level price oracle for the trading pair GAS/ETH whose reserve of gas and ether after the n-th trade are \(g_n\) and \(f_n \times g_n\), respectively. Moreover, let \(g_{n+1} = g_n + M/2 - w_n\), that is, \(g +=\) excess. It can be proved that, the limit of \(f_n\) as the initial reserve \(g_0\) goes to infinity is given by:
This observation immediately implies that both of these update rules (and any other one based on another constant function market maker) are path-independent. Ironically, this is exactly why we have arrived at these formulas in the first place when attempting to solve a simple instance of path dependence attacks.
An improvement for the premium
Even with EIP-1559, the problem of overpayment in the first price auction (winner's curse) remains relevant for the premium. A very simple solution, in terms of Kolmogorov complexity, is to use a sliding median which is more stable and predictable than the first price auction.
It is well-known that median is a robust statistic but to show this in practice, we first download the gas fee data from the Ethereum blockchain.
Before we begin, some plots from the raw data (gas price will be normalized later):
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Now, we throw out the
round_gp_10gpwei
column and divide thegas_price
by 108. Then we group our gas prices data by the blocks and we compute a summary (min,median,mean,max
). The blocks are consecutive and their numbers are made to start from zero in order to have a bit more visually appealing plots!Here are some plots.
geom_smooth()
uses by default the Local Regression (loess
for short):Loess Regression is the most common method used to smoothen a volatile time series. It is a non-parametric methods where least squares regression is performed in localized subsets, which makes it a suitable candidate for smoothing any numerical vector.
To show the effectiveness/stability of median over other methods, we plot the data points along with the prediction curve of each (
min,median,mean,max
). Notice the scale ofmax
is quite different therefore, although it seems stable its prediction curve has much higher errors than median. See the last two plots to compare the scale of their fluctutations.Here is the max, median, and min statistics summary plot:
Here is how the mean and median and minimum curves compare:
Here is how all curves compare:
Summary and further resources
Designed an attack for EIP-1559 and proposed an alternative transaction fee pricing protocol based on the Almgren–Chriss framework and median price auctions.