Enhancing and Reporting Robustness Boundary of Neural Code Models for Intelligent Code Understanding

原題: Enhancing and Reporting Robustness Boundary of Neural Code Models for Intelligent Code Understanding 著者: Tingxu Han, Wei Song, Weisong Sun, Haoze Wu, Chunrong Fang, Yuan Xiao, Xiaofang Zhang, Zhenyu Chen, Yang Liu | 会議: 2026 | 引用: 0 PDF: han26a.pdf


Enhancing and Reporting Robustness Boundary of Neural Code Models for Intelligent Code Understanding Tingxu Han , Wei Song , Weisong Sun , Hao Wu , Chunrong Fang , Yuan Xiao , Xiaofang Zhang , Zhenyu Chen , and Yang Liu Abstract—With the development of deep learning, Neural Code Models (NCMs) such as CodeBERT and CodeLlama are widely used for code understanding tasks, including defect detection and code classification. However, recent studies have revealed that NCMs are vulnerable to adversarial examples—inputs with subtle perturbations that induce incorrect predictions while remaining difficult to detect. Existing defenses attempt to address this issue through data augmentation to empirically improve robustness, but they are costly, provide no theoretical robustness guarantees, and typically require white-box access to model internals, such as gradients. To address the above challenges, we propose ENBECOME, a novel black-box training-free and lightweight adversarial defense. ENBECOME is designed to both enhance empirical robustness and report certified robustness boundaries for NCMs. ENBECOME operates solely during inference, introducing random, semantics-preserving perturbations to input code snippets to smooth the NCM’s decision boundaries. This smoothing enables ENBECOME to formally certify a robustness radius within which adversarial examples can never induce misclassification, denoted certified robustness. We conduct com- prehensive experiments across multiple NCM architectures and tasks. Results show that ENBECOME significantly reduces attack success rates while maintaining high accuracy. For example, in defect detection, it reduces the average ASR from 42.43% to 9.74% with only a 0.29% drop in accuracy. Furthermore, ENBECOME achieves an average certified robustness radius of 1.63, meaning that adversarial modifications to no more than 1.63 identifiers are provably ineffective. • Tingxu Han, Chunrong Fang, Yuan Xiao, and Zhenyu Chen are with the State Key Laboratory for Novel Software Technology, Nanjing University, Nanjing 210093, China (e-mail: {txhan, dz21320004}@smail.nju.edu.cn, {fangchunrong, zychen}@nju.edu.cn). Zhenyu Chen is also with Shen- zhen Research Institute of Nanjing University, China. • Wei Song is with the School of Computer Science and Engineering, University of New South Wales, New South Wales 2052, Australia (e-mail: wei.song1@unsw.edu.au). • Weisong Sun and Yang Liu are with the School of Computer Science and Engineering, Nanyang Technological University, Nanyang 639798, Singapore (e-mail: {weisong.sun, yangliu}@ntu.edu.sg). • Hao Wu and Xiaofang Zhang are with the School of Computer Science and Technology, Soochow University, Suzhou 215006, China (e-mail: 20224207007@stu.suda.edu.cn, xfzhang@suda.edu.cn). • Weisong Sun is the corresponding author. Tingxu Han and Wei Song have an equal contribution. FFTContext *av_fft_init(int nbits, int inverse) { FFTContext *s = av_malloc(sizeof(*s)); if (s && ff_fft_init(s, nbits, inverse)) av_freep(&s); return s; } Defect detection: Yes (a) The original code snippet. FFTContext *av_fft_init(int mp3, int CPUArchState) { FFTContext *s = av_malloc(sizeof(*s)); if (s && ff_fft_init(s, mp3, CPUArchState)) av_freep(&s); return s; } Defect detection: No (b) The adversarial code snippet. Figure 1: An adversarial example on CodeBERT in defect detection. The adversarial code snippet (ACS) is crafted by only modifying the identifiers, but it leads to a misclassifica- tion from “Yes” to “No”. The adversarial code snippet still contains the same defect as the original one.

  1. Introduction Recently, with the rapid development of deep learning (DL), it has become more and more popular to deploy it into intelligent code understanding tasks in software engineering [1]–[3]. Currently, DL models are pre-trained on a large-scale code dataset and then fine-tuned or prompted with a few task-specific data. These large pre-trained models or fine-tuned models (including large language models, LLMs) for code understanding can be collectively referred to as Neural Code Models (NCMs). Existing software systems are built on millions of lines of code [4], providing sufficient training data to pre-train NCMs. Leveraging this extensive code corpus, NCMs like CodeBERT [5] and CodeLlama [6] showcase exceptional performance on code understanding tasks, such as defect detection [7], [8]. Developers deploy these models by fine-tuning or prompting them with task- specific datasets. However, recent studies [9]–[15] have demonstrated that NCMs are vulnerable to adversarial examples (AEs). An adversary crafts AEs by making subtle perturbations on the identifiers of code snippets. The perturbations are always imperceptible for humans but significant for NCMs, inducing misclassification [16]–[18]. Figure 1 showcases an intuitive example. The original code snippet in Figure 1a contains arXiv:2603.24119v1 [cs.SE] 25 Mar 2026

The original NCM decision boundary. The “smoothed” NCM decision boundary. The original code snippet and ACS pair of class 1. The original code snippet and ACS pair of class 2. The norm ball of a given original code snippet. Figure 2: An intuitive illustration of ENBECOME’s scenario and objective in defect detection. The adversary crafts ACSs based on original code snippets to cross the original decision boundary, causing misclassification. The norm measures the difference between the original code snippets and their corresponding ACSs. ENBECOME introduces controlled randomness into the input space during inference, averaging predictions over perturbed inputs within a norm ball to achieve a “smoothed” decision boundary (from the black line to the red line). a defect where the function may return a dangling pointer. NCM CodeBERT correctly identifies this and predicts “Yes”. In contrast, the adversarial code snippet in Figure 1b, which modifies only the identifiers, causes the model to misclassify it as “No”, even though the defect is still present. Various techniques have been developed to enhance the adversarial robustness of NCMs by leveraging data augmentation and post-training. These methods typically begin by augmenting the training dataset and then use the augmented data in a post-training phase to improve robustness. For instance, RoPGen [19] implements data aug- mentation by utilizing automatic coding style transformations to create robust coding style patterns that are difficult for attackers to manipulate. SPACE, on the other hand, generates worst-case, semantic-preserving examples in the continuous embedding space rather than the discrete token space. Both approaches incorporate the augmented samples into the training pipeline, forming the basis of adversarial training. However, adversarial training is computationally expensive and requires full access to the model’s parameters, making it impractical for large-scale NCMs, such as StarCoder [20] and CodeLlama [6]. To handle the above weaknesses, we propose ENBE- COME (Enhancing and reporting robustness Boundary of nEural COde Models for Intelligent Code UndErstanding), a novel black-box and training-free method that enhances the robustness of NCM for intelligent code understanding and reports certified robustness boundaries. Unlike prior approaches, ENBECOME operates entirely at inference time and does not require access to model parameters or additional training. Intuitively, ENBECOME hardens robustness by “smooth- ing” the decision boundaries of a given NCM. Specifically, ENBECOME introduces random, semantics-preserving per- turbations to generate multiple variants of the input and aggregates their predictions through majority voting. This process effectively causes the model to perceive each input as a distribution over a local neighborhood, rather than as a single point. This makes the model less sensitive to small adversarial changes and more resistant to attacks. Figure 2 illustrates the intuition. The black line represents the original decision boundary, which adversarial examples can easily cross by making small changes to the input. By contrast, the red line represents the “smoothed” boundary achieved by ENBECOME, which generalizes better and requires an adversary to introduce significantly larger perturbations to succeed. Although many random smoothing techniques have been proposed in vision [21]–[23] and NLP [24]– [26], they operate in continuous or token-based spaces. Previous randomized smoothing techniques in vision [21]– [23] and NLP [24]–[26] are designed for continuous or token- based input spaces. Directly applying these methods to code area often breaks syntax and disrupts semantic structure. In contrast, ENBECOME introduce semantics-preserving smoothing for NCMs in the discrete and syntax-sensitive L0 space, achieving certified robustness while preserving code correctness. The contribution of this paper can be summarized as follows: • We propose a black-box, training-free approach ENBE- COME, smoothing the decision boundary and improving the robustness of NCMs for intelligent code understanding. • To the best of our knowledge, this is the first work to establish certified robustness for neural code models. We introduce a semantics-preserving smoothing technique and derive a theoretical robustness bound, guaranteeing that no adversarial example can succeed within this bound. • We conduct comprehensive evaluations of ENBECOME regarding effectiveness, time cost, and generalization. • We make all the implementation code of ENBECOME and datasets used in our paper publicly available [27]. 2. Background and preliminary NCMs interpret code using neural language models [28]. For instance, neural language models such as BERT [29] and T5 [30] are fine-tuned and adapted specifically for intelligent code understanding tasks, resulting in NCMs like CodeBERT [5] and CodeT5 [31]. In this section, we formalize the background of NCMs and intelligent code understanding tasks at first. Subsequently, we introduce the definition of adversarial examples (AEs) that ENBECOME aims to address and formalize ENBECOME’s objectives.


