Conceptio › Archive › arXiv CS
arXiv CS open access

PatchCon: Patch-aware Weighted Supervised Contrastive Learning for Vulnerability Detection

Chaomeng Lu et al. · arxiv_cs
arXiv CS · Papers
Open Source ↗Direct PDF ↓
software-architecturesoftware-engineeringtesting
Automated vulnerability detection is critical for securing modern software systems, yet existing learning-based approaches often treat functions as independent samples and underuse the supervision provided by vulnerability-fixing patches. In this paper, we propose PatchCon, a CodeBERT-based patch-aw
Conceptio Open Archive

Analyze & explore related research in Conceptio

Connect this record directly into your research workflow or AI agent. Explore citations across open repositories, query full text, and export structured proof bundles.

arXiv:2611.06583v1 [cs.SE] 4 Nov 2026

PatchCon: Patch-aware Weighted Supervised Contrastive Learning for Vulnerability Detection Chaomeng Lu · Pooya Rostami Mazrae · Bert Lagaisse

Abstract Automated vulnerability detection is critical for securing modern software systems, yet existing learning-based approaches often treat functions as independent samples and underuse the supervision provided by vulnerability-fixing patches. In this paper, we propose PatchCon, a CodeBERT-based patch-aware contrastive learning model for function-level vulnerability detection. PatchCon jointly optimizes vulnerability classification and supervised contrastive learning, and treats vulnerable–patched function pairs as hard negatives with larger contrastive weights to capture subtle security-relevant differences introduced by fixes. To evaluate patch-level discrimination, we use two pairwise metrics that measure whether a model can correctly distinguish vulnerable functions from their patched counterparts. We evaluate PatchCon on PairVul-Linux through extensive experiments, including state-of-the-art comparisons, ablation studies, hyperparameter sensitivity analysis, and statistical significance testing. We also conduct fine-grained analyses by Common Weakness Enumeration (CWE) type, function length, and patch size, and further evaluate PatchCon on Linux kernel vulnerabilities disclosed after the training data cutoff. On PairVul-Linux, PatchCon outperforms representative pretrained code models and contrastive learning baselines on both classification and pairwise metrics, improves pairwise accuracy over the strongest reproduced baseline from 0.2060 to 0.3264, and achieves pairwise accuracy comparable to that of a GPT-4o-based large language model (LLM) method at a substantially lower cost. Among the reproduced models, PatchCon also achieves the highest pairwise accuracy on test pairs from Common Vulnerabilities and Exposures (CVE) entries unseen during training and on newly disclosed vulnerabilities.

Chaomeng Lu (corresponding author) · Pooya Rostami Mazrae · Bert Lagaisse DistriNet Group T, KU Leuven, Leuven, Belgium E-mail: chaomeng.lu@kuleuven.be; pooya.rostamimazrae@kuleuven.be; bert.lagaisse@kuleuven.be

2

Chaomeng Lu et al.

Keywords Software vulnerability detection · Supervised contrastive learning · Vulnerability-fixing patches · Hard negatives · Pre-trained code models · Code representation learning

1 Introduction Software vulnerabilities remain a persistent threat to modern software ecosystems (Ohm et al. 2020). As large-scale open-source repositories are increasingly reused in safety-critical, financial, governmental, and cloud infrastructures, vulnerable code can propagate rapidly across projects and affect downstream users at scale (Ladisa et al. 2023). Automated vulnerability detection has therefore become an important research direction in software security (Le et al. 2022; Yamaguchi et al. 2014). Recent approaches based on deep learning and Large Language Models (LLMs) have shown promise in identifying vulnerable functions from source code, but reliably distinguishing vulnerable code from its patched counterpart remains challenging because vulnerability fixes often involve subtle yet security-critical changes (Risse and Böhme 2024; Steenhoek et al. 2023; Zhou et al. 2025). Existing vulnerability detection approaches still face three major limitations. Unreliable datasets. The datasets used in many previous studies are often not sufficiently reliable for realistic and fine-grained vulnerability detection evaluation. Some commonly used datasets suffer from low label accuracy, high duplication rates, and a large number of functions that are not directly related to vulnerabilities. In other cases, the data may not be constructed from real-world vulnerability reports and corresponding patches, making it difficult to assess whether a model can generalize to practical vulnerability detection scenarios (Chen et al. 2023; Croft et al. 2022; Ding et al. 2025). Underused patch supervision. Many existing methods formulate vulnerability detection as an independent single-function classification task. However, real-world vulnerabilities are often best understood through their fixes. A vulnerable function and its patched counterpart usually share most lexical and syntactic structures, while differing only in small but security-critical edits. Such vulnerable–patched pairs provide strong supervision signals for learning security-sensitive representations, but this information has not been fully exploited in many existing pipelines (Tan et al. 2025). Although contrastive learning has recently been introduced into this field (Cao et al. 2025; Tian et al. 2026), existing designs either do not use vulnerable–patched pairs or treat them in the same way as ordinary negative samples. Limited patch-level evaluation. Existing evaluation protocols provide limited insight into patch-level discrimination. Most detectors are still evaluated only with standard classification metrics, such as accuracy, precision, and F1score. These metrics are useful for measuring overall detection performance, but they do not directly evaluate whether a model assigns higher vulnerability confidence to a vulnerable function than to its fixed version. This ability

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

3

is critical in practice, because a reliable vulnerability detector should be able to distinguish a vulnerable implementation from a minimally changed but security-corrected patch. To address these limitations, this paper proposes PatchCon, a Patchaware Weighted Supervised Contrastive Learning framework for function-level vulnerability detection. To support reliable and fine-grained evaluation, we conduct experiments on PairVul-Linux (Du et al. 2026), which is constructed from real-world Linux kernel Common Vulnerabilities and Exposures (CVE) reports and their corresponding patches, removes functions that are not directly related to vulnerabilities, and applies strict filtering to improve label quality. In addition, we use the Linux kernel subset of VentiVul (Lu and Lagaisse 2026), a test set of vulnerabilities published more than a year after the most recent vulnerability in PairVul-Linux, to evaluate whether the learned discrimination generalizes to newly disclosed vulnerabilities. Different from conventional single-function classifiers, PatchCon explicitly incorporates patch-pair information by constructing four types of function pairs. In particular, vulnerable–patched pairs are treated as hard negatives and assigned larger contrastive weights. This design encourages the model to learn compact intra-class representations while enlarging the representation gap between vulnerable functions and their patched counterparts. Beyond standard classification metrics, we use two pairwise evaluation metrics, Pairwise Accuracy (PACC), which follows the pairwise evaluation of prior work (Du et al. 2026), and Mean Confidence Gap (MCG), to directly evaluate whether a model ranks vulnerable functions as more vulnerable than their corresponding fixed versions. We further conduct a comprehensive evaluation around six research questions (RQs) and discuss the robustness of the results to CVE overlap and representative cases. The main contributions of this paper are summarized as follows: – We propose PatchCon, a supervised contrastive approach to function-level vulnerability detection that treats vulnerable–patched function pairs as hard negatives, weights them more heavily than ordinary negatives, and is trained jointly with classification. – We evaluate PatchCon on PairVul-Linux and VentiVul with standard and pairwise metrics. PatchCon improves PACC over the strongest reproduced baseline from 0.2060 to 0.3264, with statistically significant gains over all evaluated baselines, and achieves pairwise accuracy comparable to a GPT4o-based method at a much lower cost. – We show that the advantage of PatchCon in vulnerable–patched discrimination persists without CVE overlap: it retains the highest PACC among the reproduced models on test pairs from CVEs unseen during training and on VentiVul. This paper is structured as follows. Section 2 reviews related work on vulnerability detection, contrastive learning, and patch-aware vulnerability analysis. Section 3 presents the design of PatchCon. Section 4 describes the datasets, baselines, implementation details, and evaluation metrics. Section 5 reports the

4

Chaomeng Lu et al.

results for the six RQs. Section 6 discusses the robustness of the results to CVE overlap, a case study, limitations, and threats to validity. Section 7 concludes the paper.

2 Related Work Early software vulnerability detection approaches relied on handcrafted features, static analysis rules, or symbolic reasoning (Ghaffarian and Shahriari 2017; Yamaguchi et al. 2014). With the advent of neural code models, vulnerability detection has shifted toward data-driven representation learning (Li et al. 2018, 2022; Zhou et al. 2019). More recently, programming language models and LLMs have been fine-tuned or prompted for vulnerability classification and have shown promising results on multiple benchmarks (Sheng et al. 2025; Shiri Harzevili et al. 2024; Wen et al. 2024). However, recent studies also show that learning-based detectors can be sensitive to dataset artifacts and distribution shifts, and may struggle to distinguish vulnerable functions from semantically similar patched counterparts (Chakraborty et al. 2024; Croft et al. 2023; Lu and Lagaisse 2026). These findings motivate vulnerability detection methods that explicitly exploit patch-level supervision rather than treating functions only as independent samples. Contrastive learning (CL) has become a powerful representation learning paradigm through both self-supervised and supervised objectives (Chen et al. 2020; He et al. 2020; Khosla et al. 2020). In software engineering, contrastive objectives have been explored for clone detection, defect prediction, code search, and code representation pretraining (Liu et al. 2023; Shi et al. 2023; Xu et al. 2023). For vulnerability detection, several studies have adapted CL to improve representation robustness and vulnerability-specific discrimination. ReVeal (Chakraborty et al. 2022) represents source code with graph-based features and introduces triplet-loss-based CL for vulnerability detection. ContraFlow (Cheng et al. 2022) leverages self-supervised CL to preserve feasible value-flow paths, improving vulnerability classification and buggy-statement localization. ContraBERT (Liu et al. 2023) combines masked language modeling with contrastive pretraining over augmented code and natural-language variants to improve pretrained code representations. Clear (Chen et al. 2024) applies CL to smart contract vulnerability detection by modeling fine-grained correlations among contracts. Ji et al. (2024) propose a hierarchical CL framework for long-tail multi-class vulnerability classification by leveraging relationships among Common Weakness Enumeration (CWE) classes and max pooling for long-code representation. SCL-CVD (Wang et al. 2024) applies supervised contrastive learning to vulnerability detection by fine-tuning GraphCodeBERT with Supervised Contrastive Learning (SupCon) loss. MCL-VD (Cao et al. 2025) combines source code, comments, and abstract syntax tree (AST) information with multimodal CL to improve vulnerability detection. These approaches demonstrate the usefulness of CL for vulnerability-related representation learning, but most of them optimize general code representations or

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

