arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2301.04757cs.PL
收藏

在以太坊字节码上推断不必要的写入内存访问(扩展版)

Inferring Needless Write Memory Accesses on Ethereum Bytecode (Extended Version)

Elvira Albert, Jesús Correas, Pablo Gordillo, Guillermo Román-Díez, Albert Rubio

摘要:

效率是任何类型程序的基本属性,但在区块链上执行的程序(称为智能合约)中更是如此。这是因为优化智能合约对降低部署和执行合约的成本有直接影响,因为需要支付与其字节大小和资源消耗(称为gas)相关的费用。优化内存使用被认为是一个具有挑战性的问题,除其他事项外,需要精确推断正在访问的内存位置。以太坊虚拟机(EVM)字节码也是如此,它是由最广泛使用的编译器\texttt{solc}生成的,它的非常规和低级内存使用挑战了自动推理。本文提出了一种静态分析,在\texttt{solc}产生的EVM字节码的水平,推断写内存访问是不必要的,因此可以安全地删除。我们在超过19,000个真实智能合约上的应用程序在不到4小时的时间内检测到大约6,200次不必要的写入访问。有趣的是,这些写操作中的许多都涉及到由\texttt{solc}生成的内存使用模式,可以通过删除整个字节码块来极大地优化这些模式。据我们所知,现有的优化工具无法推断出这种不必要的写访问,因此无法检测到这些影响以太坊智能合约部署和执行成本的低效率。

英文摘要:

Efficiency is a fundamental property of any type of program, but it is even more so in the context of the programs executing on the blockchain (known as smart contracts). This is because optimizing smart contracts has direct consequences on reducing the costs of deploying and executing the contracts, as there are fees to pay related to their bytes-size and to their resource consumption (called gas). Optimizing memory usage is considered a challenging problem that, among other things, requires a precise inference of the memory locations being accessed. This is also the case for the Ethereum Virtual Machine (EVM) bytecode generated by the most-widely used compiler, \texttt{solc}, whose rather unconventional and low-level memory usage challenges automated reasoning. This paper presents a static analysis, developed at the level of the EVM bytecode generated by \texttt{solc}, that infers write memory accesses that are needless and thus can be safely removed. The application of our implementation on more than 19,000 real smart contracts has detected about 6,200 needless write accesses in less than 4 hours. Interestingly, many of these writes were involved in memory usage patterns generated by \texttt{solc} that can be greatly optimized by removing entire blocks of bytecodes. To the best of our knowledge, existing optimization tools cannot infer such needless write accesses, and hence cannot detect these inefficiencies that affect both the deployment and the execution costs of Ethereum smart contracts.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