This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

11institutetext: Imperial College London, United Kingdom
11email: {sam.werner16,paul.pritz18,daniel.perez}@imperial.ac.uk

Step on the Gas? A Better Approach for Recommending the Ethereum Gas Price

Sam M. Werner The author would like to thank the Brevan Howard Centre for Financial Analysis for its financial support.    Paul J. Pritz    Daniel Perez The author would like to thank the Tezos Foundation for its financial support.
Abstract

In the Ethereum network, miners are incentivized to include transactions in a block depending on the gas price specified by the sender. The sender of a transaction therefore faces a trade-off between timely inclusion and cost of his transaction. Existing recommendation mechanisms aggregate recent gas price data on a per-block basis to suggest a gas price.

We perform an empirical analysis of historic block data to motivate the use of a predictive model for gas price recommendation. Subsequently, we propose a novel mechanism that combines a deep-learning based price forecasting model as well as an algorithm parameterized by a user-specific urgency value to recommend gas prices.

In a comprehensive evaluation on real-world data, we show that our approach results on average in costs savings of more than 50% while only incurring an inclusion delay of 1.3 blocks, when compared to the gas price recommendation mechanism of the most widely used Ethereum client.

Keywords:
Smart Contracts Ethereum Gas Price Oracle Gas Mechanism Blockchain.

1 Introduction

Since the introduction of Ethereum [4] and it’s virtual machine, participants have been able to create so-called smart contracts, i.e. programs that encapsulate the logic for governing funds. As these contracts have to be executed by all participating nodes in the Ethereum network, the sender of a transaction has to pay for the computational cost of execution in units of gas. The amount of gas to be paid by the sender of a transaction depends on the complexity of executing a smart contract’s logic. Additionally, the sender is required to specify the gas price, which he will have to pay per unit of consumed gas. The product of the gas cost and price determines the transaction fee, which is received by the miner who includes the transaction in a block. Hence, setting an appropriate gas price is critical for having a transaction included in a timely manner. While Ethereum employs a hard coded and transparent gas cost model, there does not exist any embedded mechanism for computing how much a sender of a transaction should pay per unit of gas. The gas price is instead determined by the supply and demand for computational resources. Therefore, choosing an optimal gas price can be challenging, as underpaying likely results in a transaction not being included by miners, whereas overpaying leads to avoidable costs.

The most widely used gas price prediction mechanism is implemented by the popular Ethereum client Geth [13]. This and comparable mechanisms only use recent gas prices and merely aggregate past data to heuristically recommend the gas price for a transaction.

In this paper, we present a novel approach for gas price prediction, motivated by the empirical analysis of a period of 522,213 blocks. We find significant seasonality in the gas price data, suggesting that this can be predicted using a machine learning model. We propose the use of Gated Recurrent Units [7] as these have been shown to be suitable for capturing such patterns. Consequently, we design an algorithm for choosing the gas price for a transaction, which leverages the predictions of our model while allowing to specify the transaction’s urgency. Our evaluation on real-world data shows that the proposed approach significantly outperforms the most widely-used Ethereum client Geth [10].

Contributions. Our contributions are as follows:

  1. 1.

    We present a comprehensive empirical analysis of the Ethereum gas price over a period of three months and identify seasonal patterns in the data,

  2. 2.

    We propose a deep-learning based model to predict the gas price and combine this with a novel algorithm for recommending the gas price for a transaction,

  3. 3.

    We evaluate our model on real-world data and show that it outperforms the most widely used gas price recommendation approach, resulting on average in costs savings of more than 50% while only incurring an inclusion delay of 1.3 blocks compared to Geth.

Structure. The remainder of this paper is organized as follows. Section 2 introduces the background of Ethereum and its embedded gas mechanism. An empirical analysis of Ethereum gas prices is presented in Section 3. We propose a methodology for better gas price recommendation in Section 4, before evaluating our model’s results in Section 5. Related work is discussed in Section 6. Lastly, we conclude in Section 7.

2 Background

In this section, we first provide a brief overview of the workings of the Ethereum network. Subsequently, we examine in greater detail the gas cost and pricing mechanisms used in Ethereum.

2.1 Ethereum