5

function-level class separation without explicitly modeling vulnerable–patched functions as hard negative pairs. Several works are more closely related to patch-aware or repair-aware vulnerability analysis. VDSimilar (Sun et al. 2021) exploits vulnerable–patched pairs with a Siamese BiLSTM-Attention network to improve vulnerability detection under limited labeled data. DELTA (Tian et al. 2026) uses vulnerable– patched function pairs and optimization-varied binaries as contrastive samples for repair-aware binary vulnerability detection. Vul-RAG (Du et al. 2026) enhances LLM-based vulnerability detection with retrieval-augmented knowledge distilled from historical vulnerabilities and fixes, improving the ability of LLMs to distinguish vulnerable code from similar patched code. These studies highlight the importance of patch information, but they differ from PatchCon in either task setting, model design, or evaluation focus. In particular, DELTA targets binary code and uses vulnerable–patched pairs in an NT-Xent objective without pair-type weighting. In contrast, PatchCon targets source-code function-level vulnerability detection, assigns larger weights to vulnerable– patched pairs than to ordinary negatives in a supervised contrastive objective jointly optimized with classification, and uses pairwise metrics to directly evaluate patch-level vulnerable–patched discrimination.

3 Methodology As shown in Fig. 1, PatchCon consists of four components: (a) Pair Construction, (b) Pair Input Encoding, (c) Training Objectives, and (d) Evaluation. Given vulnerability-fixing patches, PatchCon constructs positive pairs, ordinary negative pairs, and vulnerable–patched hard negative pairs, where patch pairs are emphasized. Each function is encoded by a shared pretrained code encoder, and long functions are processed with chunk-based encoding and max pooling to obtain function-level representations. During training, PatchCon jointly optimizes single-function classification loss and weighted SupCon loss, assigning larger weights to patch-pair hard negatives to better capture subtle differences introduced by fixes. Then the model is evaluated using both classification and pairwise metrics, including Pairwise Accuracy (PACC) and Mean Confidence Gap (MCG), to assess its ability to distinguish vulnerable functions from their patched counterparts.

3.1 Pair Construction Based on the vulnerable–patched pairs in the training data, we construct labeled function pairs with explicit semantic relations. Each function pair (fqa , fqb ) is associated with a predefined pair type tq that characterizes the relation between the two functions. The purpose of this design is to provide both class-level and patch-level supervision for contrastive representation learning.

6

Chaomeng Lu et al.

Fig. 1 Overview of the proposed PatchCon framework.

Specifically, we construct four types of function pairs: same safe (two nonvulnerable functions, treated as a positive pair), same vuln (two vulnerable functions, treated as a positive pair), random neg (a randomly sampled vulnerable–non-vulnerable pair, treated as an ordinary negative pair), patch (a vulnerable function and its corresponding patched version, treated as a patch hard negative pair). The key intuition is that patch pairs provide stronger supervision than ordinary negative pairs. A vulnerable function and its patched counterpart usually share most lexical and syntactic structures, but differ in subtle securitycritical semantics. Therefore, distinguishing patch pairs is more challenging and more informative for vulnerability detection than separating randomly sampled vulnerable and non-vulnerable functions. During training, each pair contributes two function instances to a mini-batch. For a mini-batch containing B constructed pairs, we obtain 2B function representations. The pair type is retained as metadata and later used by the weighted supervised contrastive objective to distinguish positive pairs, ordinary negative pairs, and patch hard negatives.

3.2 Pair Input Encoding Given a function-level code snippet f , we first tokenize it into a token sequence: x = (x1 , x2 , . . . , xn ).

(1)

Since real-world functions may exceed the maximum input length of pretrained code models, directly truncating the function may discard vulnerabilityrelevant statements. To mitigate this issue, we adopt a chunk-based encoding

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

7

strategy. The token sequence is divided into multiple chunks: x → {x(1) , x(2) , . . . , x(m) },

(2)

where each chunk is constrained by the maximum input length of the pretrained encoder. Each chunk is encoded by a shared pretrained code encoder E(·): c(t) = E(x(t) ), (t)

t = 1, 2, . . . , m,

(3)

d

where c ∈ R denotes the representation of the t-th chunk. In practice, we use the hidden representation of the special classification token as the chunklevel representation. To aggregate multiple chunk-level representations into a single function-level representation, we apply element-wise max pooling (MP):  h = MaxPool c(1) , c(2) , . . . , c(m) , (4) where h ∈ Rd is the final representation of function f . MP allows the model to preserve salient vulnerability-related signals that may appear in any chunk of a long function. For the q-th function pair (fqa , fqb ), the two functions are encoded by the same encoder and pooling module with shared parameters: haq = Enc(fqa ),

hbq = Enc(fqb ),

(5)

where Enc(·) denotes the chunk-based code encoder followed by MP. This shared encoding design ensures that both sides of a function pair are represented in the same embedding space. 3.3 Training Objectives PatchCon jointly optimizes single-function vulnerability classification and patch-aware SupCon. The classification objective encourages the model to correctly predict whether a function is vulnerable, while the contrastive objective encourages the model to learn a representation space that better captures semantic relations between paired functions. 3.3.1 Classification Head Given a mini-batch of B function pairs, the q-th pair is denoted as (fqa , fqb ). Although samples are organized as pairs, the classification head is applied independently to each function: ŷqa = Hcls (haq ), where ŷqa , ŷqb

ŷqb = Hcls (hbq ),

(6)

2

∈ R denote the logits for the non-vulnerable and vulnerable classes. The classification loss averages the cross-entropy losses of the two functions in each pair and then averages over the mini-batch: Lcls =

B  1 X1 CE(ŷqa , yqa ) + CE(ŷqb , yqb ) , B q=1 2

where yqa , yqb ∈ {0, 1} are the ground-truth labels.

(7)

8

Chaomeng Lu et al.

3.3.2 Projection Head After expanding the B function pairs into 2B function instances, the projection head maps each function-level representation into a contrastive embedding space: zi = Hp (hi ) ∈ Rk , (8) where k is the dimension of the contrastive embedding. The projected vector is then ℓ2 -normalized: zi z̃i = . (9) ∥zi ∥2 The normalized embedding z̃i is used in the supervised contrastive objective. 3.3.3 Patch-aware Weighted Supervised Contrastive Loss Let V denote the set of 2B function instances expanded from the B pairs in a mini-batch. Let z̃i ∈ Rk denote the normalized embedding of function instance i ∈ V. For each anchor i, we define its positive set P(i) according to the constructed positive pair relations: P(i) = {j | (i, j) forms a same safe or same vuln pair}.

(10)

Pairs of type random neg and patch are treated as negative relations in the contrastive objective. In particular, patch pairs are regarded as hard negatives because they correspond to vulnerable functions and their patched versions. For each anchor i with a non-empty positive set P(i), the supervised contrastive loss is defined as: ℓi = −

X 1 exp(z̃⊤ i z̃p /τ ) log P ⊤ |P(i)| a∈V,a̸=i exp(z̃i z̃a /τ )

(11)

p∈P(i)

where τ is the temperature hyperparameter. The denominator contains all non-anchor function instances in V, providing uniform normalization over the contrastive candidates. The supervised contrastive loss is averaged over all anchors with non-empty positive sets: 1 X ℓi , (12) Lpos = |I| i∈I

where I denotes the set of anchor instances with non-empty positive sets. Since only same safe and same vuln pairs define positive relations, instances from patch pairs do not act as anchors in Lpos . The patch-aware weighting is therefore applied to the explicit negative penalty described below. In addition to the supervised contrastive formulation above, we introduce an explicit pair-level negative penalty to further separate hard negative pairs. Specifically, for pairs of type random neg and patch, we directly penalize high

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

9

cosine similarity between the two instances. The pair-level negative loss is defined as:  ⊤  1 X z̃i z̃j − m w Lneg = wij · softplus (13) |N | τ (i,j)∈N

where N denotes the set of negative pairs (i.e., pairs of type random neg and patch), m is a margin hyperparameter, and wij is the pair-dependent weight, set to wp for patch pairs and 1 for random neg pairs, where wp > 1 is the hardnegative weight for vulnerable–patched pairs. The final patch-aware supervised contrastive objective therefore consists of two components: w Lw supcon = Lpos + Lneg

(14)

Overall, the objective combines supervised contrastive learning with an explicit, patch-aware weighted negative repulsion term. Patch pairs are emphasized through larger pair-level weights in the negative penalty, helping the model separate vulnerable functions from their patched counterparts. 3.3.4 Joint Training Objective The overall training objective combines the single-function classification loss and the weighted SupCon loss: L = Lcls + λLw supcon

(15)

