[Paper Review] Under-Optimized Smart Contracts Devour Your Money
This paper identifies that Solidity, the primary compiler for Ethereum smart contracts, generates gas-inefficient bytecode due to unoptimized programming patterns, leading to unnecessary financial costs. The authors propose GASPER, a symbolic execution-based tool that automatically detects three major gas-costly patterns—dead code, opaque predicates, and repeated SLOAD/SSTORE in loops—finding that 93.5%, 90.1%, and 80% of analyzed smart contracts suffer from these issues, respectively.
Smart contracts are full-fledged programs that run on blockchains (e.g., Ethereum, one of the most popular blockchains). In Ethereum, gas (in Ether, a cryptographic currency like Bitcoin) is the execution fee compensating the computing resources of miners for running smart contracts. However, we find that under-optimized smart contracts cost more gas than necessary, and therefore the creators or users will be overcharged. In this work, we conduct the first investigation on Solidity, the recommended compiler, and reveal that it fails to optimize gas-costly programming patterns. In particular, we identify 7 gas-costly patterns and group them to 2 categories. Then, we propose and develop GASPER, a new tool for automatically locating gas-costly patterns by analyzing smart contracts' bytecodes. The preliminary results on discovering 3 representative patterns from 4,240 real smart contracts show that 93.5%, 90.1% and 80% contracts suffer from these 3 patterns, respectively.
Motivation & Objective
- To investigate why smart contracts on Ethereum incur higher-than-necessary gas costs despite the availability of gas-efficient coding practices.
- To identify common programming patterns in Solidity that lead to excessive gas consumption, even when using the recommended compiler.
- To develop an automated tool that can detect these gas-costly patterns in real-world smart contracts without requiring source code access.
- To quantify the prevalence of these inefficiencies across the Ethereum ecosystem to demonstrate the scale of financial waste.
Proposed method
- Analyze Solidity-generated bytecode using symbolic execution to detect gas-inefficient patterns without requiring source code.
- Identify and categorize 7 gas-costly programming patterns into two groups: useless-code-related and loop-related patterns.
- Implement GASPER, a tool that leverages symbolic execution to automatically locate three representative gas-costly patterns in compiled bytecode.
- Apply GASPER to a dataset of 4,240 real-world smart contracts deployed on Ethereum up to November 5, 2016, to measure pattern prevalence.
- Use static analysis and symbolic execution to verify the presence of patterns such as dead code, opaque predicates, and redundant SLOAD/SSTORE operations in loops.
- Validate findings through real-world case studies on open-source contracts (e.g., FirstContract and Ballot) to demonstrate detectable gas savings.
Experimental results
Research questions
- RQ1To what extent do smart contracts compiled with Solidity contain gas-inefficient bytecode patterns that increase transaction and deployment costs?
- RQ2Which specific programming patterns in Solidity lead to excessive gas consumption, and how can they be automatically detected in compiled bytecode?
- RQ3How prevalent are these gas-costly patterns across the Ethereum smart contract ecosystem?
- RQ4Can symbolic execution be effectively used to detect gas-inefficient patterns in bytecode without access to source code?
- RQ5What is the potential financial impact of optimizing these patterns in real-world contracts?
Key findings
- 93.5% of the 4,240 analyzed smart contracts contain dead code or opaque predicates (patterns 1 and 2), indicating widespread inefficiency in Solidity-compiled code.
- 90.1% of contracts contain redundant SLOAD operations within loops, which can be optimized by moving the SLOAD outside the loop to reduce gas usage.
- 80% of contracts exhibit repeated SSTORE operations in loops, which can be optimized by caching the value in a stack variable.
- The case study on Ballot shows that moving a single SLOAD operation outside a loop can reduce gas consumption from 20 operations per iteration to just one, resulting in substantial savings.
- The study reveals that even with the use of the recommended Solidity compiler, a significant portion of smart contracts are not optimized for gas efficiency, leading to avoidable financial losses for users and creators.
- The prevalence of these patterns across the Ethereum ecosystem suggests that a systematic optimization effort is needed at the compiler and development tooling levels.
Better researchstarts right now
From reading papers to final review, dramatically reduce your research time.
No credit card · Free plan available
This review was created by AI and reviewed by human editors.