Ethereum employs a Proof-of-Work consensus mechanism as first introduced by Bitcoin [20]. In such a protocol, transactions are grouped into blocks and Ethereum’s block arrival time is approximately 13 seconds [11]. Ethereum allows for the creation of so-called smart contracts. These are programs which define a set of rules using a Turing-complete programming language, typically Solidity [8], that can be invoked by network participants. An Ethereum account balance is expressed in the underlying currency Ether (ETH) and directly altered via state transitions caused by transactions. The consensus rules governing transaction validity are implemented by the Ethereum Virtual Machine (EVM), a low-level stack machine which executes the compiled EVM bytecode of the smart contract. Operations performed by the EVM consume gas, a virtual unit of account used to measure the computational cost of executing a transaction. By design, each EVM instruction has a hard-coded111Note that via a hard-fork, the Ethereum Improvement Proposal 150 [3] re-aligned gas costs for instructions involving I/O-heavy operations. gas cost [26]. The total execution cost has to be paid for by the sender of a transaction.

2.2 Gas Mechanism

The total execution cost for a contract consists of two components, namely the gas cost in units and gas price per unit. The gas cost is split into a fixed base cost of 21 000 gas and an execution cost dependent on the instructions executed while running the contract.

Gas Limit. Due to the Turing-completeness of the EVM, the exact computational cost of a transaction cannot be predetermined. Hence, the sender is required to specify a gas limit, or the maximum amount of gas that may be consumed. As the computational steps of a transaction are executed, the required gas is subtracted from the paid gas. Once a transaction is completed, any unused gas will be refunded to the sender. Should a transaction try to consume gas in excess of the gas limit, an Out-of-Gas exception is thrown by the EVM. Even though such a transaction would fail, it would be recorded on-chain and any used gas will not be refunded to the sender. Note that in addition to the per transaction gas limit there is also a block gas limit222At the time of writing the average block gas limit was around 10,000,000 units of gas., which specifies the total amount of gas that may be consumed by all transactions in a block.

Gas Price. Apart from setting a gas limit, a sender will also have to specify the gas price, which refers to the amount of Ether the sender is willing to pay per unit of gas, generally expressed in wei (1 wei = 101810^{-18}ETH) or Gwei (1 Gwei = 10910^{-9}ETH). Miners set a cut-off gas price to choose which transactions to include in their memory pool. When constructing a new block, they then choose the transactions with the most lucrative gas prices from their memory pool. A higher gas price will increase the fee which miners receive from a transaction, thereby motivating a miner to include a transaction in a block. The total amount of wei to be paid by a sender is referred to as the transaction fee and amounts to the product of the gas price and gas cost.

Gas Price Oracles. The sender of an Ethereum transaction is exposed to the non-trivial task of having to decide on a gas price. Since a higher gas price will increase the likelihood of having a transaction included quickly, there is a clear trade-off between waiting and paying. We define the optimal gas price as the minimum gas price such that the transaction is included in a block within the period of time that the sender of the transaction is prepared to wait for.

In order to avoid risks of overpaying, gas price oracles exist [1, 13, 14, 12]. These oracles aim to recommend the gas price a transaction requires in order to be included in a block within a specified time period. Commonly, the recommendation mechanism uses some rule-based approach analyzing the gas prices of previous blocks. We provide a more detailed summary on existing approaches in Section 6.

3 Empirical Analysis

In this section, we empirically analyze Ethereum block data to develop a better understanding of the gas price behavior. We use data from the period of 1 October, 2019 to 31 December, 2019, which amounts to a total of 522,213 blocks. When comparing mean, minimum and maximum gas prices averaged over 3 hour intervals during this period, we can see in Figure 1 that substantial spreads exists in the gas price. More specifically, the maximum gas price exceeds the minimum gas price by an order of magnitude for the entire period.

Refer to caption
Figure 1: The mean, maximum and minimum gas price averaged over 3 hour intervals from block 8,653,173 (1 October, 2019) to 9,193,265 (31 December, 2019).
Number of blocks: 522,213
Mean gas price: 13.9598 Gwei
Median of average gas price: 10.3260 Gwei
Standard deviation of average gas price: 46.4645 Gwei
Mean gas utilization: 79.36%
Standard deviation gas utilization: 32.00%
Table 1: Mean, median and standard deviation of average gas price per block, as well as mean and standard deviation of gas utilization per block from block 8,653,173 (1 October, 2019) to 9,193,265 (31 December, 2019).

