[论文解读] Challenging Machine Learning-based Clone Detectors via Semantic-preserving Code Transformations
本文提出 CloneGen,一种框架,通过生成语义保持的代码变换来挑战基于机器学习的克隆检测器的鲁棒性。通过应用轻量级变换(如变量重命名和循环重构)并结合启发式与深度强化学习策略,CloneGen 成功规避了最先进的基于机器学习的检测器(如 ASTNN、TBCCD 和 TextLSTM)的检测,揭示了这些模型对简单代码变化的脆弱性。
Software clone detection identifies similar code snippets. It has been an active research topic that attracts extensive attention over the last two decades. In recent years, machine learning (ML) based detectors, especially deep learning-based ones, have demonstrated impressive capability on clone detection. It seems that this longstanding problem has already been tamed owing to the advances in ML techniques. In this work, we would like to challenge the robustness of the recent ML-based clone detectors through code semantic-preserving transformations. We first utilize fifteen simple code transformation operators combined with commonly-used heuristics (i.e., Random Search, Genetic Algorithm, and Markov Chain Monte Carlo) to perform equivalent program transformation. Furthermore, we propose a deep reinforcement learning-based sequence generation (DRLSG) strategy to effectively guide the search process of generating clones that could escape from the detection. We then evaluate the ML-based detectors with the pairs of original and generated clones. We realize our method in a framework named CloneGen. CloneGen In evaluation, we challenge the two state-of-the-art ML-based detectors and four traditional detectors with the code clones after semantic-preserving transformations via the aid of CloneGen. Surprisingly, our experiments show that, despite the notable successes achieved by existing clone detectors, the ML models inside these detectors still cannot distinguish numerous clones produced by the code transformations in CloneGen. In addition, adversarial training of ML-based clone detectors using clones generated by CloneGen can improve their robustness and accuracy. CloneGen Meanwhile, compared with the commonly-used heuristics, the DRLSG strategy has shown the best effectiveness in generating code clones to decrease the detection accuracy of the ML-based detectors.
研究动机与目标
- 研究近期基于机器学习的克隆检测器对语义保持代码变换的鲁棒性。
- 开发一种轻量级、自动化的框架,生成能够规避基于机器学习检测器的代码克隆。
- 评估启发式搜索策略与深度强化学习是否能有效生成降低检测器准确率的对抗性克隆。
- 证明尽管报告准确率较高,当前基于机器学习的克隆检测器仍对简单但语义保持的代码变化存在漏洞。
- 通过使用生成的克隆进行对抗性训练,倡导提升克隆检测模型的鲁棒性。
提出的方法
- 设计并实现15种轻量级、语义保持的代码变换操作符(如变量重命名、循环转换、语句重排)。
- 集成三种启发式搜索策略——随机搜索、遗传算法和马尔可夫链蒙特卡洛——以探索有效的变换组合。
- 开发一种基于深度强化学习的序列生成(DRLSG)策略,以引导搜索过程,生成更有效的对抗性克隆。
- 将该框架应用于原始源代码片段,生成保持语义等价性的变换代码克隆。
- 在基于机器学习的(ASTNN、TBCCD、TextLSTM)和传统检测器(如 FCDetector)上评估生成的克隆,以测量检测准确率的下降。
- 使用生成的对抗性克隆进行对抗性训练,以提升检测器的鲁棒性和准确率。
实验结果
研究问题
- RQ1语义保持的代码变换是否能有效规避最先进基于机器学习的克隆检测器的检测?
- RQ2不同搜索策略(启发式与 DRLSG)在生成降低检测器准确率的克隆方面表现如何比较?
- RQ3当前基于机器学习的克隆检测器在经过轻量级变换后,对语义等价的代码克隆失败的程度如何?
- RQ4使用生成的克隆进行对抗性训练是否能提升基于机器学习的克隆检测器的鲁棒性和准确率?
- RQ5现有克隆检测器在面对简单但有效的代码变换时存在哪些局限性?
主要发现
- 尽管在标准基准上准确率超过95%,基于机器学习的克隆检测器(如 ASTNN、TBCCD 和 TextLSTM)在 CloneGen 生成的语义保持变换后,仍未能检测到大量克隆。
- DRLSG 策略在生成规避检测的克隆方面优于传统启发式方法,证明其在引导搜索对抗性代码变体方面的有效性。
- 传统克隆检测器也受到生成克隆的影响,尽管程度低于基于机器学习的检测器,表明其对代码变换存在更广泛的脆弱性。
- 使用 CloneGen 生成的克隆进行对抗性训练,提升了基于机器学习检测器的鲁棒性和准确率,表明此类数据增强可增强模型泛化能力。
- 本研究揭示了当前基于机器学习的克隆检测器存在关键的鲁棒性差距,凸显了对更稳健模型及包含语义变体的更好训练数据的需求。
- 源代码和实验数据已公开发布于 https://github.com/CloneGen/CLONEGEN,支持可复现性与进一步研究。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。