一句话:通过大规模实证分析揭示 Solidity 智能合约的子合约组成、代码复用特征及常见开发模式。
Solidity 智能合约开发常依赖第三方包等外部来源以降低成本,但缺乏标准化包管理器,给下游应用的安全保障带来困难。已有研究多关注代码克隆,未考察外部组件如何引入,合约组成与特征仍不清晰。本文对超过 35 万个 Solidity 智能合约开展实证研究,分析其组成、代码复用并识别常见开发模式。结果发现:典型合约约含 10 个子合约,其中逾 80% 来自外部;自研子合约中约 50% 的独特函数占比不足 10%,函数级复用普遍;外部子合约中约 35% 是标准/协议接口模板,但子合约类型使用不一致;并提取出 61 种频繁复用的开发模式,为安全高效开发提供洞见。
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.