The gas price volatility throughout the examined 522,213 blocks is further indicated by the standard deviation of the average gas price, which is 46.4645 Gwei at an average gas price of 13.9598 Gwei, as shown in Table 1. The same can be said about the average gas utilization per block.

Refer to caption
Figure 2: Correlation matrix for the average gas price, maximum gas price, minimum gas price, number of transactions and gas utilization per block.

Figure 2 shows the cross-correlations between the average gas price, maximum gas price, minimum gas price, number of transactions and gas utilization per block. Surprisingly, the average gas price and utilization are not correlated. In fact, the average gas price is only significantly correlated with the maximum gas price. The gas utilization is only correlated with the transaction count. However, apart from these two correlated pairs, the remainder of the variables are not significantly correlated.

To investigate the presence of seasonality in the data, we examine the autocorrelation of each variable on a per block and hourly basis. Most interestingly, we find that even though the gas price does not exhibit any significant seasonality on a per block basis, there does exist seasonality when looking at the gas price averaged over one hour intervals, as indicated by the autocorrelation in the left plot of Figure 3.

Refer to caption
Figure 3: Autocorrelation function (ACF) plot of mean (left hand side) and minimum (right hand side) gas prices averaged over one hour periods for 144 lags.

It can be seen that especially for a lag of 24 hours significant seasonality can be found in the data, which could be linked to different time zones of the countries where most transactions are conducted. This seasonality can be found to an even greater extent in the autocorrelation of the minimum gas price averaged over one hour intervals. The presence of seasonal patterns in the data alludes to the viability of machine learning models for predicting future gas prices.

4 Methodology

The gas price recommendation methodology we propose consists of two key components. First, we present a deep-learning based model to predict the gas price for a pre-defined period of time. Second, we introduce an algorithm that uses these predictions to recommend a gas price for a transaction, parameterized by the sender’s willingness to delay the transaction. Both components, as well as the employed data pre-processing steps are presented in this section.

4.1 Gas Price Prediction

The methodology we propose requires a forecasting model to predict the gas price trajectory over a pre-defined number of time steps ss. In particular, we are interested in predicting the minimum gas price under rational miner behavior, since this can be seen as a lower bound for setting the gas price for a given transaction. From the preliminary data exploration in Section 3, it is apparent that the per-block data is extremely noisy, which can be attenuated by averaging over a longer period of time. We therefore average the minimum gas price of all blocks in consecutive 5 minute intervals and forecast on this level of granularity, instead of using per-block data directly. A time step is then defined as a 5 minute interval. We denote the complete time series of average minimum gas prices by yy. Furthermore, we define the aggregated time series of all features used as model input as 𝒟\mathcal{D}, where dt𝒟d_{t}\in\mathcal{D} denotes the feature vector for a single time step tt. For both model training and inference, we use a sliding window model that uses a fixed-size window of historical data with ll time steps for prediction. The problem of forecasting a window of ss time steps using a window of size ll can then be defined as

y^t+1,,y^t+s=argmaxyt+1,,yt+sp(yt+1,,yt+s|dtl,,dt).\hat{y}_{t+1},\ldots,\hat{y}_{t+s}=\operatorname*{argmax}_{y_{t+1},\ldots,y_{t+s}}p(y_{t+1},\ldots,y_{t+s}|d_{t-l},...,d_{t})\,. (1)

In the remainder of this section we present our pre-processing methodology and proposed forecasting model.

4.1.1 Pre-processing

We introduce a number of pre-processing steps to the data, which specifically aim to reduce the impact of noise while still capturing seasonal components and trends.

Feature Name Lagged by 24h
Average gas price per block Yes
Transaction count per block No
Max. gas price per block No
Min. gas price per block No
ETH price at block timestamp No
Table 2: Features used as input data for the predictive model to forecast the minimum gas price. Lagged variables are included both with and without lag.

