Skip to main content
QUICK REVIEW

[论文解读] Smart Contracts Software Metrics: a First Study

Roberto Tonelli, Giuseppe Destefanis|arXiv (Cornell University)|Feb 5, 2018
Blockchain Technology Applications and Security被引用 15
一句话总结

本研究分析了超过12,000份用Solidity编写的以太坊智能合约的软件度量,以评估其统计特性是否因区块链约束而与传统软件系统不同。主要发现是,智能合约度量表现出显著受限的取值范围,并且更符合对数正态分布(尤其是代码行数),而非传统软件中常见的重尾幂律分布,表明区块链资源限制具有显著影响。

ABSTRACT

Smart contracts (SC) are software codes which reside and run over a blockchain. The code can be written in different languages with the common purpose of implementing various kinds of transactions onto the hosting blockchain, They are ruled by the blockchain infrastructure and work in order to satisfy conditions typical of traditional contracts. The software code must satisfy constrains strongly context dependent which are quite different from traditional software code. In particular, since the bytecode is uploaded in the hosting blockchain, size, computational resources, interaction between different parts of software are all limited and even if the specific software languages implement more or less the same constructs of traditional languages there is not the same freedom as in normal software development. SC software is expected to reflect these constrains on SC software metrics which should display metric values characteristic of the domain and different from more traditional software metrics. We tested this hypothesis on the code of more than twelve thousands SC written in Solidity and uploaded on the Ethereum blockchain. We downloaded the SC from a public repository and computed the statistics of a set of software metrics related to SC and compared them to the metrics extracted from more traditional software projects. Our results show that generally Smart Contracts metrics have ranges more restricted than the corresponding metrics in traditional software systems. Some of the stylized facts, like power law in the tail of the distribution of some metrics, are only approximate but the lines of code follow a log normal distribution which reminds of the same behavior already found in traditional software systems.

研究动机与目标

  • 调查智能合约软件度量是否因区块链特定约束而表现出与传统软件不同的统计特性。
  • 评估资源限制(如大小、计算成本和不可变性)对智能合约中度量分布的影响。
  • 比较智能合约度量(如代码行数、函数数、字节码)与传统软件系统中度量的分布模式。
  • 评估LOC、ABI和字节码等度量是否符合已知的统计分布,如幂律或对数正态分布。
  • 确定智能合约开发实践是否因部署和执行约束导致度量分布无异常值且紧密受限。

提出的方法

  • 收集并分析了部署在以太坊区块链上的超过12,000个智能合约的源代码、ABI和字节码。
  • 计算了标准软件度量,包括代码行数(LOC)、函数数、注释数、循环复杂度和合约大小。
  • 应用统计拟合技术,测试度量分布中对数正态分布和幂律分布的适用性。
  • 使用R²值评估对数正态和幂律模型的拟合优度,尤其关注数据主体和尾部区域。
  • 将智能合约的度量分布与传统软件系统的度量分布进行比较,以识别领域特定的差异。
  • 分析了区块链约束(如不可变性、Gas成本)对度量变异性及分布形状的影响。

实验结果

研究问题

  • RQ1智能合约软件度量是否表现出与传统软件系统不同的统计分布?
  • RQ2像不可变性和Gas成本等区块链约束在多大程度上限制了智能合约中度量值的取值范围?
  • RQ3对于代码行数和函数数等智能合约度量,对数正态分布或幂律分布中哪一个更符合其分布?
  • RQ4智能合约度量分布中是否存在显著的异常值或重尾现象,如传统软件中所见?
  • RQ5智能合约中ABI和字节码大小如何比较?它们是否呈现钟形分布或重尾分布?

主要发现

  • 智能合约中的代码行数(LOC)度量表现出对数正态分布,R²值大于0.98,与传统软件系统高度匹配。
  • 大多数智能合约度量(包括函数数、空行数和事件数)由于区块链资源约束而表现出受限的取值范围,无显著异常值或重尾现象。
  • 幂律模型在部分分布的尾部拟合效果更好,但对数正态分布更能解释大多数度量(尤其是LOC)的数据主体部分。
  • 注释数、地址数、循环复杂度和ABI等度量在尾部对对数正态分布的拟合效果较差,表明其最大值受上界限制。
  • 映射(Mapping)和修饰符(Modifier)度量在主体部分更符合幂律分布而非对数正态分布,表明其底层结构模式不同。
  • 字节码和ABI度量在初始阶段与对数正态曲线重叠,但实际数据下降更快,表明因部署约束导致分布被截断。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。