{“f ”, “pv”, “size”, “v”} (1). Identifiers: m ⊙x {“ref ”, “vpvs”, “shape”, “ve”} (2). Attacked Identifiers: (m ⊙x) (a). The AE creation by arbitrary code token modifications. static void func(QEMUFile *f, void *pv, size_t size) { uint8_t *v = pv; qemu_put_8s(f, v); } Compiled Successfully! static void func(QEMUFile *ref, void *vpvs, size_t shape) { uint8_t *ve = vpvs; qemu_put_8s(ref, ve); } Compiled Successfully! CratWc voMq fDnc(M8YtFile *f%, voMq *wv, s>ize%_at DSze) { uintF,) *% = wv; qe;m]u”_puuvt_8s(f%, %); } Compiled Failed! (b). The AE creation by user-defined identifier modifications. Figure 3: An intuitive illustration of an AE creation. Arbitrary code token modifications to create an AE cause syntax errors, making it uncompilable (a). User-defined identifier modifications preserve code syntax correctness and keep compilable (b). 2.1. Code Understanding and NCMs Code understanding is a challenging task that requires developers to assimilate extensive information related to code semantics and domain-specific concepts. With the advancement of deep learning techniques, NCMs have been extensively utilized to effectively address various code under- standing tasks, such as defect detection [8], [32], clone detec- tion [33], [34]. Formally, given a dataset {X, Y}, an NCM f(x) maps an input code snippet x := {x1, x2, … , xN} ∈X to the ground truth label c ∈Y: f(x) = c, x ∈X, c ∈Y (1) 2.2. Adversarial Examples (AEs) Adversarial examples (AEs) are inputs intentionally modified to cause the model to make incorrect predictions. In natural language tasks, adversaries can create AEs by changing arbitrary tokens [35]–[37]. However, this approach is infeasible in code understanding due to strict syntax constraints: arbitrary token changes can easily lead to syntax errors, as shown in Figure 3a. To ensure syntactic validity, adversarial attacks on code typically modify only user-defined identifiers [12], [16]–[18], which preserves the structure and compilability of the program, as illustrated in Figure 3b. Formally, we define a binary mask vector m over a code snippet x = {x1, x2, … , xN} to indicate the positions of identifiers: mi = 1 if xi is an identifier, and mi = 0 otherwise. Adversaries perturb k identifiers based on m to generate an AE x′, inducing f(x′) ̸= c. The AE set X ∗, which means all possible AEs crafted by x, is formalized as: f(x′) ̸= c, x′ ∈X ∗, X ∗:= {x′ | x′ = (1 −m) ⊙x + A(m ⊙x)} (2) Here, ⊙denotes element-wise multiplication, and A(·) is an adversarial transformation applied to the extracted identifiers. Note that this transformation is consistent, meaning that each identifier is globally modified in a uniform and syntax- preserving manner across its occurrences in the code. The final AE x′ combines the unmodified tokens (1 −m) ⊙x with the perturbed identifiers A(m ⊙x). 2.3. Objective of ENBECOME Existing defenses such as SPACE [38] and RoPGen [19] rely on costly post-training and lack theoretical guarantees, making them impractical and unreliable as NCMs scale. To overcome these limitations, we propose ENBECOME, a training-free, black-box method that operates entirely at inference time. ENBECOME improves empirical robustness while certifying a provable robustness boundary within which no successful adversarial example can exist. In this section, we formalize the objectives of empirical and certified robustness, providing both theoretical definitions and intuitive insights. Definition 1 (Empirical Robustness). Empirical robustness means that NCMs should maintain consistent predictions for original samples and the corresponding AEs, which is formalized as follows: ∀x ∈X, x′ ∈X ∗, f(x) = f(x′), where (x, x′) means the pair of the original sample and its corresponding AE, X the original code snippet set and X ∗ the adversarial example set (defined by Eq 2). Most of the existing adversarial defense techniques focus on enhancing the empirical robustness through data augmen- tation [38] or disturbing embedding space [19], claiming improved robustness against AEs. However, this robustness is based on empirical results and does not provide a theoretical bound for future attacks. In that case, we further introduce the definition of certified robustness. Definition 2 (Certified Robustness). Certified robustness of an NCM around a given input x means that, within a calculated theoretic bound, the NCM will always maintain consistent predictions for x and the corresponding AE x′. This is formalized as the following: ∀x′ ∈X ∗, f(x) = f(x′) = c, c ∈Y, s.t.|x ⊘x′| ≤r. (3) where c denotes the ground truth label and X ∗means all possible AEs crafted by the given original sample x. x ⊘x′ indicates the different identifier set between x and x′. We define the theoretical bound r as the certified robustness


TABLE 1: The semantic-preserving operation used in our paper. Three different operations are considered. Name Description Example — The original sample. int f(void *env) Insert Randomly insert a new character into the identifier. int f(void *enQv) Replace Randomly replace a character in the identifier. int f(void *enQ) Delete Randomly delete a character from the identifier. int f(void *nv) radius. Intuitively, certified robustness means that the model’s prediction remains unchanged when an adversary modifies up to r identifiers in the input. In this case, no adversarial example within this bound can successfully fool the model. Based on this definition, the objective of ENBECOME is to construct an NCM g(·) that achieves both strong empirical robustness and certified robustness guarantees. 3. Methodology Figure 4 illustrates the overall workflow of ENBECOME. ENBECOME is a black-box requiring no alterations to NCMs. ENBECOME reduces the success rate of adversarial attacks by smoothing NCM predictions. In addition, ENBECOME can re- port the certified robustness boundary of NCMs. Specifically, given an input code snippet x0 (potentially an adversarial example) and the target NCM for defense, ENBECOME achieves robust prediction and reports certified robustness through three stages: (a) smoothed sample generation and prediction, (b) voting-based prediction selection, and (c) cer- tified radius generation. In phase (a), ENBECOME generates a set of smoothed code snippets and then collects the prediction results of the NCM for these code snippets. In phase (b), ENBECOME aggregates the above predictions by a voting- based mechanism and outputs the final robust prediction. Subsequently, ENBECOME reports certified robustness by generating the certified radius. 3.1. Smoothed Sample Generation and Prediction Different from original samples, a successful AE (ad- versarial example) is usually crafted elaborately and eas- ily destroyed by perturbation (supported by Figure 5). A smoothed sample means that a sample is modified around a given original sample while preserving the underlying structure. Traditional random smoothing techniques in nat- ural language [39], [40] employ perturbations on arbitrary tokens of a given code snippet. However, these approaches compromise the original semantics and syntax of the code, potentially leading to compilation failure. Figure 3 showcases an example. Given an input code snippet x0, ENBECOME generates N smoothed samples by perturbing identifiers in two steps: ( 1⃝) perturbation position selection and ( 2⃝) perturbation operation application. In step ( 1⃝), ENBECOME restricts perturbations to identifiers, as modifications to them do not break the code’s syntax. For each code snippet, we randomly select k identifiers. All positions of each selected identifier are then consistently perturbed, and this process is repeated N times to generate a set of smoothed samples, denoted as s1, s2, · · · , sN. Importantly, position selection is performed at the identifier level. All occurrences of the same identifier are perturbed consistently, preserving code semantics and syntactic validity. In practice, we randomly select 90% of the identifiers for each code snippet. In step ( 2⃝), ENBECOME applies a semantic-preserving character-level edit to each selected identifier. Specifically, we define three semantic-preserving operations, including Insert, Replace, and Delete. The operation Insert randomly inserts a new character into the identifier, operation Replace randomly replaces a character in the identifier with a new one, and operation Delete randomly deletes a character from the identifier. As all operations are conducted on identifiers, the perturbation is semantic-preserving and will not destroy the code syntax. Table 1 illustrates them with corresponding examples. These operations constitute a fundamental set of character-level edits that can express any transformation between identifier strings. In other words, any adversarial modification to an identifier can be decomposed into a sequence of these basic operations. To formally represent such transformations, we introduce the concept of a perturbation path P = {o1, o2, … , oL}, which denotes an ordered sequence of operations applied to an identifier. The length of the perturbation path indicates the extent of the identifier to be perturbed. Following the definition in Eq 2, we can obtain a perturbed sample s by applying a path P for a given x: s = (1 −m) ⊙x + P(m ⊙x) = (1 −m) ⊙x + |x| Y i=1 |P| Y j=1 oj((m ⊙x)i), ∀x ∈X (4) where m is the mask matrix to select identifiers from x. Based on pre-defined operations, ENBECOME produces a set of smoothed code snippets ( 2⃝). For example, given a code snippet int f(void *env){…}, ENBECOME ob- tains a smoothed code after operation Insert, int f(void *env){…}. ENBECOME inserts Q into the identifier env. The insert position and character are randomly picked. Similarly, ENBECOME obtains int f(void *enQ){…} and int f(void *nv){…} after operations Replace and Delete. In practice, we introduce a hyperparameter called perturbation rate η, which determines the expected proportion of characters to be perturbed within a selected identifier. For each identifier, we adaptively compute a character- level perturbation budget based on its length, resulting in a total of η · |P| edit operations. These operations are then applied randomly to individual characters. Thus, the actual perturbation path length |P|, i.e., the number of character-level edits, is indirectly controlled by η, ensuring that perturbation strength scales with identifier length. Subsequently, we input these smoothed samples into