Table 2 lists the features used as input for the predictive model. Due to the daily seasonality in the data, some variables are also included with a lag of 24 hours. To reduce the impact of noise in the data, we first remove outliers using a heuristic criterion, where we delete all data points that are more than 1.5 standard deviations higher or lower than the mean. Subsequently, all data is normalized to values between 0 and 1. Since the main goal of the predictive model is to capture the seasonality and predict the gas price on a fairly coarse level, we employ a further pre-processing step presented in [23]. This additional step applies a discrete Fourier transform to each window in the input data and truncates the frequency domain representation of the time series using an adaptive energy-based criterion. We then convert it back to the time-domain using an inverse Fourier transform. This methodology allows us to adaptively reduce the impact of short-term fluctuations in each window of input data, while still capturing the seasonal components and overall trend.

4.1.2 Model

As a forecasting model, we propose the use of a Gated Recurrent Unit (GRU) [7]. GRUs are a specialisation of recurrent neural networks, where a computationally efficient gating mechanism is used. Gating has been shown to improve the network’s ability to learn longer term dependencies [17], making this kind of model well-suited to the problem at hand. The GRU architecture is given by

zt\displaystyle z_{t} =σ(Wzdt+Vzht1+bz),\displaystyle=\sigma(W_{z}d_{t}+V_{z}h_{t-1}+b_{z})\,, (2)
rt\displaystyle r_{t} =σ(Wrdt+Vrht1+br),\displaystyle=\sigma(W_{r}d_{t}+V_{r}h_{t-1}+b_{r})\,, (3)
ht\displaystyle h_{t} =ztht1+(1zt)ϕ(Whdt+Vh(rtht1)+bh),\displaystyle=z_{t}\circ h_{t-1}+(1-z_{t})\circ\phi(W_{h}d_{t}+V_{h}(r_{t}\circ h_{t-1})+b_{h})\,, (4)
y^\displaystyle\hat{y} =y^t+1,,y^t+s=f(ht),\displaystyle=\hat{y}_{t+1},\ldots,\hat{y}_{t+s}=f(h_{t})\,, (5)

where \circ denotes the Hadamard product, WW, VV and bb are parameter matrices and biases, σ()\sigma(\cdot) and ϕ()\phi(\cdot) denote the sigmoid and hyperbolic tangent functions, respectively, ztz_{t}, rtr_{t} and hth_{t} are the update and reset gates and the hidden state and f()f(\cdot) denotes the final linear layer of the network. The network is trained using gradient descent and backpropagation with an Adam optimiser [18].

4.2 Recommendation Algorithm

We now describe our recommendation algorithm which leverages the gas prices predicted by our model. We use the 20th percentile of the predicted prices as the initial gas price, which we note g^\hat{g}. One of the main objectives of our algorithm is to scale g^\hat{g} such that the faster the predicted gas prices are decreasing, the lower the gas price recommended by the algorithm. On the other hand, if the prices are increasing, the predicted prices should not be significantly lower than the current gas price. We incorporate this objective by finding a coefficient 0<c10<c\leq 1 that is multiplied with the predicted gas price g^\hat{g}. Furthermore, we want cc to increase or decrease exponentially with respect to the trend to achieve aggressive gas pricing if the predicted prices decrease quickly.

First, we compute the trend of the predictions y^\hat{y} returned by our forecasting model. We fit a linear function such that y^=aX+b\hat{y}=aX+b, with X=1,2,,sX=1,2,\cdots,s, and store the slope aa, which captures the trend in the predicted gas prices. We then normalize aa to a~\tilde{a} to lie in the range between 0 to 11. This is achieved by computing the maximum AmaxA_{max} and minimum AminA_{min} values of the slopes we obtain for our training data and computing a~\tilde{a} according to Equation (6).

a~=aAminAmaxAmin\tilde{a}=\frac{a-A_{min}}{A_{max}-A_{min}} (6)

Then, to obtain the described exponential behavior, we exploit the fact that the exponential function in the interval [2,0][-2,0] has the desired properties and hence, compute cc using Equation (7).

c=e2a~2c=e^{2\tilde{a}-2} (7)

Finally, to allow the user to configure the urgency of a transaction, we define an urgency parameter 𝒰\mathcal{U}, which we use to scale the obtained coefficient cc to arrive at a recommended gas price 𝒢\mathcal{G} given by

