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.
翻译:优化记忆使用被认为是一个具有挑战性的问题,除其他外,需要精确地推断存取的记忆位置,但对于在块链上执行的程序(称为智能合同)来说,效率更为重要。这是因为优化智能合同对降低部署和执行合同的成本有着直接的影响,因为有些费用要支付与其字节大小和资源消耗(所谓的气体)相关的费用。优化记忆使用被认为是一个具有挑战性的问题,除其他外,需要精确地推断访问的记忆位置。对于Etheium虚拟机器(EVM)的元代码(EVM)来说,情况更是如此。对于Etheyum虚拟机器(EVM)的元代码(EVM),也是这样的情况,最广泛使用的编译者(\ textt{soc})产生的元代码对降低部署和执行合同的成本具有直接影响,因为后者相当非常规和低的内存使用。 令人感兴趣的是,通过最精确的读写方式,我们现有的智能合同无法在4小时以下的时间里检测到6,6200个不需要的写入。