Table of Contents
Fetching ...

Micro-Patterns in Solidity Code

Luca Ruschioni, Robert Shuttleworth, Rumyana Neykova, Barbara Re, Giuseppe Destefanis

TL;DR

The paper tackles the challenge of analyzing Solidity smart contracts by introducing a catalog of 18 Solidity-specific micro-patterns organized into five categories (Security, Functional, Optimization, Interaction, and Feedback) and an automated AST-based detection framework. It demonstrates the approach on a dataset of 23,258 verified contracts across five major blockchains, revealing that 99% of contracts exhibit at least one micro-pattern and averaging 2.76 patterns per contract, with Storage Saver showing the highest adoption. The study shows platform-specific differences in pattern adoption and largely weak inter-pattern correlations, suggesting micro-patterns capture distinct design decisions. The work provides a replicable methodology and replication package, offering a scalable foundation for automated quality and security assessment in blockchain-based software.

Abstract

Solidity is the predominant programming language for blockchain-based smart contracts, and its characteristics pose significant challenges for code analysis and maintenance. Traditional software analysis approaches, while effective for conventional programming languages, often fail to address Solidity-specific features such as gas optimization and security constraints. This paper introduces micro-patterns - recurring, small-scale design structures that capture key behavioral and structural peculiarities specific to a language - for Solidity language and demonstrates their value in understanding smart contract development practices. We identified 18 distinct micro-patterns organized in five categories (Security, Functional, Optimization, Interaction, and Feedback), detailing their characteristics to enable automated detection. To validate this proposal, we analyzed a dataset of 23258 smart contracts from five popular blockchains (Ethereum, Polygon, Arbitrum, Fantom and Optimism). Our analysis reveals widespread adoption of micro-patterns, with 99% of contracts implementing at least one pattern and an average of 2.76 patterns per contract. The Storage Saver pattern showed the highest adoption (84.62% mean coverage), while security patterns demonstrated platform-specific adoption rates. Statistical analysis revealed significant platform-specific differences in pattern adoption, particularly in Borrower, Implementer, and Storage Optimization patterns.

Micro-Patterns in Solidity Code

TL;DR

The paper tackles the challenge of analyzing Solidity smart contracts by introducing a catalog of 18 Solidity-specific micro-patterns organized into five categories (Security, Functional, Optimization, Interaction, and Feedback) and an automated AST-based detection framework. It demonstrates the approach on a dataset of 23,258 verified contracts across five major blockchains, revealing that 99% of contracts exhibit at least one micro-pattern and averaging 2.76 patterns per contract, with Storage Saver showing the highest adoption. The study shows platform-specific differences in pattern adoption and largely weak inter-pattern correlations, suggesting micro-patterns capture distinct design decisions. The work provides a replicable methodology and replication package, offering a scalable foundation for automated quality and security assessment in blockchain-based software.

Abstract

Solidity is the predominant programming language for blockchain-based smart contracts, and its characteristics pose significant challenges for code analysis and maintenance. Traditional software analysis approaches, while effective for conventional programming languages, often fail to address Solidity-specific features such as gas optimization and security constraints. This paper introduces micro-patterns - recurring, small-scale design structures that capture key behavioral and structural peculiarities specific to a language - for Solidity language and demonstrates their value in understanding smart contract development practices. We identified 18 distinct micro-patterns organized in five categories (Security, Functional, Optimization, Interaction, and Feedback), detailing their characteristics to enable automated detection. To validate this proposal, we analyzed a dataset of 23258 smart contracts from five popular blockchains (Ethereum, Polygon, Arbitrum, Fantom and Optimism). Our analysis reveals widespread adoption of micro-patterns, with 99% of contracts implementing at least one pattern and an average of 2.76 patterns per contract. The Storage Saver pattern showed the highest adoption (84.62% mean coverage), while security patterns demonstrated platform-specific adoption rates. Statistical analysis revealed significant platform-specific differences in pattern adoption, particularly in Borrower, Implementer, and Storage Optimization patterns.
Paper Structure (24 sections, 3 equations, 9 figures, 4 tables)

This paper contains 24 sections, 3 equations, 9 figures, 4 tables.

Figures (9)

  • Figure 1: Micro-Pattern Detection Framework
  • Figure 2: Data Collection Method
  • Figure 3: Analysis framework. Left: E captures entities (contracts, interfaces, libraries) from these projects, MP defines micro-patterns, ValidTypes maps patterns to applicable entity types, and M is the matching function. Right: Core metrics measure pattern occurrence (Frequency), adoption rate among eligible entities (Coverage), and relative dominance (Prevalence).
  • Figure 5: Cross-Chain Pattern similarity
  • Figure 6: Representative Subset of Auxiliary Functions and Predicates
  • ...and 4 more figures