𝒢=g^c𝒰.\mathcal{G}=\hat{g}\cdot c\cdot\mathcal{U}\,. (8)
function EvaluateRecommender(StartBlock, EndBlock, Recommend)
     Pending \leftarrow\varnothing
     Results \leftarrow\varnothing
     Block \leftarrow StartBlock
     while Block \leq EndBlock \lor (Pending BlockLastBlock)\neq\varnothing\land\text{{Block}}\leq\text{{LastBlock}}) do
         Price \leftarrow GetMinimumPrice(Block)
         while Pending mintPending(t1)Price\neq\varnothing\land\min\limits_{t\in\text{{Pending}}}(t_{1})\geq\text{{Price}} do \triangleright t1t_{1} is the transaction price
              Transaction argmintPending(t1)\leftarrow\operatorname*{argmin}\limits_{t\in\text{{Pending}}}(t_{1})
              Pending \leftarrow Pending \\backslash {Transaction}
              Results Results{(Transaction,Block,Price)}\leftarrow\text{{Results}}\cup\{(\text{{Transaction}},\text{{Block}},\text{{Price}})\}
         end while
         if Block \leq EndBlock then
              Recommended \leftarrow Recommend(Block)
              Pending \leftarrow Pending \cup {(Block, Recommended)}
         end if
         Block Block+1\leftarrow\text{{Block}}+1
     end while
     return Results
end function
Algorithm 1 Evaluation procedure of the gas recommendation efficiency

4.3 Measuring Gas Recommendation Efficiency

Up to here, we have described how we recommend a price at a given block number. However, to understand how optimal a gas price is, we need to measure the difference between the recommended and the optimal gas price.

To evaluate the efficiency of our approach, we iterate over a range of blocks, where we do the following. For each block, a new transaction using the recommended gas price is added to a set of pending transactions. Each transaction in the pending set is processed upon encountering a block with a minimum gas price lower than that specified in the transaction. We keep track of the recommended price, the inclusion price, i.e. the minimum gas price of the block where the transaction is included, and the number of blocks elapsed until inclusion. We show the detailed steps in Algorithm 1. The EvaluateRecommender function takes a start block, an end block and a recommendation function to evaluate. LastBlock is the number of the last block which we evaluate and GetMinimumPrice returns the minimum gas price for a given block.

To be able to evaluate the efficiency of our algorithm, we use the Geth gas price recommendation algorithm as the main baseline, as it is by far the most widely used Ethereum client [10].

5 Results

In this section, we present the results we obtain when using the methodology presented in the previous section and compare them with our baselines.

Refer to caption
Figure 4: Exemplary gas price predictions obtained with our forecasting model for the period between the 23 November, 2019 and 25 November, 2019.

5.1 Model Training

All models are implemented in Python, using the PyToch library [24]. We train all models on a personal computer with 32GB of RAM, an 8th8^{th} generation Intel Core i7-8700 with 3.20GHz and 6 cores and a 256GB SATA hard drive. Model training and hyper parameter tuning is performed on the data between 10 November, 2019 to 20 November, 2019, where we use the first 70% of the data for training and the remaining 30% for validation. We show exemplary predictions of our model in Figure 4.

5.2 Evaluation

We use a sample of around five days of data — from 20 November, 2019 (block 8,965,759) to November 24, 2019 (block 8,995,344) — and evaluate the different price recommendation strategies using the procedure presented in Algorithm 1.

Model Parameter Description
Geth Scaling (𝒮\mathcal{S}) Ratio by which to scale the price
(0.8 means use 80% of the recommended price)
proposed approach Urgency (𝒰\mathcal{U}) Urgency tuning parameter to trade-off price for time
Look-ahead Blocks (\mathcal{B}) Number of blocks to look ahead
Table 3: Parameters used in the different strategies

