Skip to main content
QUICK REVIEW

[论文解读] ADF-GA: Data Flow Criterion Based Test Case Generation for Ethereum Smart Contracts

Pengcheng Zhang, Jianan Yu|arXiv (Cornell University)|Feb 29, 2020
Software Testing and Debugging Techniques参考文献 25被引用 5
一句话总结

该论文提出 ADF-GA,一种基于遗传算法的以太坊智能合约测试用例生成方法,采用全使用准则(all-uses criterion)实现完整的数据流覆盖。通过构建控制流图,执行数据流分析以识别定义-使用对(dup),并采用加权适应度函数优先覆盖与 require 语句相关的 dup,ADF-GA 在更少的迭代次数内实现了比基线方法更高的测试覆盖率。

ABSTRACT

Testing is an important technique to improve the quality of Ethereum smart contract programs. However, current work on testing smart contract only focus on static problems of smart contract programs. A data flow oriented test case generation approach for dynamic testing of smart contract programs is still missing. To address this problem, this paper proposes a novel test case generation approach, called ADF-GA (All-uses Data Flow criterion based test case generation using Genetic Algorithm), for Solidity based Ethereum smart contract programs. ADF-GA aims to efficiently generate a valid set of test cases via three stages. First, the corresponding program control flow graph is constructed from the source codes. Second, the generated control flow graph is analyzed to obtain the variable information in the Solidity programs, locate the require statements, and also get the definition-use pairs to be tested. Finally, a genetic algorithm is used to generate test cases, in which an improved fitness function is proposed to calculate the definition-use pairs coverage of each test case with program instrumentation. Experimental studies are performed on several representative Solidity programs. The results show that ADF-GA can effectively generate test cases, achieve better coverage, and reduce the number of iterations in genetic algorithm.

研究动机与目标

  • 解决以太坊智能合约缺乏动态、面向数据流的测试技术的问题。
  • 克服现有方法仅关注静态分析或已知漏洞模式的局限性。
  • 开发一种针对 Solidity 特有特性的测试用例生成方法,特别是 require 语句。
  • 通过强调定义-使用对(dup)覆盖,尤其是与 require 相关的逻辑,提升测试覆盖率。
  • 优化遗传算法过程,以减少收敛时间并提高测试用例生成的效率。

提出的方法

  • 从 Solidity 源代码构建控制流图(CFG)作为中间表示。
  • 执行数据流分析,提取变量的定义、使用以及所有定义-使用对(dup),包括涉及 require 语句的对。
  • 设计一种染色体编码方案,用于在遗传算法框架中表示测试用例输入。
  • 实现一种自定义适应度函数,为与 require 相关的 dup 分配更高的权重,以指导进化选择。
  • 使用遗传操作(选择、交叉、变异)演化测试用例,以最大化 dup 覆盖率。
  • 对智能合约代码进行插桩,以在测试执行期间测量实际的 dup 覆盖率,并将结果反馈至适应度函数。

实验结果

研究问题

  • RQ1基于数据流准则的测试用例生成方法是否能有效提升以太坊智能合约测试的覆盖率?
  • RQ2在适应度函数中引入针对 require 语句相关 dup 的加权机制,对测试用例生成的效率和覆盖率有何影响?
  • RQ3ADF-GA 在覆盖率和收敛速度方面,与传统基于遗传算法的方法(如 GA-C#)相比,优势有多大?
  • RQ4适应度函数中的参数设置(如 ε)为何种取值时,能为 ADF-GA 带来最优的覆盖率和性能表现?
  • RQ5ADF-GA 是否能生成比随机测试或基线 GA 方法具有更高定义-使用对覆盖率的测试用例?

主要发现

  • 在所有 11 个评估的智能合约中,ADF-GA 在正常 dup(N_dup)和 require 相关 dup(R_dup)的覆盖率方面均达到最高,优于随机测试(RT)和 GA-C#。
  • 当 ε 设为 0.45 时,ADF-GA 实现了最优覆盖率,分别仅需 11.36 和 7.45 次迭代即可达到最大 R_dup 和 N_dup 覆盖率。
  • ADF-GA 仅需 7.45 次迭代即可达到 GA-C# 的最佳覆盖率,而 GA-C# 则需要 11.36 次迭代才能达到其首次最大适应度值。
  • 在大多数合约中,ADF-GA 的总迭代次数略少于 GA-C#,表明其收敛效率更高。
  • ADF-GA 中改进的适应度函数有效优先处理了与 require 相关的 dup,从而实现了更优的高影响力测试用例的区分与选择。
  • 在所有测试合约中,ADF-GA 的 N_dup 和 R_dup 覆盖率均与或高于 GA-C#,证明了加权适应度函数的有效性。

更好的研究,从现在开始

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

无需绑定信用卡

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