where λ controls the contribution of the contrastive objective. The classification loss encourages the model to predict the vulnerability label of each individual function, while the weighted SupCon loss encourages the model to learn a more discriminative representation space. In particular, the patch-aware weighting strategy increases the contribution of vulnerable– patched hard negatives, enabling the model to focus on subtle security-relevant differences introduced by vulnerability patches. All loss terms are optimized jointly, and gradients are backpropagated through the shared code encoder, MP module, classification head, and projection head.

4 Experimental Setup 4.1 Datasets We conduct experiments on a realistic vulnerability dataset that contains patch pair information, and further evaluate the trained models on an outof-distribution (OOD) test set of recently disclosed vulnerabilities. PairVul-Linux (Du et al. 2026) is derived from the benchmark constructed in Vul-RAG. It is built from Linux kernel CVEs and is designed to evaluate whether vulnerability detection models can distinguish vulnerable functions from their corresponding patched versions. It contains 8,628 functions, 4,314 vulnerable–patched pairs, and 2,073 CVEs across 95 different

10

Chaomeng Lu et al.

CWEs. Each instance provides a vulnerable function and a patched function, together with vulnerability-related metadata such as CVE ID, CWE ID, and patched code. In this work, PairVul-Linux serves as the primary benchmark because its paired structure naturally supports both function-level vulnerability classification and pairwise discrimination. VentiVul (Lu and Lagaisse 2026) is a temporally separated OOD test set of recently disclosed Linux and Chromium vulnerabilities from our previous work. We use its Linux kernel subset, which follows the construction procedure of PairVul (Du et al. 2026) and contains the functions modified by the fixing commits of Linux kernel CVEs published between May 1 and May 29, 2025, as vulnerable–patched pairs. This subset contains 116 pairs from 100 CVEs across 20 CWEs. No CVE in VentiVul appears in PairVul-Linux, whose most recent CVE (CVE-2024-0193) was published in January 2024. To further avoid code-level overlap, we remove four pairs whose two versions are identical after whitespace normalization and one pair whose vulnerable function also appears in PairVul-Linux, resulting in 111 pairs from 96 CVEs, which we use only for testing and refer to as VentiVul in the following.

4.2 Baseline Models We compare PatchCon with three pretrained code-model baselines and several representative vulnerability detection methods that are closely related to CL or patch-pair-based vulnerability analysis. CodeBERT (Feng et al. 2020), GraphCodeBERT (Guo et al. 2021), and UniXcoder (Guo et al. 2022) are used as pretrained code model baselines to study the effect of different encoders on vulnerability detection. CodeBERT is a bimodal Transformer pretrained on code and natural language, and serves as our function-level classification baseline and the default backbone of PatchCon. GraphCodeBERT enhances code representation with data-flow information and structure-aware pretraining, while UniXcoder supports cross-modal code understanding and generation by leveraging multimodal signals such as code comments. ReVeal (Chakraborty et al. 2022) is a Graph Neural Network (GNN)based approach for vulnerability detection. It represents source code with graph-based features and introduces a contrastive learning mechanism through triplet loss, making it an early attempt to incorporate contrastive learning into vulnerability detection. We include ReVeal as a representative graph-based and contrastive-learning-based vulnerability detection baseline. ContraBERT (Liu et al. 2023) introduces InfoNCE-based CL to improve the semantic structure of code embeddings. It provides both CodeBERT- and GraphCodeBERT-based variants; in this work, we adopt the CodeBERT-based version to keep the backbone consistent with our main experimental setting. SCL-CVD (Wang et al. 2024) is a supervised contrastive learning-based vulnerability detection method. It fine-tunes a pretrained code model with supervised contrastive learning and uses a multilayer perceptron (MLP) classifier

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

11

for vulnerability prediction. However, unlike PatchCon, it does not explicitly model vulnerable–patched pairs as weighted hard negatives. As its public implementation does not include the GraphCodeBERT-based module, we replicate its CodeBERT version. DELTA (Tian et al. 2026) is a contrastive learning method for optimization-resilient binary vulnerability detection. It constructs contrastive samples from vulnerable and patched function pairs, and fine-tunes CodeBERT with contrastive learning. As DELTA is originally designed for binary code, we reproduce its source-code training version for our setting. Vul-RAG (Du et al. 2026) is a retrieval-augmented LLM framework for vulnerability detection. It incorporates vulnerability knowledge distilled from historical vulnerabilities and fixes to help LLMs distinguish vulnerable code from similar patched code. Vul-RAG can be instantiated with different LLM backbones; in this work, we report the best-performing version, Vul-RAG with GPT-4o, which achieves the highest pairwise accuracy among the four LLMs evaluated in the original paper and whose per-sample outputs are publicly released. Unless otherwise specified, “Vul-RAG” in the following sections refers to this GPT-4o-based version.

4.3 Implementation Details We implement PatchCon with PyTorch 2.3.1 and HuggingFace Transformers 4.37.2 under Python 3.12.4 and CUDA 11.8.0. All experiments are conducted on a multi-GPU server equipped with NVIDIA H100 GPUs. Unless otherwise stated, CodeBERT is the default encoder. We use AdamW with learning rate 2 × 10−5 , batch size 16, SupCon temperature τ = 0.07, chunk length 512, and MP size 2048. Hyperparameters and model checkpoints are selected according to the performance on the validation set, and the final objective in Eq. (15) uses λ = 0.01 and patch-pair weight wp = 2. Training PatchCon takes about 53 minutes per epoch on a single H100 GPU (at most 10 epochs with early stopping), and inference takes about 23 ms per function. PairVul-Linux is randomly split into training, validation, and test sets with an 8:1:1 ratio at the pair level, so that the two functions of each patch pair always fall into the same partition and the class balance is preserved. As in the original PairVul benchmark (Du et al. 2026), the split is performed at the pair level rather than grouped by CVE; we discuss the effect of CVE overlap between partitions in Section 6.1.

4.4 Evaluation Metrics We use standard binary classification metrics, including Accuracy (ACC), Precision, Area Under the Precision-Recall Curve (AUCPRC ) and Matthews Correlation Coefficient (MCC). Since our evaluation sets consist of vulnerable– patched pairs and are therefore class-balanced, Accuracy and MCC are re-

12

Chaomeng Lu et al.

ported as primary threshold-based metrics. Precision is included to characterize prediction exactness, while AUCPRC , computed from the predicted vulnerability probabilities, summarizes the precision–recall trade-off across thresholds. Recall and F1 are reported as supplementary metrics rather than primary metrics because they may obscure asymmetric behavior when a model overpredicts the vulnerable class. Let true positives (T P ), true negatives (T N ), false positives (F P ), and false negatives (F N ) denote the elements of the confusion matrix. The AUCPRC is computed as: Z 1 AUCPRC = P (R) dR, (16) 0

where P (R) denotes Precision as a function of Recall R. MCC is computed as: TP · TN − FP · FN . MCC = p (T P + F P )(T P + F N )(T N + F P )(T N + F N )

(17)

To evaluate vulnerable–patched discrimination, we use two pairwise metrics. PACC corresponds to the pair-wise correct prediction metric of PrimeVul (Ding et al. 2025) and the pairwise accuracy of Vul-RAG (Du et al. 2026), while MCG complements it from a confidence-based perspective. Given a patch pair (fv , fp ), where fv denotes the vulnerable function and fp denotes the patched function, let s(f ) denote the predicted vulnerability confidence of function f , and let ŷ(f ) denote its predicted label. Pairwise Accuracy (PACC) measures the proportion of patch pairs that are correctly distinguished at the prediction-label level. A patch pair is considered successful only when the vulnerable function is predicted as vulnerable and its patched counterpart is predicted as safe: PACC =

1

X

|Ppatch |

 I ŷ(fv ) = 1 ∧ ŷ(fp ) = 0 ,

(18)

(fv ,fp )∈Ppatch

where Ppatch denotes the set of vulnerable–patched function pairs. Following PrimeVul (Ding et al. 2025), we further divide the pairs that are not correctly distinguished into three failure modes: both functions predicted as vulnerable (P-V), both predicted as safe (P-B), and reversed predictions (P-R). Mean Confidence Gap (MCG) further measures the average difference in vulnerability confidence between vulnerable functions and their patched counterparts: MCG =

1 |Ppatch |

X

 s(fv ) − s(fp ) .

(19)

(fv ,fp )∈Ppatch

A higher MCG indicates that the model assigns a larger vulnerability confidence margin to vulnerable functions over their patched counterparts. Together, PACC and MCG evaluate pairwise vulnerable–patched discrimination from complementary perspectives.

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

13

5 Evaluation Our evaluation is designed to answer the following research questions. – RQ1. How effective is PatchCon compared with state-of-the-art vulnerability detection approaches? – RQ2. How do PatchCon’s components and backbone choices affect performance? – RQ3. How do key hyperparameters affect PatchCon’s performance? – RQ4. How does PatchCon perform across CWE types, function lengths, and patch sizes? – RQ5. Are PatchCon’s improvements statistically significant? – RQ6. Does PatchCon’s vulnerable–patched discrimination generalize to vulnerabilities disclosed after its training data? Section 6 further discusses the robustness of the results to CVE overlap and representative cases.