Code Snippet NCM Smoothed Code Snippets Perturbation Position Selection Smoothed Perturbation Selected Positions Code Snippet 𝒙 Perturbation Operations 𝑠!: 𝑦! ⋯ 𝑠”: 𝑦” Smoothed Predictions NCM Majority Voting 𝒙: 𝑦’ Final Prediction 𝑠!: 𝑦! ⋯ 𝑠”: 𝑦” Smoothed Predictions 𝑠!: 𝑦! ⋯ 𝑠”: 𝑦” Smoothed Predictions Bound Estimation Upper and Lower Bounds Certified Radius Determination Certified Radius (a) Smoothed Sample Generation and Prediction (b) Voting-based Prediction Aggregation (c) Certified Radius Generation 𝑦’ Final Prediction Certified Radius Input Output ① ① ② ② ② ③ ③ ④ ④ ⑤ ⑤ ⑥ ⑥ Figure 4: The workflow of ENBECOME. ENBECOME first generates smoothed samples and conducts predictions of them in phase (a). In phase (b), ENBECOME aggregates the predictions and outputs the final prediction ˜y. In phase (c), ENBECOME generates the certified radius and reports the certified robustness. 0 10 20 30 40 50 MHM 0 20 40 60 80 100 Score 0 10 20 30 40 50 ALERT 0 10 20 30 40 50 CODA Figure 5: Evidence for our insight. ENBECOME generates N(N=100) smoothed samples per code snippet, with the score indicating how many are predicted as the ground-truth label. The color represents the final prediction ˜y, where blue indicates a correct prediction and red indicates an incorrect one. NCMs to obtain the corresponding predictions y1, y2, … , yN, which are then used in the following stages ( 3⃝). 3.2. Voting-Based Prediction Aggregation To mitigate the influence of incorrectly classifying AEs, ENBECOME utilizes a voting-based prediction mechanism to determine the final predictive label. Rather than predicting based only on a single sample, we generate a collection of smoothed samples and subsequently aggregate the predictions corresponding to this ensemble. The motivation for this step is that, although one single smoothed sample may not disable an attack, a collection of perturbed samples tends to neutralize such attacks. Figure 5 supports empirical evidence of the insight. The x-axis denotes the code index for AEs crafted by different attack methods, and the y-axis denotes the score. Observe that around a crafted AE, most samples are benign samples and will be predicted as the ground truth label. In phase (a), we obtain the corresponding predictions y1, y2, … , yN. Therefore, ENBECOME further aggregates all predictions to determine ˜y. Below is a formal expression: ˜y = arg max y∈Y ” N X i=1 I{f(si) = y}

, (5) where Y is the set of all possible class labels. I returns 1 if the condition inside the parentheses is true and 0 otherwise. ˜y is the output prediction. From the above definition, we can further formally define a smoothed NCM g(·) from a given base NCM f(·): g(x) = arg max y∈Y h P s∼D(f(s) = y) i , (6) where D is the distribution of the smoothed sample s. To simplify, we define: g(x, y) = P s∼D(f(s) = y), (7) which is the probability (“soft score”) that f returns the class y after perturbation. Intuitively, g(x) denotes the most likely class y to be returned and g(x, y) the corresponding probability. 3.3. Certified Radius Generation Based on the smoothed predictions, ENBECOME gener- ates a certified radius through two sequential steps: bound estimation ( 5⃝) and certified radius determination ( 6⃝). Bound Estimation. We propose a practical algorithm in ENBECOME to estimate lower and upper bounds (g(x, y) and g(x, y)), which is necessary to determine the certified radius. Beta distribution is generally utilized to model the distribution of probabilities and to estimate the confidence intervals (upper and lower bounds) of a proportion under a confidence level. The estimation is based on the observed number of successes and failures in a series of trials. In that case, we employ it to estimate the upper bound and lower bounds for the probability of success. Specifically, N copies of a given x are crafted in the perturbation step, and then N predictions are conducted. Specifically, during the perturbation step, N copies of a given x are generated, followed by forward propagation through the model. It can be considered as N independent trials. According to Eq 5, let c denote the ground truth label. Then, we define nc = PN 1 I(f(s) = c), meaning the number of times f(·) predicts c among N copies for a given x. We can assume that nc

(cont.) nc は n と nc/n をパラメータとする二項分布に従います。つまり、(nc ∼B (n, nc/n)) です。ベータ分布は二項分布に対する共役事前分布として機能し、成功確率の事後分布を導出し、以下の式を用いてその下限および上限を計算することを可能にします。


ベータ分布の分位数を用いて。すると、以下が得られます: g(x, c) = Beta(1 −α, nc, n −nc + 1) g(x, c) = Beta(α, nc, n −nc + 1), (8) ここで、Beta(α, u, v) はパラメータ u および v を持つベータ分布の α-分位数を意味します。デフォルトでは α を 0.001 に設定します。直感的には、パラメータ nc および n −nc + 1 を持つベータ分布の α-分位数および (1 −α)-分位数を利用し、g(x, c) の下限および上限を推定します。

Certified Radius Determination(認証済み半径の決定). 認証済み半径は、攻撃者が決して成功して攻撃できない入力に対する理論的限界を示すことを思い出してください。定理 1 を通じて、入力近傍内での予測の一貫性に関する確率の上界を確立し、定理 2(すなわち、g(x, y) と g(x′, y) の間の整合性)の理論的基礎を提供します。定理 2 はその後、この上界を用いて認証済み半径を決定し、この範囲内の敵対的コードスニペットに対する認証済みモデルの堅牢性を報告します。この確率に基づく近似により、ENBECOME は NCM のパラメータにアクセスすることなく認証済み堅牢性を決定できます。定義 2 に従って NCM の認証済み堅牢性を報告するために、まず x と x′ の間の距離計算を宣言します。認証済み半径はこの距離の下で決定されます。攻撃者は与えられたコードスニペット x の識別子のみを変更できるため、x と x′ の違いは識別子のみに存在します。式 2 に従い、m⊙x は x から抽出された識別子(すなわち、{0, iden0, …, 0})を示し、ここで iden0 は最初の識別子を意味し、0 はマスクされたコードトークンを意味します。その場合、∥m∥0 = ∥m⊙x∥0 は x の識別子の数を意味します。∥x −x′∥0 を x と x′ の間の距離とすると、それは以下のように計算できます: ∥x−x′∥0 = |x| X i=0 ∥xi −x′ i∥0 = ∥m∥0 X i=0 ∥(m ⊙x)i −(m ⊙x′)i∥0 簡略化のため、x は N トークンを含み、そのうち h 個の識別子が存在し、各識別子は独立した特別なトークンと見なされると仮定します。それらの識別子の k をランダムに摂動させます。x⊖x′を x と x′ が異なる識別子インデックスの集合と定義します。その場合、定義 2 において x ⊖x′ = |x ⊘x′| です(x と x′ は識別子でのみ異なります)。例えば、x ⊘x′ = {1, 3} の場合、x と x′ の最初のおよび三番目の識別子が異なります。さらに平滑化されたサンプル s を形式化するために、インデックスの観点から s の生成プロセスを記述します。S をインデックスの集合 {1, 2, …, h} とします。I(h, k) ⊆P(S) は、ちょうど k 個の異なる要素を含む S のすべての部分集合のコレクションを表し、ここで P(S) は S のべき集合(power set)を示します。U(h, k) を I(h, k) 上の一様分布として定義します。U(h, k) からのサンプリングは、各可能な部分集合が選択される等しい確率を持つように、S から k 個の一意なインデックスを選択することを含みます。例えば、U(3, 2) からのサンプルは部分集合 {1, 2} を生成する可能性があります。さらに M : X × I(h, k) −→X ′を定義し、ここで X ′ は一部の識別子がマスクされたコードスニペットを示します。M は h 個の識別子とインデックスのセットを入力として受け取り、マスクされた識別子セットを出力します。すると、ランダムな平滑化サンプルが得られます。U(h, k) は I(h, k) 上の一様分布です。平滑化サンプル s の作成は以下のように形式化できます: s = M(x, H) x ∈X, H ∼U(hx, kx) ここで x は元のコードスニペット、H は一様分布 U(hx, kx) から選択される摂動されるインデックスのセットです。hx は x 内の識別子の総数を表し、kx は選択された識別子のサブセットを表します。

定理 1. x と x′ が与えられ、|x ⊘x′| ≤r の場合、以下が成り立ちます: g(x, y) −g(x′, y) ≤β × g(x, y), ここで β = 1−Ckx hx−r Ckx hx であり、g(x, y) は g(x, y) の上界です。 証明. H ∼U(hx, kx) および以下のことを思い出してください: g(x, y) = P(f(s) = y) = P(f(M(x, H)) = y), g(x′, y) = P(f(s′) = y) = P(f(M(x′, H)) = y) 全確率の法則に基づき: g(x, y) = P([f(M(x, H)) = c] ∧[H ∩(x ⊘x′) ̸= ∅])

  • P([f(M(x, H)) = c] ∧[H ∩(x ⊘x′) = ∅]), g(x′, y) = P([f(M(x′, H)) = c] ∧[H ∩(x ⊘x′) ̸= ∅])
  • P([f(M(x′, H)) = c] ∧[H ∩(x ⊘x′) = ∅]) H ∩(x ⊘x′) = ∅ の場合、M(x, H) = M(x′, H) が成り立ちます。 直感的には、H は保持される(すなわち、マスクされない)識別子のインデックスを表し、x⊘x′は x と x′ が異なるインデックスを示します。それらの交わりが空である場合、それはすべての保持された識別子が同一であり、x と x′ の間のすべての異なる識別子がマスクされることを意味します。すると、 P([f(M(x, H)) = c] ∧[H ∩(x ⊘x′) = ∅]) = P([f(M(x′, H)) = c] ∧[H ∩(x ⊘x′) = ∅]) (9) したがって、 g(x, y) −g(x′, y) = P([f(M(x, H)) = c] ∧[H ∩(x ⊘x′) ̸= ∅]) −P([f(M(x′, H)) = c] ∧[H ∩(x ⊘x′) = ∅]) ≤ P([f(M(x, H)) = c] ∧[H ∩(x ⊘x′) ̸= ∅]) ≤ P(f(M(x, H)) = c) × P(H ∩(x ⊘x′) ̸= ∅) = g(x, y) × P(H ∩(x ⊘x′) ̸= ∅) ≤ g(x, y) × P(H ∩(x ⊘x′) ̸= ∅) (10)