We first describe the parameters of each strategy in Table 3. For Geth we use a scaling ratio parameter 𝒮\mathcal{S} with which the recommended gas price is multiplied. The main purpose of this parameter is to ensure that giving a lower gas price does have a direct impact on the number of blocks waited. Our proposed recommendation strategy accepts a single parameter 𝒰\mathcal{U} representing the urgency. The urgency parameter is used to trade off gas price for waiting time: the lower the urgency, the lower the gas price and hence, the longer the waiting time. Empirically, reasonable values for these parameters are roughly between 0.70.7 and 1.31.3, where 0.70.7 will result in cheap but long to be accepted transactions and 1.31.3 will result in more expensive but faster transactions. Finally, our look-ahead model, which we use to estimate the lowest possible price takes a parameter \mathcal{B} representing the maximum look-ahead as a number of blocks. We note that the look-ahead strategy is for validation purposes only as it uses information about future blocks, which would obviously not be available in practice.

Strategy Parameter Gas price Blocks waited
Geth 𝒮=1.0\mathcal{S}=1.0 4,414,902,746 1.97
Geth 𝒮=0.9\mathcal{S}=0.9 4,080,968,868 15.49
Geth 𝒮=0.8\mathcal{S}=0.8 3,531,922,197 25.52
Look-ahead =15\mathcal{B}=15 1,166,965,099 4.80
Look-ahead =30\mathcal{B}=30 969,559,938 8.52
Look-ahead =60\mathcal{B}=60 782,105,012 18.84
Proposed approach 𝒰=1.0\mathcal{U}=1.0 2,120,108,703 3.28
Proposed approach 𝒰=0.9\mathcal{U}=0.9 1,908,097,833 3.79
Proposed approach 𝒰=0.8\mathcal{U}=0.8 1,696,086,963 5.13
Proposed approach 𝒰=0.7\mathcal{U}=0.7 1,484,076,092 10.06
Table 4: Results of the different recommendation strategies presented. Gas price and wait time are averaged over the number of blocks processed. Parameters are described in Table 3.

We present a summary of the results for the different recommendation strategies in Table 4. We use several values for the parameters of each strategy and order its results so that the gas price decreases and the number of blocks to wait increases. We can see that using the price recommended by Geth, the waiting time is very short — on average less than 2 blocks — with an average gas price of around 4.4 Gwei. However, by just using 90% of the recommended price, the waiting time increases to an average of 15.5 blocks. Comparing these results to the minimum possible gas price, obtained from the look-ahead model, we can see that by only waiting for an average of 4.8 blocks a saving of 75% could be obtained. Although these numbers are hypothetical, they suggest the potential for significant improvement.

Refer to caption
Figure 5: Effect of the urgency parameter on the average gas price paid and number of blocks waited.

We now show how our model performs in comparison to the price recommended by Geth and the hypothetical minimum price. With the urgency parameter set to 1.01.0, our model recommends a gas price on average twice as low as the Geth price, while waiting for an average of approximately 3.3 blocks. When decreasing the urgency parameter, we can see that the number of blocks elapsed increases fairly slowly at first but doubles between 0.8 and 0.7, showing that at this point the gas price becomes too low for the transaction to be included in a timely manner. In Figure 5, we show the effect of our urgency parameter on the average gas price paid and the average number of blocks elapsed until the transaction is included.

6 Related Work

For Ethereum in particular, there has been extensive research on smart contract correctness, upper-bound gas consumption and imperfections in the current EVM gas cost model. Nonetheless, very little work has been done with the goal of determining optimal gas prices. In this section, we first present existing work on the gas mechanism, before examining the most widely used gas price recommendation methods.

6.1 Gas Mechanism

The overconsumption of gas can be harmful for the contract user for two main reasons: higher monetary costs and potential vulnerabilities. Gas overconsumption is examined by Chen et al. [5], who focus on gas usage optimization by introducing Gasper, a tool leveraging symbolic execution for detecting costly patterns in the bytecode of smart contracts which are not optimized by the Solidity compiler. Potential issues in the form of gas-related vulnerabilities are carefully examined by Grech et al. [15], who propose a static analysis tool, called MadMax, predominantly suitable for detecting out-of-gas exceptions which may cause contract funds being locked. Elvira et al. [2] present Gastap, a static analysis tool for inferring gas upper bounds for smart contracts and are thereby able to detect whether any out-of-gas vulnerabilities could exist. A further approach for computing gas consumption upper bounds was introduced by Marescotti et al. [19], however, the authors are yet to implement and test their algorithms in an EVM setting. For a more general summary of existing smart contract verification tools we point the reader to [16].

