Professional Documents
Culture Documents
Gas Consumption Prediction SBouraga BRAINS2020
Gas Consumption Prediction SBouraga BRAINS2020
net/publication/344406010
CITATIONS READS
0 89
1 author:
Sarah Bouraga
University of Namur
13 PUBLICATIONS 36 CITATIONS
SEE PROFILE
All content following this page was uploaded by Sarah Bouraga on 28 September 2020.
Abstract
The author uses data about transactions on Ethereum as sources for
studying the relationship between the historic of transactions for a given
address and the amount of gas consumed for a transaction. The author
combines data about transactions, and blocks to predict the gas usage
for a transaction. Specifically, how much gas will be consumed for the
next transaction, given the initiator’s transaction history. The results
demonstrate the value of considering the transaction history for gas usage
predictions.
Keywords: Blockchain, Ethereum, Gas Consumption, Prediction, Re-
gression
1 Introduction
Since Ethereum was launched in 2015, it has become the world’s leading pro-
grammable blockchain, allowing anyone to write Smart Contracts and Decen-
tralized Applications (DApps), on top of the possibility to transfer ether (ETH),
Ethereum’s own cryptocurrency. On Ethereum, the execution of a transaction
requires some computational resources (called Gas) which the initiator of the
transaction has to pay for. She sets (i) the amount she is willing to pay per
unit of gas (i.e., the GasPrice), and (ii) the maximum units of gas she is willing
to pay for (i.e., the GasLimit); and she pays in advance the amount GasPrice
× GasLimit. If the transaction does not exceed the amount of gas set by the
initiator, then the latter will get back the (GasPrice × GasLimit) − Gas Cost;
while the Gas Cost is paid to the miner. Otherwise, the amount is lost.
The goals and corresponding contributions of this paper are twofold. Firstly,
transaction history summarization is used to predict the amount of gas used by
1
transaction for a given address. Secondly, drawing on previous works [1, 2]
the author aims to discover whether features in the history of transactions on
Ethereum can be as good predictors as the ones on the Bitcoin blockchain.
Being able to predict gas consumption has two main practical implications.
It can help the initiator of a transaction set the GasLimit, and hence set the
GasPrice. Also, a gas consumption prediction can help the network identify
fraudulent activity.
The rest of the paper is structured as follows. Section 2 proposes a literature
review. Section 3 presents the research methodology. Finally, Section 4 and
Section 5 discusses the results and concludes the paper respectively.
2 Background
Building on Bitcoin, Ethereum [3] offers a platform with a built-in Turing-
complete programming language which anyone can use to write Smart Contracts
and DApps. A risk when dealing with Turing-complete programming languages
is the problem of the infinite loop in code. Ethereum mitigates that risk with
the concept of Gas. Each transaction must contain, among other elements:
the Startgas (or GasLimit) and the GasPrice. The Startgas is the maximum
number of computational steps of code execution the sender is willing to pay
for; while the GasPrice is the price per computational step. Both are set by
the sender. If the transaction execution consumes more gas than was originally
paid for, then the execution stops. Thus, one will not encounter the infinite
loop problem because the transaction will run out of gas eventually.
The present article draws mainly on [1] and [2], where the summarization of
transaction history is used for the classification of Bitcoin addresses.
On the Ethereum blockchain, researchers conducted studies about smart
contracts and about the gas used on the blockchain. Here, the author does not
analyse the code of smart contracts to identify flaws or other vulnerability issues
as in [4–7]; but rather, analyses the effects of the execution of smart contracts.
Also, the purpose here is not the analysis nor the handling of Denial-of-Service,
as it is the case in [8,9]. Finally, this work proposes an analysis of the transaction
history summarization to predict gas consumption - something that, as far as
the author knows, has not been carried out - instead of using the structure of
the smart contract code as it is the case in [10].
3 Methodology
3.1 Data Collection and Feature Engineering
The author used Python scripts Ethereum-ETL to retrieve 101002 blocks and
their corresponding transactions, features, and contracts. She also retrieved the
conversion rate from ETH to USD from etherchain.org. Building on [1] and [2],
the author constructed two categories of features, Basic and Extra Statistics
(Table 1).
2
Table 1: Basic and Extra Statistics
Features Description
fT X Frequency, i.e. the number of all transac-
tions per day
rrec Ratio of received transactions to all trans-
actions
rrec ET H Ratio of received transfer transactions to
all transactions
rsent ET H Ratio of sent transfer transactions to all
transactions
rcontract Ratio of contract creation transactions to
all transactions
µgas pc Mean value of the GasPrice all transac-
tions
σgas pc Standard deviation value of the GasPrice
µstartgas Mean value of the StartGas all transactions
σstartgas Standard deviation value of the StartGas
all transactions
µgas used Mean value of the gas used in all transac-
tions
σgas used Standard deviation value of the gas used
in all transactions
lif etime Duration between the first and the last
transaction
gasspent Total gas spent
ET Hspent Total spent in Ether
ET Hreceived Total received in Ether
U SDspent Total spent in USD
U SDreceived Total received in USD
NT X Number of transactions
Nsent Total number of sent transactions
Nreceived Total number of received transactions
Ncall Total number of call function transactions
Ncontract Total number of smart contract creation
transactions
3
3.2 Prediction Models
The author used Skikit-Learn Python library [11] for the application of various
prediction models. After splitting the dataset into a train set and a test set,
the author first trained several models (Ordinary Least Squares (OLS), Ridge,
Bayesian Ridge, Lasso, and Stochastic Gradient Descent Linear Regressions,
Linear Support Vector Regression, and Decision Tree Regressor) with the de-
fault hyperparameters, using a 5-fold cross-validation on the train set. Using
R-Squared (R2 ) as the performance measure, which indicates how well the se-
lected independent variables explain the variability in the dependent variable,
the author selected and fine-tuned the best models (OLS and Lasso) using a
GridSearch [11]. At the end, with a R2 = 0,729373, the Lasso model performs
best and gives the following equation:
5 Conclusion
On Ethereum, peers can transfer ETH, write Smart Contracts and DApps. An
important concept is the concept of Gas, the number of computational steps
necessary to execute the transaction. In this paper, the author demonstrates
4
the predictive power of transaction summarization to forecast the gas consumed
for each transaction. Future work will consist of addressing the limitations
mentioned in Section 4.
References
[1] K. Toyoda, T. Ohtsuki, and P. T. Mathiopoulos, “Multi-class bitcoin-
enabled service identification based on transaction history summarization,”
in 2018 IEEE International Conference on Internet of Things (iThings)
and IEEE Green Computing and Communications (GreenCom) and IEEE
Cyber, Physical and Social Computing (CPSCom) and IEEE Smart Data
(SmartData). IEEE, 2018, pp. 1153–1160.
[2] Y.-J. Lin, P.-W. Wu, C.-H. Hsu, I.-P. Tu, and S.-w. Liao, “An evaluation of
bitcoin address classification based on transaction history summarization,”
in 2019 IEEE International Conference on Blockchain and Cryptocurrency
(ICBC). IEEE, 2019, pp. 302–310.
5
[9] 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 International Conference on Information Security
Practice and Experience. Springer, 2017, pp. 3–24.
[10] M. Marescotti, M. Blicha, A. E. Hyvärinen, S. Asadi, and N. Sharygina,
“Computing exact worst-case gas consumption for smart contracts,” in
International Symposium on Leveraging Applications of Formal Methods.
Springer, 2018, pp. 450–465.
[11] F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel,
M. Blondel, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Pas-
sos, D. Cournapeau, M. Brucher, M. Perrot, and E. Duchesnay, “Scikit-
learn: Machine learning in Python,” Journal of Machine Learning Re-
search, vol. 12, pp. 2825–2830, 2011.