Skip to main content
QUICK REVIEW

[Paper Review] How to Save My Gas Fees: Understanding and Detecting Real-world Gas Issues in Solidity Programs

Mengting He, Shihao Xia|arXiv (Cornell University)|Mar 5, 2024
Global Energy and Sustainability ResearchEnergy3 citations
TL;DR

This paper presents the first empirical study of real-world gas waste in Solidity smart contracts, identifying root causes and fixing strategies, and introduces PeCatch—a static analysis tool that detects 383 previously unknown gas inefficiencies with 94.4% accuracy and 41 out of 54 real-world gas wastes covered, significantly outperforming prior tools in detection coverage and precision.

ABSTRACT

The execution of smart contracts on Ethereum, a public blockchain system, incurs a fee called gas fee for its computation and data storage. When programmers develop smart contracts (e.g., in the Solidity programming language), they could unknowingly write code snippets that unnecessarily cause more gas fees. These issues, or what we call gas wastes, can lead to significant monetary losses for users. This paper takes the initiative in helping Ethereum users reduce their gas fees in two key steps. First, we conduct an empirical study on gas wastes in open-source Solidity programs and Ethereum transaction traces. Second, to validate our study findings, we develop a static tool called PeCatch to effectively detect gas wastes in Solidity programs, and manually examine the Solidity compiler's code to pinpoint implementation errors causing gas wastes. Overall, we make 11 insights and four suggestions, which can foster future tool development and programmer awareness, and fixing our detected bugs can save $0.76 million in gas fees daily.

Motivation & Objective

  • To empirically study real-world gas waste in Solidity smart contracts, focusing on root causes and fixing strategies.
  • To identify and categorize gas waste patterns specific to Solidity’s unique data storage mechanisms (stack, memory, storage, calldata).
  • To develop a static analysis tool, PeCatch, capable of detecting gas wastes with high accuracy and coverage.
  • To improve tooling, language design, and developer awareness by providing actionable insights and checkers for gas optimization.
  • To enable developers to reduce gas fees by detecting and fixing previously unknown gas-inefficient code patterns.

Proposed method

  • Conducted an empirical study on 100 gas waste instances from 5 popular Solidity projects, manually analyzing commit logs to identify root causes and fixing strategies.
  • Categorized gas wastes into four types based on Solidity’s data storage areas: stack, memory, storage, and calldata, each with distinct gas cost characteristics.
  • Designed PeCatch as a static analysis tool using rule-based checkers tailored to detect 8 specific gas-waste patterns, including Non-Overflow, And-in-If, Ret-Local, Alloc-Loop, Re-Sload, Bool-Field, Calldata-Para, and others.
  • Implemented PeCatch with precise static analysis techniques, including path-condition analysis and inter-procedural checks, to minimize false positives.
  • Evaluated PeCatch on benchmark programs, measuring execution time (4 seconds to 7 minutes) and comparing detection accuracy and coverage against Slither, Python-Opt, and GasSaver.
  • Extended PeCatch with future plans for inter-procedural analysis, path-condition refinement, and support for low-level opcodes and type-specific values.

Experimental results

Research questions

  • RQ1What are the root causes of gas waste in real-world Solidity smart contracts, particularly those tied to Solidity’s unique data storage mechanisms?
  • RQ2How do developers currently fix gas waste issues, and what are the common patterns in their solutions?
  • RQ3To what extent can existing static analysis tools detect real-world gas waste patterns in Solidity programs?
  • RQ4Can a new static analysis tool, PeCatch, detect more gas wastes with higher accuracy and lower false-positive rates than prior tools?
  • RQ5What are the key limitations of PeCatch, and how can future versions improve detection coverage for complex or edge-case gas-waste patterns?

Key findings

  • PeCatch detected 41 out of 54 gas wastes identified in the empirical study, demonstrating 75.9% coverage of real-world gas waste patterns.
  • PeCatch achieved a false-positive rate of less than 1.5%, significantly lower than Slither (62.5%), Python-Opt (300%), and GasSaver (9.5%).
  • PeCatch identified 383 previously unknown gas wastes across popular Solidity libraries, highlighting the prevalence of undetected gas inefficiencies.
  • The tool’s execution time ranged from 4 seconds to 7 minutes per benchmark program, indicating feasibility for integration into daily development workflows.
  • PeCatch outperformed existing tools in detecting Solidity-specific gas-waste patterns such as Non-Overflow, And-in-If, and Re-Sload, which were missed by Slither and GasSaver.
  • The main limitations of PeCatch include missing 13 gas wastes due to lack of inter-procedural analysis, path-condition complexity, and incomplete support for specific opcodes (e.g., mstore8) and values (e.g., type(uint256).max).

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.