5.1 Overall Performance (RQ1) Table 1 compares PatchCon with representative baselines on PairVul-Linux, including pretrained code-model baselines, CL-based vulnerability detection methods, and a prompt-based LLM method. As the Vul-RAG configuration uses the closed-source GPT-4o model, we do not rerun it within our experimental pipeline. Instead, we compute its metrics from the per-sample outputs released by its authors, which cover 585 of the 586 pairs in its own test split of PairVul. Since Vul-RAG outputs only binary decisions, AUCPRC and MCG cannot be computed and are marked as “–”, and undetermined answers, which occur in 19 pairs, are counted as incorrect predictions. The recomputed PACC (0.2923) differs from the 0.32 reported in the original paper; we use the recomputed values so that all metrics of Vul-RAG are derived from the same predictions. Since these results were obtained on a different test split of PairVul, they are not directly comparable with ours. Overall, PatchCon achieves the strongest performance among the evaluated models, especially on MCC and pairwise metrics. Compared with the CodeBERT (CB) baseline, PatchCon improves ACC from 0.5174 to 0.6030 and MCC from 0.0596 to 0.2060. The gains are more pronounced on pairwise metrics, where PACC increases from 0.0486 to 0.3264 and MCG increases from 0.0035 to 0.1838. Similar trends are observed for GraphCodeBERT (GraphCB) and UniXcoder (UX), whose PACC and MCG remain close to zero. Compared with CL-based baselines, PatchCon also shows clear advantages. ContraBERT, which introduces InfoNCE-based contrastive learning, brings only marginal changes over CodeBERT across all metrics, suggesting that general contrastive pretraining alone may not be sufficient for fine-grained vulnerable–patched discrimination. ReVeal uses triplet loss but is not designed

14

Chaomeng Lu et al.

Table 1 Overall performance comparison with representative baselines on the PairVulLinux test set. Pair: uses vulnerable–patched function pairs (for Vul-RAG, to build its knowledge base); PW: patch-pair weighting; InfoNCE, Triplet, NT-Xent, and SupCon also represent contrastive loss types. Approach

Backbone

Contrastive type

Pair

PW

ACC

Precision

MCC

AUCPRC

PACC

MCG

UniXcoder GraphCodeBERT CodeBERT ContraBERT ReVeala SCL-CVD DELTA Vul-RAGb

UX GraphCB CB CB GNN CB CB GPT-4o

× × × InfoNCE Triplet SupCon SimCLR NT-Xent ×

× × × × × × ✓ ✓

× × × × × × × ×

0.5023 0.5069 0.5174 0.5150 0.5024 0.5544 0.5729 0.5974

0.5012 0.5035 0.5096 0.5096 0.5017 0.5540 0.5609 0.6004

0.0482 0.0486 0.0596 0.0364 0.0052 0.1088 0.1487 0.1950

0.5355 0.5363 0.5329 0.5312 0.5022 0.5561 0.5786 –

0.0046 0.0185 0.0486 0.0671 0.0481 0.1505 0.2060 0.2923

0.0024 0.0076 0.0035 0.0026 0.0000 0.0271 0.0855 –

PatchCon

CB

Weighted SupCon

✓

✓

0.6030

0.6018

0.2060

0.6239

0.3264

0.1838

a Graph construction failed for 16 of the 432 test pairs, so ReVeal is evaluated on the re-

maining 416 pairs. b Computed from the per-sample outputs released by the authors of Vul-RAG for 585 of the 586 pairs in its own test split, with undetermined answers counted as incorrect; AUCPRC and MCG cannot be computed from its binary outputs.

Fig. 2 Overall performance comparison of different models.

to explicitly model patch pairs, which may explain its lower pairwise performance in this setting. SCL-CVD and DELTA improve over ordinary classification by using supervised CL and pair-based CL, respectively, reaching PACC scores of 0.1505 and 0.2060, respectively, which PatchCon further improves to 0.3264. Vul-RAG obtains a competitive PACC of 0.2923 under a promptbased LLM setting; however, it relies on closed-source LLMs, and its result is obtained on a different test split. PatchCon achieves a comparable PACC (0.3264) while also yielding a substantially positive MCG, which cannot be computed from the binary outputs of Vul-RAG. To compare the two methods on identical inputs, we further identify the 59 pairs that appear in both our test set and the test split of Vul-RAG. On these pairs, PatchCon achieves a PACC of 0.3729 and an MCC of 0.2888, compared with 0.2881 and 0.2381 for Vul-RAG, although this subset is small. In addition, PatchCon is lightweight: it builds on a 125M-parameter encoder and requires about 23 ms of inference per function on a single GPU, whereas Vul-RAG issues on average 2.3 GPT-4o calls per function at detection time (about 2.0k input and 2.2k output tokens per function according to its released outputs), in addition to the LLM calls used for knowledge extraction. Figure 2 visually summarizes the same trend across ACC, MCC, PACC, and MCG.

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

15

Table 2 further reports Recall, F1, and the distribution of pairwise failure modes. The pretrained encoders obtain high Recall and F1 mainly because they predict almost all functions as vulnerable, so most of their pairs fall into P-V (e.g., 0.9954 for UniXcoder and 0.8750 for CodeBERT). PatchCon distributes its remaining errors more evenly between P-V (0.2824) and P-B (0.2708). Its proportion of reversed predictions (0.1204) is the highest among the models, as models that predict almost all functions as vulnerable rarely produce reversed pairs; nevertheless, most of its failures stem from assigning the same label to both versions of a function rather than inverting them.

Table 2 Supplementary metrics on the PairVul-Linux test set. P-C: both functions of a patch pair are correctly classified (equal to PACC); P-V: both are predicted as vulnerable; P-B: both are predicted as safe; P-R: the predictions are reversed. Approach

Recall

F1

P-C

P-V

P-B

P-R

UniXcoder GraphCodeBERT CodeBERT ContraBERT ReVeala SCL-CVD DELTA Vul-RAGb

1.0000 0.9861 0.9236 0.7963 0.6899 0.5579 0.6713 0.5829

0.6677 0.6667 0.6568 0.6215 0.5810 0.5559 0.6112 0.5915

0.0046 0.0185 0.0486 0.0671 0.0481 0.1505 0.2060 0.2923

0.9954 0.9676 0.8750 0.7292 0.6418 0.4074 0.4653 0.2906

0.0000 0.0093 0.0625 0.1667 0.2668 0.4005 0.2685 0.3197

0.0000 0.0046 0.0139 0.0370 0.0433 0.0417 0.0602 0.0974

PatchCon

0.6088

0.6053

0.3264

0.2824

0.2708

0.1204

a Evaluated on the 416 test pairs available for ReVeal. b Computed from the released outputs of Vul-RAG on its own test split (585 pairs; see

Table 1).

Answer to RQ1. PatchCon achieves the strongest overall performance on PairVul-Linux, especially on MCC, PACC, and MCG, showing more reliable vulnerable–patched discrimination than the evaluated baselines.

5.2 Ablation Study (RQ2) For all ablation settings, we use the same training/validation/test splits, optimizer, batch size, learning rate, and random seeds. Each ablation removes or modifies only the corresponding component of the full model. 5.2.1 PatchCon Ablation Table 3 reports the ablation results of different variants of the proposed framework. Overall, the full PatchCon model achieves the best performance on all metrics except AUCPRC , where the unweighted SupCon variant is slightly higher. Compared with the CB baseline, PatchCon improves performance on

16

Chaomeng Lu et al.

both classification and pairwise metrics. These results indicate that the proposed framework not only improves vulnerability classification, but also substantially strengthens the model’s ability to distinguish vulnerable functions from their patched counterparts. The comparison between CB and PairCodeBERT (a pair-input variant introduced in this work by adapting CodeBERT to constructed function pairs) shows that pair-based input construction alone brings no consistent gains in standard metrics, but improves PACC from 0.0486 to 0.0903 and MCG from 0.0035 to 0.0176, suggesting that paired inputs provide useful discriminative signals. Adding MP further improves both classification and pairwise metrics, confirming the importance of preserving vulnerability-relevant signals from long functions. The degradation observed in the “w/o MP” variant further supports this conclusion, where removing MP reduces ACC to 0.5463 and PACC to 0.1551. However, the improvements of PatchCon do not stem from MP alone. MP only changes the representations of functions that exceed a single 512-token chunk, and on the 224 test pairs (51.9%) whose two versions both fit into a single chunk, PatchCon still achieves a PACC of 0.3527, compared with 0.2723 for DELTA and 0.2009 for SCL-CVD (see also Section 5.4). Table 3 Performance comparison of different variants of PatchCon. MP: max pooling; Patch: patch-pair input; ✓ indicates that the component is used, × indicates that it is not used, and ◦ indicates that only a subset of pair types is retained. Approach

MP

Pair

Patch

SupCon

Weight

ACC

Precision

MCC

AUCPRC

PACC

MCG

CodeBERT PairCodeBERT PairCodeBERT + MP PairCodeBERT + SupCon

× × ✓ ✓

× ✓ ✓ ✓

× ✓ ✓ ✓

× × × ✓

– – – 1

0.5174 0.5197 0.5729 0.5706

0.5096 0.5206 0.5897 0.5840

0.0596 0.0394 0.1485 0.1430

0.5329 0.5382 0.5981 0.6367

0.0486 0.0903 0.2384 0.2708

0.0035 0.0176 0.1310 0.1499

w/o MP w/o patch pairs w/o random neg pairs w/o positive pairs

× ✓ ✓ ✓

✓ ✓ ◦ ◦

✓ × ✓ ✓

✓ ✓ ✓ ✓

2 – 2 2

0.5463 0.5104 0.5428 0.5752

0.5629 0.5102 0.5437 0.5900

0.0960 0.0208 0.0857 0.1525

0.5614 0.5298 0.5498 0.6128

0.1551 0.0718 0.1435 0.2755

0.0561 0.0039 0.0187 0.1479

PatchCon (full model)

✓

✓

✓

✓

2

0.6030

0.6018

0.2060

0.6239

0.3264

0.1838

