Manuscript Offprint
arXiv:2610.37797Structured Security Explanations for Learning-Based Vulnerability Detection
FARES TRAD, York University, Canada
YIZHOU CHEN, Peking University, China
HUNG VIET PHAM, York University, Canada
ZEYU SUN, Institute of Software, Chinese Academy of Sciences, China
GIAS UDDIN, York University, Canada
Software vulnerability detection remains difficult because existing approaches either rely on predefined analysis rules, learn vulnerability patterns implicitly from code and labels, or use large language models (LLMs) themselves to produce the final security judgment. These approaches can be limited by rigid analysis rules, implicit learning of security-relevant program behavior, or reliance on the LLM itself for the final decision. This leaves open whether structured security-relevant program behavior can be made explicit and learned jointly with source code for vulnerability detection.
We present VULNLENS, an explanation-augmented framework for binary C/C++ vulnerability detection that separates program-behavior analysis from the final vulnerability decision. A label-blind LLM-based EXPLAINER analyzes each function from seven fixed program-analysis perspectives, including data flow, memory access, object lifetime, arithmetic and type behavior, control flow, shared state, and external-resource access, without receiving vulnerability labels or CWE information. A supervised DETECTOR then combines the source code with these structured explanations through sequential cross-attention to learn vulnerability-relevant code-explanation relationships.
We evaluate VULNLENS on a PrimeVul-derived dataset covering ten CWE categories and assess cross-dataset transfer on SecVulEval, a separate benchmark never used for training or retraining. On the 526-function PrimeVul test set, VULNLENS achieves 75.5% accuracy and 77.2% F1. Among the closest direct-LLM baselines, VULNLENS exceeds DeepSeek V4 Pro by 4.2 percentage points in accuracy and Gemini 2.5 Pro by 2.2 percentage points in F1. Compared with a separately trained code-only detector, matched explanations improve F1 by 7.3 percentage points. When transferred directly to SecVulEval without retraining, VULNLENS achieves 66.4% accuracy and 65.8% F1, outperforming DeepSeek V4 Pro by 7.6 points in accuracy and 20.0 points in F1, and Gemini 2.5 Pro by 16.6 points in accuracy and 7.8 points in F1.
CCS Concepts: • Security and privacy → Software security engineering.
Additional Key Words and Phrases: vulnerability detection, software security, large language models, structured prompts, secure code analysis
1 Introduction
Software vulnerability detection aims to identify security-relevant flaws in programs that may be exploited to compromise confidentiality, integrity, or availability. Such flaws can have substantial real-world consequences. For example, the 2017 Equifax breach exposed the personal information of approximately 147 million people and resulted in a settlement of at least $575 million following allegations that Equifax failed to address known security weaknesses in its systems [9]. Despite extensive work on automated techniques, reliably detecting vulnerabilities in source code remains difficult [2, 5, 38].
Existing vulnerability-detection approaches broadly follow three technical pathways. First, static analyzers such as Clang Static Analyzer, Semgrep, and Cppcheck use predefined rules and program models to identify potentially unsafe program behavior [6, 22, 31]. Their reliance on manually
Authors' Contact Information: Fares Trad, York University, Toronto, Canada, fares610@my.yorku.ca; Yizhou Chen, Peking University, Beijing, China, yizhouchen@stu.pku.edu.cn; Hung Viet Pham, York University, Toronto, Canada, hvpham@yorku.ca; Zeyu Sun, Institute of Software, Chinese Academy of Sciences, Beijing, China, zeyu.zys@gmail.com; Gias Uddin, York University, Toronto, Canada, guddin@yorku.ca.

Fig. 1. An example of results from different vulnerability detectors.
constructed rules and analysis models can make them costly to develop and maintain and can limit their flexibility across vulnerability patterns [3, 15]. Second, learning-based detectors learn vulnerability-related patterns from labeled source code using representations derived from tokens, program structure, or pretrained code models [10–13, 19, 20, 33, 40]. More recently, LLMs have been applied to vulnerability detection through prompting, instruction tuning, reasoning, and additional program context, demonstrating promising but still imperfect detection performance [8, 17, 23]. Despite these advances, each pathway has limitations in how vulnerability-relevant program behavior is represented and used for detection.
These approaches nevertheless expose vulnerability-relevant program behavior in different and incomplete ways. Static analysis makes program properties explicit, but does so through predefined rules and analysis models. Learning-based detectors are more flexible, but primarily rely on source code and vulnerability labels, requiring them to infer vulnerability-relevant semantics and code–vulnerability relationships implicitly from supervision. Without explicit semantic guidance, the detector must learn which program behaviors are relevant to vulnerability detection from the labels alone. LLM-based approaches can provide additional context and intermediate reasoning [27, 34]; however, it remains unclear whether the generated context consistently captures the program behavior most relevant to vulnerability detection. Moreover, existing LLM-based vulnerability-detection approaches commonly use the LLM itself to produce the final security judgment [8, 17, 23]. These limitations motivate a complementary question: Can we explicitly provide vulnerability-relevant program knowledge and learn useful relationships between this knowledge and source code for detection?
We propose VULNLENS, an explanation-augmented framework for binary C/C++ vulnerability detection that explicitly separates program-behavior analysis from the final vulnerability decision. We focus on C/C++ because our evaluation benchmarks consist of C/C++ functions; however, the framework itself does not rely on language-specific analysis rules and can be extended to other programming languages. To make the additional knowledge consistently relevant to vulnerability detection, an LLM-based EXPLAINER examines every function from seven fixed vulnerability-related perspectives: data flow, memory access, object lifetime, arithmetic and type behavior, control flow, shared state, and external-resource access. These perspectives determine what program behavior the EXPLAINER should describe rather than allowing the added context to be unconstrained.
The resulting human-readable explanations make vulnerability-relevant program semantics explicit, providing semantic guidance beyond the binary vulnerability label. A supervised DETECTOR, trained to predict the vulnerability label, then jointly learns from the source code and these explanations through cross-attention, which relates the explanation representations to the source-code representation. The EXPLAINER receives neither the ground-truth label nor dataset-assigned CWE and is explicitly prohibited from producing a vulnerability verdict, so its role is to provide behavioral evidence rather than perform the final classification. Figure 1 illustrates this design using a vulnerable QEMU function from CVE-2019-3812 (CWE-125) [25]. The function reads edid_blob[s->reg] and then increments reg without a visible bounds check. GPT-5.4, when given only the source code, classified it as non-vulnerable. In contrast, the generated memory-access explanation identifies that no visible check constrains s->reg to the valid range of edid_blob before the read. VULNLENS correctly classifies the function as vulnerable; the corresponding security patch constrains the index using the size of edid_blob [28].
We evaluate VULNLENS on a PrimeVul-derived dataset [7] covering ten CWE categories. In our manual audit, two reviewers rated an average of 98.6% of GPT-5.4 explanations as fully correct (97.6% and 99.5%, respectively; Section 5.1). On the 526-function held-out test set, VULNLENS achieved 75.5% accuracy and 77.2% F1. Among the direct-LLM baselines, VULNLENS outperformed DeepSeek V4 Pro by 4.2 percentage points in accuracy, Gemini 2.5 Pro by 2.2 points in F1, and GPT-5.5 by 7.4 points in accuracy and 14.2 points in F1 (Table 3). We further study explanation source, detector backbone, prompt design, input components, failure cases, and cost.
This paper makes the following contributions:
- Explanation-first framework: We introduce a vulnerability-detection framework in which a label-blind EXPLAINER generates structured program-analysis evidence rather than vulnerability verdicts.
- Structured perspectives & cross-attention fusion: We design seven guided analysis perspectives and a cross-attention DETECTOR that learns vulnerability-relevant relationships between source code and generated explanations.
- Comprehensive empirical evaluation: We evaluate VULNLENS against direct LLMs and static analyzers, studying transferability, explanation quality, model choices, component contributions, failure cases, and cost.
Learning-Based Vulnerability Detection. Learning-based approaches learn vulnerability patterns from code tokens, program slices, and structural representations [19, 20, 29]. Later systems incorporate code property graphs, graph neural networks, and pretrained transformers to capture program semantics and localize vulnerable statements [2, 4, 11, 18, 40]. These methods primarily learn from code and labels, without explicit supervision of the security reasoning underlying each label. In contrast, VULNLENS augments source code with structured, label-blind descriptions of program behavior.
LLM-Based Vulnerability Detection. Recent studies apply LLMs to vulnerability detection and show that performance depends strongly on the prompt, program context, and evaluation setting [32, 38, 39]. Proposed approaches enhance detection through retrieved demonstrations, chain-of-thought prompting, instruction tuning, and program-graph augmentation [8, 17, 23, 24, 26]. These methods generally use the LLM as the final detector or rely on its reasoning at inference time. In contrast, VULNLENS separates behavioral analysis from classification: the EXPLAINER generates structured program-analysis explanations, while the DETECTOR learns the final vulnerability decision.
Explanation-Augmented Learning. Prior vulnerability-detection methods improve interpretability by identifying or highlighting security-relevant statements [18, 30, 37]. More broadly, chain-of-thought and scratchpad prompting demonstrate the value of intermediate reasoning [16, 27, 34],

