一句话:提出字节码重构方法 FunRedisp,通过将热函数前移优化函数分派,降低智能合约调用 Gas 消耗。
智能合约多以 Solidity 编写并在以太坊等区块链上执行,部署或调用时需支付 Gas 费用以防止资源滥用。尽管节省 Gas 已有较多研究,但函数分派对调用 Gas 消耗的影响尚未被专门研究。本文首先揭示函数分派如何影响调用 Gas 消耗,然后提出 FunRedisp,一种字节码重构方法及开源工具:在源代码层识别智能合约中较可能被调用的热函数,再在字节码层将这些函数移动到函数分派的前端。作者在从以太坊随机选取的 50 个真实智能合约上评估 FunRedisp,实验表明其平均每笔交易可节省约 125.17 单位 Gas,而编译开销仅增加 0.37 秒。
Smart contracts mostly written in Solidity are Turing-complete programs executed on the blockchain platforms such as Ethereum. To prevent resource abuse, a gas fee is required when users deploy or invoke smart contracts. Although saving gas consumption has received much attention, no work investigates the effect of function dispatch on the invocation gas consumption. In this paper, after demystifying how the function dispatch affects the invocation gas consumption, we present FunRedisp, a bytecode refactoring method and an open-source tool, to reduce the overall invocation gas consumption of smart contracts. At the source code level, FunRedisp initially identifies hot functions in a smart contract that have a big chance to be invoked, and then move them to the front of the function dispatch at the bytecode level. We implement FunRedisp and evaluate it on 50 real-world smart contracts randomly selected from Ethereum. The experimental results demonstrate that FunRedisp can save approximately 125.17 units of gas per transaction with the compilation overhead increased by only 0.37 seconds.
DOI 原文 ·
@inproceedings{paperbot8509,
title = {FunRedisp: Reordering Function Dispatch in Smart Contract to Reduce Invocation Gas Fees},
author = {Yunqi Liu and Wei Song},
booktitle = {ISSTA},
year = {2024},
doi = {10.1145/3650212.3652146}
}