アルゴリズム 1:認証済み半径を決定するための実用的アルゴリズム 入力:平滑化された予測 y1, y2, … , yN、元のコードスニペット x、正解ラベル c、ターゲット NCM g(·) 出力:認証済み堅牢性半径 r 1: ˜y ←多数決投票から最終予測を取得する。 2: if ˜y ̸= c then 3: return ABSTAIN(棄権) 4: else 5: g(x, y), g(x, y) ←式 8 を通じて Bound Estimation(境界推定)により下限/上限を取得する 6: hx ←x 内の識別子の数を取得する 7: for r in 0, … , hx do 8: β ←式 11 を通して β値を取得する 9: if g(x, y) −β × g(x, y) > 0.5 then 10: r ←r + 1 11: else 12: break(中断) 13: return r 組み合わせ論的手法を用いて、以下を計算します: P(H ∩(x ⊘x′) ̸= ∅) = 1 −P(H ∩(x ⊘x′) = ∅)

1 − Ckx hx−|x⊘x′| Ckx hx ≤ 1 −Ckx hx−r Ckx hx = β (11) 式 10 と式 11 を組み合わせることで、g(x, y)−g(x′, y) ≤β× g(x, y) が得られ、摂動下での予測を制限します。

定理 2. x と x′ が与えられ、∥x ⊘x′∥≤r および g(x, y) −β ×g(x, y) > 0.5 の場合、少なくとも (1−α) の確率で以下が成り立ちます: g(x′) = y. 証明。少なくとも (1 −α) の確率で以下が成り立ちます: 0.5 < g(x, y)−β×g(x, y) ≤g(x, y)−β×g(x, y) ≤g(x′, y) (12) ここで、最後の不等式は定理 1 に由来し、g(x′) = y は式 6 で与えられた定義から得られます。y = c(x の正解ラベル)であり g(x, y) −β × g(x, y) > 0.5 の場合、NCM g(·) は x の周囲で認証済み堅牢性が保証されます。 g(x, y) の上界および下界は以前に推定されており、βは式 8 で計算できます。定理 2 から、認証済み半径を近似するための段階的な実用的アルゴリズムにより最終的な認証済み堅牢性を報告できます。

実用的アルゴリズム. ENBECOME が NCM の推論段階で動作し、内部モデル情報へのアクセスなしにモデルフィードバックのみを必要とすることを思い出してください。アルゴリズム 1 は認証済み半径を決定するための実用的アルゴリズムを示しています。平滑化された予測 y1, y2, … , yN およびターゲット NCM g(·) が与えられ、まず最終予測˜y を決定し、その正しさを評価します(行 1-3)。式 8 に基づき、g(x, y) の下限および上限を推定します(行 5)。摂動される識別子の数 r を 0 から 1 つずつ増加させ(行 7)、式 11 を使用してβを計算します(行 8)。このプロセスは g(x, y) −β × g(x, y) ≤0.5 (定理 2)になるまで続きます(行 13)。終了時に、ENBECOME は r を x の認証済み堅牢性として返します(行 16)。したがって、|x ⊘x′| ≤r の場合、(1 −α) の信頼度で g(x′) が c を返すと報告できます。

  1. 評価 包括的な評価を確保するために、ENBECOME を堅牢性、汎化、時間コスト、およびコアコンポーネントとハイパーパラメータに焦点を当てたアブレーションスタディの 4 つの異なる側面 across で包括的な実験を実施します。以下の研究質問に答えることで評価を完了します: RQ1. ENBECOME は経験的および理論的観点からどの程度堅牢ですか? RQ2. ENBECOME の効率性はどの程度ですか? RQ3. ENBECOME はアーキテクチャとタスクにわたってどの程度効果的に汎化を示しますか? RQ4. 異なるパラメータ(平滑化サンプル数 N および摂動率ηを含む)は ENBECOME のパフォーマンスにどのように影響しますか?

4.1. 実験設定 コード理解タスクおよびデータセットの使用。実験には、欠陥検出 [8], [41]、クローン検出 [42]、関数分類 [43] を含む 3 つのコード理解タスクとその対応するデータセットが含まれます。データセットの詳細な説明は GitHub [27] に要約されています。

コード理解モデルの使用。4 つの異なる NCM アーキテクチャ、CodeBERT [5], GraphCodeBERT [44]、および 2 つのコード LLM(大規模言語モデル)、CodeLlama [6] および StarCoder [45] が考慮されます。詳細は Github [27] で利用可能です。

4.2. メトリクス 実験では、既存の敵対的技術 [16], [17] に従い、効果性を評価するために精度(Accuracy, Acc)を、経験的堅牢性のために攻撃成功率(Attack Successful Rate, ASR)を利用します。特定のコード理解データセット X = {(x1, c1), (x2, c2), … , (xn, cn)} が与えられた場合、xi はコードスニペットを示し、ci は xi の正解ラベルです。f を NCM とし、f(x) をコードスニペット x に対する NCM の予測とします。ACC は f(·) によって正しく分類されたコードスニペットの割合を測定し、以下のように計算されます: ACC = 1 |X| |X| i=1 I{f(xi) = ci}, xi ∈X (13) ここで I は f(xi) = ci の場合に 1 を返し、それ以外の場合は 0 を返します。 X ∗を X に基づく対応する AE(敵対的例)データセットとします。X ∗= {(x′ 1, c1), (x′ 2, c2), … , (x′ n, cn)} とし、x′ i は元のサンプル xi の対応する AE であり、ci は正解ラベルです。ASR


は誤分類される AE の割合を測定し、以下のように定義されます: ASR = 1 |X ∗| |X ∗| i=1 I{f(x′ i) ̸= ci}, x′ i ∈X ∗ (14) ここで I は f(xi) ̸= ci の場合に 1 を返し、それ以外の場合は 0 を返します。 しかしながら、ASR は堅牢性の経験的評価に限定されています。理論的観点から堅牢性を評価するために、新しいメトリクスである正規化認証済み堅牢性半径(Normalized Certified Robustness Radius, NCRR)を導入します。元のサンプル x が与えられた場合、最大認証済み堅牢性半径は x から意思決定境界までの最小距離を意味します。プログラミング言語における距離が式 3.3 に示すように識別子によって定義されることを思い出してください。アルゴリズム 1 で計算された r に基づき、NCRR を以下のように定義します: NCRR = 1 |X| |X| i=1 rx hx , x ∈X (15) ここで rx は ENBECOME が返す認証済み堅牢性結果であり、hx は x 内の識別子の数を表します。半径 rx はサンプルごとに rx/hx で正規化されます。NCRR は各サンプルに対して摂動可能な平均安全半径を示します。理想的には、NCRR は 1 に等しく、これは攻撃者が与えられたコードスニペットのすべての識別子を操作しても決して成功する AE を見つけることができないことを意味します。 要約すると、ACC は効果性を測定し、高い値ほど大きな効果性を示します。ASR は経験的堅牢性を測定し、低い ASR はより堅牢な NCM であることを示します。

4.3. RQ1. ENBECOME の堅牢性。 ENBECOME は経験的にどの程度堅牢ですか? 設計。ENBECOME を欠陥検出およびクローン検出の 2 つのコード理解タスクで評価します。表 2 は、MHM [17]、ALERT [16]、CODA [18] の 3 つの敵対的攻撃に対する結果を示しています。識別子ターゲティング攻撃(MHM および ALERT)に加えて、構造ターゲティング攻撃 CODA も考慮されていることに注意してください。「Victim Model(被害者モデル)」列は防御されていない NCM を示し、後の列は比較対象となる現在の防御手法、すなわち RoP-Gen [19]、SPACE [38]、および平滑化サンプル数 N=100 および N=1000 の ENBECOME を示します。すべてのモデルは同じデータセット [27] 上で評価され、モデルは CodeBERT [5] です。公平な比較のために、RoPGen および SPACE の元のポストトレーニング設定に従います。

結果と分析。欠陥検出の場合、ENBECOME[N=100] は平均 ASR を 42.43%(Victim Model)から 9.74% に削減し、RoP-Gen (21.77%) および SPACE (27.29%) を大幅に上回ります。同様に、クローン検出の場合、ENBECOME は ASR を 0.95% から 1.68% の範囲で達成し、RoPGen (3.52%) および SPACE (12.47%) を上回りながら、高い ACC (>96%) を維持します。RoP-Gen および SPACE はわずかに高い ACC を示しますが、その改善は広範なポストトレーニング変更によるものです。一方、ENBECOME はトレーニングフェーズなしで推論時に効率的に動作するため、実世界アプリケーションに対してより実践的かつ適応可能です。ENBECOME[N=1000] は ENBECOME[N=100] と同等の結果しか達成できないことに注意してください。これは、平滑化サンプルの増加に伴って収益が逓減することを示しています。効率性と堅牢性のトレードオフを考慮し、デフォルト設定として N = 100 を採用します。さらに、RQ4 で詳細なアブレーションスタディを通じてパラメータ N の影響を分析します。

