Like other permission-less blockchains and cryptocurrencies, Ethereum obtains consensus using a form of cryptographic zero-knowledge proof called “Proof-of-work“. In such protocols, a character called “miner”, groups transactions into a block and appends it to the end of blockchains.
This work is resource consumptive, and thus, operations using Ethereum require a fee, which is received by miner in exchange for performing the work. Each block on the chain has an upper bound on the amount of gas that can be included in it, so miners maximize profit by prioritizing transactions offering higher gas prices.
It produces a challenging question: how do we determine a gas price that ensures a transaction will be included in a block within a user’s required timeline without overpaying? Accompanying with Eth raising price, it becomes an important topic to predict an appropriate gas price. AMIS studied this question and proposed an effective and low-cost algorithm, which is accepted by The 2nd International Conference on Deep Learning, Big Data and Blockchaina (ref. the paper). Furthermore, we also prepare to implement this algorithm in our product: AMIS Gas Price Prediction.
Understanding Ethereum Gas Mechanism
At first, we recall some background of this topic quickly. More details can be found in the yellow paper.
Gas is referred to the fuel required to conduct a transaction or execute a smart contract. These fee are calculated in Gas, using a unit called wei, which satisfies:
and
Here ETH is the currency in Ethereum. The cost of execution is equal to:
Here
- The gas cost is bounded by the lower bound 21,000 and the upper bound gas limit, which represents the maximum amount of gas a user is willing to use for an operation. The precise amount of gas cost depends on the complexity of performing “smart contracts”, which define a set of rules using a Turing-complete programming language. After the transaction is completed, all unused gas is returned to the user’s account. If the gas limit is less than the gas cost, then the transaction is viewed as invalid and will be rejected; the gas spent to perform calculations will not be returned to the account.
- The gas price is also determined by the user and represents the price per unit of gas the user is offering to pay. Since a miner’s reward is largely determined by the gas price, a higher gas price results in a greater probability of transactions being selected by miners and grouped into blocks.
Existing Approaches to Gas Prediction
To date, there exists two different starting points to approach the considering question:
- One method for gas price prediction is to analyze the pricing structure of pending transactions in large mempools (ref. Gas platform). This method is resource intensive as it requires accessing large quantities of mempools to obtain enough pending transaction data for analysis. Further, it can only accurately predict the gas prices under the assumption that the data from mempools is correct, something that is difficult for users to verify.
- Another method is to utilize recent transactions that were included by miners to recommend a price. Some algorithms based on this concept have been used to develop gas price oracles including Geth, EthGasStation, GasStation-Express (abrev. GS-Express) and the work of Sam M. Werner et al.
Analyzing to the above two approaches, AMIS prefers to the method 2 because data on the blockchain are more valuable and reliable. This is our fundamental faith.
One such gas price oracle, GS-Express, proposed using the set of minimum gas prices in the most recent 200 blocks. An additional oracle, Geth, uses the set of minimum gas prices in the most recent 100 blocks and takes the 60th percentile of the set as a recommended gas price. These models provide an efficient way to recommend gas prices when the quantity of pending transactions are relatively few. However, when there is a surge of pending transactions, these models will underestimate the prices.
The Proposed Methodology: Gaussian Process (GP)
For the sake reducing the risk of underestimating gas price, AMIS proposes a new method to predict a suitable value. The proposed methodology bases on Gaussian process (abrev. GP) models to predict the distribution of the minimum price in the upcoming block. Stochastic processes, including GP, are often used to study numerous stock market micro-structure related questions, including price discovery, competition among related markets, strategic behavior of market participants, and modeling of real time market dynamics. These processes present potentially efficient estimators and predictors for volatility, time-varying correlation structures, trading volume, bid-ask spreads, depth, trading costs, and liquidity risks. The market forces acting within Ethereum markets are very similar to these, making GP an appropriate method to capture the dynamics of Ethereum gas prices. Another attractive feature of stochastic processes is the covariance functions, which allows the model to estimate the time correlation between blocks; that is, it can capture the stronger correlation between closer blocks. Our method provides stable price prediction even when there is a surge in transaction volume. Over the long-term, the gas prices recommended by the model are more economical and practical compared with existing methods.
We reduce the training data of GS-Express to achieve better prediction value. This figure demonstrated that GP predicted more acurate when the price dropped rapidly while the other overestimated largely.
Fair Evaluation and Success Rate Statistics
In order to evaluate each prediction model fairly, we introduce a “Statistics” to help us analyze. The idea of this statistic is simple: Using past data can give a prediction called x. Assume that the minimal gas price in the upcoming block is denoted by y. If x > y, then your prediction has some possibility of being accepted by miners, whereas if x < y, then the prediction has high possibility of being rejected by miners. We formalize this concept to compute “success rate” during some time and observe its behavior of short term and long term for each prediction oracle. This statistic looks reliable, because it can indicate the behavior of GS-Express and Geth in the long run is stable. But their performance are not as good in the short term.
Long term
Short term success rate
The above data indicate that GS-Express and Geth over/under-estimated the price when the transaction volume fluctuates greatly.
The formal definition of success rate is given by:
AMIS's Innovative Gas Price Prediction Model
A new method proposed by AMIS has not only the short term success rate maintain reasonable accuracy but also possesses time efficiencies in model training and prediction. Our prediction oracle is a practical and economical gas price oracle which retains the advantages of both GP and GS-Express and avoids the disadvantages of each.
Our method is superior in achieving the targeted short-term and long-term success rates among the considered blocks compared with existing methods. Remarkably, except for P50, the average cost of our method is still less than the others. More details can be found in our upcoming paper.
FAQ
Existing models often underestimate gas prices during sudden surges in transaction volume, which can cause user transactions to get stuck or rejected by miners.
Gaussian Process models are excellent at capturing time-based correlations and the dynamic nature of market forces, similar to how they are used in stock market modeling.
The success rate is defined by comparing the predicted price (x) with the actual minimum price (y) of the upcoming block. If x > y, the prediction is considered a success because the transaction is likely to be accepted.