Introduction: The Problem of Code Stylometry
Every programmer possesses a unique "signature"—a stylistic fingerprint reflected in their choice of variable names, loop structures, and API usage. Authorship attribution leverages these patterns to identify the creator of source code. While beneficial for software forensics and plagiarism detection, it poses a significant privacy risk to developers who wish to remain anonymous, such as contributors to sensitive open-source projects.
Modern attribution methods, often based on deep learning, have achieved high accuracy. However, they face a fundamental vulnerability: the problem-feature space dilemma. While it is trivial to mathematically perturb a feature vector in a latent space, translating those changes back into valid, functional, and "natural-looking" source code is exceptionally difficult.
Methodology: Adversarial Code Transformations
To address this, researchers developed a novel black-box attack that combines compiler engineering with adversarial learning. The attack consists of two primary components:
1. Semantics-Preserving Transformations
Using the Clang compiler frontend, the authors implemented 36 different code transformers. These changes are designed to alter the stylistic features of the code without changing its functional behavior. Examples include:
- Control Flow: Swapping
forloops forwhileloops. - API Usage: Replacing C++
coutwith C-styleprintfstatements. - Declarations: Widening variable types (e.g.,
inttolong).
2. Monte-Carlo Tree Search (MCTS)
Because the space of possible code transformations is discrete and vast, the attack uses Monte-Carlo Tree Search (MCTS)—the algorithm behind AlphaGo—to navigate the search space. MCTS iteratively probes the attribution model to find the shortest sequence of transformations that either hides the original author's identity (untargeted attack) or successfully mimics a specific target author (targeted attack).
Experimental Setup and Datasets
The study utilized a dataset from the 2017 Google Code Jam (GCJ), consisting of 1,632 C++ files from 204 programmers. To ensure the attack focused on deep syntactic patterns rather than superficial formatting, all code was preprocessed with clang-format to remove layout-based features like indentation.
Key Results
The attack was tested against state-of-the-art attribution methods, including Random Forests and LSTMs, with striking results:
- Evasion Success: In untargeted attacks, the accuracy of attribution models plummeted from over 88% to just 1%.
- Impersonation: In targeted attacks, the model was successfully fooled into attributing code to a specific "victim" author in 77% to 81% of cases.
- Human Plausibility: A study with 15 human participants revealed that the modified code remains highly readable. Participants could only distinguish modified code from original code 60% of the time, which is only slightly better than a random guess.
- Transferability: Adversarial examples generated against one model often successfully fooled others, suggesting that the vulnerabilities are inherent to the stylistic features themselves.
Conclusion
The findings demonstrate that current code stylometry is "security by obscurity." Because models rely on features that are easily manipulated by automated tools, they are inherently fragile. This research highlights the need for more resilient attribution techniques that focus on high-level logic or algorithmic choices, which are far more difficult to automate and transform while preserving semantics.
Summary updated