要約すると、ENBECOME はすべてのタスクおよび攻撃において一貫して最高の経験的堅牢性(最低の ASR)を達成し、高い効果性(ACC)を維持しており、ベースラインと比較してその優れたパフォーマンスを強調しています。

ENBECOME は理論的にどの程度堅牢ですか? 設計。アルゴリズム 1 を使用して認証済み半径を計算することにより、ENBECOME の認証済み堅牢性を評価します。これは、摂動バウンド r(定義 2 で定義)内で敵対的例が決して成功しないことを保証します。「Radius(半径)」メトリクスはタスクあたりの平均認証済み識別子数を表し、「NCRR」(式 15)はこれらの識別子の正規化パーセンテージを表します。すべての計算は各コード理解タスクのテストセット上で行われます。

結果と分析。図 6 は、「Radius」および「NCRR」で測定された報告された認証済み堅牢性を示しています。「#Identifiers(識別子数)」は、各コードスニペットに含まれる平均識別子数を意味します。ENBECOME は欠陥検出に対して平均半径 1.63 を達成し、各サンプルには平均 6.55 の識別子が含まれ、NCRR は 29% です。これは、堅牢に認証された識別子の相当な割合を示しています。クローン検出の場合、平均半径は 2.39 で、サンプルあたりの平均識別子数は 8.20、NCRR は 31% です。これは、敵対的例に対する ENBECOME の強力な堅牢性境界を示しています。

要約すると、結果は ENBECOME がすべてのタスクで一貫して強い認証済み堅牢性を達成することを示しています。相当な割合の識別子が証明された堅牢性を持ち、認証済み摂動バウンド内で敵対的攻撃から防御する ENBECOME の有効性を強調しています。

4.4. RQ2. ENBECOME の効率性はどの程度ですか? 設計。このセクションでは、準備コストおよび推論コストを通じて測定される効率性の観点から、ENBECOME をベースライン手法(SPACE および RoPGen)と比較します。準備コストは、推論前に必要な追加時間を指します。SPACE および RoPGen の場合、これはポストトレーニング時間を含みますが、ENBECOME の場合はテストセットの平滑化サンプルを生成することから構成されます。公平な比較を確保するために、すべてのベースラインのデフォルトハイパーパラメータを採用し、ランダムに選択した 1,000 元のクリーンサンプルで構築された同じテストセット上で評価します。

結果と分析。表 3 は、ENBECOME と他の手法(特に SPACE および RoPGen)との効率性の比較を示しています。クローン検出において ENBECOME は RoPGen と比較して最大 139,682 秒(約 38 時間)および 341,180 秒(約 95 時間)の節約を達成することに注意してください。ENBECOME のサンプルあたりの推論時間(欠陥検出で 0.724 秒、クローン検出で 1.535 秒)は SPACE および RoPGen (0.010〜0.016 秒) より高いですが、このトレードオフは


Identifiers(識別子数) 0 100 200 300 400 500 600 クローン検出 欠陥検出 (a) Indentifiers の分布 半径 (2.39)

識別子 (8.20)

識別子 (8.20)

(b) クローン検出 (NCRR=0.31) 半径 (1.63)

識別子 (6.55)

(c) 欠陥検出 (NCRR=0.29) 図 6: ENBECOME の認証済み堅牢性。#Identifiers は与えられたコードスニペットにおける識別子の数を意味します。 図 6(a) は Identifiers の分布を示しています。図 6(b)(c) は、Radius↑および NCRR↑によって測定された認証済み堅牢性を報告しています。

表 2: 異なるホワイトボックス()/ブラックボックス()防御手法による経験的堅牢性(パーセント %)。列「Attack」は AE を構築するために使用される異なる技法を示します。列「Victim Model」は、いかなる堅牢性の議論技法も適用されていない元のモデルを示します。ACC は NCM の有効性を測定するために利用され、ASR は堅牢性を測定するために利用されます。ACC↑、ASR↓。

タスク | 攻撃 | 被害者モデル | RoPGen | SPACE | ENBECOME [N=100] | ENBECOME [N=1000] ホワイト/ブラックボックス | - | メトリクス | ACC | ASR | ACC | ASR | ACC | ASR | ACC | ASR 欠陥検出 | MHM | 61.86 | 36.12 | 63.40 | 20.50 | 64.23 | 23.40 | 62.15 | 8.80 | 62.18 | 8.38 欠陥検出 | ALERT | 61.86 | 46.80 | 63.40 | 21.47 | 64.23 | 29.85 | 62.15 | 8.74 | 62.18 | 8.62 欠陥検出 | CODA | 61.86 | 44.39 | 63.40 | 23.34 | 64.23 | 28.64 | 62.15 | 11.70 | 62.18 | 13.32 欠陥検出 | Average | 61.86 | 42.43 | 63.40 | 21.77 | 64.23 | 27.29 | 62.15 | 9.74 | 62.18 | 10.10 クローン検出 | MHM | 96.72 | 8.71 | 97.30 | 2.19 | 97.05 | 5.76 | 96.72 | 0.95 | 96.62 | 1.08 クローン検出 | ALERT | 96.72 | 17.73 | 97.30 | 3.92 | 97.05 | 10.64 | 96.72 | 1.36 | 96.62 | 1.42 クローン検出 | CODA | 96.72 | 38.10 | 97.30 | 10.51 | 97.05 | 21.03 | 96.72 | 1.68 | 96.62 | 1.52 クローン検出 | Average | 96.72 | 21.51 | 97.30 | 3.52 | 97.05 | 12.47 | 96.72 | 1.33 | 96.62 | 1.34 ENBECOME | ENBECOME 図 7: 他のデータセットにおける ENBECOME、OJ(機能分類)および CodeChef。より濃い色調は高いパーセントを表し、各データセット上の NCM の ASR 間の顕著な違いを示しています。 RoPGen (クローン検出) RoPGen (欠陥検出) SPACE (欠陥検出) SPACE (クローン検出) ENBECOME (クローン検出) ENBECOME (欠陥検出) 図 8: バックドア攻撃における ENBECOME。

表 3: ENBECOME および他の手法の効率性。± はテストセット上で 1000 回の反復推論にわたって計算された標準偏差を示します。 タスク | メソッド | 準備時間コスト (s) | 推論時間コスト (s / sample) 欠陥検出 | SPACE | 2,240 | 0.015 ± 0.039 欠陥検出 | RoPGen | 141,010 | 0.010 ± 0.034 欠陥検出 | ENBECOME | 1,328 | 0.724 ± 0.122 クローン検出 | SPACE | 10,268 | 0.016 ± 0.037 クローン検出 | RoPGen | 342,545 | 0.014 ± 0.035 クローン検出 | ENBECOME | 1,365 | 1.535 ± 0.062

そのトレーニングフリー、ブラックボックスな性質および展開における顕著な効率向上を考慮すると許容可能です。ENBECOME は推論オーバーヘッドのわずかな増加をもたらしますが、サンプルあたりの平均時間コストは 2 秒未満に留まり、実用的使用には許容可能です。

4.5. RQ3. ENBECOME の汎化性。 ENBECOME の汎化性を評価するために、NCM アーキテクチャ、他のコードインテリジェンスデータセット、およびバックドア攻撃を含む 3 つの異なる視点が考慮されます。

複数のモデルアーキテクチャにおける ENBECOME 設計。5 つの NCM アーキテクチャにおいて ENBECOME を評価します:GraphCodeBERT [44]、CodeBERT [5]、CodeT5 [31]、および 2 つのコード LLM(大規模言語モデル)、StarCoder [46] および CodeLlama [6]。

表 4: 複数の NCM アーキテクチャにおける ENBECOME のパフォーマンス。伝統的アーキテクチャ(上位 3 つ)およびコード LLM(下位 2 つ)を含む。 NCM Arch | 被害者モデル | ENBECOME ACC | ASR | ACC | ASR | Radius | NCRR GraphCodeBERT | 64.31 | 79.11 | 63.10 | 25.46 | 1.43 | 0.17 CodeBERT | 61.86 | 46.80 | 62.15 | 8.74 | 1.85 | 0.22 CodeT5 | 64.20 | 77.88 | 63.61 | 13.32 | 1.61 | 0.22 StarCoder | 50.14 | 86.54 | 49.01 | 30.04 | 1.74 | 0.24 CodeLlama | 48.16 | 68.74 | 45.75 | 28.65 | 1.02 | 0.13

表 5: アブレーションスタディ。ENBECOME のパラメータ N および η が考慮されます。N は平滑化サンプル数を示し、ηは摂動率を示します。 パラメータ:N N=0 | N=100 | N=1000 | N=10000 ACC | ASR | ACC | ASR | ACC | ASR | ACC | ASR 64.3 | 47.0 | 62.9 | 8.8 | 63.3 | 8.9 | 63.2 | 8.9 パラメータ:η η=0 | η=0.3 | η=0.6 | η=1.0 ACC | ASR | ACC | ASR | ACC | ASR | ACC | ASR 64.1 | 47.0 | 63.1 | 10.2 | 63.1 | 9.4 | 62.9 | 9.1