Fig. 2. Overview of the VulnLens framework.
while rationale distillation shows that generated explanations can supervise smaller, specialized models [14, 35]. Our work connects these directions by using structured, label-blind program-analysis explanations as inputs to a supervised vulnerability detector rather than as post-hoc descriptions or direct LLM reasoning traces. We evaluate this approach on PrimeVul, a real-world vulnerability dataset designed to address weaknesses in prior data construction [7].
3 Approach
3.1 Overview
This section presents VULNLENS, an explanation-augmented vulnerability detection framework that separates describing program behavior from deciding whether it is vulnerable. Figure 2 shows the overall workflow. Given a C/C++ function, VULNLENS produces a binary vulnerability prediction for that function. The framework consists of two modules:
- EXPLAINER module generates seven structured explanations of the function from program-analysis perspectives, using neither the ground-truth label nor the dataset-assigned CWE, and passes the explanations to the DETECTOR module.
- DETECTOR module encodes the source code and the seven explanations with a shared frozen Transformer, integrates the explanations through sequential cross-attention, and predicts the binary vulnerability label.
Together, these modules make behavioral observations available under the same conditions for training and unseen functions and let a separately trained classifier combine those observations with the code.
3.2 Structured Program-Analysis Explanation Generation
The goal of this module is to produce, for every function, structured behavioral observations that describe how the code operates without revealing whether it is vulnerable. The module is necessary because a binary label records the outcome of a function but not the behavioral relationships—bounds, object lifetimes, and the checks that guard them—that produce that outcome, and because explanations built from known patches are unavailable for an unseen function. This
Table 1. Example structured explanations for the same input function.
| Analysis Perspective | Representative Generated Observation |
| Data sources and data flow | The input parameter i2c is used to derive s; state from s->edid Blob[s->reg] then flows into value and directly to the return value. |
| Memory objects, accesses, and bounds | The function reads edid blob at index s->reg. No visible check constrains s->reg relative to the valid index range or capacity of edid blob before the read. |
| Object lifetime and ownership | The function derives s from the caller-provided i2c object and uses its state, but performs no visible allocation, release, or ownership transfer. |
| Arithmetic operations and type behavior | The current value of s->reg is used as an index and is then incremented by one; assigning the selected element to int value may also involve an implicit conversion depending on the unseen element type. |
| Control flow and execution progress | Execution follows a single straight-line path: derive s, perform the indexed read, increment s->reg, and return, with no visible branches, loops, or alternate exits. |
| Shared state and concurrent operations | The function reads object state through s, uses s->reg as an index, and then updates it. No lock, atomic operation, or other synchronization is visible around this read-then-update sequence. |
| Path construction and external-resource access | The function constructs no path or external-resource identifier and performs no visible filesystem, command, or network access; its operations are limited to the in-memory state referenced through s. |
module therefore derives such observations from the code itself, so that they are available under the same conditions for training and inference.
The input to this module is a single C/C++ function C together with non-label provenance metadata. To cover the behavioral aspects relevant to vulnerabilities while avoiding dependence on any particular defect category, VULNLENS uses seven complementary analysis perspectives:
(1) data sources and data flow,
(2) memory objects, accesses, and bounds,
(3) object lifetime and ownership,
(4) arithmetic operations and type behavior,
(5) control flow and execution progress,
(6) shared state and concurrent operations, and
(7) path construction and external-resource access.
Table 1 shows representative behavioral observations generated from these seven perspectives for the example function in Figure 1.
Each prompt asks EXPLAINER to describe observable program behavior rather than produce a vulnerability verdict. The ground-truth binary label and dataset-assigned CWE are not provided, and the instructions prohibit labels such as vulnerable, non-vulnerable, safe, unsafe, exploitable, and non-exploitable. Claims must be grounded in the visible function or non-label provenance metadata; unavailable information, such as caller constraints or hidden ownership contracts, is recorded as missing context rather than inferred. This label-blind protocol is what makes the explanations usable as ordinary inputs: because they never encode the answer, they can be generated for an unseen function in the same way as for a training function.
Let denote a function and the seven prompts. The generation of one explanation per perspective is written as
where denotes EXPLAINER, contains non-label provenance metadata such as project and file name, and is the explanation produced under perspective . Each is returned as structured JSON containing the perspective, scope, relevant inputs and state, grounded observations, program relationships, missing context, and a concise summary. The schema contains no vulnerability label or confidence field, so the seven explanations can be consumed directly as additional inputs without discarding task-relevant information. In the principal experiment, GPT-5.4 generates the explanations without Semgrep or Cppcheck outputs. The resulting set is passed to the DETECTOR module, which decides whether the function is vulnerable.
3.3 Semantic Fusion of Code and Explanations
The goal of this module is to learn how the seven explanations relate to the source code and to predict whether the function is vulnerable. The module is necessary because supplying additional analysis at inference time is not sufficient on its own: when an LLM both interprets the analysis and issues the verdict, the resulting decision is not connected to the code by a classifier trained for that purpose. This module instead pairs the explanations with the code in a supervised model, so that the combination is learned against the vulnerability labels.
The input to this module is the source code together with the seven explanations produced by the previous module. A shared pretrained Transformer independently encodes both modalities. In the principal experiment, we use deepseek-ai/DeepSeek-R1-Distill-Qwen-7B.
Let denote the shared encoder:
Here, is the initial code representation and is the encoding of explanation . Reusing one encoder for both modalities keeps the two representations directly comparable. The encoder parameters remain frozen. Training optimizes only the cross-attention, LayerNorm, projection, and classification parameters, which keeps the number of trained parameters small and isolates the effect of the explanations from changes to the code encoder.
The seven explanation channels are fused sequentially. At step i, the current code representation is the query and explanation provides the key and value:
Here, is the code representation after i-1 fusion steps, is the explanation attention mask, and is the attended explanation signal. The result is incorporated through a residual connection and LayerNorm,
followed by a block-specific projection:
Table 2. Datasets used in the experiments.
| Split | Functions | Vulnerable | Non-vulnerable |
|---|---|---|---|
| Training | 1,000 | 476 | 524 |
| Validation | 607 | 288 | 319 |
| Test | 526 | 266 | 260 |
Here, and are the projection parameters of fusion step , and is the updated code representation. Each explanation position has independent cross-attention, LayerNorm, and projection parameters, so the model can weight each perspective differently instead of treating the seven explanations as a single undifferentiated context. The order is fixed across training and inference: data flow, memory, lifetime, arithmetic, control flow, shared state, and resource access. The final fused representation is .
Because sequences differ in length and are padded, the fused representation must be reduced to a fixed dimension without being biased by padding. We obtain a fixed-dimensional representation using mask-aware mean pooling:
where is a sequence of length and is its attention mask, so that only valid positions contribute to the average. The final representation also retains the original code encoding through a residual path:
where is the source-code attention mask and is the final function representation. The residual path keeps the code's own encoding available even when an explanation offers little additional evidence, so the classifier does not have to recover existing code features.
A linear classifier then predicts the binary label:
where contains the non-vulnerable and vulnerable logits and is the predicted label distribution. Training minimizes cross-entropy over the ground-truth binary labels, which is the only place where the labels enter the framework.
4 Experimental Settings
4.0.1 Dataset. We evaluate VULNLENS on a C/C++ dataset derived from PrimeVul [7]. We first identify the ten CWE categories with the largest numbers of functions in PrimeVul: CWE-119, CWE-125, CWE-787, CWE-416, CWE-190, CWE-362, CWE-415, CWE-835, CWE-120, and CWE-22.
For training, we randomly sample 100 functions from each selected CWE within PrimeVul's original training split, yielding 1,000 functions with 476 vulnerable and 524 non-vulnerable samples. For validation and test construction, we retain the vulnerable functions for each selected CWE and randomly sample an equal number of non-vulnerable functions using seed 1337, while preserving each function's original PrimeVul split assignment. This yields 607 validation functions (288 vulnerable, 319 non-vulnerable) and 526 test functions (266 vulnerable, 260 non-vulnerable). The validation set is used for checkpoint selection and the test set for final evaluation.
4.0.2 Explanation Generation. We generate seven explanations per function using the perspectives defined in Section 3.2. EXPLAINER receives the function together with non-label provenance metadata, but not the ground-truth label, dataset-assigned CWE, CVE description, commit information, or static-analysis findings.
We compare GPT-5.4 and DeepSeek-R1-Distill-Qwen-32B (DeepSeek-R1-Qwen-32B) as EXPLAINER configurations. GPT-5.4 is accessed through its API, while DeepSeek-R1-Qwen-32B runs locally on the same GPU server used for the remaining experiments. For the seven-prompt configuration, each EXPLAINER generates seven explanations for each of the 2,133 functions across the training, validation, and test sets, yielding 14,931 explanations per EXPLAINER.
For RQ5, we additionally evaluate a CWE-specific-10 prompt set. Unlike seven-prompt, which was designed without assuming knowledge of the target CWE, CWE-specific-10 contains one analysis prompt for each of the ten selected CWE categories. Every function receives all ten prompts, allowing us to evaluate whether explicitly organizing explanations around known candidate weakness categories improves downstream detection.
4.0.3 Baselines and Ablations. We compare VULNLENS with three baseline categories and several ablation families covering input components, prompt design, EXPLAINER choice, and DETECTOR backbone choice.
Static-analysis baselines. We evaluate Semgrep OSS v1.86.0 using the Semgrep Registry p/default configuration and Cppcheck v2.15.0 with all checks enabled. Each function is written to a separate .c or .cpp file according to its original extension. Findings are mapped to functions using the reported file and line locations together with a manifest containing each function's line interval.
We apply a mechanical rule to obtain binary predictions. Semgrep classifies a function as vulnerable when it reports at least one finding with WARNING or ERROR severity. Cppcheck classifies a function as vulnerable when it reports at least one finding with warning or error severity and a non-empty CWE identifier. These severity labels refer to reported findings, not tool execution failures. All other functions are classified as non-vulnerable.
Direct-LLM baselines. GPT-5.5, DeepSeek V4 Pro, and Gemini 2.5 Pro receive one request per test function containing the function body and non-label metadata, including sample identifier, source split and line number, project name, and file name. The prompt excludes the ground-truth label, CWE, CVE and commit information, static-analysis findings, and generated explanations. We retain one successful prediction per function and model; requests are repeated only after API errors, malformed responses, or missing binary decisions.
Explanation baselines. GPT-5.4 and DeepSeek-R1-Qwen-32B are each evaluated in direct and self-explanation settings. In the direct setting, the model receives only the code-based classification prompt. In the self-explanation setting, it additionally receives the same seven explanations that it generated for that function and that are used by the corresponding VULNLENS configuration. This tests whether providing the explanatory information directly to the LLM is sufficient without the learned DETECTOR.
Input ablations. We compare full VULNLENS with code-only, explanation-removal, and shuffled-explanation variants. The code-only model is trained using source code alone. Explanation removal trains with both modalities but withholds explanations at inference, measuring reliance under a missing-modality distribution shift.
For the shuffled-explanation control, complete seven-explanation bundles are reassigned across training functions using a seeded Sattolo derangement. Perspective identities and bundle structure are preserved, every bundle is used exactly once, and no function receives its own explanations. Source code and labels remain unchanged, while validation and test explanations remain correctly aligned.
Prompt-set ablation. We compare seven-prompt and CWE-specific-10 explanations while holding the EXPLAINER, DETECTOR backbone, data, and optimization settings fixed within each configuration.
EXPLAINER ablation. We train equivalent DETECTOR configurations using GPT-5.4 or DeepSeek-R1-Qwen-32B explanations with prompts, data, labels, splits, and optimization settings fixed.
DETECTOR backbone ablation. We compare frozen DeepSeek-Coder-1.3B, DeepSeek-Coder-6.7B, DeepSeek-R1-Qwen-7B, and Qwen-Coder-7B backbones while holding the EXPLAINER, fusion mechanism, and training data fixed.
4.0.4 Evaluation Metrics. We formulate vulnerability detection as binary classification at the function level and evaluate the vulnerable class as positive. Here, true positives (TP) are vulnerable functions correctly predicted as vulnerable, false positives (FP) are non-vulnerable functions incorrectly predicted as vulnerable, true negatives (TN) are non-vulnerable functions correctly predicted as non-vulnerable, and false negatives (FN) are vulnerable functions incorrectly predicted as non-vulnerable. We report accuracy, precision (), recall (), and F1:
Precision measures how often a vulnerable prediction is correct, recall measures how many vulnerable functions are detected, and F1 balances the two. Validation F1 is used to select checkpoints.
VULNLENS is implemented in PyTorch and Hugging Face Transformers. The pretrained DETECTOR backbone is frozen; training updates only the cross-attention, LayerNorm, projection, and classification parameters.
Unless otherwise stated, DETECTOR experiments use a maximum sequence length of 2,048 tokens, batch size 1, 32 attention heads per fusion layer, dropout 0.3, AdamW with learning rate , unweighted cross-entropy, gradient clipping at 1.0, and bfloat16 weights; each DETECTOR configuration is trained for 50 epochs under five random seeds, and reported results are averaged across the five runs. Within each run, a checkpoint is saved only when validation F1 strictly exceeds the best previously observed value, so the earliest checkpoint is retained in the case of a tie. For each seed, only the checkpoint selected on the 607-function validation set is evaluated on the 526-function test set.
Experiments run primarily on a server with two Intel Xeon Gold 6442Y CPUs, 251 GiB RAM, and four NVIDIA L40S GPUs with approximately 46 GB each. Each training run uses one GPU, while multiple GPUs execute independent experiments concurrently.
Protocol and reproducibility. We preserve PrimeVul's original training, validation, and test assignments when constructing our subsets and track sample identifiers to avoid accidental cross-split reuse. The validation split is used only for checkpoint selection, and the test split is used only for the final evaluation reported in Section 5. Test labels are never used during training or checkpoint selection. Across explanation generation and direct-LLM baselines, the models receive no ground-truth vulnerability label, dataset-assigned CWE, CVE description, commit information, or static-analysis findings.
5 Empirical Study
We evaluate VULNLENS through nine research questions. RQ1 examines the quality of the explanations that VULNLENS relies on. RQ2 is the main comparison against the baseline categories. RQ3–RQ6 evaluate the design choices of the DETECTOR backbone, the EXPLAINER, the explanation prompts, and the input components. RQ7 examines when VULNLENS succeeds or fails relative to the baselines. RQ8 evaluates transfer to a new dataset, and RQ9 examines the computational cost of the framework.
- RQ1: How reliable are the explanations generated by the EXPLAINER?
- RQ2: How does VULNLENS compare with LLM-based and static-analysis detection?
- RQ3: How do DETECTOR backbone architecture and size affect performance?
- RQ4: How does the choice of EXPLAINER affect performance?
- RQ5: How do different explanation prompt-set configurations affect performance?
- RQ6: Which components of VULNLENS contribute most to performance?
- RQ7: How does VULNLENS succeed or fail relative to direct LLM baselines?
- RQ8: How well does VULNLENS generalize to an external dataset?
- RQ9: What are the training, inference, and cost trade-offs of the approach?
5.1 RQ1: How reliable are the explanations generated by the EXPLAINER?
We audited a stratified sample of three functions from each of the ten CWE categories. For each of the resulting 30 functions, we evaluated all seven explanations generated by GPT-5.4 and DeepSeek-R1-Qwen-32B, yielding 210 explanations per EXPLAINER and 420 overall. We classified factual quality as correct, partial, incorrect, or hallucinated, and independently recorded whether each explanation completely covered the material behavior relevant to its prompt.
The two reviewers rated 205 and 209 of the 210 GPT-5.4 explanations as fully correct (97.6% and 99.5%), respectively; the remaining explanations were rated partial. For DeepSeek-R1-Qwen-32B, the reviewers rated 122 and 138 explanations as fully correct and an additional 44 and 57 as partial, respectively. Thus, 166/210 (79.0%) and 195/210 (92.9%) of its explanations were judged either fully correct or partially correct. A partial rating indicates that the main analysis was supported by the visible code but contained at least one material inaccuracy or unsupported claim. Completeness was evaluated separately and captures whether relevant behavior was omitted, rather than whether the stated analysis was factually correct.
After independent rating and codebook-guided reconsideration of disagreements, the reviewers agreed on 349 of 420 correctness labels (83.1%; Cohen's = 0.501) and 356 of 420 completeness judgments (84.8%; = 0.636). The moderate values occurred alongside high raw agreement and a strong prevalence of correct judgments, which increases chance-expected agreement.
Answer to RQ1: GPT-5.4 generated more accurate and complete explanations than DeepSeek-R1-Qwen-32B, with 83.1% exact reviewer agreement on correctness.
5.2 RQ2: How does VULNLENS compare with LLM-based and static-analysis detection?
To answer RQ2, we compare VULNLENS with five directly prompted LLMs—GPT-5.4, GPT-5.5, DeepSeek V4 Pro, Gemini 2.5 Pro, and DeepSeek-R1-Qwen-32B—and two static analyzers, Semgrep and Cppcheck, on the 526-function PrimeVul test set. The direct LLM baselines classify functions from code alone; static-analysis predictions are derived from actionable security findings. Table 3 reports accuracy, positive-class precision, recall, F1, and false-positive rate (FPR) for these methods and the GPT-5.4–DeepSeek-R1-Qwen-7B configuration of VULNLENS.
Table 3. Overall test-set performance. All metrics are percentages; FPR denotes false-positive rate. Best values are bold.
| Model | Accuracy | Precision | Recall | F1 | FPR |
|---|---|---|---|---|---|
| Static analysis | |||||
| Semgrep | 49.6 | 100.0 | 0.4 | 0.7 | 0.0 |
| Cppcheck | 52.5 | 94.4 | 6.4 | 12.0 | 0.4 |
| Frontier LLMs | |||||
| Gemini 2.5 Pro | 67.9 | 61.9 | 95.1 | 75.0 | 60.0 |
| GPT-5.5 | 68.1 | 76.1 | 53.8 | 63.0 | 17.3 |
| DeepSeek V4 Pro | 71.3 | 71.9 | 71.1 | 71.5 | 28.5 |
| Explanation baselines | |||||
| DeepSeek-R1-Qwen-32B (self-expl.) | 58.4 | 65.2 | 38.0 | 48.0 | 20.8 |
| DeepSeek-R1-Qwen-32B (direct) | 59.5 | 61.0 | 55.3 | 58.0 | 36.2 |
| GPT-5.4 (self-expl.) | 65.4 | 82.8 | 39.8 | 53.8 | 8.5 |
| GPT-5.4 (direct) | 68.3 | 84.6 | 45.5 | 59.2 | 8.5 |
| VULNLENS | 75.5 | 72.8 | 82.3 | 77.2 | 31.5 |
VULNLENS provides the strongest aggregate accuracy and F1, although different baselines lead on individual metrics. Its accuracy of 75.5% exceeds DeepSeek V4 Pro, the strongest baseline by accuracy, by 4.2 percentage points. Its F1 of 77.2% exceeds Gemini, the strongest baseline by F1, by 2.2 points. Relative to Gemini, VULNLENS increases precision by 10.9 points and reduces FPR by 28.5 points, while sacrificing 12.8 points of recall. Conversely, its FPR of 31.5% exceeds DeepSeek V4 Pro's 28.5%, so the aggregate improvement does not imply uniformly fewer false alarms. Semgrep and Cppcheck achieve precision of 100.0% and 94.4%, respectively, but recall of only 0.4% and 6.4%, limiting their coverage on this function-level benchmark.
This pattern is consistent with the different decision mechanisms. Direct prompting delegates the final decision to an LLM, whereas VULNLENS learns a task-specific decision function from code and structured explanations. The latter can combine explanatory evidence with labeled examples to balance missed vulnerabilities and false alarms. Static analyzers instead rely on the security patterns covered by their configured checks, which can yield precise findings without covering most vulnerable functions in this setting. These aggregate results support the learned classifier's precision-recall balance, rather than superiority on every metric.
Answer to RQ2: VULNLENS achieves the highest accuracy and F1 among the evaluated methods, improving on the strongest baseline for each metric by 4.2 and 2.2 percentage points, respectively.
5.3 RQ3: How do DETECTOR architecture and model size affect performance?
To answer RQ3, we compare DeepSeek-Coder-1.3B, DeepSeek-Coder-6.7B, DeepSeek-R1-Qwen-7B, and Qwen-Coder-7B using the same GPT-5.4 seven-prompt explanations, data splits, and hyperparameters. The pretrained encoder remains frozen while the fusion and classification components are trained. Table 4 reports test-set accuracy before and after this training. Untrained values summarize five randomly initialized detector heads; trained configurations use the best validation-F1 checkpoint.
The best overall result comes from DeepSeek-R1-Qwen-7B, but performance does not increase monotonically with parameter count. It achieves 75.5% accuracy, while DeepSeek-Coder-1.3B
Table 4. Detector performance before and after training. Accuracy values are mean ± standard deviation over five randomly initialized heads; denotes the improvement in percentage points (pp).
| DETECTOR | Architecture | Size | Version | Accuracy | (pp) |
|---|---|---|---|---|---|
| DeepSeek-Coder-1.3B | Llama | 1.3B | Untrained Trained | -+21.7 | |
| DeepSeek-Coder-6.7B | Llama | 6.7B | Untrained Trained | -+19.6 | |
| Qwen-Coder-7B | Qwen2 | 7B | Untrained Trained | -+20.8 | |
| DeepSeek-R1-Qwen-7B | Qwen2 | 7B | Untrained Trained | -+24.7 |
Table 5. Effect of Explainer choice on Detector performance. All configurations use the same seven prompts, data, and hyperparameters.
| EXPLAINER | DETECTOR | Acc. | Prec. | Rec. | F1 |
|---|---|---|---|---|---|
| GPT-5.4 | DeepSeek-Coder-1.3B | 72.1 | 66.9 | 88.7 | 76.3 |
| DeepSeek-R1-Qwen-32B | DeepSeek-Coder-1.3B | 72.4 | 67.6 | 87.2 | 76.2 |
| GPT-5.4 | DeepSeek-Coder-6.7B | 69.8 | 63.5 | 94.7 | 76.0 |
| DeepSeek-R1-Qwen-32B | DeepSeek-Coder-6.7B | 70.3 | 64.9 | 89.8 | 75.4 |
| GPT-5.4 | DeepSeek-R1-Qwen-7B | 75.5 | 72.8 | 82.3 | 77.2 |
| DeepSeek-R1-Qwen-32B | DeepSeek-R1-Qwen-7B | 74.9 | 72.8 | 80.5 | 76.4 |
reaches 72.1%, only 3.4 points lower. The 1.3B model also exceeds DeepSeek-Coder-6.7B and Qwen-Coder-7B by 2.3 and 2.5 accuracy points, respectively. Based on the displayed untrained means, training increases accuracy by 21.7, 19.6, 24.7, and 20.8 points for the four backbones, respectively.
The non-monotonic results suggest that the usefulness of frozen representations depends on the backbone's architecture and pretraining as well as its size. In particular, the two 7B Qwen-family backbones differ by 5.9 accuracy points despite similar parameter counts. This comparison does not isolate architecture from pretraining, but it shows that size alone is insufficient to select a detector. The untrained results also exhibit substantial variability because the detector heads are randomly initialized; they measure the effect of learning the downstream components rather than the performance of prompted pretrained models.
Answer to RQ3: Backbone choice affects detection performance, but larger models are not consistently better: DeepSeek-R1-Qwen-7B performs best, while DeepSeek-Coder-1.3B remains within 3.4 accuracy points.
5.4 RQ4: How does the choice of EXPLAINER affect performance?
RQ4 compares GPT-5.4 and DeepSeek-R1-Qwen-32B as EXPLAINERS while holding the prompts, data, DETECTOR architecture, and training procedure fixed. GPT-5.4 achieved slightly higher F1 for all three DETECTORS, but the differences were small: 0.1, 0.6, and 0.8 percentage points for DeepSeek-Coder-1.3B, DeepSeek-Coder-6.7B, and DeepSeek-R1-Qwen-7B, respectively.
Table 6. 7-prompt versus CWE-specific-10 explanations for matched Explainer–Detector configurations. All metrics are percentages.
| EXPLAINER | DETECTOR | Prompt set | Acc. | Prec. | Rec. | F1 |
|---|---|---|---|---|---|---|
| GPT-5.4 | DeepSeek-Coder-6.7B | CWE-specific-10 | 69.2 | 64.4 | 87.6 | 74.2 |
| GPT-5.4 | DeepSeek-Coder-6.7B | 7-prompt | 69.8 | 63.5 | 94.7 | 76.0 |
| DeepSeek-R1-Qwen-32B | DeepSeek-R1-Qwen-7B | CWE-specific-10 | 72.1 | 69.5 | 79.7 | 74.3 |
| DeepSeek-R1-Qwen-32B | DeepSeek-R1-Qwen-7B | 7-prompt | 74.9 | 72.8 | 80.5 | 76.4 |
This similarity does not contradict RQ1. RQ1 evaluates whether an explanation is fully accurate and suitable for a human reader, whereas downstream performance measures whether it contains signals useful to a classifier. Many DeepSeek explanations rated as partial still identified relevant operations and data flows. Moreover, the DETECTOR receives the source code and seven explanation channels, allowing useful evidence to remain available even when one explanation contains incomplete or unsupported details. Thus, explanation quality and predictive utility are related but not equivalent.
Answer to RQ4: GPT-5.4 produced more accurate human-readable explanations and consistently achieved higher downstream F1, but DeepSeek-R1-Qwen-32B remained within 0.8 F1 points across all three DETECTORS. The DETECTOR was therefore relatively insensitive to the choice of EXPLAINER in these experiments.
5.5 RQ5: How do different explanation prompt-set configurations affect performance?
Our main configuration uses seven broad program-analysis perspectives rather than prompts tied to specific vulnerability categories. RQ5 examines whether this category-agnostic organization is preferable to a more vulnerability-specific alternative. To answer RQ5, we compare the seven-prompt and CWE-specific-10 explanation sets in two matched EXPLAINER-DETECTOR configurations: GPT-5.4 with DeepSeek-Coder-6.7B, and DeepSeek-R1-Qwen-32B with DeepSeek-R1-Qwen-7B. Within each pair, the EXPLAINER, DETECTOR backbone, training data, evaluation split, and hyperparameters are fixed. Table 6 reports accuracy, precision, recall, and F1. Because the two configurations differ in both prompt organization and number of explanation channels, the comparison evaluates the prompt sets as complete configurations rather than isolating either factor independently.
The seven-prompt configuration yields higher F1 in both matched comparisons despite using fewer explanation channels. With GPT-5.4 and DeepSeek-Coder-6.7B, it improves F1 from 74.2% to 76.0%, a gain of 1.8 percentage points. This gain accompanies a 7.1-point increase in recall and a 0.9-point decrease in precision. With DeepSeek-R1-Qwen-32B and DeepSeek-R1-Qwen-7B, it improves F1 by 2.1 points and accuracy by 2.8 points, with increases in both precision (3.3 points) and recall (0.8 points).
A plausible explanation is that the seven prompts describe broadly applicable program properties, such as data flow, memory access, and object lifetime, without asking every function to supply evidence for a predetermined vulnerability category. Such descriptions can provide relevant features even when a particular CWE does not apply. However, because channel count also changes from ten to seven, these results cannot attribute the gain solely to prompt organization or rule out an effect of the amount of explanatory input. They support the seven-prompt configuration as a whole in the two evaluated settings.
Table 7. Input and explanation ablations using DeepSeek-R1-Qwen-7B. All metrics are percentages.
| Configuration | Acc. | Prec. | Rec. | F1 |
|---|---|---|---|---|
| Full VULNLENS | 75.5 | 72.8 | 82.3 | 77.2 |
| Code only | 67.9 | 66.4 | 73.7 | 69.9 |
| No explanations at test | 71.3 | 79.8 | 57.9 | 67.1 |
| Shuffled training explanation sets | 62.0 | 59.8 | 75.6 | 66.8 |
Answer to RQ5: The seven-prompt configuration outperforms CWE-specific-10 in both matched configurations, improving F1 by 1.8–2.1 percentage points with fewer explanations.
5.6 RQ6: Which input components contribute most to performance?
To answer RQ6, we examine the contributions of source code, generated explanations, and their correspondence using DeepSeek-R1-Qwen-7B, the same 1,000-function training set, and the original 526-function test set. We compare full VULNLENS with three controls: code-only training, joint training with explanations withheld at inference, and training with explanation sets shuffled across functions. Table 7 reports accuracy, precision, recall, and F1 for these configurations. The code-only variant assesses the contribution of explanations relative to source code alone, while explanation removal and shuffling examine reliance on explanations and the importance of matching them to the source function, respectively.
The full model achieves the highest F1, outperforming code-only training by 7.3 percentage points. Adding matched explanations increases accuracy from 67.9% to 75.5%, F1 from 69.9% to 77.2%, precision from 66.4% to 72.8%, and recall from 73.7% to 82.3%.
Withholding explanations at inference reduces F1 by 10.1 points to 67.1%, while training with shuffled explanation sets reduces F1 by 10.4 points to 66.8%. These controls distinguish complementary information from learned reliance. Removing explanations after joint training introduces a missing-modality distribution shift, so its performance drop measures dependence on explanation inputs rather than their incremental benefit. Shuffling instead disrupts the correspondence between code and explanations. The cleaner contribution estimate comes from the separately trained code-only control: matched explanations improve F1 by 7.3 points and accuracy by 7.6 points, providing evidence that the explanation representation contributes complementary predictive information beyond source code alone.
Answer to RQ6: Full VULNLENS improves F1 over code-only training by 7.3 percentage points, while removing or shuffling explanations reduces F1 by 10.1 and 10.4 points, respectively.
5.7 RQ7: How does VULNLENS succeed or fail relative to direct LLM baselines?
To answer RQ7, we compare the correctness of VULNLENS and three direct-LLM baselines—GPT-5.5, DeepSeek V4 Pro, and Gemini 2.5 Pro—on all 526 test functions. For VULNLENS, we use predictions from the run with the highest validation F1. We examine agreement patterns and representative cases of shared success, exclusive success by VULNLENS, failure by VULNLENS despite correct LLM predictions, and shared failure. This analysis characterizes complementary errors in the selected methods; it does not include every baseline evaluated in RQ2.
The methods share many outcomes but also make complementary errors. All four are correct on 199 functions (37.8%) and incorrect on 25 (4.8%). VULNLENS is the only correct method on 16 functions (3.0%); 11 of these are non-vulnerable, showing that some exclusive successes arise from
Table 8. Transfer performance of VulnLens, DeepSeek V4 Pro, and Gemini 2.5 Pro on SecVulEval.
| Model | Accuracy | Precision | Recall | F1 | FPR |
|---|---|---|---|---|---|
| Gemini 2.5 Pro | 49.8% | 49.9% | 69.2% | 58.0% | 69.6% |
| DeepSeek V4 Pro | 58.8% | 66.9% | 34.8% | 45.8% | 17.2% |
| VULNLENS | 66.4% | 66.9% | 64.8% | 65.8% | 32.0% |
avoiding false alarms shared by all three LLMs. Conversely, VULNLENS is incorrect on 69 functions (13.1%) for which at least two LLMs are correct. Thus, the aggregate advantage of VULNLENS coexists with complementary errors in which direct LLM classification succeeds.
The selected cases illustrate three forms of disagreement. VULNLENS correctly classifies r_bin_java_print_float_cp_summary as non-vulnerable, while all three LLMs infer a vulnerability from an unverified nested-pointer precondition. This case is consistent with a learned detector avoiding a speculative report. All methods correctly identify unsafe length arithmetic in string_number_format, but VULNLENS misses pjmedia_rtcp_xr_rx_rtcp_xr, where the LLMs identify missing validation of variable-length report blocks. Thus, useful explanatory evidence need not translate into a correct detector decision. All methods also miss seq_buf_alloc, a thin allocation wrapper whose vulnerability label is not explained by the visible function alone, illustrating the limits of function-level input when relevant behavior depends on callers or callees. These examples illustrate failure mechanisms without establishing their prevalence across all errors.
Answer to RQ7: VULNLENS shows complementary errors relative to direct LLMs: it can avoid speculative false positives shared by those baselines, but it can also miss structural validation flaws they detect, while all methods remain limited when relevant security evidence lies outside the provided function.
5.8 RQ8: How well does VULNLENS generalize to an external dataset?
Motivation. Performance on PrimeVul may reflect dataset-specific characteristics. We therefore test whether VULNLENS transfers to independently collected functions without additional training.
Experimental setting. We construct a balanced SecVulEval [1] test set of 500 C/C++ functions from the same ten CWE categories, with 25 vulnerable and 25 non-vulnerable functions per CWE. We exclude exact function-code overlaps with all PrimeVul splits.
We evaluate the primary VULNLENS configuration—GPT-5.4 seven-prompt explanations with the DeepSeek-R1-Qwen-7B detector—using the RQ7 checkpoint without retraining. We compare it with DeepSeek V4 Pro and Gemini 2.5 Pro, the highest-accuracy and highest-F1 direct-LLM baselines in Section 5.2.
Results. As shown in Table 8, VULNLENS achieved 66.4% accuracy and 65.8% F1. It outperformed DeepSeek V4 Pro by 7.6 points in accuracy and 20.0 points in F1, primarily through higher recall (64.8% vs. 34.8%), although with a higher FPR (32.0% vs. 17.2%). Compared with Gemini 2.5 Pro, VULNLENS improved accuracy by 16.6 points and F1 by 7.8 points, with higher precision, lower FPR, and slightly lower recall.
Answer to RQ8: Without retraining on SecVulEval, VULNLENS achieved the highest accuracy and F1 among the evaluated methods, exceeding DeepSeek V4 Pro by 7.6 and 20.0 points, and Gemini 2.5 Pro by 16.6 and 7.8 points, respectively.
Table 9. Explanation-generation cost for the 1,000-function training set. Token counts and total cost aggregate all seven explanations; /Func. are averages.
| EXPLAINER | Input Tok. (M) | Output Tok. (M) | Cost ($) | $/Expl. | $/Func. |
|---|---|---|---|---|---|
| GPT-5.4 | 9.77 | 15.86 | 262.30 | 0.0375 | 0.2623 |
| DeepSeek-R1-Qwen-32B | 10.07 | 6.79 | 38.15 | 0.0054 | 0.0381 |
DeepSeek was executed locally; the reported monetary cost applies Cloudflare Workers AI rates to the recorded token usage and is a hosted-equivalent estimate.

Fig. 3. Representative disagreement cases across vulnerability detectors. Each example shows a case where one method uniquely matches the dataset label under incomplete function-level context.
5.9 RQ9: What are the training, inference, and cost trade-offs of the approach?
To answer RQ9, we examine explanation generation, Detector training, and inference. Table 9 reports explanation-generation costs for the 1,000-function training set. GPT-5.4 costs 0.2623 per function. DeepSeek-R1-Qwen-32B was executed locally; comparable hosted API pricing yields an estimated 0.0381 per function.
On one NVIDIA L40S, DeepSeek-R1-Qwen-32B generates all seven explanations for a function in approximately 6.27 minutes, corresponding to about 104.5 GPU-hours for the full training set. Detector training requires 0.652 GPU-hours per epoch and 21.69 GiB peak GPU memory.
With explanations cached, Detector inference averages 1.391 seconds per function, with 1.423-second p95 latency and 15.40 GiB peak GPU memory. Explanation generation is therefore a reusable preprocessing cost for cached functions. Previously unseen functions still require seven explanations before Detector inference, so end-to-end latency also depends on the selected Explainer.
Answer to RQ9: Explanation generation is the main upfront cost: GPT-5.4 costs $0.2623 per function, while local DeepSeek-R1-Qwen-32B generation requires approximately 6.27 minutes per function on one L40S. Detector training requires 0.652 GPU-hours per epoch and 21.69 GiB peak GPU memory. With explanations cached, inference takes 1.391 seconds per function with 15.40 GiB peak GPU memory.
6 Discussion
6.1 What Do the Explanations Add?
Full VULNLENS substantially outperforms the independently trained code-only detector, achieving 77.2% versus 69.9% F1, a gain of 7.3 percentage points. This result suggests that matched explanations provide complementary predictive information beyond source code alone. Removing explanations from the trained fusion model at inference reduces F1 from 77.2% to 67.1%, showing substantial reliance on this input. Because this also introduces a missing-modality distribution shift, we treat it as a reliance test rather than an independent estimate of explanation benefit.
Figure 3 shows one such case. The TensorFlow output is allocated using the shape of in0, while the final operation consumes both in0 and in1. The explanations connect these facts and note the absence of a visible compatibility check. VULNLENS predicts vulnerable, whereas the code-only detector, the same fusion model without explanations, GPT-5.4, GPT-5.5, and DeepSeek V4 Pro predict non-vulnerable. This case is consistent with explanations helping DETECTOR represent cross-object relationships rather than directly supplying the label.
6.2 Different Models Require Different Evidence
Direct LLMs differ in how they handle missing program context. Gemini more readily acts on plausible local evidence, while GPT-5.4 and GPT-5.5 more often withhold a vulnerable prediction when the conclusion depends on missing callees, caller contracts, or framework semantics. These differences help explain their precision-recall trade-offs.
DeepSeek V4 Pro. Figure 3 shows a case where DeepSeek V4 Pro alone matches the non-vulnerable label. The other direct LLMs and VULNLENS predict vulnerable based on a possible out-of-bounds access after advancing cp. DeepSeek instead notes that confirming the flaw requires unavailable helper semantics. We therefore treat this as a context-ambiguity case rather than evidence that the other predictions are necessarily wrong.
Gemini. Figure 3 shows one of 12 vulnerable samples detected only by Gemini. It identifies that input (0) is accessed at dimension 1 without a visible rank check, matching the security-fixing commit. VULNLENS and the other direct LLMs predict non-vulnerable. Gemini's willingness to act on missing preconditions can recover such vulnerabilities, but also contributes to its higher false-positive rate.
GPT-5.5. In Figure 3, GPT-5.5 alone matches the non-vulnerable label. The other systems treat unchecked size multiplications as sufficient evidence for an integer-overflow path, whereas GPT-5.5 does not conclude that an out-of-bounds access follows without allocation and downstream-write semantics. The vulnerable function in the same fixing commit is a different function, illustrating a limitation of function-level labels.
Overall, these disagreements often reflect different evidentiary thresholds under incomplete context rather than one model simply “understanding” the code better.
6.3 Explanation Quality Is Not the Same as Downstream Utility
GPT-5.4 explanations were substantially more accurate than DeepSeek-R1-Qwen-32B explanations in the manual audit, yet the corresponding DETECTOR configurations achieve similar downstream performance. Thus, human-rated explanation quality is not the sole determinant of utility. Evidence may be redundant across channels, and DETECTOR may learn to ignore unsupported details. Explanation quality should therefore be evaluated intrinsically and through downstream performance.
6.4 Model Size and Reusability
A larger DETECTOR backbone does not automatically yield substantially better performance. The 1.3B model reaches 72.1% accuracy, compared with 75.5% for the 7B model, indicating that scale is only one factor alongside pretraining, fusion design, and explanation representation.
VULNLENS caches explanations before DETECTOR training, so explanations are generated once per function and can be reused across training epochs, checkpoint evaluations, and subsequent inference on cached functions.
7 Threats to Validity
External validity. Our evaluation uses C/C++ functions from PrimeVul and focuses on the ten CWE categories with the largest numbers of functions in that dataset, which may limit generalization to rarer weakness types, other programming languages, projects, or settings requiring broader program context. To reduce dependence on a single benchmark, Section 5.8 evaluates the same trained VULNLENS configuration on SecVulEval without retraining.
Internal validity. Threats to internal validity arise from implementation choices, dataset labels, and the reliability of generated explanations. To reduce experimental variation, we use fixed data splits, prompts, hyperparameters, and evaluation procedures when comparing configurations, preserve PrimeVul's original validation and test assignments, and select checkpoints using validation F1 only. Function-level labels and CWE mappings derived from vulnerability-fixing commits may contain noise or depend on surrounding program context. To assess explanation reliability, we manually inspect all seven explanations for 30 stratified functions from each EXPLAINER using independent reviewers and report inter-rater agreement.
Construct validity. Function-level vulnerability detection may omit caller, callee, type, or project-level context needed to determine whether a function is vulnerable. To characterize performance under this setting, we report accuracy, precision, recall, and F1, while Section 5.1 evaluates explanation correctness and completeness and Section 5.6 examines their contribution.
8 Conclusion
This paper presented VULNLENS, an explanation-augmented framework for binary C/C++ vulnerability detection that separates structured program-behavior analysis from the final vulnerability decision. A label-blind EXPLAINER analyzes each function from seven fixed perspectives, while a supervised DETECTOR integrates the explanations through sequential cross-attention.
On the 526-function PrimeVul test set, VULNLENS achieves 75.5% accuracy and 77.2% F1, exceeding the strongest evaluated baseline for each metric by 4.2 and 2.2 percentage points, respectively. Compared with a separately trained code-only detector, matched explanations improve F1 by 7.3 points. Without retraining, VULNLENS also achieves 66.4% accuracy and 65.8% F1 on SecVulEval.
These results show that structured, label-blind explanations can provide complementary predictive information beyond source code alone and serve as effective intermediate representations for vulnerability detection. Future work can extend this approach to richer program context, broader vulnerability categories, and more efficient explanation generation.
9 Data Availability
The replication package for this study is available on Zenodo (Record 23108024).
References
[1] Md Basim Uddin Ahmed, Nima Shiri Harzevili, Jiho Shin, Hung Viet Pham, and Song Wang. 2026. SecVulEval: Context-Aware Benchmarking of LLMs for Vulnerability Detection. In Proceedings of the 3rd ACM International Conference on AI-Powered Software (AIware '26). Association for Computing Machinery, 388–396. doi:10.1145/3805760.3814932
[2] Saikat Chakraborty, Rahul Krishna, Yangruibo Ding, and Baishakhi Ray. 2022. Deep Learning Based Vulnerability Detection: Are We There Yet? IEEE Transactions on Software Engineering 48, 9 (2022), 3280–3296. doi:10.1109/TSE.2021.3087402
[3] Wachiraphan Charoenwet, Patanamon Thongtanunam, Van-Thuan Pham, and Christoph Treude. 2024. An Empirical Study of Static Analysis Tools for Secure Code Review. In Proceedings of the 33rd ACM SIGSOFT International Symposium on Software Testing and Analysis. Association for Computing Machinery, 691–703. doi:10.1145/3650212.3680313
[4] Xiao Cheng, Haoyu Wang, Jiayi Hua, Guoai Xu, and Yulei Sui. 2021. DeepWukong: Statically Detecting Software Vulnerabilities Using Deep Graph Neural Network. ACM Transactions on Software Engineering and Methodology 30, 3, Article 38 (2021), 33 pages. doi:10.1145/3436877
[5] Brian Chess and Gary McGraw. 2004. Static Analysis for Security. IEEE Security & Privacy 2, 6 (2004), 76–79. doi:10.1109/MSP.2004.111
[6] Cppcheck Project. [n.d.]. Cppcheck: A Tool for Static C/C++ Code Analysis. https://cppcheck.sourceforge.io/. Accessed May 19, 2026.
[7] Yangruibo Ding, Yanjun Fu, Omniyyah Ibrahim, Chawin Sitawarin, Xinyun Chen, Basel Alomair, David Wagner, Baishakhi Ray, and Yizheng Chen. 2025. Vulnerability Detection with Code Language Models: How Far Are We? In 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE). IEEE, 1729–1741. doi:10.1109/ICSE55347.2025.00038
[8] Xiaohu Du, Ming Wen, Jiahao Zhu, Zifan Xie, Bin Ji, Huijun Liu, Xuanhua Shi, and Hai Jin. 2024. Generalization-Enhanced Code Vulnerability Detection via Multi-Task Instruction Fine-Tuning. In Findings of the Association for Computational Linguistics: ACL 2024. Association for Computational Linguistics, 10507–10521. doi:10.18653/v1/2024.findings-acl.625
[9] Federal Trade Commission. 2019. Equifax to Pay $575 Million as Part of Settlement with FTC, CFPB, and States Related to 2017 Data Breach. https://www.ftc.gov/news-events/news/press-releases/2019/07/equifax-pay-575-million-part-settlement-ftc-cfpb-states-related-2017-data-breach. Accessed: 2026-10-01.
[10] Zhangyin Feng, Daya Guo, Duyu Tang, Nan Duan, Xiaocheng Feng, Ming Gong, Linjun Shou, Bing Qin, Ting Liu, Daxin Jiang, and Ming Zhou. 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, Online, 1536–1547. doi:10.18653/v1/2020.findings-emnlp.139
[11] Michael Fu and Chakrit Tantithamthavorn. 2022. LineVul: A Transformer-Based Line-Level Vulnerability Prediction. In Proceedings of the 19th International Conference on Mining Software Repositories. Association for Computing Machinery, 608–620. doi:10.1145/3524842.3528452
[12] Daya Guo, Shuai Lu, Nan Duan, Yanlin Wang, Ming Zhou, and Jian Yin. 2022. UniXcoder: Unified Cross-Modal Pre-training for Code Representation. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers). Association for Computational Linguistics, Dublin, Ireland, 7212–7225. doi:10.18653/v1/2022.acl-long.499
[13] Daya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng, Duyu Tang, Shujie Liu, Long Zhou, Nan Duan, Alexey Svyatkovskiy, Shengyu Fu, Michele Tufano, Shao Kun Deng, Colin Clement, Dawn Drain, Neel Sundaresan, Jian Yin, Daxin Jiang, and Ming Zhou. 2021. GraphCodeBERT: Pre-Training Code Representations with Data Flow. In International Conference on Learning Representations. https://arxiv.org/abs/2009.08366
[14] Cheng-Yu Hsieh, Chun-Liang Li, Chih kuan Yeh, Hootan Nakhost, Yasuhisa Fujii, Alex Ratner, Ranjay Krishna, Chen-Yu Lee, and Tomas Pfister. 2023. Distilling Step-by-Step! Outperforming Larger Language Models with Less Training Data and Smaller Model Sizes. In Findings of the Association for Computational Linguistics: ACL 2023. Association for Computational Linguistics, 8003–8017. doi:10.18653/v1/2023.findings-acl.507
[15] Arvinder Kaur and Ruchikaa Nayyar. 2020. A Comparative Study of Static Code Analysis Tools for Vulnerability Detection in C/C++ and JAVA Source Code. Procedia Computer Science 171 (2020), 2023–2029. doi:10.1016/j.jprocs.2020.04.217
[16] Takeshi Kojima, Shixiang Shane Gu, Machel Reid, Yutaka Matsuo, and Yusuke Iwasawa. 2022. Large Language Models Are Zero-Shot Reasoners. In Advances in Neural Information Processing Systems, Vol. 35. Curran Associates, Inc., 22199–22213. doi:10.52202/068431-1613
[17] Ahmed Lekssays, Hamza Mouhcine, Khang Tran, Ting Yu, and Issa Khalil. 2025. LLMxCPG: Context-Aware Vulnerability Detection Through Code Property Graph-Guided Large Language Models. In 34th USENIX Security Symposium (USENIX Security 25). USENIX Association, 489–507. https://www.usenix.org/conference/usenixsecurity25/presentation/lekssays
[18] Yi Li, Shaohua Wang, and Tien N. Nguyen. 2021. Vulnerability Detection with Fine-Grained Interpretations. In Proceedings of the 29th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering. Association for Computing Machinery, 292–303. doi:10.1145/3468264.3468597
[19] Zhen Li, Deqing Zou, Shouhuai Xu, Hai Jin, Yawei Zhu, and Zhaoxuan Chen. 2022. SySeVR: A Framework for Using Deep Learning to Detect Software Vulnerabilities. IEEE Transactions on Dependable and Secure Computing 19, 4 (2022), 2244–2258. doi:10.1109/TDSC.2021.3051525
[20] Zhen Li, Deqing Zou, Shouhuai Xu, Xinyu Ou, Hai Jin, Sujuan Wang, Zhijun Deng, and Yuyi Zhong. 2018. VulDeePecker: A Deep Learning-Based System for Vulnerability Detection. In Proceedings 2018 Network and Distributed System Security Symposium. Internet Society. doi:10.14722/ndss.2018.23158
[21] V. Benjamin Livshits and Monica S. Lam. 2005. Finding Security Vulnerabilities in Java Applications with Static Analysis. In 14th USENIX Security Symposium (USENIX Security 05). USENIX Association, 271–286. https://www.usenix.org/conference/14th-usenix-security-symposium/finding-security-vulnerabilities-java-applications-static
[22] LLVM Project. [n.d.]. Clang Static Analyzer. https://clang-analyzer.llvm.org/. Accessed May 19, 2026.
[23] Guilong Lu, Xiaolin Ju, Xiang Chen, Wenlong Pei, and Zhilong Cai. 2024. GRACE: Empowering LLM-Based Software Vulnerability Detection with Graph Structure and In-Context Learning. Journal of Systems and Software 212 (2024), 112031. doi:10.1016/j.jss.2024.112031
[24] Andrew A Mahyari. 2024. Harnessing the Power of LLMs in Source Code Vulnerability Detection. arXiv:2408.03489 [cs.SE] https://arxiv.org/abs/2408.03489
[25] National Institute of Standards and Technology. [n.d.]. CVE-2019-3812 Detail. https://nvd.nist.gov/vuln/detail/CVE-2019-3812. National Vulnerability Database.
[26] Yu Nong, Mohammed Aldeen, Long Cheng, Hongxin Hu, Feng Chen, and Haipeng Cai. 2024. Chain-of-Thought Prompting of Large Language Models for Discovering and Fixing Software Vulnerabilities. arXiv:2402.17230 [cs.CR] https://arxiv.org/abs/2402.17230
[27] Maxwell Nye, Anders Johan Andreassen, Guy Gur-Ari, Henryk Michalewski, Jacob Austin, David Bieber, David Dohan, Aitor Lewkowycz, Maarten Bosma, David Luan, Charles Sutton, and Augustus Odena. 2021. Show Your Work: Scratchpads for Intermediate Computation with Language Models. arXiv:2112.00114 [cs.LG] https://arxiv.org/abs/2112.00114
[28] QEMU Project. 2019. i2c-ddc: fix oob read. https://github.com/qemu/qemu/commit/b05b267840515730dbf6753495d5b7bd8b04ad1c. Commit b05b267840515730dbf6753495d5b7bd8b04ad1c.
[29] Rebecca Russell, Louis Kim, Lei Hamilton, Tomo Lazovich, Jacob Harer, Onur Ozdemir, Paul Ellingwood, and Marc McConley. 2018. Automated Vulnerability Detection in Source Code Using Deep Representation Learning. In 2018 17th IEEE International Conference on Machine Learning and Applications (ICMLA). IEEE, 757–762. doi:10.1109/ICMLA.2018.00120
[30] Adriana Sejfia, Satyaki Das, Saad Shafiq, and Nenad Medvidović. 2024. Toward Improved Deep Learning-Based Vulnerability Detection. In Proceedings of the IEEE/ACM 46th International Conference on Software Engineering. Association for Computing Machinery, Article 62, 12 pages. doi:10.1145/3597503.3608141
[31] Semgrep. [n.d.]. Semgrep. https://github.com/semgrep/semgrep. Accessed May 19, 2026.
[32] Benjamin Steenhoek, Md Mahbubur Rahman, Richard Jiles, and Wei Le. 2023. An Empirical Study of Deep Learning Models for Vulnerability Detection. arXiv:2212.08109 [cs.SE] https://arxiv.org/abs/2212.08109
[33] Yue Wang, Weishi Wang, Shafiq Joty, and Steven C.H. Hoi. 2021. CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing. Association for Computational Linguistics, Online and Punta Cana, Dominican Republic, 8696–8708. doi:10.18653/v1/2021.emnlp-main.685
[34] Jason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma, Brian Ichter, Fei Xia, Ed Chi, Quoc V. Le, and Denny Zhou. 2022. Chain-of-Thought Prompting Elicits Reasoning in Large Language Models. In Advances in Neural Information Processing Systems, Vol. 35. Neural Information Processing Systems Foundation, Inc., 24824–24837. doi:10.52202/068431-1800
[35] Sarah Wiegrefre and Ana Marasović. 2021. Teach Me to Explain: A Review of Datasets for Explainable Natural Language Processing. arXiv:2102.12060 [cs.CL] https://arxiv.org/abs/2102.12060
[36] Fabian Yamaguchi, Nico Golde, Daniel Arp, and Konrad Rieck. 2014. Modeling and Discovering Vulnerabilities with Code Property Graphs. In Proceedings of the 2014 IEEE Symposium on Security and Privacy. IEEE, 590–604. doi:10.1109/SP.2014.44
[37] Weining Zheng, Yuan Jiang, and Xiaohong Su. 2021. VulSPG: Vulnerability Detection Based on Slice Property Graph Representation Learning. arXiv:2109.02527 [cs.CR] https://arxiv.org/abs/2109.02527
[38] Xin Zhou, Sicong Cao, Xiaobing Sun, and David Lo. 2025. Large Language Model for Vulnerability Detection and Repair: Literature Review and the Road Ahead. ACM Transactions on Software Engineering and Methodology 34, 5, Article 145 (2025), 31 pages. doi:10.1145/3708522
[39] Xin Zhou, Ting Zhang, and David Lo. 2024. Large Language Model for Vulnerability Detection: Emerging Results and Future Directions. In 2024 IEEE/ACM 46th International Conference on Software Engineering: New Ideas and Emerging Results (ICSE-NIER). IEEE, 47–51. doi:10.1145/3639476.3639762
[40] Yaqin Zhou, Shangqing Liu, Jingkai Siow, Xiaoning Du, and Yang Liu. 2019. Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networks. In Advances in Neural Information Processing Systems, Vol. 32. Curran Associates, Inc. https://proceedings.neurips.cc/paper_files/paper/2019/file/49265d2447bc3bbfe9e76306ce40a31f-Paper.pdf