Abstract
Code clone is common in software development, which usually leads to software defects or copyright infringement. Researchers have paid significant attention to code clone detection, and many methods have been proposed. However, the patterns for generating the code clones do not always remain the same. In order to fool the clone detection systems, the plagiarists, known as the clone creator, usually conduct a series of tricky modifications on the code fragments to make the clone difficult to detect. The existing clone detection approaches, which neglects the dynamics of the “contest” between the plagiarist and the detectors, is doomed to be not robust to adversarial revision of the code. In this paper, we propose a novel clone detection approach, namely ACD, to mimic the adversarial process between the plagiarist and the detector, which enables us to not only build strong a clone detector but also model the behavior of the plagiarists. Such a plagiarist model may in turn help to understand the vulnerability of the current software clone detection tools. Experiments show that the learned policy of plagiarist can help us build stronger clone detector, which outperforms the existing clone detection methods.
Introduction
In the modern software engineering landscape, the practice of code cloning—reusing code fragments through copying and pasting—is a double-edged sword. While it can accelerate development, it often introduces significant risks, including the propagation of bugs and potential copyright infringement. Consequently, the research community has invested heavily in automated code clone detection. However, these efforts face a persistent challenge: the "arms race" between those who create clones (plagiarists) and those who seek to detect them.
Traditional detection tools often rely on lexical or syntactical similarity, looking for textual overlap or structural patterns. However, a sophisticated plagiarist can easily bypass these systems by applying semantic-preserving modifications, such as renaming variables, restructuring loops, or inserting redundant logic. Because most existing models are trained on static datasets, they fail to account for the dynamic, adversarial nature of this contest. To address this, the paper "Find Me if You Can" introduces a framework that models the interaction between the hider and the seeker.
The Adversarial Clone Detection (ACD) Framework
The core contribution of this research is the Adversarial Clone Detection (ACD) framework. Unlike static models, ACD treats clone detection as a game played between two competing neural networks: the Plagiarist and the Detector. This adversarial setup forces the detector to evolve alongside increasingly sophisticated camouflage techniques.
1. The Plagiarist ($P_\theta$)
The Plagiarist is modeled as a Reinforcement Learning (RL) agent. Its objective is to modify a code fragment just enough to deceive the detector while ensuring the code's original functionality remains intact. Using Policy Gradient methods and Monte Carlo Tree Search, the agent explores a space of potential modifications to find the most effective "tricky" changes.
- Actions: The agent can perform two primary types of modifications: Insertions (e.g., adding "always-true" conditional blocks) and Replacements (e.g., substituting logic conditions with boolean variables).
- Reward: The agent receives a positive reward whenever the Detector fails to identify its modified code as a clone, effectively maximizing the False Negative Rate of the detection system.
2. The Detector ($D_\phi$)
The Detector is an AST-based LSTM (Long Short-Term Memory) network. Instead of treating code as simple text, it parses the source code into an Abstract Syntax Tree (AST). This allows the model to capture the structural and hierarchical flow of the program. By training against the Plagiarist, the Detector learns to ignore superficial changes and focus on the underlying semantic logic.
Modeling Tricky Modifications
The effectiveness of the ACD framework stems from the Plagiarist's ability to apply diverse modifications across various code constructs. By simulating these adversarial actions, the system identifies which parts of a program are most vulnerable to camouflage.
As shown in the figure above, the Plagiarist can target specific structures like for loops, try-catch blocks, and if statements. In Java, for instance, modifying do-while loops proved highly effective at deceiving standard detectors. In C, the agent often targeted function calls and declarations to hide clones.
Experimental Evaluation and Results
The researchers evaluated ACD against two major benchmarks: BigCloneBench (a massive Java dataset with over 6 million clone pairs) and OJClone (a collection of C programs from an Online Judge system). These datasets provide a rigorous testing ground for identifying "Type-4" clones—fragments that are functionally similar but syntactically distinct.
Key findings include:
- State-of-the-Art Performance: ACD significantly outperformed existing tools like Deckard, SourcererCC, and CDLH. On BigCloneBench, ACD achieved an F1-score of 0.92, a substantial improvement over the previous best of 0.82.
- Enhanced Robustness: The most notable gain was in Recall. In the OJClone dataset, ACD's ability to find camouflaged clones was nearly double that of traditional tools. This suggests that the adversarial training successfully taught the model to look past the "noise" introduced by the plagiarist.
- Understanding Vulnerabilities: By analyzing the Plagiarist's learned policy, the researchers were able to pinpoint specific structural vulnerabilities in current deep-learning-based clone detectors.
Conclusion
The ACD framework demonstrates that the most effective way to build a robust clone detector is to simulate the very adversary it is meant to defeat. By framing clone detection as a dynamic contest, the model moves beyond simple pattern matching toward a deeper semantic understanding of code. While future work is needed to expand the modification space and adapt the system to more dynamic languages like Python, "Find Me if You Can" provides a powerful blueprint for the next generation of software security tools.
Summary updated