表 2 に示す最良の攻撃、ALERT [16] が欠陥検出タスク上で敵対的例を生成するために使用されます。 結果と分析。表 4 は NCM アーキテクチャ全体における ENBECOME のパフォーマンスを要約しており、ACC、ASR、Radius、NCRR の 4 つの異なるメトリクスで評価しています。ENBECOME は ACC に最小限の影響を与えながら ASR を大幅に低下させます。ASR は GraphCodeBERT で 79.11% から 25.46%、CodeBERT で 46.80% から 8.74%、CodeT5 で 77.88% から 13.32% に低下し、強力な Radius/NCRR 値を達成します。コード LLM は同様の傾向を示しており、StarCoder の ASR は 86.54% から 30.04%(Radius: 1.74, NCRR: 0.24)に減少し、CodeLlama は 68.74% から 28.65%(Radius: 1.02, NCRR: 0.13)に減少しますが、ブラックボックスな性質によりわずかに低い ACC を示します。CodeLlama のより広範な言語サポートは、StarCoder よりも脆弱性が高いことを意味します。全体的に、ENBECOME は異なる NCM アーキテクチャ全体で堅牢性を効果的に向上させ、ASR を大幅に削減しながらモデルパフォーマンスを維持します。

他のデータセットにおける ENBECOME。 設計。機能分類のための OJ データセット [43] および欠陥検出のための CodeChef [41] において ENBECOME の汎化性を評価します。OJ データセット [47] は Open Judge ベンチマークに基づいており、CodeChef は実行結果を「OK」(欠陥なし)、「WA」、「TLE」、および「RE」(欠陥)に分類します。 結果と分析。図 7 は OJ および CodeChef における ENBECOME を示しています。ENBECOME は OJ で ASR を 32.10% から 1.93%(ACC: 96.72%)に、CodeChef では 81.53% から 17.12% に削減し、ACC の低下はわずか 4.26% です。これらの結果は、ENBECOME が多様なインテリジェントコード理解タスク全体で NCM を強化する堅牢性を確認しています。

バックドア攻撃における ENBECOME。 設計。ENBECOME のさまざまなセキュリティ脅威に対するパフォーマンスを評価するために、バックドア攻撃、特に最先端手法である BadCode [48] を考慮します。AE による誤分類を引き起こす従来の敵対的攻撃とは異なり、BadCode は特定のパターンが現れたときに誤分類を引き起こすバックドアを埋め込みます。 結果と分析。図 8 は欠陥検出およびクローン検出におけるバックドア攻撃に対する ENBECOME のパフォーマンスを示しています。レーダーチャートでは、RoPGen、SPACE、ENBECOME にわたって ACC(青)と ASR(赤)が比較されます。クローン検出の場合、ENBECOME は ASR を 96% 以上から 9.30% に削減し、ACC の低下は最小限です(95.87% から 95.35%)。欠陥検出の場合、ASR を 91.55% から 42.31% に低下させながら ACC を 62.18% に維持し、強力な防御能力を強調しています。

4.6. RQ4. アブレーションスタディ。 ENBECOME のパフォーマンスが平滑化サンプル数 N および摂動率 ηによってどのように影響されるかを分析します。すべての評価は、ALERT [16] によって生成された敵対的例を持つ 1000 件の欠陥検出サンプルを利用します。

平滑化サンプル数 N の影響。セクション 3 で概説されているように、ENBECOME は入力あたり N 個の摂動済みサンプルを生成します。N = 100, 1000, 10000 でその影響を評価し、N = 0 の場合は被害者 NCM に戻ります。表 5 が結果を示しています。摂動がない場合、被害者 NCM は 64.3% の ACC を達成しますが、ASR は 47.0% と高く、脆弱性が明らかになります。N = 100 では、ACC はわずかに 62.9% に低下しますが、ASR は 8.8% に大幅に改善され、最小限の精度損失で堅牢性が増加していることを示しています。N = 1000 を超えると、ACC および ASR は安定し、堅牢性のさらなる向上はないことを示しています。効率性を考慮して、N = 100 に設定します。

摂動率 ηの影響。ENBECOME は平滑化サンプルあたり ηの割合で識別子を摂動します。η = 0.3, 0.6, 1.0 をテストすることによりその影響を評価し、η = 0 の場合はベースライン NCM に戻ります。表 5 が結果を示しています。摂動がない場合(η = 0)、ASR は 47.0% で、高い脆弱性を示します。ηを 0.3 に増加させると、ACC への影響は最小限で ASR が 10.2% に急激に低下します。さらに 0.6 および 1.0 に増加すると、ASR はそれぞれ 9.4% および 9.1% に低下し、ACC は安定しています。改善が η = 1.0 で頭打ちになるため、適度な摂動率が堅牢性と精度の間の最良のバランスを提供します。

  1. 関連研究 このセクションでは、本論文の関連研究を紹介します。 ニューラルコードモデル。ニューラルコードモデル(NCM)は、コード関連タスク [28] にディープラーニングを活用しており、コード検索 [49]–[51]、要約 [52]–[56]、および欠陥検出 [7], [8] などの分野で優れています。従来、彼らはコードをテキストとして扱ってきましたが [57]、一部のモデルは構造的表現(AST, CFG, DFG など)を組み込んでいます [58]–[60]。BERT [29] や T5 [30] などのモデルによる転移学習の進展が NCM の開発を推進しました。CodeBERT [5] や GraphCodeBERT [44] などの事前トレーニング済みモデルは、トークン予測およびグラフベースの関係を通じて理解力を強化します。最近では、StarCoder [20] や CodeLlama [6] などのコードに特化した大規模言語モデル(LLM)が NCM の能力を再定義しました。我々は、機能分類 [43], [58]、欠陥検出 [7], [8]、およびクローン検出 [33], [42], [61], [62] などの重要なソフトウェアエンジニアリングのコード理解タスクのために NCM に焦点を当てています。

ニューラルコードモデルの敵対的堅牢性。敵対的堅牢性とは、敵対的摂動下で正しい予測を維持するモデルの能力を指します [63], [64]。最近の研究は、NLP 敵対的技法をニューラルコードモデル(NCM)に適応させ、攻撃および防御の両方を開発しています。同様に、NCM の敵対的堅牢性とは、パフォーマンスを大幅に劣化させることなく、識別子の警告などの摂動に対して耐えることを指します。NCM の敵対的堅牢性に関する研究は、コードインテリジェンスタスクで使用される NCM を悪用することに焦点を当てています [16]–[18]。例えば、Yang ら [16] は貪欲探索および遺伝的アルゴリズムを使用して自然な敵対的サンプルを生成し、Zhang ら [17] は識別子改名のために Metropolis-Hastings サンプリングを採用しています。他の研究では勾配ベースの最適化 [41], [65], [66] を活用するか、汎化性を向上させるためにコード変換を適用します [19]。また、コード固有の制約に合わせた敵対的トレーニングフレームワークを設計するものもあります [38]。しかし、これらの手法はポストトレーニングを必要とし、高い計算コストをもたらします。対照的に、我々は ENBECOME を導入し、モデルパラメータを変更せずに NCM の堅牢性を強化すると同時に理論的バウンドを提供するブラックボックスかつトレーニングフリーなアプローチです。

  1. 妥当性への脅威 このセクションでは、内部および外部の要因を考慮して、ENBECOME の妥当性に対する潜在的な脅威について議論します。 内部妥当性。内部妥当性は 2 つの側面を含みます:パラメータ感度および精度低下。ENBECOME の有効性は、平滑化サンプル数 N および摂動率 ηなどのハイパーパラメータに依存し、その影響は標準設定によるアブレーションスタディで検討されます。認証済み半径の推定には理論的近似が含まれ、わずかな不正確さを導入する可能性がありますが、我々の結果では ENBECOME が実用上競争力があり許容可能な精度を維持していることが示されています。 外部妥当性。外部妥当性の脅威は、異なる NCM アーキテクチャ全体での汎化性に焦点を当てています。CodeBERT, CodeT5, GraphCodeBERT, StarCoder, および CodeLlama を含むいくつかの NCM アーキテクチャで ENBECOME を評価しましたが、その知見はコード理解のためのすべての NCM に一般化するとは限らず、特に新規アーキテクチャまたは非標準的なトレーニングレジームを持つモデルには当てはまらない可能性があります。この問題に対処するために、ENBECOME は NCM の内部パラメータに依存せず、モデル出力予測のみを利用します。この設計により、ブラックボックス適応フレームワークとして ENBECOME の汎化性を最大化しています。 これらの脅威に対処することで、我々の知見の信頼性を強化し、コード理解タスクにおける NCM 防御のための ENBECOME の堅牢な評価を確保することを目指します。

  2. 結論 我々は ENBECOME を提案しました。これは、インテリジェントコード理解タスクのための NCM の堅牢性境界を強化し報告するトレーニングフリー、ブラックボックスな手法です。推論時に動作する ENBECOME は、最小限のパフォーマンス損失で ASR を大幅に削減し、ポストトレーニングを必要としません。これは、インテリジェントコード理解タスクにおける NCM に対して認証済み堅牢性を初めて提供するものです。広範な評価により、ENBECOME が敵対的脅威を効果的に緩和し、多様な NCM アーキテクチャ全体でよく汎化することが示されています。

