Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/3611643.3616270acmconferencesArticle/Chapter ViewAbstractPublication PagesfseConference Proceedingsconference-collections
research-article
Open access

Demystifying the Composition and Code Reuse in Solidity Smart Contracts

Published: 30 November 2023 Publication History

Abstract

As the development of Solidity smart contracts has increased in popularity, the reliance on external sources such as third-party packages increases to reduce development costs. However, despite the use of external sources bringing flexibility and efficiency to the development, they could also complicate the process of assuring the security of downstream applications due to the lack of package managers for standardized ways and sources. While previous studies have only focused on code clones without considering how the external components are introduced, the compositions of a smart contract and their characteristics still remain puzzling.
To fill these gaps, we conducted an empirical study with over 350,000 Solidity smart contracts to uncover their compositions, conduct code reuse analysis, and identify prevalent development patterns. Our findings indicate that a typical smart contract comprises approximately 10 subcontracts, with over 80% of these originating from external sources, reflecting the significant reliance on third-party packages. For self-developed subcontracts, around 50% of the subcontracts have less than 10% unique functions, suggesting that code reuse at the level of functions is also common. For external subcontracts, though around 35% of the subcontracts are interfaces to provide templates for standards or protocols, an inconsistency in the use of subcontract types is also identified. Lastly, we extracted 61 frequently reused development patterns, offering valuable insights for secure and efficient smart contract development.

Supplementary Material

Video (fse23main-p222-p-video.mp4)
"Smart contracts are a special form of program that use blockchain technology to automate, verify, and enforce agreements between parties. As the development of Solidity smart contracts has increased in popularity, the reliance on third-party packages increases to reduce development costs. However, the diverse and flexible approaches to introducing external subcontracts (i.e., contract-level code blocks) make it difficult to assure the security of downstream applications. Hence, it is crucial to properly manage external subcontracts in the development of smart contracts to ensure the security of Web3 applications. While previous studies have only focused on a single part of smart contracts such as subcontracts or functions during analysis, the common compositions of a smart contract and their characteristics still remain mysterious. To fill these gaps, we first decomposed smart contracts into various subcontracts and discussed the common approaches to introduce subcontracts and their origins in smart contract development. We then conducted code reuse analysis for various subcontracts separately to better understand the compositions of smart contracts. Through the study, we identified that over 80% of the subcontracts in smart contracts are from external sources while the largest identified external source is NPM, accounting for over 72% of the total external subcontracts. For self-developed subcontracts, around 50% of the subcontracts have less than 10% unique functions, suggesting that code reuse at the level of functions is also common. For external subcontracts, though around 35% of the subcontracts are interfaces to provide templates for standards or protocols, an inconsistency in the use of subcontract types is also identified. Lastly, we extracted and accessed 10 frequently reused development patterns."

References