The results further validate the effectiveness of SupCon and patch-aware weighting. Compared with PairCodeBERT with MP, the unweighted SupCon variant achieves similar ACC and MCC but improves PACC from 0.2384 to 0.2708 and MCG from 0.1310 to 0.1499, suggesting that SupCon helps learn representations that better separate vulnerable and patched functions. Applying patch-aware weighting further improves MCC from 0.1430 to 0.2060 and PACC from 0.2708 to 0.3264, showing that patch pairs provide informative hard negatives due to their lexical and syntactic similarity but distinct security semantics. Pair-type ablations confirm that patch pairs are crucial for learning security-sensitive distinctions: removing them causes the largest degradation, reducing PACC to 0.0718 and MCG to 0.0039, close to the CodeBERT baseline. Removing random negatives also reduces PACC to 0.1435, indicating that random negatives are important for stabilizing the general vulnerable/non-vulnerable boundary. Although removing positive pairs still yields reasonable results, the full model remains consistently better, indicating that positive pairs also contribute to intra-class compactness. Overall, max

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

17

pooling, pair construction, SupCon, and patch-aware weighting are complementary, and their combination achieves the strongest classification and pairwise discrimination performance. 5.2.2 PatchCon Variants with Different Backbone Table 4 compares PatchCon with different pretrained code backbones under a fixed contrastive setting (wp = 3, λ = 0.01), i.e., before the hard-negative weight was set to its final value wp = 2. Overall, CodeBERT performs best in this setting. Without SupCon, the CodeBERT-based PatchCon already outperforms the other backbones in the same setting, achieving 0.5729 ACC, 0.5897 Precision, 0.1485 MCC, 0.5981 AUCPRC , 0.2384 PACC, and 0.1310 MCG. With SupCon, it further achieves the best results across all metrics, suggesting that CodeBERT provides stronger initial representations for the patch-aware contrastive framework. Across all three backbones, SupCon consistently improves performance, especially on PACC and MCG, suggesting the backbone-agnostic effectiveness of the proposed patch-aware contrastive strategy, while final performance still depends on encoder quality. Table 4 Performance of PatchCon with different pretrained code backbones with MP size 2048 and SupCon loss λ = 0.01, and patch-pair weight wp = 3. Backbone

SupCon

ACC

Precision

MCC

AUCPRC

PACC

MCG

CodeBERT

× ✓

0.5729 0.5961

0.5897 0.6040

0.1485 0.1927

0.5981 0.6208

0.2384 0.3218

0.1310 0.1715

GraphCodeBERT

× ✓

0.5058 0.5613

0.5034 0.5556

0.0158 0.1234

0.5275 0.5683

0.0671 0.2870

0.0050 0.1179

UniXcoder

× ✓

0.4977 0.5637

0.4977 0.5610

-0.0046 0.1274

0.5384 0.6006

0.0856 0.2593

0.0086 0.1221

Answer to RQ2. The ablation and backbone results show that MP, pair construction, SupCon, and patch-aware weighting provide complementary benefits, and that the proposed contrastive strategy improves performance across different pretrained code backbones.

5.3 Hyperparameter Sensitivity (RQ3) This RQ examines how sensitive PatchCon is to its three main hyperparameters: the SupCon loss weight λ, the hard negative weight wp , and the max pooling size. Starting from the default configuration described in Section 4.3, we vary one hyperparameter at a time and report the test-set results in Tables 5–7. Because the hyperparameters were tuned sequentially, λ is varied with wp = 3, wp with λ = 0.01, and the pooling size with λ = 0.01 and wp = 2.

18

Chaomeng Lu et al.

5.3.1 Effect of SupCon Loss Table 5 shows that PatchCon is robust to λ within a moderate range. For λ between 0.005 and 0.05, PACC ranges from 0.2639 to 0.3218 and MCC from 0.1554 to 0.1984, all above the variant trained without SupCon (PACC 0.2384 and MCC 0.1485; Table 3). Performance drops sharply at λ = 0.1 (PACC 0.1458 and MCC 0.1016), suggesting that an overly strong contrastive term weakens the classification objective. Table 5 Sensitivity of PatchCon to the SupCon loss weight λ on the test set, with MP size 2048 and patch-pair weight wp = 3. λ

ACC

Precision

MCC

AUCPRC

PACC

MCG

0.005 0.01 (default) 0.05 0.1

0.5775 0.5961 0.5938 0.5463

0.5730 0.6040 0.5707 0.5787

0.1554 0.1927 0.1984 0.1016

0.6174 0.6208 0.6235 0.5737

0.2639 0.3218 0.2917 0.1458

0.1501 0.1715 0.1723 0.0478

5.3.2 Effect of Hard Negative Weight Table 6 shows that weighting patch pairs more heavily than ordinary negatives is beneficial within a limited range. With wp = 2 and wp = 3, PACC reaches 0.3264 and 0.3218 and MCC 0.2060 and 0.1927, compared with 0.2708 and 0.1430 when patch pairs are treated as ordinary negatives (wp = 1), although wp = 1 obtains the highest AUCPRC . A smaller increase (wp = 1.5) brings no clear gain, whereas wp = 4 reduces PACC to 0.1736, indicating that excessive emphasis on patch pairs disrupts the balance between hard negative separation and classification. Table 6 Sensitivity of PatchCon to the patch-pair hard negative weight wp on the test set, with MP size 2048 and λ = 0.01. wp

ACC

Precision

MCC

AUCPRC

PACC

MCG

1 1.5 2 (default) 3 4

0.5706 0.5764 0.6030 0.5961 0.5451

0.5840 0.5965 0.6018 0.6040 0.5575

0.1430 0.1562 0.2060 0.1927 0.0924

0.6367 0.6159 0.6239 0.6208 0.5792

0.2708 0.2616 0.3264 0.3218 0.1736

0.1499 0.1409 0.1838 0.1715 0.0581

5.3.3 Effect of Pooling Size Table 7 shows that the pooling size has the strongest effect. PACC increases from 0.1551 with a single 512-token chunk to 0.2755 with 1,536 tokens and

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

19

0.3264 with 2,048 tokens, the largest size we evaluate, whereas 1,024 tokens performs worse than 512 tokens (PACC 0.0880), possibly because additional code context introduces spurious chunk-level activations into the max-pooled representation. This indicates that sufficient coverage of long functions is important for preserving vulnerability-relevant signals, consistent with the analysis by function length in RQ4. Table 7 Sensitivity of PatchCon to the max pooling size on the test set, with λ = 0.01 and patch-pair weight wp = 2. Size

ACC

Precision

MCC

AUCPRC

PACC

MCG

512 1024 1536 2048 (default)

0.5463 0.5220 0.5961 0.6030

0.5629 0.5212 0.5819 0.6018

0.0960 0.0440 0.1951 0.2060

0.5614 0.5293 0.6124 0.6239

0.1551 0.0880 0.2755 0.3264

0.0561 0.0054 0.1560 0.1838

Answer to RQ3. PatchCon is robust to the SupCon loss weight between 0.005 and 0.05 and to the hard negative weight between 2 and 3, but degrades when either weight is too large. The pooling size has the strongest effect, and covering up to 2,048 tokens gives the best results among the evaluated sizes.

5.4 Analysis by CWE Type, Function Length, and Patch Size (RQ4) To further examine whether the improvement of PatchCon is concentrated in specific vulnerability types or generalizes across different CWEs, we conduct a CWE-specific analysis based on patch-pair-level PACC. Fig. 3 reports the results on the 12 most frequent CWE types in PairVul-Linux. Overall, PatchCon achieves the best or tied-best PACC on 11 out of the 12 CWE types, indicating that the proposed patch-aware SupCon strategy improves vulnerable–patched discrimination across most vulnerability categories. For the four CWE types with the most training pairs (CWE-416, CWE-476, CWE-362, and CWE-20), PatchCon obtains PACC scores of 0.2308, 0.2432, 0.3636, and 0.2778, respectively, outperforming all compared baselines. These results suggest that explicitly modeling vulnerable–patched pairs as hard negatives helps the model capture subtle security-relevant differences across multiple CWE categories. The relative improvement of PatchCon still varies across CWE types. For CWE416, which has the most training pairs (514) and test pairs (78), SCL-CVD and DELTA already outperform vanilla pretrained encoders, but PatchCon further improves PACC to 0.2308. For several CWE types where most baselines obtain very low or even zero PACC, PatchCon achieves clear gains on different CWE types. The only exception is CWE-119 (25 test pairs), where DELTA achieves 0.4400 while PatchCon obtains 0.4000. Moreover, the per-CWE PACC of PatchCon is not associated with the amount of training data (Spearman’s

20

Chaomeng Lu et al.

Fig. 3 CWE-specific PACC comparison across the 12 most frequent CWE types in PairVulLinux. Bars denote the number of training pairs for each CWE type, lines denote the PACC achieved by each model on the test set, and n denotes the number of test pairs.

ρ = 0.09 across the 12 CWE types): CWE-416 has the most training pairs but a relatively low PACC, whereas CWE-264, with only 92 training pairs, reaches 0.5833. This indicates that the difficulty of a CWE type depends more on the characteristics of its vulnerabilities and fixes than on the number of training pairs. These findings suggest that the improvement of PatchCon is not limited to aggregate performance but extends to most vulnerability categories. We further group the test pairs into four bins of similar size according to the number of lines of the vulnerable function. As shown in Fig. 4, PatchCon achieves the highest PACC in all bins. Both versions of the pairs with at most 20 lines contain at most 376 tokens and thus fit into a single 512token chunk, so that MP does not affect their representations. On these pairs, PatchCon still achieves a PACC of 0.3636, compared with 0.3131 for DELTA and 0.2727 for SCL-CVD, indicating that its advantage stems from the patchaware contrastive objective rather than from long-function coverage alone. As functions become longer, the PACC of the baselines decreases markedly: for functions with more than 80 lines, DELTA drops to 0.0901 and SCL-CVD to 0.0541, whereas PatchCon remains at 0.3063. Since baselines such as SCLCVD and DELTA truncate each function to 400 and 512 tokens, respectively, vulnerability-relevant statements in long functions may be lost, whereas PatchCon covers up to 2,048 tokens through chunk-based encoding. Finally, we group the test pairs by patch size, measured as the number of changed lines in a line-level diff between the vulnerable and patched versions. As shown in Fig. 5, 195 of the 432 test pairs (45.1%) are fixed by changing only one or two lines, so that the two versions are almost identical. On these pairs, PatchCon achieves a PACC of 0.3333, compared with 0.1897 for DELTA and 0.1231 for SCL-CVD. PatchCon also achieves the highest PACC on patches with 3–5 and 6–10 changed lines (0.3774 and 0.3200), whereas on patches with more than 10 changed lines, its PACC (0.2143) is on par with that of DELTA. This indicates that patch-aware hard negatives are most beneficial when the vulnerable and patched versions differ only slightly, which is the setting PatchCon is designed for.

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