There have been several pieces of work focusing on imperfections in the current gas cost mechanism. Both Yang et al. [27] and Perez and Livshits [21] identify inconsistencies in the pricing of EVM instructions in the current gas cost model. The latter propose a new type of attack aimed at exploiting EVM design flaws by generating resource exhaustive contracts, which are on average significantly slower in terms of throughput than typical contracts. As a means of preventing Denial-of-Service attacks stemming from under-priced EVM instructions a modification of the current gas cost mechanism has been proposed by [6].

While several pieces of existing work examine the current gas cost mechanism, limited work exists on gas price recommendation. Pierro et al. [22] investigate potential factors that influence transaction fees in Ethereum from a technical and economic perspective, yet leave a gas price prediction model for future research.

6.2 Gas Price Oracles

In the following, we examine existing approaches for gas price recommendation that are used in practice.

Geth. The Ethereum client implementation in go, namely Geth [13], accounts for over 79% of all Ethereum clients [10]. To recommend a gas price, Geth uses the minimum gas price of the previous blocks. It looks back at the 100 blocks preceding the current one and then uses the value of the 60th percentile of the minimum gas prices as the price recommendation.

EthGasStation. A further gas price oracle has been introduced by EthGasStation [1], a third-party tool, which estimates the expected number of blocks required to confirm a transaction at a given gas price using a Poisson regression model based on data of the previous 10,000 blocks. This approach has also been implemented by the popular Ethereum block explorer Etherchain [9]. Unfortunately, no historical data was available for comparison.

GasStation – Express. EthGasStation also released a more simple gas price oracle called “GasStation – Express” [12]. This approach predicts the likelihood of a transaction being included in the next block at a given gas price by examining the percentage of the last 200 blocks that included a transaction with the same or lower gas price [25]. The percentage thresholds of recent block inclusions are fixed for the categories Fast (90%), Standard (60%) and SafeLow (35%). Additionally a Fastest option is given, whereby the suggested gas price was included by all of the previous 200 mined blocks, which likely results in the sender overpaying considerably. Just like the threshold percentages, the associated expected confirmation times are also hard-coded, which limits the speed at which the system can react to changes.

7 Conclusion

Motivated by an empirical analysis of 3 months of data, we have proposed a novel approach for recommending the Ethereum gas price that outperforms the method of the most widely used Ethereum client. Our approach uses a deep-learning based price forecasting model as well as an algorithm parameterized by an urgency value that can be set by the user. In a comprehensive evaluation, we show that our approach is able to reduce the average gas price paid by the sender of a transaction by more than 50% while only introducing an average additional waiting time of 1.3 blocks compared to Geth.

Our evaluation of the proposed approach aimed to focus on common-sized transactions. For more computationally intensive transactions, the gas price would likely need to be increased to ensure timely inclusion in a block. However, this could be easily accomplished by adjusting the urgency parameter.

Future work can examine the usefulness of additional data, such as memory pool data, as model inputs. Additionally, the evaluation and comparison of our approach and previous approaches in a larger simulation may be a fruitful avenue for further research.