[1]
2022. https://github.com/ethereum/solidity
[2]
2022. https://github.com/
[3]
2022. https://docs.ipfs.tech/concepts/ipfs-gateway/
[4]
2022. https://gateway.ethswarm.org/
[5]
2022. https://remix-ide.readthedocs.io/en/latest/import.html
[6]
2022. ANTLR v4. https://github.com/antlr/antlr4 original-date: 2010-02-04T01:36:28Z
[7]
2022. Ethereum (ETH) Blockchain Explorer. http://etherscan.io/
[8]
2022. Ethereum Improvement Proposals (EIPs). https://github.com/ethereum/EIPs original-date: 2015-10-26T13:57:23Z
[9]
2022. npm. https://www.npmjs.com/
[10]
2022. OpenZeppelin/openzeppelin-contracts. https://github.com/OpenZeppelin/openzeppelin-contracts original-date: 2016-08-01T20:54:54Z
[11]
2023. anyswap/multichain-smart-contracts: multichain smart contracts. https://github.com/anyswap/multichain-smart-contracts (Accessed on 01/23/2023)
[12]
2023. Contracts — Solidity 0.8.17 documentation. https://docs.soliditylang.org/en/v0.8.17/contracts.html (Accessed on 01/29/2023)
[13]
2023. EIPs/eip-20.md at master · ethereum/EIPs. https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md (Accessed on 01/31/2023)
[14]
2023. EXPLAINED: THE MULTICHAIN HACK (JANUARY 2022). https://halborn.com/explained-the-multichain-hack-january-2022/ (Accessed on 01/23/2023)
[15]
2023. goerli.etherscan.io. https://goerli.etherscan.io/ (Accessed on 01/23/2023)
[16]
2023. Hardhat | Ethereum development environment for professionals by Nomic Foundation. https://hardhat.org/ (Accessed on 01/27/2023)
[17]
2023. Home. https://sites.google.com/view/solidity-contract-analysis/home (Accessed on 02/02/2023)
[18]
2023. Home | ethereum.org. https://ethereum.org/en/ (Accessed on 01/20/2023)
[19]
2023. Home | Uniswap Protocol. https://uniswap.org/ (Accessed on 01/27/2023)
[20]
2023. manifoldxyz/creator-core-solidity. https://github.com/manifoldxyz/creator-core-solidity (Accessed on 06/11/2023)
[21]
2023. PatrickAlphaC/storage-factory-fcc. https://github.com/PatrickAlphaC/storage-factory-fcc (Accessed on 02/01/2023)
[22]
2023. polygon.technology. https://polygon.technology/ (Accessed on 06/25/2023)
[23]
2023. Smart contract - Wikipedia. https://en.wikipedia.org/wiki/Smart_contract (Accessed on 01/24/2023)
[24]
2023. www.bnbchain.org. https://www.bnbchain.org/ (Accessed on 06/25/2023)
[25]
Massimo Bartoletti and Livio Pompianu. 2017. An Empirical Analysis of Smart Contracts: Platforms, Applications, and Design Patterns. Lecture Notes in Computer Science, 03, https://doi.org/10.1007/978-3-319-70278-0_31
[26]
Lexi Brent, Neville Grech, Sifis Lagouvardos, Bernhard Scholz, and Yannis Smaragdakis. 2020. Ethainter: a smart contract security analyzer for composite vulnerabilities. In Proceedings of the 41st ACM SIGPLAN Conference on Programming Language Design and Implementation. 454–469.
[27]
Jiachi Chen, Xin Xia, David Lo, John Grundy, and Xiaohu Yang. 2021. Maintenance-related concerns for post-deployed Ethereum smart contract development: issues, techniques, and future challenges. Empirical Software Engineering, 26, 6 (2021), 1–44.
[28]
Xiangping Chen, Peiyong Liao, Yixin Zhang, Yuan Huang, and Zibin Zheng. 2021. Understanding Code Reuse in Smart Contracts. 470–479. https://doi.org/10.1109/SANER50967.2021.00050
[29]
W. G. Cochran. 1934. The distribution of quadratic forms in a normal system, with applications to the analysis of covariance. Mathematical Proceedings of the Cambridge Philosophical Society, 30, 2 (1934), 178–191. https://doi.org/10.1017/S0305004100016595
[30]
Token Generator. 2023. Token Generator | Create ERC20 or BEP20 Token | SmartContracts Tools. https://www.smartcontracts.tools/token-generator/ (Accessed on 02/03/2023)
[31]
Jiawei Han, Hong Cheng, Dong Xin, and Xifeng Yan. 2007. Frequent pattern mining: current status and future directions. Data mining and knowledge discovery, 15, 1 (2007), 55–86.
[32]
Lingxiao Jiang, Ghassan Misherghi, Zhendong Su, and Stephane Glondu. 2007. Deckard: Scalable and accurate tree-based detection of code clones. In 29th International Conference on Software Engineering (ICSE’07). 96–105. https://doi.org/10.1109/ICSE.2007.30
[33]
Faizan Khan, Istvan David, Daniel Varro, and Shane McIntosh. 2022. Code Cloning in Smart Contracts on the Ethereum Platform: An Extended Replication Study. IEEE Transactions on Software Engineering, 1–13. issn:1939-3520 https://doi.org/10.1109/TSE.2022.3207428 Conference Name: IEEE Transactions on Software Engineering
[34]
Shafaq Naheed Khan, Faiza Loukil, Chirine Ghedira-Guegan, Elhadj Benkhelifa, and Anoud Bani-Hani. 2021. Blockchain smart contracts: Applications, challenges, and future trends. Peer-to-peer Networking and Applications, 14, 5 (2021), 2901–2925.
[35]
Masanari Kondo, Gustavo A. Oliva, Zhen Ming (Jack) Jiang, Ahmed E. Hassan, and Osamu Mizuno. 2020. Code cloning in smart contracts: a case study on verified contracts from the Ethereum blockchain platform. Empirical Software Engineering, 25, 6 (2020), Nov., 4617–4675. issn:1573-7616 https://doi.org/10.1007/s10664-020-09852-5
[36]
Paul Levy. 2014. Finite Population Correction. isbn:9781118445112 https://doi.org/10.1002/9781118445112.stat05700
[37]
Chao Liu, Han Liu, Zhao Cao, Zhong Chen, Bangdao Chen, and Bill Roscoe. 2018. ReGuard: Finding Reentrancy Bugs in Smart Contracts. In Proceedings of the 40th International Conference on Software Engineering: Companion Proceeedings (ICSE ’18). Association for Computing Machinery, New York, NY, USA. 65–68. isbn:9781450356633 https://doi.org/10.1145/3183440.3183495
[38]
Bill Marino and Ari Juels. 2016. Setting Standards for Altering and Undoing Smart Contracts. 9718, 151–166. isbn:978-3-319-42018-9 https://doi.org/10.1007/978-3-319-42019-6_10
[39]
Bhabendu Kumar Mohanta, Soumyashree S Panda, and Debasish Jena. 2018. An Overview of Smart Contract and Use Cases in Blockchain Technology. In 2018 9th International Conference on Computing, Communication and Networking Technologies (ICCCNT). 1–4. https://doi.org/10.1109/ICCCNT.2018.8494045
[40]
Gustavo A. Oliva, Ahmed E. Hassan, and Zhen Ming (Jack) Jiang. 2020. An exploratory study of smart contracts in the Ethereum blockchain platform. Empirical Software Engineering, 25, 3 (2020), May, 1864–1904. issn:1573-7616 https://doi.org/10.1007/s10664-019-09796-5 Company: Springer Distributor: Springer Institution: Springer Label: Springer Number: 3 Publisher: Springer US
[41]
Giuseppe Antonio Pierro and Roberto Tonelli. 2021. Analysis of Source Code Duplication in Ethreum Smart Contracts. 701–707. https://doi.org/10.1109/SANER50967.2021.00089
[42]
Chanchal Roy and James Cordy. 2007. A Survey on Software Clone Detection Research. School of Computing TR 2007-541, Jan.
[43]
Amritraj Singh, Reza Meimandi Parizi, Qi Zhang, Kim-Kwang Raymond Choo, and Ali Dehghantanha. 2020. Blockchain smart contracts formalization: Approaches and challenges to address vulnerabilities. Comput. Secur., 88 (2020).
[44]
Anna Vacca, Andrea Di Sorbo, Corrado A Visaggio, and Gerardo Canfora. 2021. A systematic literature review of blockchain and smart contract development: Techniques, tools, and open challenges. Journal of Systems and Software, 174 (2021), 110891.
[45]
Zhiyuan Wan, Xin Xia, David Lo, Jiachi Chen, Xiapu Luo, and Xiaohu Yang. 2021. Smart contract security: A practitioners’ perspective. In 2021 IEEE/ACM 43rd International Conference on Software Engineering (ICSE). 1410–1422.
[46]
Maximilian Wohrer and Uwe Zdun. 2018. Smart contracts: security patterns in the ethereum ecosystem and solidity. In 2018 International Workshop on Blockchain Oriented Software Engineering (IWBOSE). 2–8.
[47]
Carl R. Worley and Anthony Skjellum. 2018. Opportunities, Challenges, and Future Extensions for Smart-Contract Design Patterns. In Business Information Systems.
[48]
Jiahui Wu, Zhengzi Xu, Wei Tang, Lyuye Zhang, Yueming Wu, Chengyue Liu, Kairan Sun, Lida Zhao, and Yang Liu. 2023. OSSFP: Precise and Scalable C/C++ Third-Party Library Detection using Fingerprinting Functions. In 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE). 270–282. https://doi.org/10.1109/ICSE48619.2023.00034
[49]
Zibin Zheng, Shaoan Xie, Hong-Ning Dai, Weili Chen, Xiangping Chen, Jian Weng, and Muhammad Imran. 2020. An overview on smart contracts: Challenges, advances and platforms. Future Generation Computer Systems, 105 (2020), 475–491.
[50]
Zibin Zheng, Shaoan Xie, Hong-Ning Dai, Xiangping Chen, and Huaimin Wang. 2018. Blockchain challenges and opportunities: A survey. International Journal of Web and Grid Services, 14 (2018), 10, 352. https://doi.org/10.1504/IJWGS.2018.095647
[51]
Weiqin Zou, David Lo, Pavneet Singh Kochhar, Xuan-Bach Dinh Le, Xin Xia, Yang Feng, Zhenyu Chen, and Baowen Xu. 2019. Smart contract development: Challenges and opportunities. IEEE Transactions on Software Engineering, 47, 10 (2019), 2084–2106.

