Trace-Based Dynamic Gas Estimation of Loops in Smart Contracts

Trace-Based Dynamic Gas Estimation of Loops in Smart Contracts
复制标题

DOI:
10.1109/ojcs.2020.3039991
复制
发表时间:
2020
影响因子:
5.9
通讯作者:
Chunmiao Li;Shijie Nie;Yang Cao;Yijun Yu;Zhenjiang Hu
Chunmiao Li;Shijie Nie;Yang Cao;Yijun Yu;Zhenjiang Hu
中科院分区:
--
文献类型:
--
作者:
Chunmiao Li;Shijie Nie;Yang Cao;Yijun Yu;Zhenjiang Hu

文献摘要

相似文献

以太坊上的智能合约可用于编码业务逻辑,并已应用于许多不同的领域,例如令牌交换和游戏。与一般程序不同,以太坊合约的计算受到gas限制。如果一个交易在执行结束前耗尽了gas限制,以太坊虚拟机抛出一个out- gas异常,整个交易失败,恢复到交易开始前的状态,尽管交易费用仍然被扣除。因此,在发送交易之前进行gas估计是必要的。由于循环的迭代次数不能静态确定,现有的研究大多无法估计循环函数的气体。然而,我们发现四分之一的合约都有循环函数,循环的gas成本高于其他函数。因此,有必要对回路函数进行气体估计。在本研究中,我们提出了一种基于交易轨迹的气体估计方法来动态估计循环函数的气体。我们的信念是,我们可以了解历史交易轨迹与其天然气成本之间的关系,以估计新交易的天然气。我们考虑了原始事务跟踪的三种不同抽象,并将它们提供给不同的机器学习模型。结果表明,该方法在气体估计中是有效的,随机森林可以达到最准确的估计。
Smart contracts on Ethereum can be used to encode business logic and have been applied to many different areas, such as token exchanges and games. Unlike general programs, the computations of contracts on Ethereum are restricted by the gas limit. If a transaction runs out of the gas limit before an execution finishes, the Ethereum virtual machine throws an out-of-gas exception, and the entire transaction fails, which reverts to the state before the transaction started, although the transaction fee is still deducted. It is therefore, essential to conduct a gas estimation before sending a transaction. Existing studies have mostly failed in estimating the gas for a loop function because the number of iterations of the loops cannot be statically determined. However, we found that a quarter of all contracts have loop functions, and the gas cost for the loops is higher than for the other functions. Therefore, it is necessary to apply a gas estimation for the loop functions. In this study, we propose a gas estimation approach based on the transaction trace to dynamically estimate the gas for the loop functions. Our belief is that we can learn the relationship between the historical transaction traces and their gas costs to estimate the gas for new transactions. We considered three different abstractions of the original transaction trace and fed them to different machine learning models. The results show that our approach is effective in gas estimation and that a random forest can achieve the most accurate estimation.