References

  • [1] Ethgasstation. https://ethgasstation.info/, 2020. ”[Online; accessed 14-January-2020]”.
  • [2] E. Albert, P. Gordillo, A. Rubio, and I. Sergey. GASTAP: A Gas Analyzer for Smart Contracts. CoRR, abs/1811.1, nov 2018.
  • [3] V. Buterin. EIP 150: Gas cost changes for IO-heavy operations . https://eips.ethereum.org/EIPS/eip-150. [Online; accessed 05-June-2019].
  • [4] V. Buterin. A next-generation smart contract and decentralized application platform. Ethereum, (January):1–36, 2014.
  • [5] T. Chen, X. Li, X. Luo, and X. Zhang. Under-optimized smart contracts devour your money. SANER 2017 - 24th IEEE International Conference on Software Analysis, Evolution, and Reengineering, pages 442–446, 2017.
  • [6] T. Chen, X. Li, Y. Wang, J. Chen, Z. Li, X. Luo, M. H. Au, and X. Zhang. An adaptive gas cost mechanism for ethereum to defend against under-priced dos attacks. In J. K. Liu and P. Samarati, editors, Information Security Practice and Experience, pages 3–24, Cham, 2017. Springer International Publishing.
  • [7] K. Cho, B. van Merrienboer, Ç. Gülçehre, F. Bougares, H. Schwenk, and Y. Bengio. Learning phrase representations using RNN encoder-decoder for statistical machine translation. CoRR, abs/1406.1078, 2014.
  • [8] C. Dannen. Introducing Ethereum and Solidity: Foundations of Cryptocurrency and Blockchain Programming for Beginners. Apress, Berkely, CA, USA, 1st edition, 2017.
  • [9] etherchain.org. Gas price oracle. https://www.etherchain.org/tools/gasPriceOracle, 2020. ”[Online; accessed 15-January-2020]”.
  • [10] ethernodes.org. Ethereum mainnet statistics. https://www.ethernodes.org/, 2020. ”[Online; accessed 15-January-2020]”.
  • [11] Etherscan. Ethereum average block time chart. https://etherscan.io/chart/blocktime. Accessed 28-January-2020.
  • [12] Github. Gasstation-express. https://github.com/ethgasstation/gasstation-express-oracle, 2020. ”[Online; accessed 15-January-2020]”.
  • [13] Github. Official go implementation of the ethereum protocol. https://github.com/ethereum/go-ethereum/, 2020. [Online; accessed 14-January-2020].
  • [14] Github. Parity ethereum: The fastest and most advanced ethereum client. https://github.com/paritytech/parity-ethereum, 2020. [Online; accessed 16-January-2020].
  • [15] N. Grech, M. Kong, A. Jurisevic, L. Brent, B. Scholz, and Y. Smaragdakis. MadMax: Surviving Out-of-Gas Conditions in Ethereum Smart Contracts. SPLASH 2018 Oopsla, 2(October), 2018.
  • [16] D. Harz and W. Knottenbelt. Towards safer smart contracts: A survey of languages and verification methods. arXiv preprint arXiv:1809.09805, 2018.
  • [17] S. Hochreiter and J. Schmidhuber. Long short-term memory. Neural Comput., 9(8):1735–1780, Nov. 1997.
  • [18] D. P. Kingma and J. Ba. Adam: A method for stochastic optimization, 2014.
  • [19] M. Marescotti, M. Blicha, A. E. J. Hyvärinen, S. Asadi, and N. Sharygina. Computing Exact Worst-Case Gas Consumption for Smart Contracts. In T. Margaria and B. Steffen, editors, Leveraging Applications of Formal Methods, Verification and Validation. Industrial Practice, pages 450–465, Cham, 2018. Springer International Publishing.
  • [20] S. Nakamoto. Bitcoin: A peer-to-peer electronic cash system. https://bitcoin.org/bitcoin.pdf, Dec 2008. Accessed: 2015-07-01.
  • [21] D. Perez and B. Livshits. Broken metre: Attacking resource metering in evm. arXiv preprint arXiv:1909.07220, 2019.
  • [22] G. A. Pierro and H. Rocha. The influence factors on ethereum transaction fees. In 2019 IEEE/ACM 2nd International Workshop on Emerging Trends in Software Engineering for Blockchain (WETSEB), pages 24–31. IEEE, 2019.
  • [23] P. J. Pritz, D. Perez, and K. K. Leung. Fast-fourier-forecasting resource utilisation in distributed systems. In 29th International Conference on Computer Communications and Networks, ICCCN 2020, Honolulu, HI, USA, August 3-6, 2020, pages 1–9. IEEE, 2020.
  • [24] PyTorch Contributors. PyTorch online documentation. https://pytorch.org/docs. Accessed 13-August-2019.
  • [25] M. E. G. Station. Gasstation express: A simple gas price oracle for anyone running a full ethereum node. https://medium.com/@ethgasstation/gasstation-express-a-simple-gas-price-oracle-for-anyone-running-a-full-ethereum-node-f1bde46260f5, 2017. ”[Online; accessed 15-January-2020]”.
  • [26] G. Wood. Ethereum yellow paper, 2014.
  • [27] R. Yang, T. Murray, P. Rimba, and U. Parampalli. Empirically Analyzing Ethereum’s Gas Mechanism. CoRR, abs/1905.0, 2019.