21

UniXcoder

0.0202

0.0000

0.0000

0.0000

GraphCodeBERT

0.0505

0.0167

0.0098

0.0000

CodeBERT

0.1313

0.0583

0.0098

0.0000

ContraBERT

0.1010

0.0583

0.0588

0.0541

ReVeal

0.0625

0.0593

0.0500

0.0196

SCL-CVD

0.2727

0.1583

0.1275

0.0541

DELTA

0.3131

0.2417

0.1863

0.0901

PatchCon

0.3636

0.3167

0.3235

0.3063

≤20 (n=99)

21–40 (n=120)

41–80 (n=102)

>80 (n=111)

Number of lines of the vulnerable function

Fig. 4 PACC on the PairVul-Linux test set grouped by the number of lines of the vulnerable function; n denotes the number of test pairs in each group. ReVeal is evaluated on the pairs for which graphs can be constructed. UniXcoder GraphCodeBERT

0.4

CodeBERT ContraBERT

ReVeal SCL-CVD

DELTA PatchCon

0.3774 0.3333

0.3200

PACC

0.3 0.2143

0.2 0.1 0

1–2 (n=195)

3–5 (n=106)

6–10 (n=75)

>10 (n=56)

Number of changed lines in the patch

Fig. 5 PACC on the PairVul-Linux test set grouped by the number of changed lines in the patch; n denotes the number of test pairs in each group, and the values above the bars give the PACC of PatchCon. ReVeal is evaluated on the pairs for which graphs can be constructed.

Answer to RQ4. PatchCon improves patch-level discrimination across most CWE categories, although the magnitude of improvement varies by vulnerability type and is not explained by the number of training pairs. PatchCon also achieves the highest or tied-highest PACC across all function lengths and patch sizes, including short functions where MP has no effect, and its advantage is most pronounced on long functions and on small patches that change only a few lines.

22

Chaomeng Lu et al.

5.5 Statistical Significance Analysis (RQ5) To assess the statistical significance of the observed improvements, we compute 95% bootstrap confidence intervals for MCC and PACC. For MCC, bootstrap resampling is performed over function-level test samples, while for PACC, resampling is performed over patch pairs. For model-difference intervals, we perform paired bootstrap resampling on the same patch pairs to preserve samplelevel correspondence between PatchCon and each baseline. We repeat the bootstrap procedure 1,000 times and report the 2.5th and 97.5th percentiles as the confidence interval. As shown in Table 8, PatchCon consistently achieves higher MCC and PACC confidence intervals than all baselines. More importantly, all ∆PACC confidence intervals are strictly above zero, and so are the ∆MCC confidence intervals for all baselines except DELTA, whose ∆MCC interval ([-0.0075, +0.1256]) includes zero. This indicates that the improvements of PatchCon in vulnerable–patched discrimination are statistically significant under bootstrap resampling of the test set, whereas its MCC improvement over DELTA is not. The advantage is particularly clear on PACC, indicating that the proposed strategy substantially improves the model’s ability to distinguish vulnerable functions from their patched counterparts.

Table 8 Bootstrap 95% confidence intervals (CIs) on key metrics. ∆ denotes PatchCon minus the corresponding baseline. Approach

MCC 95% CI

∆MCC 95% CI

PACC 95% CI

∆PACC 95% CI

UniXcoder GraphCodeBERT CodeBERT ContraBERT ReVeala SCL-CVD DELTA

[0.0000, 0.0779] [-0.0212, 0.1075] [-0.0020, 0.1194] [-0.0294, 0.1019] [-0.0643, 0.0739] [0.0395, 0.1721] [0.0811, 0.2166]

[+0.0915, +0.2388] [+0.0850, +0.2333] [+0.0776, +0.2135] [+0.1025, +0.2391] [+0.1316, +0.2742] [+0.0325, +0.1643] [-0.0075, +0.1256]

[0.0000, 0.0116] [0.0069, 0.0324] [0.0278, 0.0718] [0.0440, 0.0880] [0.0288, 0.0697] [0.1157, 0.1829] [0.1666, 0.2431]

[+0.2778, +0.3681] [+0.2638, +0.3542] [+0.2315, +0.3241] [+0.2106, +0.3079] [+0.2307, +0.3341] [+0.1273, +0.2292] [+0.0694, +0.1714]

PatchCon

[0.1456, 0.2710]

–

[0.2824, 0.3704]

–

a Computed on the 416 test pairs available for ReVeal.

Answer to RQ5. The strictly positive paired bootstrap confidence intervals for ∆PACC indicate that PatchCon’s improvements in vulnerable– patched discrimination over all baselines are statistically significant under bootstrap resampling of the test set; for MCC, the improvement is statistically significant over all baselines except DELTA.

5.6 Generalization to Future Vulnerabilities (RQ6) To answer RQ6, we apply the models trained on PairVul-Linux in RQ1 to VentiVul without retraining, fine-tuning, or threshold adjustment. Since all CVEs in VentiVul were published more than a year after the most recent CVE

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

23

in PairVul-Linux and none of them appears in PairVul-Linux, this evaluation is free from the CVE overlap discussed in Section 6.1 and reflects how the models perform on vulnerabilities that were unknown at training time. Since RQ6 concerns vulnerable–patched discrimination, we evaluate the models on the 111 vulnerable–patched pairs with PACC, MCG, and the failure modes defined in Section 4.4.

Table 9 Pairwise results on VentiVul (111 vulnerable–patched pairs from 96 CVEs published in May 2025). P-V, P-B, and P-R are defined as in Table 2. Approach

PACC

MCG

P-V

P-B

P-R

UniXcoder GraphCodeBERT CodeBERT ContraBERT ReVeala SCL-CVD DELTA

0.0000 0.0000 0.0450 0.0270 0.0459 0.1351 0.1261

0.0034 0.0051 0.0068 0.0012 -0.0001 0.0278 0.0324

1.0000 1.0000 0.8559 0.7838 0.7064 0.4324 0.4865

0.0000 0.0000 0.0811 0.1441 0.2018 0.4054 0.3694

0.0000 0.0000 0.0180 0.0450 0.0459 0.0270 0.0180

PatchCon

0.1622

0.0324

0.4324

0.2973

0.1081

a Graph construction failed for 2 of the 111 pairs, so ReVeal is evaluated on the remaining

109 pairs.

Table 9 reports the results on VentiVul. Under this temporal distribution shift, all models perform worse than on the PairVul-Linux test set. The pretrained encoders predict almost all functions as vulnerable, so their PACC remains close to zero and most of their pairs fall into P-V. Among all models, PatchCon achieves the highest PACC (0.1622) and the highest MCG (0.0324, on par with DELTA), followed by SCL-CVD (0.1351) and DELTA (0.1261); the same ordering holds on all 116 pairs before removing the five pairs described in Section 4.1 (0.1552, 0.1293, and 0.1207). These results are consistent with those on unseen CVEs in Section 6.1, where PatchCon also achieves the highest PACC, and suggest that the vulnerable–patched discrimination learned by PatchCon transfers to newly disclosed vulnerabilities better than that of the compared models. Since VentiVul contains only 111 pairs, the differences among PatchCon, SCL-CVD, and DELTA should be interpreted with caution.

Answer to RQ6. On newly disclosed Linux kernel vulnerabilities, all models perform worse than on PairVul-Linux, while PatchCon still achieves the best vulnerable–patched discrimination among the evaluated models in terms of PACC and MCG.

24

Chaomeng Lu et al.

6 Discussion 6.1 Robustness to CVE Overlap Following the original PairVul benchmark, our split is performed at the pair level, so different function pairs of the same CVE may appear in both the training and test sets. To examine whether the advantage of PatchCon depends on such overlap, we divide the test pairs into pairs whose CVE appears in the training set (Seen, 271 pairs) and pairs whose CVE appears in neither the training nor the validation set (Unseen, 154 pairs); the remaining seven test pairs share their CVE only with the validation set. Table 10 reports PACC and MCG on both subsets.

Table 10 PACC and MCG on all test pairs, on test pairs whose CVE appears in the training set (Seen, 271 pairs), and on test pairs whose CVE appears in neither the training nor the validation set (Unseen, 154 pairs). PACC

Approach

MCG

All

Seen

Unseen

All

Seen

Unseen

UniXcoder GraphCodeBERT CodeBERT ContraBERT ReVeala SCL-CVD DELTA

0.0046 0.0185 0.0486 0.0671 0.0481 0.1505 0.2060

0.0074 0.0295 0.0554 0.0812 0.0467 0.1624 0.2325

0.0000 0.0000 0.0325 0.0455 0.0395 0.1169 0.1558

0.0024 0.0076 0.0035 0.0026 0.0000 0.0271 0.0855