References References [1] C. Watson, N. Cooper, D. Nader-Palacio, K. Moran, and D. Poshy- vanyk, “A systematic literature review on the use of deep learning in software engineering research,” ACM Transactions on Software Engineering and Methodology, vol. 31, no. 2, pp. 32:1–32:58, 2022. [2] X. Hou, Y. Zhao, Y. Liu, Z. Yang, K. Wang, L. Li, X. Luo, D. Lo, J. C. Grundy, and H. Wang, “Large language models for software engineering: A systematic literature review,” CoRR, vol. abs/2308.10620, no. 1, pp. 1–62, 2023. [3] Q. Zhang, C. Fang, Y. Xie, Y. Zhang, Y. Yang, W. Sun, S. Yu, and Z. Chen, “A survey on large language models for software engineering,” CoRR, vol. abs/2312.15223, no. 1, pp. 1–57, 2023. [4] Y. Shin, A. Meneely, L. Williams, and J. A. Osborne, “Evaluating complexity, code churn, and developer activity metrics as indicators of software vulnerabilities,” IEEE transactions on software engineering, vol. 37, no. 6, pp. 772–787, 2010. [5] Z. Feng, D. Guo, D. Tang, N. Duan, X. Feng, M. Gong, L. Shou, B. Qin, T. Liu, D. Jiang, and M. Zhou, “Codebert: A pre-trained model for programming and natural languages,” in Proceedings of the 25th Conference on Empirical Methods in Natural Language Processing: Findings. Online Event: Association for Computational Linguistics, 16-20 November 2020, pp. 1536–1547. [6] B. Roziere, J. Gehring, F. Gloeckle, S. Sootla, I. Gat, X. E. Tan, Y. Adi, J. Liu, T. Remez, J. Rapin et al., “Code llama: Open foundation models for code,” arXiv preprint arXiv:2308.12950, 2023. [7] Y. Wu, Z. Li, J. M. Zhang, M. Papadakis, M. Harman, and Y. Liu, “Large language models in fault localisation,” arXiv preprint arXiv:2308.15276, 2023. [8] Y. Zhou, S. Liu, J. K. Siow, X. Du, and Y. Liu, “Devign: Effective vulnerability identification by learning comprehensive program seman- tics via graph neural networks,” in Proceedings of the 33rd Annual Conference on Neural Information Processing Systems. Vancouver, BC, Canada: Curran Associates Inc., December 8-14 2019, pp. 10 197– 10 207. [9] Y. Chen, W. Sun, C. Fang, Z. Chen, Y. Ge, T. Han, Q. Zhang, Y. Liu, Z. Chen, and B. Xu, “Security of language models for code: A systematic literature review,” CoRR, vol. abs/2410.15631, no. 1, pp. 1–63, 2024. [10] P. Bielik and M. T. Vechev, “Adversarial robustness for code,” in Pro- ceedings of the 37th International Conference on Machine Learning, vol. 119. Virtual Event: PMLR, 13-18 July 2020, pp. 896–907. [11] L. Chen, Y. Ye, and T. Bourlai, “Adversarial machine learning in malware detection: Arms race between evasion attack and defense,” in Proceedings of the European Intelligence and Security Informatics Conference. Athens, Greece: IEEE Computer Society, September 11-13 2017, pp. 99–106. [12] A. Jha and C. K. Reddy, “Codeattack: Code-based adversarial attacks for pre-trained programming language models,” in Proceedings of the AAAI Conference on Artificial Intelligence, vol. 37, no. 12, 2023, pp. 14 892–14 900.


[13] Q. Liu, S. Ji, C. Liu, and C. Wu, “A practical black-box attack on source code authorship identification classifiers,” IEEE Transactions on Information Forensics and Security, vol. 16, pp. 3620–3633, 2021. [14] E. Quiring, A. Maier, and K. Rieck, “Misleading authorship attribution of source code using adversarial learning,” in 28th USENIX Security Symposium (USENIX Security 19), 2019, pp. 479–496. [15] G. Severi, J. Meyer, S. Coull, and A. Oprea, “{Explanation-Guided} backdoor poisoning attacks against malware classifiers,” in 30th USENIX security symposium (USENIX security 21), 2021, pp. 1487– 1504. [16] Z. Yang, J. Shi, J. He, and D. Lo, “Natural attack for pre-trained models of code,” in Proceedings of the 44th International Conference on Software Engineering, 2022, pp. 1482–1493. [17] H. Zhang, Z. Li, G. Li, L. Ma, Y. Liu, and Z. Jin, “Generating adversarial examples for holding robustness of source code processing models,” in Proceedings of the 34th AAAI Conference on Artificial Intelligence. New York, NY, USA: AAAI Press, February 7-12 2020, pp. 1169–1176. [18] Z. Tian, J. Chen, and Z. Jin, “Code difference guided adversarial example generation for deep code models,” in 2023 38th IEEE/ACM International Conference on Automated Software Engineering (ASE). IEEE, 2023, pp. 850–862. [19] Z. Li, G. Chen, C. Chen, Y. Zou, and S. Xu, “Ropgen: Towards robust code authorship attribution via automatic coding style transformation,” in Proceedings of the 44th International Conference on Software Engineering, 2022, pp. 1906–1918. [20] R. Li, L. B. Allal, Y. Zi, N. Muennighoff, D. Kocetkov, C. Mou, M. Marone, C. Akiki, J. Li, J. Chim, Q. Liu, E. Zheltonozhskii, T. Y. Zhuo, T. Wang, O. Dehaene, M. Davaadorj, J. Lamy-Poirier, J. Monteiro, O. Shliazhko, N. Gontier, N. Meade, A. Zebaze, M. Yee, L. K. Umapathi, J. Zhu, B. Lipkin, M. Oblokulov, Z. Wang, R. M. V, J. Stillerman, S. S. Patel, D. Abulkhanov, M. Zocca, M. Dey, Z. Zhang, N. Moustafa-Fahmy, U. Bhattacharyya, W. Yu, S. Singh, S. Luccioni, P. Villegas, M. Kunakov, F. Zhdanov, M. Romero, T. Lee, N. Timor, J. Ding, C. Schlesinger, H. Schoelkopf, J. Ebert, T. Dao, M. Mishra, A. Gu, J. Robinson, C. J. Anderson, B. Dolan-Gavitt, D. Contractor, S. Reddy, D. Fried, D. Bahdanau, Y. Jernite, C. M. Ferrandis, S. Hughes, T. Wolf, A. Guha, L. von Werra, and H. de Vries, “Starcoder: may the source be with you!” CoRR, vol. abs/2305.06161, no. 1, pp. 1–44, 2023. [21] L. Li, T. Xie, and B. Li, “Sok: Certified robustness for deep neural networks,” in 2023 IEEE symposium on security and privacy (SP). IEEE, 2023, pp. 1289–1310. [22] J. Cohen, E. Rosenfeld, and Z. Kolter, “Certified adversarial robustness via randomized smoothing,” in international conference on machine learning. PMLR, 2019, pp. 1310–1320. [23] K. Fang, Q. Tao, Y. Wu, T. Li, X. Huang, and J. Yang, “Multi-head ensemble of smoothed classifiers for certified robustness,” Neural Networks, vol. 188, p. 107426, 2025. [24] M. Ye, C. Gong, and Q. Liu, “Safer: A structure-free approach for certified robustness to adversarial word substitutions,” in Annual Meeting of the Association for Computational Linguistics (ACL), 2020. [25] X. Zhang, H. Hong, Y. Hong, P. Huang, B. Wang, Z. Ba, and K. Ren, “Text-crs: A generalized certified robustness framework against textual adversarial attacks,” in 2024 IEEE Symposium on Security and Privacy (SP). IEEE, 2024, pp. 2920–2938. [26] V. Cevher, “Certified robustness under bounded levenshtein distance,” in The Thirteenth International Conference on Learning Representa- tions, 2025. [27] T. Han, “Our artifacts,” https://github.com/GeniusHTX/SecCode. [28] D. N. Palacio, A. Velasco, N. Cooper, A. Rodriguez, K. Moran, and D. Poshyvanyk, “Toward a theory of causation for interpreting neural code models,” IEEE Transactions on Software Engineering, 2024. [29] J. D. M.-W. C. Kenton and L. K. Toutanova, “Bert: Pre-training of deep bidirectional transformers for language understanding,” in Proceedings of naacL-HLT, vol. 1. Minneapolis, Minnesota, 2019, p. 2. [30] C. Raffel, N. Shazeer, A. Roberts, K. Lee, S. Narang, M. Matena, Y. Zhou, W. Li, and P. J. Liu, “Exploring the limits of transfer learning with a unified text-to-text transformer,” Journal of Machine Learning Research, vol. 21, pp. 140:1–140:67, 2020. [31] Y. Wang, W. Wang, S. R. Joty, and S. C. H. Hoi, “Codet5: Identifier- aware unified pre-trained encoder-decoder models for code under- standing and generation,” in Proceedings of the 26th Conference on Empirical Methods in Natural Language Processing. Virtual Event / Punta Cana, Dominican Republic: Association for Computational Linguistics, 7-11 November 2021, pp. 8696–8708. [32] S. Wang, T. Liu, and L. Tan, “Automatically learning semantic features for defect prediction,” in Proceedings of the 38th international conference on software engineering, 2016, pp. 297–308. [33] C. Fang, Z. Liu, Y. Shi, J. Huang, and Q. Shi, “Functional code clone detection with syntax and semantics fusion learning,” in Proceedings of the 29th ACM SIGSOFT International Symposium on Software Testing and Analysis. Virtual Event, USA: ACM, July 18-22 2020, pp. 516–527. [34] H. Wei and M. Li, “Supervised deep features for software functional clone detection by exploiting lexical and syntactical information in source code.” in IJCAI, 2017, pp. 3034–3040. [35] J. Gao, J. Lanchantin, M. L. Soffa, and Y. Qi, “Black-box generation of adversarial text sequences to evade deep learning classifiers,” in

