TL;DR
This paper challenges the robustness of modern machine learning (ML)-based code clone detectors by introducing a framework called CLONEGEN. CLONEGEN generates semantic-preserving code transformations that can fool these detectors, revealing a significant vulnerability. The authors also propose a novel Deep Reinforcement Learning-based Sequence Generation (DRLSG) strategy that proves most effective in creating these "evasive" clones, and demonstrate that adversarial training with these clones can improve detector robustness.
What Problem Does This Paper Address?
Software clone detection, the task of identifying duplicated code snippets, has seen remarkable progress with the advent of ML techniques, particularly deep learning. These advanced detectors often achieve over 95% accuracy, leading to a perception that the problem is largely solved. However, the authors argue that the robustness of these ML models against subtle, yet semantically equivalent, code modifications remains largely untested. Existing detectors might be brittle, failing when faced with code that looks syntactically different but functions identically. This paper aims to systematically challenge these ML models by generating such semantically equivalent but syntactically altered code snippets, thereby exposing and quantifying their robustness limitations.
Methods
The core of the paper is the CLONEGEN framework, designed to generate semantic-preserving code transformations. CLONEGEN employs two main components:
- Transformation Operators: A set of 15 lightweight, atomic code transformation operators are used. These operators are designed to alter code syntax (e.g., renaming variables, changing loop structures, reordering independent statements) without changing the underlying program semantics. This is crucial, as the goal is to create "semantic clones" that are not detected.
- Transformation Strategy: To guide the application of these operators, CLONEGEN supports several strategies:
- Heuristic Strategies: Random Search (RS), Genetic Algorithm (GA), and Markov Chain Monte Carlo (MCMC) are used to combine transformations. These strategies aim to create diverse code variants.
- DRLSG (Deep Reinforcement Learning-based Sequence Generation): This is the paper's novel contribution. DRLSG uses a deep reinforcement learning agent (specifically, a Proximal Policy Optimization - PPO - model) to learn an optimal sequence of applying transformations. The agent is trained to maximize a reward function that encourages generating code that is classified as a non-clone by the target detector. This strategy is designed to be more adaptive and effective by incorporating feedback from the clone detectors themselves.
The generated clone pairs (original code and its transformed variant) are then fed to various clone detectors to assess their detection accuracy.
Datasets
The primary dataset used is OJClone [21], a widely used benchmark for source code clone detection. OJClone contains 104 folders, each with 500 solutions to the same programming problem, making it suitable for evaluating semantic clone detection. The authors create four new datasets (DRS, DGA, DMCMC, DDRL) by applying the respective transformation strategies (RS, GA, MCMC, DRLSG) to the original OJClone dataset. These new datasets are used to test the robustness of the clone detectors.
Key Insights and Ideas
- ML Detectors are Brittle: Despite high reported accuracy, state-of-the-art ML-based clone detectors are surprisingly vulnerable to simple, semantic-preserving code transformations.
- Lightweight Transformations Suffice: Complex obfuscation techniques are not necessary to fool these detectors; simple syntactic changes can be highly effective.
- DRLSG Outperforms Heuristics: The proposed DRLSG strategy is significantly more effective than traditional heuristics (RS, GA, MCMC) in generating code clones that evade detection. This highlights the power of adaptive, feedback-driven generation.
- Adversarial Training Improves Robustness: Training ML-based clone detectors with the generated adversarial samples can significantly improve their accuracy and resilience against these evasive clones.
- Token-based Detectors are More Vulnerable: Detectors relying solely on token-level information (like TEXTLSTM) are more easily fooled than those incorporating structural information (AST, CFG, PDG).
Key Results
- CLONEGEN, particularly with the DRLSG strategy, can drastically reduce the F1-score of ML-based detectors from over 90% to as low as 50-70%.
- TEXTLSTM, a token-based detector, showed the most significant drop in accuracy, with an F1-score as low as 0.421 against DRLSG-generated clones.
- TBCCD, which uses both AST and token information, demonstrated better robustness but was still significantly impacted.
- Adversarial training using CLONEGEN-generated clones improved the F1-scores of ML-based detectors. For instance, TEXTLSTM's F1 improved by an average of 0.236.
- The DRLSG strategy was consistently the most effective in generating clones that bypassed detectors, even after adversarial training.
- Traditional clone detectors (SOURCERERCC, NICAD, CCALIGNER, DECKARD) also showed very low recall values (less than 10% in some cases) against CLONEGEN-generated clones, indicating their limitations against semantic variations.
Limitations and Future Work
- Dataset Specificity: The evaluation was primarily conducted on the OJClone dataset, which is C/C++ focused. While the authors believe findings generalize to other high-level languages, further validation is needed.
- Limited ML Detectors: Due to tool availability, only three ML-based detectors were evaluated. The authors suggest supporting more detectors and code plagiarism tools in the future.
- Parameter Tuning: While efforts were made to use reported parameters and fine-tune others, the sensitivity of ML models to parameter settings is a general challenge.
- Future Work: The authors call for more attention to the robustness of ML-based clone detectors and suggest that hybrid source code representations might be a promising direction for improving their resilience. They also plan to make their source code and experimental data publicly available.
Summary updated