0.0025 0.0117 0.0036 0.0027 0.0000 0.0325 0.1104

0.0020 0.0015 0.0033 0.0025 0.0001 0.0173 0.0383

PatchCon

0.3264

0.3727

0.2403

0.1838

0.2442

0.0828

a Evaluated on the test pairs available for ReVeal (257 seen and 152 unseen pairs).

PatchCon achieves the highest PACC and MCG on both subsets. On unseen CVEs, its PACC (0.2403) is 54% and 106% higher than that of DELTA (0.1558) and SCL-CVD (0.1169), respectively, and its MCG (0.0828) is more than twice that of DELTA (0.0383). All models obtain lower scores on unseen CVEs, for which no pair of the same CVE is available during training, but the ranking of the three strongest models remains unchanged. The components analyzed in RQ2 also remain effective on unseen CVEs: removing patch pairs reduces PACC from 0.2403 to 0.0844, removing MP reduces it to 0.1234, and patch-aware weighting improves it over the unweighted SupCon variant from 0.1818 to 0.2403. These results indicate that the advantage of PatchCon in vulnerable–patched discrimination persists without CVE overlap, consistent with its results on newly disclosed vulnerabilities in RQ6. Since pair-level splits are also used in the original PairVul benchmark (Du et al. 2026), we recommend that future evaluations on paired vulnerability benchmarks additionally report results on CVE-disjoint test pairs.

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

25

6.2 Case Study We further analyze three real-world vulnerability cases from the PairVul-Linux test set, including two correctly distinguished pairs and one failure case, to examine which security-relevant patch differences PatchCon captures and where it fails. None of the three CVEs appears in the training or validation data. For each case, we compare a vulnerable function and its patched version, together with their predicted vulnerability scores, providing intuitive evidence of whether PatchCon captures subtle but security-critical differences introduced by patches. Fig. 6 shows the two correctly distinguished examples from CWE-416 and CWE-119. In both cases, PatchCon assigns substantially higher vulnerability scores to the vulnerable functions than to their patched counterparts. For case 1, the vulnerable function receives a score of 0.7429, while the patched version is assigned a lower score of 0.2638. The key difference lies in the additional condition “|| set->dead” introduced in the patched version, which prevents operations on invalid or freed objects; PatchCon successfully captures this semantic change and reduces the vulnerability confidence accordingly. A similar pattern is observed in case 2, where the vulnerable function receives a very high score of 0.9860, while the patched version is assigned a much lower score of 0.0619. The patch introduces additional boundary checks for inode allocation, ensuring that invalid inode indices are filtered out before further operations. Although the two functions are highly similar at the syntactic level, PatchCon distinguishes them after the safety checks are introduced, which is consistent with sensitivity to fine-grained vulnerability-fixing semantics. These examples suggest that, in such cases, the model responds to patch-level differences related to vulnerability causes and fixes rather than only to global code patterns. The consistent separation between vulnerable and patched functions in terms of prediction scores also aligns with the improvements observed in PACC and MCG, providing qualitative support for the quantitative results.

Fig. 6 Case studies of PatchCon. Case 1 (up): CVE-2024-0193 (CWE-416), Case 2 (down): CVE-2022-3649 (CWE-119).

However, PatchCon does not always capture such checks. In another case (CVE-2022-3113, CWE-476), the patch adds a missing NULL check after a

26

Chaomeng Lu et al.

memory allocation in mtk vcodec fw vpu init(), but PatchCon assigns almost identical scores to both versions (0.9981 and 0.9988). Since allocationand-dereference patterns are common in kernel code regardless of whether a guard is present, such a small defensive check may not change the function representation sufficiently, which suggests a direction for future improvement. Overall, these case studies suggest that PatchCon assigns clearly lower scores to patched functions when security-relevant checks are introduced, and the resulting score differences may assist security developers in reviewing whether a patch reduces the predicted vulnerability risk.

6.3 Limitations Although PatchCon improves both standard vulnerability detection and patchpair discrimination metrics, several limitations remain. PatchCon relies on the availability of vulnerable–patched function pairs, which may be noisy or incomplete in projects beyond the Linux kernel, and its hyperparameters are tuned on the Linux kernel, so the optimal weighting may differ across projects. PatchCon targets function-level detection and does not localize vulnerable statements; moreover, since our evaluation focuses on vulnerable functions and their patched counterparts, its false-positive behavior on ordinary functions in file- or repository-level scanning remains to be evaluated. Per-CWE results are limited by the small number of test pairs per CWE type. Finally, our main experiments follow the pair-level split of PairVul; although the analyses on unseen CVEs and on VentiVul show that the advantage of PatchCon persists, function-level classification on unseen CVEs remains challenging for all models, and a CVE-grouped split would provide a stricter evaluation. Future work may explore richer patch representations, line-level explanations, hierarchical CWEaware contrastive objectives, and stronger code encoders to improve robustness and interpretability.

6.4 Threats to Validity Following Wohlin et al. (2012), we discuss threats to construct, internal, external, and conclusion validity, together with the strategies used to mitigate them. Construct validity. Standard metrics may not reflect vulnerabilityfixing semantics; thus, we include PACC and MCG, which directly measure vulnerable–patched discrimination, while acknowledging that they remain proxies. Internal validity. Differences in model architectures and training setups may affect the comparison between PatchCon and the baselines. We reduce this threat by using consistent data splits and evaluation protocols and clearly distinguishing reproduced and non-reproduced results. In addition, the pairlevel split allows pairs from the same CVE to appear in both the training and

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

27

test sets, which may lead to optimistic performance estimates. To mitigate this threat, we additionally evaluate all models on test pairs whose CVE appears in neither the training nor the validation set (Section 6.1) and on newly disclosed vulnerabilities (RQ6). External validity. Our findings may be affected by project-specific bias, as our experiments use Linux kernel vulnerabilities. The Linux kernel is a large and security-critical C codebase with a large number of disclosed vulnerabilities and fixes, but our findings may not fully generalize to other projects. In addition, our evaluation is constrained to C code; future work should extend evaluation to more languages, datasets, and industrial deployment scenarios. Conclusion validity. Randomness in training may influence the results. The bootstrap confidence intervals and model-difference confidence intervals quantify the uncertainty due to test-set sampling, but each configuration is trained once with a fixed random seed, so the variance across training runs is not captured.

7 Conclusion In this paper, we proposed PatchCon, a patch-aware supervised contrastive learning framework for function-level vulnerability detection. PatchCon explicitly leverages vulnerable–patched function pairs as hard negatives and combines chunk-based max pooling, classification learning, and weighted contrastive learning. Experiments on PairVul-Linux show that PatchCon improves both standard detection metrics and pairwise discrimination metrics, and its gains in pairwise accuracy over all evaluated baselines are statistically significant. Ablation studies, hyperparameter sensitivity analysis, backbone comparisons, fine-grained analyses by CWE type, function length, and patch size, and case studies further support the effectiveness of the proposed design. Among the reproduced models, PatchCon also achieves the highest pairwise accuracy on test pairs from CVEs unseen during training and on Linux kernel vulnerabilities disclosed after the training data. Our analysis further suggests that future evaluations on paired vulnerability benchmarks should also report results on CVE-disjoint test pairs. Data availability The processed datasets and splits, the source code of PatchCon, the trained models, the per-sample predictions of PatchCon, and the scripts used for the analyses in this paper are available at https://figshare.com/s/cb1d02d2cea2f6582744. Funding Chaomeng Lu is supported by the CSC-IMEC-KU Leuven scholarship, jointly funded by the China Scholarship Council (CSC) and KU Leuven (CSC No. 202308130074). Author contributions Chaomeng Lu was responsible for conceptualization, methodology, software, data curation, experiments, analysis, visualization, and writing of the original draft. Pooya Rostami Mazrae contributed to the conceptualization of the study and reviewed and edited the manuscript. Bert Lagaisse supervised the work and reviewed and edited the manuscript.

28

Chaomeng Lu et al.

Declarations Ethical Approval Not applicable. Informed Consent Not applicable. Conflict of interest The authors declare that they have no conflict of interest. Clinical Trial Number Not applicable.