2018 IEEE Security and Privacy Workshops (SPW). 2018 IEEE Security and Privacy Workshops (SPW). IEEE, 2018, pp. 50–56. [36] L. Li, R. Ma, Q. Guo, X. Xue, and X. Qiu, “Bert-attack: Adversarial attack against bert using bert,” arXiv preprint arXiv:2004.09984, 2020. [37] D. Jin, Z. Jin, J. T. Zhou, and P. Szolovits, “Is bert really robust? a strong baseline for natural language attack on text classification and entailment,” in Proceedings of the AAAI conference on artificial intelligence, vol. 34, no. 05, 2020, pp. 8018–8025. [38] Y. Li, H. Wu, and H. Zhao, “Semantic-preserving adversarial code comprehension,” arXiv preprint arXiv:2209.05130, 2022. [39] J. Zeng, J. Xu, X. Zheng, and X. Huang, “Certified robustness to text adversarial attacks by randomized [mask],” Computational Linguistics, vol. 49, no. 2, pp. 395–427, 2023. [40] M. Ye, C. Gong, and Q. Liu, “Safer: A structure-free approach for certified robustness to adversarial word substitutions,” arXiv preprint arXiv:2005.14424, 2020. [41] H. Zhang, Z. Fu, G. Li, L. Ma, Z. Zhao, H. Yang, Y. Sun, Y. Liu, and Z. Jin, “Towards robustness of deep program processing models—detection, estimation, and enhancement,” ACM Transactions on Software Engineering and Methodology (TOSEM), vol. 31, no. 3, pp. 1–40, 2022. [42] J. Svajlenko, J. F. Islam, I. Keivanloo, C. K. Roy, and M. M. Mia, “Towards a big data curated benchmark of inter-project code clones,” in 2014 IEEE International Conference on Software Maintenance and Evolution. IEEE, 2014, pp. 476–480. [43] L. Mou, G. Li, L. Zhang, T. Wang, and Z. Jin, “Convolutional neural networks over tree structures for programming language processing,” in Proceedings of the 30th AAAI Conference on Artificial Intelligence. Phoenix, Arizona, USA: AAAI Press, February 12-17 2016, pp. 1287–1293. [44] D. Guo, S. Ren, S. Lu, Z. Feng, D. Tang, S. Liu, L. Zhou, N. Duan, A. Svyatkovskiy, S. Fu, M. Tufano, S. K. Deng, C. B. Clement, D. Drain, N. Sundaresan, J. Yin, D. Jiang, and M. Zhou, “Graphcodebert: Pre-training code representations with data flow,” in Proceedings of the 9th International Conference on Learning Representations. Virtual Event, Austria: OpenReview.net, May 3-7 2021, pp. 1–12.

[45] A. Lozhkov, R. Li, L. B. Allal, F. Cassano, J. Lamy-Poirier, N. Tazi, A. Tang, D. Pykhtar, J. Liu, Y. Wei et al., “Starcoder 2 and the stack v2: The next generation,” arXiv preprint arXiv:2402.19173, 2024. [46] Bigcode, “Starcoderplus,” Hugging Face Blog, 2023, https://huggingface.co/bigcode/starcoderplus. [47] S. Lu, D. Guo, S. Ren, J. Huang, A. Svyatkovskiy, A. Blanco, C. Clement, D. Drain, D. Jiang, D. Tang et al., “Codexglue: A machine learning benchmark dataset for code understanding and generation,” arXiv preprint arXiv:2102.04664, 2021. [48] W. Sun, Y. Chen, G. Tao, C. Fang, X. Zhang, Q. Zhang, and B. Luo, “Backdooring neural code search,” in Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics. Toronto, Canada: Association for Computational Linguistics, July 9-14 2023, pp. 9692–9708. [49] X. Gu, H. Zhang, and S. Kim, “Deep code search,” in Proceedings of the 40th International Conference on Software Engineering. Gothenburg, Sweden: ACM, May 27 - June 03 2018, pp. 933–944. [50] S. Sachdev, H. Li, S. Luan, S. Kim, K. Sen, and S. Chandra, “Retrieval on source code: a neural code search,” in Proceedings of the 2nd ACM SIGPLAN International Workshop on Machine Learning and Programming Languages, 2018, pp. 31–41. [51] W. Sun, C. Fang, Y. Chen, G. Tao, T. Han, and Q. Zhang, “Code search based on context-aware code translation,” in Proceedings of the 44th IEEE/ACM International Conference on Software Engineering. May 25-27: ACM, Pittsburgh, PA, USA 2022, pp. 388–400. [52] A. LeClair, S. Jiang, and C. McMillan, “A neural model for generating natural language summaries of program subroutines,” in Proceedings of the 2019 IEEE/ACM 41st International Conference on Software Engineering. IEEE, 2019, pp. 795–806. [53] S. Haque, A. LeClair, L. Wu, and C. McMillan, “Improved automatic summarization of subroutines via attention to file context,” in Proceedings of the 17th International Conference on Mining Software Repositories, 2020, pp. 300–310. [54] W. U. Ahmad, S. Chakraborty, B. Ray, and K. Chang, “A transformer-based approach for source code summarization,” in Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics. Online: Association for Computational Linguistics, July 5-10 2020, pp. 4998–5007. [55] C. Fang, W. Sun, Y. Chen, X. Chen, Z. Wei, Q. Zhang, Y. You, B. Luo, Y. Liu, and Z. Chen, “Esale: Enhancing code-summary alignment learning for source code summarization,” IEEE Transactions on Software Engineering (Early Access), pp. 1–18, 2024. [56] W. Sun, Y. Miao, Y. Li, H. Zhang, C. Fang, Y. Liu, G. Deng, Y. Liu, and Z. Chen, “Source code summarization in the era of large language models,” CoRR, vol. abs/2407.07959, no. 1, pp. 1–13, 2024. [57] A. Mastropaolo, S. Scalabrino, N. Cooper, D. N. Palacio, D. Poshyvanyk, R. Oliveto, and G. Bavota, “Studying the usage of text-to-text transfer transformer to support code-related tasks,” in Proceedings of the 2021 IEEE/ACM 43rd International Conference on Software Engineering. IEEE, 2021, pp. 336–347. [58] J. Zhang, X. Wang, H. Zhang, H. Sun, K. Wang, and X. Liu, “A novel neural source code representation based on abstract syntax tree,” in Proceedings of the 41st International Conference on Software Engineering. Montreal, QC, Canada: IEEE / ACM, May 25-31 2019, pp. 783–794. [59] Y. Wan, J. Shu, Y. Sui, G. Xu, Z. Zhao, J. Wu, and P. S. Yu, “Multi-modal attention network learning for semantic source code retrieval,” in Proceedings of the 34th International Conference on Automated Software Engineering. San Diego, CA, USA: IEEE, November 11-15 2019, pp. 13–25. [60] C. Zeng, Y. Yu, S. Li, X. Xia, Z. Wang, M. Geng, L. Bai, W. Dong, and X. Liao, “degraphcs: Embedding variable-based flow graph for neural code search,” ACM Transactions on Software Engineering and Methodology, vol. 32, no. 2, pp. 1–27, 2023. [61] M. Z. Nasrabadi, S. Parsa, M. Ramezani, C. Roy, and M. Ekhtiarzadeh, “A systematic literature review on source code similarity measurement and clone detection: Techniques, applications, and challenges,” Journal of Systems and Software, vol. 204, p. 111796, 2023. [62] Y. Du, T. Ma, L. Wu, X. Zhang, and S. Ji, “Adaccd: Adaptive semantic contrasts discovery based cross lingual adaptation for code clone detection,” in Proceedings of Thirty-Eighth AAAI Conference on Artificial Intelligence. Vancouver, Canada: AAAI Press, February 20-27 2024, pp. 17942–17950. [63] Y. Li, B. Wu, Y. Feng, Y. Fan, Y. Jiang, Z. Li, and S.-T. Xia, “Semi-supervised robust training with generalized perturbed neighborhood,” Pattern Recognition, vol. 124, p. 108472, 2022. [64] J. Bai, B. Chen, Y. Li, D. Wu, W. Guo, S. Xia, and E. Yang, “Targeted attack for deep hashing based retrieval,” in Proceedings of the 16th European Conference on Computer Vision. Glasgow, UK: Springer, August 23-28 2020, pp. 618–634. [65] F. Gao, Y. Wang, and K. Wang, “Discrete adversarial attack to models of code,” Proceedings of the ACM on Programming Languages, vol. 7, no. PLDI, pp. 172–195, 2023. [66] J. M. Springer, B. M. Reinstadler, and U.-M. O’Reilly, “Strata: simple, gradient-free attacks for models of code,” arXiv preprint arXiv:2009.13562, 2020.