Robust and accurate code authorship attribution via program normalizationRobust and Accurate Authorship Attribution via Program Normalization
The authors propose the N&P framework, using code normalization to defend against authorship attribution attacks, achieving accuracy about 70% higher than vanilla models under all attacks on the Google Code Jam data.
At test time the attacker applies an arbitrary sequence of semantics-preserving transformations to the source code input (relational adversary), causing the authorship attribution model to predict the wrong author; the attack is black-box, the attacker does not know the model structure and parameters but can query model predictions (the theoretical results also apply to the white-box setting); the victim system is a source code authorship attribution model.
- Source-code authorship attribution models can be fooled by semantics-preserving code transformations (forging or concealing authorship); the authors raise two general questions: whether models provably robust to such transformations can be obtained, and what their highest accuracy is.
- The authors propose the relational adversary threat model and give the normalize-and-predict (N&P) framework: normalize both training and test inputs to the same normal form, then train and predict, with a theoretical guarantee of robustness; the accompanying heuristic algorithm FAST NORM uses monotonically decreasing transformations to efficiently find an approximate normal form.
- On the Google Code Jam data (1,632 C++ files, 204 authors), defending two attribution models: N&P-LSTM accuracy under Full attack is 71.5%, Vanilla-LSTM 0.9%, Adv-LSTM 25.1% (Table 3); N&P normalization overhead <12 小时,对抗训练 >20 days (Table 5).
- The authors state that future directions include a general normalizer for more code types and programming languages, application to non-adversarial settings, and combination with other defenses (Section 8). The experiments cover only the Google Code Jam dataset, two model architectures, and the MCTS attack of Quiring et al.; FAST NORM does not normalize the two transformation categories of function inlining and function/variable renaming.
- Evaluated models
- N&P-RFN&P-LSTMVanilla-RFVanilla-LSTM
- Benchmarks
- Google Code Jam dataset (Quiring et al. [33])
- Metrics
- test accuracy under attack (robust accuracy)clean accuracyl2-norm perturbation ratiotraining time
Researchers propose the normalize-and-predict (N&P) framework, which theoretically guarantees the robustness of any code authorship attribution method. The work formalizes attacks as a relational adversary threat model, allowing any number of semantics-preserving transformations to be applied to the input. In an evaluation defending two recent authorship attribution methods against state-of-the-art attacks, N&P improved accuracy on adversarial inputs by up to 70% over the original models, achieved 45% higher robust accuracy than adversarial training, and ran more than 40 times faster.
Paper analysis
What problem does this paper attempt to solve?
Defending source code authorship attribution models against adversarial attacks using semantics-preserving code transformations, and providing a provably robust learning framework.
Core problem: deep learning-based source code authorship attribution models are easily deceived by semantics-preserving code transformations; how to obtain a model that is provably robust to such transformations and accurate.
- Scenario and importance: authorship attribution can be used for software forensics (identifying malware authors) and also poses a privacy risk to programmers who wish to remain anonymous; Simko et al. [39] and Quiring et al. [33] have shown that attacks can make models misjudge the author through transformations such as for-to-while (Figure 1).
- Shortcomings of existing methods: the authors consider adversarial training too costly in the problem space (code transformations)—generating one adversarial example with the MCTS attack takes minutes and is CPU-intensive, and cannot be parallelized with parameter updates on GPU; moreover, adversarial training relies on gradients and is not applicable to non-parametric models such as random forests.
- Core observation: if both original inputs and adversarial inputs are mapped to the same normal form, a model trained and predicting on it is naturally robust to transformations; the normalization paradigm was previously used for network intrusion detection [18].
- Contributions of the paper: it proposes a general threat model, the relational adversary; a theoretical analysis of the robustness condition and the robustness-accuracy trade-off; the N&P learning framework and its practical normalization algorithm FAST NORM; and it instantiates and evaluates them on the authorship attribution task.
- Threat model:
- Goal: make the authorship attribution model predict the wrong author for transformed code.
- Knowledge: black-box—the attacker does not know the model structure and parameters but can query predictions for any valid input; the authors state the theoretical results also apply to the white-box setting where the attacker fully understands the learning pipeline.
- Capability: at test time, apply any number and any sequence of semantics-preserving transformations to the input (relational adversary); the transformed code still compiles and runs with unchanged behavior.
- Victim system: source code authorship attribution models (in the evaluation, two types: random forest and LSTM).
What related research exists?
Related work is divided into four groups: authorship attribution attacks, problem-space adversarial attacks, transformation defenses and adversarial training, and normalization techniques.
Authorship attribution and attacks against it
- Caliskan-Islam et al. [8] and Abuhamad et al. [2]—source-code authorship attribution using code stylometry (random forest) and LSTM, respectively; these are the two models defended in this paper.
- Simko et al. [39]—found the vulnerability of authorship attribution methods under forgery attacks; Quiring et al. [33] used a Monte-Carlo tree search variant for semantics-preserving transformation attacks, which is the main attack evaluated in this paper; Liu et al. [27] proposed a similar black-box attack.
Problem-space adversarial attacks
- Pierazzi et al. [31]—emphasized the importance of generating adversarial examples in the problem space, using automated software transplantation to construct realistic attack instances.
- Al-Dujaili et al. [3], Grosse et al. [17]—bypassed malware detectors based on API/library usage by adding redundant API calls; Rosenberg et al. [36], Hu & Tan [21], Rosenberg et al. [35]—attacked runtime-behavior-based detectors by adding redundant execution traces.
Defenses: adversarial training and transformation-oriented defenses
- Madry et al. [28], Shafahi et al. [38], Wong et al. [42]—adversarial training and its acceleration, the main defense paradigm in deep learning; Wang et al. [41], Yang et al. [45]—data pruning defenses for non-parametric models, but the authors point out that these defenses mainly consider small lp-norm perturbations.
- Yang et al. [43]—added invariance regularization against image-space transformation attacks; Hendrycks et al. [20]—used self-supervised learning to let the model detect transformations and predict labels, but the authors point out that it can only handle a single transformation or a short sequence of transformations; Incer et al. [22], Kouzemtchenko [25]—imposed monotonicity on model outputs, but the authors point out that it can only defend against addition-type attacks and lacks generality.
Normalization techniques
- Handley et al. [19]—introduced traffic normalization in network intrusion detection to eliminate evasion opportunities; since then normalization has been used in malware detection and deobfuscation [5, 6, 10, 12, 37].
Baselines and benchmarks: the defense comparison baseline is adversarial training (Adv-LSTM, only LSTM-compatible); the attack baseline is the MCTS attack of Quiring et al. [33]; the dataset is the Google Code Jam dataset provided by Quiring et al. The authors position this paper as answering the open question of "whether normalization is useful under a relational adversary", while covering both parametric and non-parametric models and giving provable robustness guarantees.
How does the paper address this problem?
N&P normalizes both training and test inputs to the normal form before training and prediction, theoretically guaranteeing robustness to a relational adversary.
Overall idea: define the normal form of each input relative to a set of transformations, and train and predict only on the normal form, so that adversarial inputs are automatically reduced and predictions remain constant. The framework is called normalize-and-predict (N&P), with the accompanying practical normalization algorithm FAST NORM.
Problem formalization and robustness condition
- A relation R is a set of input pairs (x, z) representing one admissible transformation; a relational adversary can apply any number of transformations in R to x, i.e., the feasible set S(x) = {z | x →∗R z}.
- Robustness condition (Observation 1): a classifier is robust to all x in a weakly connected component (WCC) Ci if and only if it returns the same label for all inputs in Ci.
- Normalizer choice (Definition 3): if N maps x ∈ Ci to any deterministic element in Ci, then f(N(·)) is robust to an R-relational adversary.
Robustness-accuracy trade-off
- The optimal robust accuracy under N&P is Acc∗R = ∑Ci maxl ∈ Y ∑x ∈ Ci μ(x)η(x, l), i.e., predicting for each connected component its most likely label.
- Observation 2: adding one edge to relation R only leaves the optimal robust accuracy unchanged or decreases it, with no loss only when the two merged components have the same most likely label—the authors call this the "cost of robustness".
- Figure 3 gives three cases: when labels agree, robustness is "free"; when two-way reachability holds but labels differ, N&P maintains the optimal robust accuracy; when one-way transformations lead to two inputs with different labels, N&P may be suboptimal (example in the text: N&P accuracy at most 0.49, whereas the highest robust accuracy is 0.98).
Relationship to adversarial training
- The authors point out two pain points of adversarial training: the inner maximization of a relational adversary is PSPACE-hard (Proposition 1), and it relies on iterative gradient updates, which is incompatible with non-parametric models such as random forests.
- Theorem 1: if relation R is reversible, N&P and adversarial training have the same optimal robust accuracy; on this basis the authors propose a combined scheme—first normalize over a reversible sub-relation R0, then perform adversarial training over the remaining relation R\R0.
FAST NORM algorithm
- Main algorithm (Algorithm 1): iteratively apply any available transformation in TN to the current code xN until no transformation is available, returning an approximate normal form.
- Finding the normal form is turned into an optimization problem: define an order function λ that scores code, and take the normal form to be the node with the smallest λ in the connected component; choosing TN as monotonically decreasing transformations (Definition 5) guarantees that the loop keeps decreasing λ.
- Theorem 2: if the transformations in TN are all ε-strongly decreasing, FAST NORM terminates within s/ε iterations (s is the λ score of the input).
Instantiation for authorship attribution attacks
- The attack has 42 transformation options in total, of which FAST NORM considers 35 (Table 2), covering API usage, variable declarations, I/O style, and control flow; it does not normalize function inlining (which the authors consider difficult to guarantee semantics-preserving) and function/variable renaming (which the authors consider to obscure the ground truth).
- 16 syntactic features are defined (SFoI, such as the number of for loops and the number of C-style I/O), λ is the sum of all SFoI; TN keeps only transformation directions that strictly decrease SFoI (e.g., keeping for-to-while and discarding while-to-for), all of which are 1-strongly decreasing.
- The normalizer is implemented based on Clang (LLVM's C/C++ front end); Figure 4 shows the original code, two intermediate variants, and the final adversarial example being normalized to the same normal form.
What experiments did the paper conduct?
On the Google Code Jam data, N&P is substantially higher than the vanilla model and the adversarial training baseline under all three attack modes.
Experimental setup
- Models tested: Vanilla-RF (the random forest of Caliskan-Islam et al. [8]), Vanilla-LSTM (the LSTM of Abuhamad et al. [2]), and their respective N&P versions N&P-RF and N&P-LSTM; the adversarial training baseline Adv-LSTM (only LSTM is compatible with adversarial training).
- Dataset: the Google Code Jam dataset provided by Quiring et al. [33], 1,632 C++ files, 204 authors, 8 programming problems; 8 train-test splits are made by problem (one problem as test, the other seven for training), and the average result over the 8 splits is reported.
- Attacks: the MCTS attack of Quiring et al. [33], in three modes—Matched (the 35 transformations normalized by FAST NORM), Full (all 42), and Adaptive (the 7 unnormalized ones, with the attacker fully aware of the N&P pipeline and using the normal form as the initial state).
- Metrics: test accuracy under clean and under attack (robust accuracy); feature-space l2 perturbation rate; training time.
- Adversarial training adjustments: fine-tuned with Vanilla-LSTM as the initial model; adversarial examples generated in batches at the start of each epoch; MCTS max-depth reduced from 25 to 5 and random play-outs per node reduced from 50 to 10; after 10 epochs of training, accuracy against the attack within the training loop is about 60%.
- Infrastructure: Amazon EC2 c5.18xlarge (72 cores, 144GB memory), sklearn and keras (tensorflow backend).
Main results
Test accuracy under attack (%, per Table 3, averaged over 8 splits):
Swipe horizontally to read the table
Attack mode N&P-RF N&P-LSTM Adv-LSTM Vanilla-RF Vanilla-LSTM Clean 76.1 78.7 76.7 90.4 88.4 Matched 72.3 73.7 30.8 13.2 21.1 Full 70.2 71.5 25.1 0.8 0.9 Adaptive 37.3 49.9 26.2 10.2 21.1 - The authors state that the N&P models outperform the corresponding vanilla models under all three attacks: an improvement of more than 50 percentage points under the Matched attack and about 70 percentage points under the Full attack; the advantage over the adversarial training baseline is >40 percentage points under Matched, >45 percentage points under Full, and up to 23 percentage points under Adaptive.
- The authors point out that under the Adaptive attack N&P still has 37.3%/49.9% accuracy, because N&P forces the attacker to use only a smaller transformation set, narrowing the attack surface, and the MCTS initial state is set to the normal form.
- On clean inputs N&P accuracy is lower than vanilla (LSTM differs by <10 个百分点、RF 差 <15 个百分点),作者将其归因于第 3 节分析的鲁棒性-准确率权衡。
FAST NORM 的归一化效果
- 测了什么:full attack 下原始输入的 l2 范数、对抗扰动的 l2 范数及扰动率(Table 4)。
- 结果:扰动率从 Vanilla-RF 的 21.4% 降到 N&P-RF 的 6.8%,从 Vanilla-LSTM 的 61.4% 降到 N&P-LSTM 的 14.3%。
- 作者的解读:归一化后攻击者对输入的操纵程度降低;理想归一化器下 Matched 攻击准确率应等于 clean 准确率,FAST NORM 的实际差距仅 3.8%(RF)和 4.0%(LSTM),接近理想情形。
运行时间
- 测了什么:各流程在同一基础设施上的训练时间(Table 5)。
- 结果:vanilla 训练 <12 小时;N&P 的归一化开销 <12 小时;对抗训练即使降低搜索参数仍需 >20 days, which the authors call 40 times the vanilla training time.
- The authors' interpretation: N&P normalization only needs to be performed once and is decoupled from the training pipeline, giving it an advantage in runtime.
Other ablations and analyses
- Effect of adversarial training strength: Adv-LSTM has about 60% accuracy against the full attack within the training loop, but drops to 25.1% against the full-strength MCTS attack at test time (Table 3 and Section 6.4); the authors believe that the performance of adversarial training depends on the strength of the attack in the training loop.
- Negative result: under the Adaptive attack N&P-RF is only 37.3%, lower than its 72.3%/70.2% under Matched/Full (Table 3); the authors explain that the size of the improvement depends on the transformations used by the adaptive attack.
- Exception: on clean accuracy both N&P models are lower than the corresponding vanilla models (Table 3), which the authors attribute to the robustness-accuracy trade-off.
What are some points that can be further explored?
The authors list three directions: a general normalizer, non-adversarial applications, and combination with defenses; the experiments cover only a single dataset and one attack.
Limitations and future directions noted by the authors
- A general transformation normalizer for more code types and programming languages, usable for robustness evaluation at larger scale and in more application scenarios (Section 8).
- N&P can be used in non-adversarial scenarios, such as removing dataset bias and enhancing model interpretability (Section 8).
- Explore the synergy of N&P with other defense mechanisms such as adversarial training, combining the advantages of both (Section 8).
- FAST NORM does not normalize function inlining transformations; the authors consider function boundaries hard to track in large projects and this transformation hard to guarantee semantics preservation (Section 5.4.1).
- It does not normalize template-based function/variable renaming transformations; the authors consider that this would blur the ground truth, and in extreme cases the attacker may know the target author better than the defender, making evasion unavoidable (Section 5.4.1).
Experimental coverage
- The models tested are two architectures, random forest and LSTM (including their respective N&P versions); the adversarial training baseline covers only LSTM (Table 3).
- The dataset is only Google Code Jam (1,632 C++ files, 204 authors, 8 problems), and only the C++ language (Section 6.1).
- The attack is only the MCTS attack of Quiring et al. [33], including three modes: Matched/Full/Adaptive (Section 6.3).
- Results are averages over 8 train-test splits; the paper does not report variance for individual splits or statistical significance tests (Section 6.1).
- The adversarial training baseline was speed-adjusted (MCTS max-depth reduced from 25 to 5, play-out reduced from 50 to 10, adversarial examples generated in batches per epoch), differing from standard adversarial training (Section 6.3).
Summarize the main content of the paper
N&P makes authorship attribution models provably robust to semantics-preserving transformations through code normalization, and its accuracy under attack is substantially better than adversarial training.
A defense paper: addressing the problem that source code authorship attribution models are deceived by semantics-preserving code transformations, it proposes a provably robust learning framework.
- Problem: Quiring et al. [33] and others have shown that applying semantics-preserving transformations such as for-to-while and API replacement to code can make attribution models misjudge the author; the authors consider adversarial training too costly on such problem-space attacks and incompatible with non-parametric models.
- Method: It proposes the relational adversary threat model and proves that a sufficient and necessary condition for robustness is outputting a constant label for each weakly connected component of the relation graph; the N&P framework normalizes both training and test inputs to a normal form before training the predictor; FAST NORM uses 16 syntactic features to define an order function and iteratively applies monotonically decreasing transformations to approximate the normal form, with the number of iterations bounded by the λ score (Theorem 2).
- Main results (Google Code Jam, 1,632 C++ files, 204 authors, Table 3): under Full attack, N&P-LSTM accuracy is 71.5%, Vanilla-LSTM 0.9%, Adv-LSTM 25.1%; under Matched attack, N&P-LSTM 73.7%, Vanilla-LSTM 21.1%.
- Cost and trade-off: clean accuracy drops from 88.4% (Vanilla-LSTM) to 78.7% (N&P-LSTM); under Adaptive attack (the attacker fully understands the N&P pipeline), N&P-LSTM is 49.9%.
- Efficiency: normalization overhead <12 小时,对抗训练 >20 days (Table 5); after normalization the feature perturbation rate drops from 61.4% to 14.3% (LSTM, Table 4).
- Authors' conclusion: N&P theoretically guarantees robustness to the relational adversary, and in practice improves accuracy under attack at far lower cost than adversarial training; the authors state future directions include a general normalizer, non-adversarial applications, and combination with other defenses.