References Cao Y, Ju X, Chen X, Gong L (2025) MCL-VD: Multi-modal contrastive learning with LoRA-enhanced GraphCodeBERT for effective vulnerability detection. Autom Softw Eng 32(2):67, https://doi.org/10.1007/s10515-025-00543-3 Chakraborty P, Arumugam KK, Alfadel M, Nagappan M, McIntosh S (2024) Revisiting the performance of deep learning-based vulnerability detection on realistic datasets. IEEE Trans Softw Eng 50(8):2163–2177, https://doi.org/10.1109/TSE.2024.3423712 Chakraborty S, Krishna R, Ding Y, Ray B (2022) Deep learning based vulnerability detection: Are we there yet? IEEE Trans Softw Eng 48(9):3280–3296, https://doi.org/10. 1109/TSE.2021.3087402 Chen T, Kornblith S, Norouzi M, Hinton G (2020) A simple framework for contrastive learning of visual representations. In: Daumé H III, Singh A (eds) Proceedings of the 37th International Conference on Machine Learning, PMLR, Proceedings of Machine Learning Research, vol 119, pp 1597–1607 Chen Y, Ding Z, Alowain L, Chen X, Wagner D (2023) DiverseVul: A new vulnerable source code dataset for deep learning based vulnerability detection. In: Proceedings of the 26th International Symposium on Research in Attacks, Intrusions and Defenses, Association for Computing Machinery, New York, NY, USA, RAID ’23, pp 654–668, https://doi.org/10.1145/3607199.3607242 Chen Y, Sun Z, Gong Z, Hao D (2024) Improving smart contract security with contrastive learning-based vulnerability detection. In: Proceedings of the IEEE/ACM 46th International Conference on Software Engineering, Association for Computing Machinery, New York, NY, USA, ICSE ’24, https://doi.org/10.1145/3597503.3639173 Cheng X, Zhang G, Wang H, Sui Y (2022) Path-sensitive code embedding via contrastive learning for software vulnerability detection. In: Proceedings of the 31st ACM SIGSOFT International Symposium on Software Testing and Analysis, Association for Computing Machinery, New York, NY, USA, ISSTA 2022, pp 519–531, https://doi.org/10.1145/ 3533767.3534371 Croft R, Xie Y, Babar MA (2022) Data preparation for software vulnerability prediction: A systematic literature review. IEEE Trans Softw Eng 49(3):1044–1063, https://doi. org/10.1109/TSE.2022.3171202 Croft R, Babar MA, Kholoosi MM (2023) Data quality for software vulnerability datasets. In: 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE), pp 121–133, https://doi.org/10.1109/ICSE48619.2023.00022 Ding Y, Fu Y, Ibrahim O, Sitawarin C, Chen X, Alomair B, Wagner D, Ray B, Chen Y (2025) Vulnerability detection with code language models: How far are we? In: 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE), IEEE Computer Society, Los Alamitos, CA, USA, pp 1729–1741, https://doi.org/10.1109/ICSE55347.2025. 00038 Du X, Zheng G, Wang K, Zou Y, Wang Y, Deng W, Feng J, Liu M, Chen B, Peng X, Ma T, Lou Y (2026) Vul-RAG: Enhancing LLM-based vulnerability detection via knowledgelevel RAG. ACM Trans Softw Eng Methodol 35(10), https://doi.org/10.1145/3797277 Feng Z, Guo D, Tang D, Duan N, Feng X, Gong M, Shou L, Qin B, Liu T, Jiang D, Zhou M (2020) CodeBERT: A pre-trained model for programming and natural languages. In: Findings of the Association for Computational Linguistics: EMNLP 2020, Association for Computational Linguistics, pp 1536–1547, https://doi.org/10.18653/v1/ 2020.findings-emnlp.139

PatchCon: Patch-aware Weighted Supervised Contrastive Learning

29

Ghaffarian SM, Shahriari HR (2017) Software vulnerability analysis and discovery using machine-learning and data-mining techniques: A survey. ACM Comput Surv 50(4), https://doi.org/10.1145/3092566 Guo D, Ren S, Lu S, Feng Z, Tang D, Liu S, Zhou L, Duan N, Svyatkovskiy A, Fu S, Tufano M, Deng SK, Clement C, Drain D, Sundaresan N, Yin J, Jiang D, Zhou M (2021) GraphCodeBERT: Pre-training code representations with data flow. In: International Conference on Learning Representations Guo D, Lu S, Duan N, Wang Y, Zhou M, Yin J (2022) UniXcoder: Unified cross-modal pre-training for code representation. In: Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics, Association for Computational Linguistics, pp 7212–7225, https://doi.org/10.18653/v1/2022.acl-long.499 He K, Fan H, Wu Y, Xie S, Girshick R (2020) Momentum contrast for unsupervised visual representation learning. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pp 9726–9735, https://doi.org/10.1109/ CVPR42600.2020.00975 Ji C, Yang S, Sun H, Zhang Y (2024) Applying contrastive learning to code vulnerability type classification. In: Al-Onaizan Y, Bansal M, Chen YN (eds) Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing, Association for Computational Linguistics, Miami, Florida, USA, pp 11942–11952, https://doi. org/10.18653/v1/2024.emnlp-main.666 Khosla P, Teterwak P, Wang C, Sarna A, Tian Y, Isola P, Maschinot A, Liu C, Krishnan D (2020) Supervised contrastive learning. In: Advances in Neural Information Processing Systems, vol 33 Ladisa P, Plate H, Martinez M, Barais O (2023) SoK: Taxonomy of attacks on open-source software supply chains. In: 2023 IEEE Symposium on Security and Privacy (SP), IEEE, pp 1509–1526, https://doi.org/10.1109/SP46215.2023.10179304 Le THM, Chen H, Babar MA (2022) A survey on data-driven software vulnerability assessment and prioritization. ACM Comput Surv 55(5):1–39, https://doi.org/10.1145/ 3529757 Li Z, Zou D, Xu S, Ou X, Jin H, Wang S, Deng Z, Zhong Y (2018) VulDeePecker: A deep learning-based system for vulnerability detection. In: Proceedings of the Network and Distributed System Security Symposium, NDSS, https://doi.org/10.14722/ndss. 2018.23158 Li Z, Zou D, Xu S, Jin H, Zhu Y, Chen Z (2022) SySeVR: A framework for using deep learning to detect software vulnerabilities. IEEE Trans Dependable Secure Comput 19(4):2244– 2258, https://doi.org/10.1109/TDSC.2021.3051525 Liu S, Wu B, Xie X, Meng G, Liu Y (2023) ContraBERT: Enhancing code pre-trained models via contrastive learning. In: 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE), pp 2476–2487, https://doi.org/10.1109/ICSE48619.2023.00207 Lu C, Lagaisse B (2026) From lab to reality: A practical evaluation of deep learning models and LLMs for vulnerability detection. J Syst Softw (in press). Preprint available at https://doi.org/10.48550/arXiv.2512.10485 Ohm M, Plate H, Sykosch A, Meier M (2020) Backstabber’s knife collection: A review of open source software supply chain attacks. In: International Conference on Detection of Intrusions and Malware, and Vulnerability Assessment, Springer, pp 23–43, https: //doi.org/10.1007/978-3-030-52683-2_2 Risse N, Böhme M (2024) Uncovering the limits of machine learning for automatic vulnerability detection. In: 33rd USENIX Security Symposium (USENIX Security 24), USENIX Association, Philadelphia, PA, pp 4247–4264 Sheng Z, Chen Z, Gu S, Huang H, Gu G, Huang J (2025) LLMs in software security: A survey of vulnerability detection techniques and insights. ACM Comput Surv 58(5), https://doi.org/10.1145/3769082 Shi E, Wang Y, Gu W, Du L, Zhang H, Han S, Zhang D, Sun H (2023) CoCoSoDa: Effective contrastive learning for code search. In: 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE), pp 2198–2210, https://doi.org/10.1109/ICSE48619. 2023.00185 Shiri Harzevili N, Boaye Belle A, Wang J, Wang S, Jiang ZM, Nagappan N (2024) A systematic literature review on automated software vulnerability detection using machine

30

Chaomeng Lu et al.

learning. ACM Comput Surv 57(3), https://doi.org/10.1145/3699711 Steenhoek B, Rahman MM, Jiles R, Le W (2023) An empirical study of deep learning models for vulnerability detection. In: 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE), pp 2237–2248, https://doi.org/10.1109/ICSE48619. 2023.00188 Sun H, Cui L, Li L, Ding Z, Hao Z, Cui J, Liu P (2021) VDSimilar: Vulnerability detection based on code similarity of vulnerabilities and patches. Comput Secur 110:102417, https://doi.org/10.1016/j.cose.2021.102417 Tan Z, Zhou J, Hu X, Pan S, Liu K, Xia X (2025) Similar but patched code considered harmful: The impact of similar but patched code on recurring vulnerability detection and how to remove them. In: 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE), pp 2445–2457, https://doi.org/10.1109/ICSE55347.2025.00110 Tian Z, Zhao J, Fan M, Sun J, Chen Y, Chen L (2026) When fixes teach: Repair-aware contrastive learning for optimization-resilient binary vulnerability detection. J Syst Archit 173:103722, https://doi.org/10.1016/j.sysarc.2026.103722 Wang R, Xu S, Tian Y, Ji X, Sun X, Jiang S (2024) SCL-CVD: Supervised contrastive learning for code vulnerability detection via GraphCodeBERT. Comput Secur 145:103994, https://doi.org/10.1016/j.cose.2024.103994 Wen XC, Gao C, Luo F, Wang H, Li G, Liao Q (2024) LIVABLE: Exploring long-tailed classification of software vulnerability types. IEEE Trans Softw Eng 50(6):1325–1339, https://doi.org/10.1109/TSE.2024.3382361 Wohlin C, Runeson P, Höst M, Ohlsson MC, Regnell B, Wesslén A (2012) Experimentation in software engineering. Springer, Berlin, Heidelberg, https://doi.org/10.1007/ 978-3-642-29044-2 Xu L, Xie H, Li Z, Wang FL, Wang W, Li Q (2023) Contrastive learning models for sentence representations. ACM Trans Intell Syst Technol 14(4), https://doi.org/10.1145/ 3593590 Yamaguchi F, Golde N, Arp D, Rieck K (2014) Modeling and discovering vulnerabilities with code property graphs. In: 2014 IEEE Symposium on Security and Privacy, pp 590–604, https://doi.org/10.1109/SP.2014.44 Zhou X, Cao S, Sun X, Lo D (2025) Large language model for vulnerability detection and repair: Literature review and the road ahead. ACM Trans Softw Eng Methodol 34(5), https://doi.org/10.1145/3708522 Zhou Y, Liu S, Siow J, Du X, Liu Y (2019) Devign: Effective vulnerability identification by learning comprehensive program semantics via graph neural networks. In: Advances in Neural Information Processing Systems, vol 32

Related documents

Record · ID 1571874 · SHA-256 f4f66338962f7d82
Retrieved via Conceptio: every document is proof-bundled with source, license, and retrieval metadata.
Bring this data into your agent: Connect via MCP or API · 20 free credits to start · no card required
Read the Docs → · View CLI source on GitHub · Conceptio Open Knowledge Archive