Cited By

View all
  • (2024)Decoding Web3: In-depth Analysis of the Third-Party Package Supply ChainProceedings of the 15th Asia-Pacific Symposium on Internetware10.1145/3671016.3671402(457-466)Online publication date: 24-Jul-2024
  • (2024)Static Application Security Testing (SAST) Tools for Smart Contracts: How Far Are We?Proceedings of the ACM on Software Engineering10.1145/36607721:FSE(1447-1470)Online publication date: 12-Jul-2024

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
ESEC/FSE 2023: Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering
November 2023
2215 pages
ISBN:9798400703270
DOI:10.1145/3611643
This work is licensed under a Creative Commons Attribution-NonCommercial International 4.0 License.

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 30 November 2023

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. code reuse
  2. development pattern
  3. smart contract composition

Qualifiers

  • Research-article

Funding Sources

  • the National Research Foundation, Singapore, and the Cyber Security Agency under its National Cybersecurity R&D Programme

Conference

ESEC/FSE '23
Sponsor:

Acceptance Rates

Overall Acceptance Rate 112 of 543 submissions, 21%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)486
  • Downloads (Last 6 weeks)52
Reflects downloads up to 11 Feb 2025

Other Metrics

Citations

Cited By

View all
  • (2024)Decoding Web3: In-depth Analysis of the Third-Party Package Supply ChainProceedings of the 15th Asia-Pacific Symposium on Internetware10.1145/3671016.3671402(457-466)Online publication date: 24-Jul-2024
  • (2024)Static Application Security Testing (SAST) Tools for Smart Contracts: How Far Are We?Proceedings of the ACM on Software Engineering10.1145/36607721:FSE(1447-1470)Online publication date: 12-Jul-2024

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media