Attribution-Guided Prompt Optimization for Cross-CWE Vulnerability Detection
Abstract
1. Introduction
- New method: We propose IGPO, an attribution-informed prompt optimization method that converts line-level IG feedback from FP and FN validation samples into diagnostic guidance for LLM-based prompt revision. The key novelty lies in grounding prompt feedback directly in the detector’s token-level sensitivity, rather than relying on aggregate metrics, complete error samples, or language-model-generated critiques.
- Novel diagnostic design: We apply IG, originally used for model interpretability, as a lightweight diagnostic signal for iterative prompt optimization in a cross-domain transfer setting, combining it with False Positive (FP)/False Negative (FN) error typing and LLM-assisted revision.
- New empirical setting: We formulate low-resource cross-CWE vulnerability detection as a prompt-level adaptation problem and construct a 14-CWE transfer matrix with 182 non-diagonal source–target pairs from PrimeVul, DiverseVul, and BigVul, providing a systematic evaluation framework for cross-CWE prompt optimization.
- We empirically show that IGPO improves prompt optimization on positive-transfer source–target pairs, where the source-CWE fine-tuned detector remains a suitable backbone.
- We analyze the limitation of attribution-guided prompt optimization under negative transfer, emphasizing the need for backbone selection or fallback strategies.
2. Related Work
2.1. Learning-Based Software Vulnerability Detection
2.2. LLM-Based Vulnerability Detection and Prompting
2.3. Automated Prompt Optimization and Text-Based Optimization
2.4. Attribution-Based Diagnosis for Code Models
3. Materials and Methods
3.1. Task Setting and Dataset Construction
3.2. Cross-CWE Transfer Protocol
3.3. Integrated-Gradient-Guided Prompt Optimization
| Algorithm 1 Integrated-Gradient-Guided Prompt Optimization |
|
3.4. Attribution Feedback and Prompt Revision
3.5. Models and Baselines
- Base-ZS: zero-shot prompting with the base model;
- Fine-ZS: zero-shot prompting with the source-CWE fine-tuned model;
- Fine-checklist: a checklist-style vulnerability inspection prompt;
- Fine-CWE-definition: a prompt that injects the target CWE definition;
- Fine-few-shot: a prompt with few-shot examples drawn from a validation split. There are two variants: one draws examples from the target-CWE validation split, and the other draws examples from the source-CWE validation split. The examples are selected by stratified sampling to include both vulnerable and non-vulnerable instances, and no target test-split samples are used.
- Fine-role-play: a role-based software-security-analyst prompt;
- Fine-CodeSpeak: an automated method using code-related feedback;
- Fine-DLAP-simplified: a simplified validation-feedback prompt adaptation method;
- Fine-OPRO: an optimization-by-prompting method using prompt history and validation metrics;
- Fine-TextGrad: a text-gradient-based method using natural-language error feedback;
- Fine-IGPO: the proposed attribution-informed prompt optimization method.
3.6. Evaluation Protocol and Research Questions
- RQ1: What is the overall cross-CWE transfer behavior across the 14-CWE transfer matrix?
- RQ2: On positive-transfer pairs, does IGPO outperform zero-shot, manual prompting, and automated prompt optimization baselines?
- RQ3: How does IGPO behave under negative transfer, especially catastrophic negative transfer?
- RQ4: Which IGPO components contribute to performance, including attribution-line selection, FP/FN feedback, top-k line selection, and LLM-based error diagnosis?
- RQ5: What computational overhead does attribution-informed prompt optimization introduce?
4. Results
4.1. Cross-CWE Transfer Background
4.2. Performance on Positive-Transfer Pairs
4.3. Ablation Study
4.4. Attribution-Based Diagnostic Case Study
4.5. Computational Cost
4.6. Performance on Negative-Transfer Pairs
5. Discussion
5.1. Main Findings
5.2. Method-Level Limitations
5.3. Study-Level Limitations
5.4. Future Work
6. Conclusions
Supplementary Materials
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
Abbreviations
| API | Application Programming Interface |
| APE | Automatic Prompt Engineer |
| CFG | Control-Flow Graph |
| CWE | Common Weakness Enumeration |
| DFG | Data-Flow Graph |
| DLAP | Deep Learning Augmented LLMs Prompting |
| FN | False Negative |
| FP | False Positive |
| F1 | F1 score |
| IG | Integrated Gradients |
| IGPO | Integrated-Gradient-Guided Prompt Optimization |
| LIME | Local Interpretable Model-Agnostic Explanations |
| LLM | Large Language Model |
| LoRA | Low-Rank Adaptation |
| NLP | Natural Language Processing |
| OPRO | Optimization by PROmpting |
| P | Precision |
| R | Recall |
| SHAP | SHapley Additive exPlanations |
| UAF | Use-After-Free |
| ZS | Zero-Shot |
Appendix A. Complete Cross-CWE Transfer Matrix
| Train/Eval | CWE-284 | CWE-416 | CWE-200 | CWE-399 | CWE-264 | CWE-119 | CWE-20 | CWE-190 | CWE-189 | CWE-362 | CWE-787 | CWE-125 | CWE-476 | CWE-703 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CWE-284 | 0.8571 | Deg. | Deg. | Deg. | Deg. | Deg. | Deg. | Deg. | 0.6293 | 0.6325 | Deg. | 0.6611 | 0.6611 | 0.6316 |
| CWE-416 | 0.7391 | 0.8627 | 0.7013 | 0.8267 | 0.7758 | 0.7293 | 0.7595 | 0.5096 | 0.6519 | 0.6771 | 0.4037 | 0.5280 | 0.5379 | 0.5333 |
| CWE-200 | 0.7019 | 0.6923 | 0.8344 | 0.7910 | 0.8605 | 0.6696 | 0.7629 | 0.6429 | 0.7094 | 0.7128 | 0.6753 | 0.5957 | 0.6024 | 0.5957 |
| CWE-399 | 0.6757 | 0.7550 | 0.7006 | 0.9182 | 0.7629 | 0.7253 | 0.7564 | 0.7292 | 0.6698 | 0.6984 | 0.5769 | 0.6328 | 0.6387 | 0.6310 |
| CWE-264 | 0.6842 | 0.6767 | 0.7770 | 0.8590 | 0.9317 | 0.6919 | 0.7429 | 0.6522 | 0.7333 | 0.6957 | 0.5366 | 0.5950 | 0.5345 | 0.2913 |
| CWE-119 | 0.6000 | 0.5273 | 0.7287 | 0.8571 | 0.7857 | 0.9299 | 0.8000 | 0.5556 | 0.6119 | 0.6107 | 0.2151 | 0.4956 | 0.4112 | 0.1489 |
| CWE-20 | 0.7097 | 0.7273 | 0.7545 | 0.8774 | 0.7513 | 0.8000 | 0.8375 | 0.6477 | 0.6845 | 0.7081 | 0.6093 | 0.5500 | 0.5833 | 0.4143 |
| CWE-190 | 0.5437 | 0.4444 | 0.6142 | 0.7015 | 0.7188 | 0.7283 | 0.6667 | 0.8302 | 0.6927 | 0.6716 | 0.5455 | 0.5410 | 0.5690 | 0.4691 |
| CWE-189 | 0.6522 | 0.6087 | 0.6893 | 0.6781 | 0.6737 | 0.6582 | 0.6667 | 0.7243 | 0.8994 | 0.7950 | 0.6667 | 0.6327 | 0.6596 | 0.6129 |
| CWE-362 | 0.6505 | 0.6396 | 0.6758 | 0.6723 | 0.6736 | 0.6611 | 0.6639 | 0.7394 | 0.7816 | 0.9146 | 0.6372 | 0.6040 | 0.6667 | 0.6707 |
| CWE-787 | 0.6250 | 0.4151 | 0.4960 | 0.5088 | 0.6282 | 0.4426 | 0.5333 | 0.5786 | 0.6519 | 0.5833 | 0.8171 | 0.5676 | 0.5000 | 0.4892 |
| CWE-125 | 0.6995 | 0.7651 | 0.7531 | 0.8193 | 0.8391 | 0.6878 | 0.7077 | 0.7232 | 0.6834 | 0.6700 | 0.6667 | 0.8148 | 0.6154 | 0.5914 |
| CWE-476 | 0.6126 | 0.6869 | 0.6961 | 0.6762 | 0.7831 | 0.6582 | 0.6781 | 0.7079 | 0.6579 | 0.7273 | 0.6702 | 0.7310 | 0.8249 | 0.6452 |
| CWE-703 | 0.6574 | 0.6498 | 0.6525 | 0.6695 | 0.6325 | Deg. | 0.6611 | 0.6407 | 0.7282 | 0.6933 | 0.6441 | 0.6320 | 0.6376 | 0.7684 |
Appendix B. Statistical Significance Tests
| Method | Mean ΔF1 | Median ΔF1 | Win/Tie/Loss | p-Value | |
|---|---|---|---|---|---|
| Fine-IGPO | 0.0487 | 0.0421 | 151/4/4 | ||
| Fine-OPRO | 0.0195 | 0.0084 | 86/55/18 | ||
| Fine-TextGrad | 0.0195 | 0.0131 | 104/32/23 | ||
| Fine-role-play | 0.0007 | 0.0000 | 41/89/28 | ||
| Fine-CWE-definition | −0.0003 | 0.0000 | 43/85/30 | ||
| Fine-checklist | −0.0094 | 0.0000 | 29/82/47 | ||
| Fine-CodeSpeak | −0.0234 | −0.0058 | 68/3/88 | ||
| Fine-few-shot † | −0.0253 | −0.0058 | 72/2/85 | ||
| Fine-few-shot ‡ | −0.0295 | −0.0107 | 63/3/92 | ||
| Fine-DLAP-simplified | −0.0510 | −0.0344 | 24/0/135 |
| Baseline | Baseline Avg. F1 Score | Mean ΔF1 | Median ΔF1 | Win/Tie/Loss | p-value | |
|---|---|---|---|---|---|---|
| Fine-DLAP-simplified | 0.6270 | 0.0997 | 0.0830 | 159/0/0 | ||
| Fine-few-shot ‡ | 0.6480 | 0.0785 | 0.0471 | 153/4/1 | ||
| Fine-few-shot † | 0.6526 | 0.0740 | 0.0583 | 148/2/9 | ||
| Fine-CodeSpeak | 0.6546 | 0.0721 | 0.0551 | 157/1/1 | ||
| Fine-checklist | 0.6681 | 0.0584 | 0.0424 | 152/3/3 | ||
| Fine-CWE-definition | 0.6772 | 0.0493 | 0.0358 | 152/3/3 | ||
| Fine-ZS | 0.6780 | 0.0487 | 0.0421 | 151/4/4 | ||
| Fine-role-play | 0.6782 | 0.0482 | 0.0399 | 151/3/4 | ||
| Fine-OPRO | 0.6974 | 0.0292 | 0.0178 | 144/4/11 | ||
| Fine-TextGrad | 0.6975 | 0.0292 | 0.0173 | 148/2/9 |
| Target CWE | N | Mean ΔF1 | Median ΔF1 | Win | Win Rate (%) | |
|---|---|---|---|---|---|---|
| CWE-119 | 12 | 0.0456 | 0.0432 | 11 | 91.67 | |
| CWE-125 | 13 | 0.0763 | 0.0634 | 13 | 100.00 | |
| CWE-189 | 13 | 0.0523 | 0.0387 | 13 | 100.00 | |
| CWE-190 | 13 | 0.0581 | 0.0502 | 13 | 100.00 | |
| CWE-20 | 12 | 0.0328 | 0.0356 | 10 | 83.33 | |
| CWE-200 | 12 | 0.0404 | 0.0389 | 11 | 91.67 | |
| CWE-264 | 13 | 0.0250 | 0.0166 | 11 | 84.62 | |
| CWE-284 | 13 | 0.0537 | 0.0329 | 13 | 100.00 | |
| CWE-362 | 13 | 0.0444 | 0.0398 | 13 | 100.00 | |
| CWE-399 | 13 | 0.0338 | 0.0184 | 13 | 100.00 | |
| CWE-416 | 10 | 0.0471 | 0.0397 | 9 | 90.00 | |
| CWE-476 | 9 | 0.0629 | 0.0708 | 9 | 100.00 | |
| CWE-703 | 8 | 0.0735 | 0.0796 | 8 | 100.00 | |
| CWE-787 | 5 | 0.0448 | 0.0493 | 4 | 80.00 |
| Source CWE | N | Mean ΔF1 | Median ΔF1 | Win | Win Rate (%) | |
|---|---|---|---|---|---|---|
| CWE-119 | 9 | 0.0740 | 0.0753 | 8 | 88.89 | |
| CWE-125 | 13 | 0.0409 | 0.0376 | 12 | 92.31 | |
| CWE-189 | 13 | 0.0568 | 0.0595 | 13 | 100.00 | |
| CWE-190 | 10 | 0.0627 | 0.0592 | 10 | 100.00 | |
| CWE-20 | 11 | 0.0379 | 0.0238 | 11 | 100.00 | |
| CWE-200 | 13 | 0.0438 | 0.0468 | 11 | 84.62 | |
| CWE-264 | 10 | 0.0289 | 0.0262 | 9 | 90.00 | |
| CWE-284 | 13 | 0.0305 | 0.0258 | 10 | 76.92 | |
| CWE-362 | 12 | 0.0605 | 0.0585 | 12 | 100.00 | |
| CWE-399 | 12 | 0.0456 | 0.0375 | 12 | 100.00 | |
| CWE-416 | 11 | 0.0551 | 0.0421 | 11 | 100.00 | |
| CWE-476 | 13 | 0.0610 | 0.0600 | 13 | 100.00 | |
| CWE-703 | 12 | 0.0406 | 0.0331 | 12 | 100.00 | |
| CWE-787 | 7 | 0.0496 | 0.0398 | 7 | 100.00 |
Appendix C. Prompt Templates
Appendix C.1. Shared Detection Prompt
| Listing A1. Shared detection prompt template. |
| System: You are a vulnerability detection expert. You will perform a security analysis task to determine whether a given C/C++ function contains a vulnerability. User: Information hint: [INFO_HINT_PROMPT] Code: [BEGIN_C_CODE] [FUNCTION_CODE] [END_C_CODE] Output only one digit. Output 1 if the function is vulnerable. Output 0 if the function is not vulnerable. Assistant: Answer: |
Appendix C.2. Baseline Prompting Methods
Appendix C.2.1. Fine-ZS
| Listing A2. Fine-ZS information hint. |
| [EMPTY] |
Appendix C.2.2. Fine-Role-Play
| Listing A3. Fine-role-play information hint. |
| You are an experienced C/C++ security auditor. Analyze the function
as a vulnerability detection task. Focus on whether the implementation contains a
real security vulnerability rather than merely suspicious coding style. |
Appendix C.2.3. Fine-CWE-Definition
| Listing A4. Fine-CWE-definition information hint. |
| CWE-aware vulnerability definition:
[CWE_DESCRIPTION] Use this CWE definition as security background. Determine whether the given C/C++ function exhibits this type of vulnerability. Consider whether attacker-controlled data can trigger unsafe behavior, memory corruption, invalid access, information exposure, or other security-relevant consequences. |
Appendix C.2.4. Fine-Checklist
| Listing A5. Fine-checklist information hint. |
| Analyze the function using the following vulnerability checklist:
1. Identify all external inputs, parameters, pointer arguments, buffer arguments, length fields, and integer values. 2. Trace how these values flow into memory reads, memory writes, pointer arithmetic, array indexing, allocation sizes, copy operations, string operations, and loop bounds. 3. Check whether all bounds, lengths, offsets, and allocation sizes are validated before use. 4. Check whether integer computations can overflow, underflow, wrap around, or become negative before being used in memory operations. 5. Check whether pointers and resources are validated before dereference, release, or reuse. 6. Distinguish true vulnerabilities from safe code that contains adequate checks. 7. Output 1 only if the function contains a real vulnerability. Otherwise output 0. |
Appendix C.2.5. Fine-Few-Shot
| Listing A6. Fine-few-shot information hint. |
| The following are labeled examples for C/C++ vulnerability
detection. Example 1: Code: [BEGIN_C_CODE] [FEW_SHOT_CODE_1] [END_C_CODE] Label: [FEW_SHOT_LABEL_1] Example 2: Code: [BEGIN_C_CODE] [FEW_SHOT_CODE_2] [END_C_CODE] Label: [FEW_SHOT_LABEL_2] Example 3: Code: [BEGIN_C_CODE] [FEW_SHOT_CODE_3] [END_C_CODE] Label: [FEW_SHOT_LABEL_3] Example 4: Code: [BEGIN_C_CODE] [FEW_SHOT_CODE_4] [END_C_CODE] Label: [FEW_SHOT_LABEL_4] Use the examples only as guidance for the binary vulnerability decision. For the target function, output 1 if it is vulnerable and 0 otherwise. |
Appendix C.3. Optimizer-LLM-Assisted Non-Iterative Methods
Appendix C.3.1. Fine-CodeSpeak
| Listing A7. Fine-CodeSpeak optimizer prompt. |
| Describe the following C/C++ code in natural language. Focus on:
memory operations, data flow from inputs to buffers, and any potential security risks.
Be concise. [BEGIN_C_CODE] [FUNCTION_CODE] [END_C_CODE] |
| Listing A8. Fine-CodeSpeak information hint. |
| Semantic description of the code: [SEMANTIC_DESCRIPTION] |
Appendix C.3.2. Fine-DLAP-Simplified
| Listing A9. Fine-DLAP-simplified optimizer prompt. |
| Analyze the following C/C++ code and provide a concise static
analysis summary covering: (1) dangerous function calls found, (2) data flow paths
from user input to memory write operations, (3) missing boundary or length checks.
Output as a short structured list. [BEGIN_C_CODE] [FUNCTION_CODE] [END_C_CODE] |
| Listing A10. Fine-DLAP-simplified information hint. |
| Static analysis summary: [STATIC_ANALYSIS_SUMMARY] |
Appendix C.4. Iterative Prompt Optimization Baselines
Appendix C.4.1. Fine-OPRO
| Listing A11. Fine-OPRO optimizer prompt. |
| You are an expert prompt engineer optimizing an INFO_HINT_PROMPT
for a C/C++ vulnerability detection task. The detection model sees: - A fixed system message with an expert role. - INFO_HINT_PROMPT, which is the text you must improve. - The C/C++ code to analyze. - A fixed output instruction requiring the model to output 0 or 1. Your goal is to write an INFO_HINT_PROMPT that maximizes positiveclass F1 on the validation set. You may include role descriptions, checklists, CWE definitions, analysis instructions, or concise decision guidance. Output only the new INFO_HINT_PROMPT text, and nothing else. Past attempts: [HISTORY_OF_PROMPTS_AND_VALIDATION_F1] Training CWE: [TRAIN_CWE] Generate a new INFO_HINT_PROMPT that achieves higher positive-class F1 than the best attempt so far. Best validation positive-class F1: [BEST_VALIDATION_F1] Output only the INFO_HINT_PROMPT text: |
| Listing A12. Fine-OPRO history format. |
| Attempt [INDEX]: Positive-class F1: [VALIDATION_F1] INFO_HINT_PROMPT: [PREVIOUS_INFO_HINT_PROMPT] |
Appendix C.4.2. Fine-TextGrad
| Listing A13. Fine-TextGrad error-analysis prompt. |
| You are evaluating an INFO_HINT_PROMPT used for C/C++ vulnerability
detection. Current INFO_HINT_PROMPT: [CURRENT_INFO_HINT_PROMPT] The detection model made the following errors on the validation set: FALSE POSITIVES, predicted vulnerable but actually safe: [FALSE_POSITIVE_CODE_SNIPPETS] FALSE NEGATIVES, predicted safe but actually vulnerable: [FALSE_NEGATIVE_CODE_SNIPPETS] Analyze why the current INFO_HINT_PROMPT caused these errors. Identify specific patterns or missing guidance that led to each error type. Be concise and specific. This analysis will be used to improve the prompt. |
| Listing A14. Fine-TextGrad error sample format. |
| Sample [INDEX]: [BEGIN_C_CODE] [ERROR_CODE_SNIPPET] [END_C_CODE] |
| Listing A15. Fine-TextGrad prompt-update prompt. |
| You are improving an INFO_HINT_PROMPT for C/C++ vulnerability detection. Current INFO_HINT_PROMPT: [CURRENT_INFO_HINT_PROMPT] Text gradient, failure analysis: [TEXT_GRADIENT] Based on the failure analysis, rewrite the INFO_HINT_PROMPT to fix the identified issues. Output only the new INFO_HINT_PROMPT text, and nothing else. |
Appendix C.5. Proposed Method: Fine-IGPO
Appendix C.5.1. Fine-IGPO Error Evidence Format
| Listing A16. Fine-IGPO integrated-gradient evidence format. |
| Sample [INDEX]: error_type: [FP_OR_FN] gold_label: [GOLD_LABEL] model_prediction: [MODEL_PREDICTION] evidence_type: integrated_gradient_top_code_lines Line [LINE_NUMBER], attribution_score: [ATTRIBUTION_SCORE] [CODE_LINE] Line [LINE_NUMBER], attribution_score: [ATTRIBUTION_SCORE] [CODE_LINE] |
Appendix C.5.2. Fine-IGPO Error-Analysis Prompt
| Listing A17. Fine-IGPO error-analysis prompt. |
| You are analyzing errors made by a local C/C++ vulnerability
detection model. The model receives: - A fixed system role. - An INFO_HINT_PROMPT. - A C/C++ function. - A fixed instruction to output 1 for vulnerable and 0 for nonvulnerable. Current INFO_HINT_PROMPT: [CURRENT_INFO_HINT_PROMPT] Validation metrics: - Precision: [VALIDATION_PRECISION] - Recall: [VALIDATION_RECALL] - F1: [VALIDATION_F1] - Accuracy: [VALIDATION_ACCURACY] Below are misclassified validation samples. For integrated-gradient-based evidence, only code tokens were attributed; prompt tokens were excluded. The shown lines are the code lines the model focused on most. Misclassification evidence: [INTEGRATED_GRADIENT_ERROR_EVIDENCE] Analyze why the current INFO_HINT_PROMPT caused these errors. Focus on: 1. Why false positives happened. 2. Why false negatives happened. 3. What vulnerability reasoning guidance is missing. 4. What misleading patterns the model may be overusing. Be concise and specific. Output only the error analysis. |
Appendix C.5.3. Fine-IGPO Prompt-Optimization Prompt
| Listing A18. Fine-IGPO prompt-optimization prompt. |
| You are improving an INFO_HINT_PROMPT for a C/C++ vulnerability
detection model. Current INFO_HINT_PROMPT: [CURRENT_INFO_HINT_PROMPT] Validation metrics: - Precision: [VALIDATION_PRECISION] - Recall: [VALIDATION_RECALL] - F1: [VALIDATION_F1] - Accuracy: [VALIDATION_ACCURACY] Error analysis: [ERROR_ANALYSIS] Rewrite the INFO_HINT_PROMPT to improve validation positive-class F1. The prompt should help the model distinguish truly vulnerable code from safe code. It may include: - vulnerability reasoning checklist - boundary and data-flow analysis guidance - false-positive reduction guidance - false-negative reduction guidance - concise CWE-aware cues Constraints: - Do not ask the model to output explanations. - The final detector must still output only 0 or 1. - Do not include irrelevant verbosity. - Output only the new INFO_HINT_PROMPT text. |
Appendix C.6. Summary of Prompting Methods
| Method | Information Hint Source | Optimizer LLM Used | Final Detector |
|---|---|---|---|
| Fine-ZS | Empty hint | No | Local fine-tuned model |
| Fine-role-play | Fixed role instruction | No | Local fine-tuned model |
| Fine-CWE-definition | Fixed CWE-aware definition | No | Local fine-tuned model |
| Fine-checklist | Fixed vulnerability checklist | No | Local fine-tuned model |
| Fine-few-shot | Selected labeled examples | No | Local fine-tuned model |
| Fine-CodeSpeak | Per-sample semantic description | Yes, hint generation only | Local fine-tuned model |
| Fine-DLAP-simplified | Per-sample static-analysis summary | Yes, hint generation only | Local fine-tuned model |
| Fine-OPRO | Iteratively optimized information hint | Yes, prompt optimization only | Local fine-tuned model |
| Fine-TextGrad | Error-feedback-based optimized hint | Yes, prompt optimization only | Local fine-tuned model |
| Fine-IGPO | IG-guided error evidence and optimized hint | Yes, prompt optimization only | Local fine-tuned model |
Appendix D. Representative IGPO Optimization Trajectories
Appendix D.1. Category A1: Positive Transfer with the Largest Validation F1 Score Improvement
Appendix D.1.1. CWE-787 → CWE-362 [Positive Transfer]

| Listing A19. Best prompt for CWE-787 to CWE-362 (round 3, validation F1 = 0.6458). |
| Analyze the C/C++ code for vulnerabilities. Focus on data flow from
untrusted sources (stdin, argv, environment, network) to sensitive sinks (memory
writes, system calls, pointer dereferences). Use the checklist below to decide between
0 (safe) and 1 (vulnerable). Output only 0 or 1. Checklist for vulnerability detection: 1. Buffer overflow Every copy or format operation must have a known destination size strictly larger than the source length, including the null terminator. - Unsafe: strcpy, sprintf, memcpy without an explicit size limit; strncpy with size greater than or equal to the destination size. - Safe: snprintf with size less than or equal to the real capacity; strncpy with size equal to destination size minus 1, followed by null termination. - Check loops: index i must be smaller than the allocated size for all iterations. 2. Integer overflow or underflow Arithmetic in size, index, or allocation arguments can wrap around. - Flag any signed or unsigned mismatch or unsafe cast in expressions such as malloc(a ∗ b), arr[i + j], or loop bounds derived from user input. - Even if the final result appears valid, intermediate overflow can still be unsafe. 3. Format string bug If a user-controlled string appears as the format argument in printf, fprintf, sprintf, or similar functions, it is vulnerable. Safe example: printf(“%s”, user_str). 4. Null pointer dereference After any allocation or pointer-returning function, check for NULL before dereference. Also, strlen(NULL) is undefined behavior. 5. Use-after-free or double-free Flag any pointer used after free or realloc, including through aliases. Watch for dangling pointers in loops, realloc with shrinking, or multiple frees of the same pointer. 6. Unsafe type casts Pointer casts may break alignment or strict aliasing. Flag casts that can make later dereferences invalid. Boundary and data-flow analysis guidance: - Every array index, pointer offset, and length must be strictly smaller than the allocated size. - Off-by-one errors are vulnerabilities. - Trace through function arguments, return values, global variables, and aliased pointers. - Consider chained vulnerabilities: integer overflow causes small allocation, followed by buffer overflow. False-positive reduction: - Static arrays with known fixed size and in-bounds access are safe. - strncpy(dst, src, n) is safe only if n is less than or equal to sizeof(dst) - 1, or if the destination is later null-terminated. - snprintf(dst, size, …) is safe if size is less than or equal to sizeof(dst). - Bounded loops with proper termination are safe if the bound is trusted or validated. - Trust standard library functions only when used correctly. False-negative reduction: - Do not assume that input is safe without an explicit validation path. - Check edge cases such as zero length, negative values, unsigned wraparound, and off-by-one boundaries. |
Appendix D.1.2. CWE-189 → CWE-476 [Positive Transfer]

| Listing A20. Best prompt for CWE-189 to CWE-476 (round 4, validation F1 = 0.6724). |
| INFO_HINT_PROMPT: Analyze each code snippet for true exploitable security vulnerabilities only. Output 1 only if all of the following conditions hold; otherwise output 0. Conditions for output 1: 1. External untrusted data reaches a dangerous sink through a direct or indirect path. 2. No validating check exists on that path, or the existing check is insufficient. 3. The missing or insufficient check directly enables out-of-bounds access, code execution, or state corruption under realistic input. 4. The exploitation path is not blocked by defensive code and is not guarded by unreachable conditions or dead code. Do not output 1: - For isolated benign patterns, such as static strings, constantsize arrays, pointer assignments without dereference, function declarations, or fixedbound loops. - If checks fully cover the range of possible inputs. - If integer overflow does not affect memory safety. - If defensive code correctly handles all error cases. - If concurrency issues require unrealistic timing and do not lead to visible corruption or crash. - If safe standard functions are used correctly. Data-flow and boundary guidance: - Trace all paths from input sources to sinks. - Integer arithmetic with tainted values must not wrap. - Loop bounds derived from tainted input without a hard cap indicate possible out-of-bounds access. - Check implicit integer conversions, such as int to size_t. - Check unsigned underflow in loop conditions. - Check error paths that leave resources or state inconsistent. Output only 0 or 1. |
Appendix D.1.3. CWE-362 → CWE-399 [Positive Transfer]

| Listing A21. Best prompt for CWE-362 to CWE-399 (round 7, validation F1 = 0.7955). |
| Focus on actual dangerous operations: buffer overflows from
unchecked external input, use-after-free, double-free, race conditions on shared data,
and integer overflows that directly cause memory corruption. Ignore safe patterns: controlled format strings, struct field accesses, bounded arithmetic, type signatures, debug macros, and test registration macros that only wrap function calls. For false negatives, do not dismiss test code. Analyze the implemented function logic, not the registration. Use this reasoning checklist: 1. Does data flow from an untrusted source into a memory operation without size validation? 2. Is a pointer used after free or realloc? 3. Is the same memory freed twice? 4. Is there a data race on a shared object without locking? 5. Does integer arithmetic wrap and lead to undersized allocation or out-of-bounds write? Only flag when a concrete violation is proven by data-flow evidence. Disregard superficial complexity or non-critical lines. |
Appendix D.2. Category A2: Negative Transfer with Measurable Optimization Gain
Appendix D.2.1. CWE-787 → CWE-703 [Negative Transfer]

| Listing A22. Best prompt for CWE-787 to CWE-703 (round 9, validation F1 = 0.5895). |
| Consider the following when analyzing C/C++ code for
vulnerabilities: - Data flow: track tainted inputs to unsafe operations without validation. - Bounds: verify array indices and pointer offsets stay within allocated memory. - Integer overflow: check arithmetic on sizes, lengths, and indexes that could wrap and bypass checks. - Memory safety: confirm proper allocation and free pairing; avoid use-after-free, double-free, and null pointer dereference. - Dangerous functions: strcpy, sprintf, and gets without size limits. - False-positive reduction: only flag if the vulnerability path is reachable and not mitigated by existing guards. - False-negative reduction: consider edge cases such as negative values, zero-length buffers, unsigned underflow, and hidden paths. - CWE-aware focus: buffer overflow, integer overflow, use-afterfree, and null pointer dereference. |
Appendix D.2.2. CWE-787 → CWE-20 [Negative Transfer]

| Listing A23. Best prompt for CWE-787 to CWE-20 (round 3, validation F1 = 0.5455). |
| Analyze C/C++ code for vulnerabilities using strict data-flow and
boundary reasoning. Checklist: 1. Identify all external inputs, including network packets, user input, file contents, environment variables, command-line arguments, and data from outside the trust domain. 2. Trace tainted paths to sensitive sinks such as memcpy, memmove, strcpy, strcat, sprintf, snprintf, read, write, send, recv, malloc, free, array indexing, and pointer arithmetic. 3. Inspect arithmetic on tainted values used as sizes, indices, or loop bounds. 4. Verify that loop-based buffer accesses stay within allocated space. 5. Check use-after-free and double-free paths. 6. Trace indirect and multi-step flows through arguments, return values, global variables, struct members, and pointer aliases. 7. Reduce false positives by avoiding flags for constant-size allocations, validated loops, safe wrappers, and trusted constants. 8. Focus on input validation, buffer safety, integer overflow, and memory lifetime issues. Output only 0 or 1. |
Appendix D.2.3. CWE-787 → CWE-200 [Negative Transfer]

| Listing A24. Best prompt for CWE-787 to CWE-200 (round 9, validation F1 = 0.6897). |
| Analyze the code for vulnerabilities with precise reasoning. 1. Untrusted data to dangerous sinks Trace user, network, file, or IPC inputs to memory copies, dynamic allocations, array indexing, pointer arithmetic, file operations, format strings, and shared state. 2. Bounds and overflow validation For every buffer access, confirm that the size or index is checked against actual allocated capacity before use. The check must not be bypassable by integer overflow or off-by-one errors. 3. Integer handling Check multiplication, addition, subtraction, implicit conversions, loop counters, and bit shifts when they affect size, index, or loop bounds. 4. Memory safety and concurrency Check use-after-free, double-free, missing synchronization, race conditions, and resources not released on all paths. 5. Format string and path traversal Flag user-controlled format strings and unsafe path construction. Output only 0 or 1. |
Appendix D.3. Category B: Smooth Ascending Trajectories
Appendix D.3.1. CWE-399 → CWE-190 [Positive Transfer]

| Listing A25. Best prompt for CWE-399 to CWE-190 (round 3, validation F1 = 0.7292). |
| INFO_HINT_PROMPT: Analyze the code for vulnerabilities. Output 1 only if an exploit is clearly reachable under realistic inputs. Output 0 if any required condition fails. 1. Buffer overflow or out-of-bounds access Flag only when user-controlled size or index reaches a memory access without a sufficient bounds check. 2. Integer overflow Flag only when overflow in a size or length calculation directly causes under-allocation, buffer underrun, or out-of-bounds write. 3. Use-after-free or double-free Flag only when a pointer is freed and then dereferenced or freed again on a reachable path. 4. Null pointer dereference Flag only when a possibly NULL pointer is dereferenced without a prior check. 5. Format string Flag only when a user-controlled string is used as the format argument. Output only 0 or 1. |
Appendix D.3.2. CWE-362 → CWE-20 [Positive Transfer]

| Listing A26. Best prompt for CWE-362 to CWE-20 (round 1, validation F1 = 0.7475). |
| INFO_HINT_PROMPT: Focus on actual memory unsafety, integer overflow or underflow, use -after-free, or tainted data flow that leads to security impact. Ignore defensive checks, safe security-related function names, and function signatures alone. Do not flag API calls without context of unsafe input or missing validation. Flag only when the vulnerability logic is present in the code body, not merely in the function name or signature. Output only 0 or 1. |
Appendix D.3.3. CWE-200 → CWE-190 [Positive Transfer]

| Listing A27. Best prompt for CWE-200 to CWE-190 (round 6, validation F1 = 0.7692). |
| You are a vulnerability detection model for C/C++ code. Analyze the
provided code snippet and output 0 for safe or 1 for vulnerable. Focus only on observable and exploitable memory safety or controlflow issues. Ignore style, naming, memory leaks, dead code, or low-severity concerns. Checklist: 1. Buffer and string operations Flag only when a write to a fixed-size buffer uses an unsafe operation and the source length is not verified against destination capacity before the write. 2. User input and taint propagation Flag only when externally controllable data flows directly into a dangerous sink without sanitization or bounds checks. 3. Integer overflow Flag only when arithmetic overflow directly affects allocation size, memory indexing, or loop bounds. 4. Memory lifetime Flag use-after-free, double-free, or dereference of possibly NULL pointers. Output only 0 or 1. |
Appendix D.4. Category C: Peak-Then-Drop Trajectories
Appendix D.4.1. CWE-190 → CWE-399 [Positive Transfer]

| Listing A28. Best prompt for CWE-190 to CWE-399 (round 5, validation F1 = 0.7671). |
| Analyze the code for C/C++ vulnerabilities, including buffer
overflow, use-after-free, integer overflow, null pointer dereference, and format
string bugs. For every path from an input source to a dangerous sink, verify: 1. Taint propagation through assignments, casts, pointer arithmetic, array indexing, function calls, global variables, and struct fields. 2. Boundary checks for every memory access involving tainted data. 3. Integer arithmetic affecting memory size, offset, or index. 4. Use-after-free after free or realloc. 5. Null pointer dereference after allocation or pointer-returning functions. 6. User-controlled format strings. Do not mark a check as safe unless it is both present and sufficient for all values of the tainted input. Output only 0 or 1. |
Appendix D.4.2. CWE-190 → CWE-476 [Positive Transfer]

| Listing A29. Best prompt for CWE-190 to CWE-476 (round 3, validation F1 = 0.5806). |
| INFO_HINT_PROMPT: Focus on actual data flow and boundary conditions. Detect vulnerabilities by reasoning through these patterns: - Buffer overflow or underflow: tainted length or index used in memory access without valid bounds checks. - Integer overflow: tainted arithmetic used as allocation size, array index, or pointer offset. - Format string: non-constant format argument in printf-family functions. - Use-after-free: pointer dereferenced after free or realloc. - Null pointer dereference: possibly NULL pointer dereferenced without a check. Output only 0 or 1. |
Appendix D.4.3. CWE-362 → CWE-476 [Positive Transfer]

| Listing A30. Best prompt for CWE-362 to CWE-476 (round 6, validation F1 = 0.6596). |
| INFO_HINT_PROMPT: Perform static analysis with strict data-flow and control-flow reachability. For each memory or pointer operation, flag a vulnerability if there exists any executable path where the operation executes without sufficient validation or bounds checks. To reduce false negatives, flag ambiguous cases where a data-flow path to an unsafe operation exists and the guard is not provably sufficient. To reduce false positives, exclude cases where every reachable path is provably safe. Checklist: 1. Identify all memory and pointer reads or writes. 2. Trace indices, lengths, and sizes back to inputs or computed values. 3. Verify that each reachable path includes a guard that exactly constrains the operation. 4. Flag paths where a guard is missing, too weak, or uses an unsafe boundary. 5. Treat off-by-one, integer overflow, under-allocation, and useafter- free as high-risk patterns. Output only 0 or 1. |
Appendix D.5. Category D: Fast-Converging Trajectories
Appendix D.5.1. CWE-119 → CWE-399 [Positive Transfer]

Appendix D.5.2. CWE-119 → CWE-416 [Negative Transfer]

| Listing A31. Best prompt for CWE-119 to CWE-416 (round 1, validation F1 = 0.5091). |
| Analyze the code for potential vulnerabilities by focusing on
common unsafe patterns: buffer overflows, integer overflows, format string misuse, use
-after-free, double-free, null pointer dereferences, and uninitialized memory. Trace data flow from user-controlled inputs to sensitive operations such as memory allocation, array access, pointer dereference, and system calls. Flag any path where input can influence size, index, or length without proper validation. Consider explicit and implicit casts that may truncate or sign-extend values. Output only 0 or 1. |
Appendix D.6. Category E: Highest Absolute Test F1 Score
Appendix D.6.1. CWE-200 → CWE-264 [Positive Transfer]

| Listing A32. Best prompt for CWE-200 to CWE-264 (round 4, validation F1 = 0.8750). |
| To improve validation positive F1, focus on distinguishing truly
vulnerable code from safe code by confirming both the presence of untrusted data flow
and the absence of effective sanitization. Checklist: - Source and sink: trace external data to dangerous sinks. - Sanitization validity: a guard is effective only if applied before the sink, uses correct bounds, and cannot be bypassed by integer issues. - Bounds and sizes: size arguments must be constants or correctly validated. - Format strings: flag only if the format argument is directly user -controlled. - Use-after-free: flag only if the pointer is dereferenced after free without reassignment, reallocation, or reset. - Control flow: prioritize reachable paths and ignore dead code. Output only 0 or 1. |
Appendix D.6.2. CWE-264 → CWE-399 [Positive Transfer]

| Listing A33. Best prompt for CWE-264 to CWE-399 (round 8, validation F1 = 0.8315). |
| Analyze C/C++ code for true vulnerabilities: memory safety issues,
integer overflow, format string bugs, and type confusion. For each potential vulnerability: 1. Trace untrusted input to sensitive operations. 2. Check whether validation is effective and cannot be bypassed by overflow, underflow, or signedness issues. 3. Ensure checks are applied on every reachable path. 4. Recognize safe patterns such as correct bounds checks, safe wrappers, and managed containers. 5. Flag common patterns such as buffer overflow, use-after-free, double-free, null pointer dereference, user-controlled format strings, and integer overflow leading to undersized allocation. Output 0 only if every path to the sensitive operation has an effective and non-bypassable check. Output 1 if any path lacks an effective check. Output only 0 or 1. |
Appendix D.6.3. CWE-20 → CWE-399 [Positive Transfer]

| Listing A34. Best prompt for CWE-20 to CWE-399 (round 6, validation F1 = 0.8421). |
| Analyze C/C++ code for true memory safety vulnerabilities: buffer
overflow, out-of-bounds write, use-after-free, null pointer dereference, and integer
overflow leading to corruption. 1. Taint and sink tracing Identify inputs from read, recv, gets, scanf, command-line arguments, environment, file I/O, struct fields, globals, return values, and pointer chains. 2. Validation checks A safe check must appear before the operation and must constrain the tainted value against the real buffer capacity or valid range. 3. Integer issues Check overflow, underflow, signedness conversion, and truncation when values influence allocation, indexing, or memory operation sizes. 4. Memory lifetime Check whether freed pointers are reused or freed again, and whether possibly NULL pointers are dereferenced. Output only 0 or 1. |
Appendix E. Category F: Strongest Validation/Test Consistency
CWE-125 → CWE-399 [Positive Transfer]

| Listing A35. Best prompt for CWE-125 to CWE-399 (round 8, validation F1 = 0.8506). |
| INFO_HINT_PROMPT: Analyze C/C++ code for true vulnerabilities to maximize positive F1. Use the following reasoning to distinguish vulnerable code from safe code. Core principles: - Flag if a dangerous operation is reachable with an input that can violate a safety property on any demonstrable data-flow path. - Treat functions as correctly implemented only when their contract is evident from the code. - Compile-time constants and inherently safe constructs are safe. - A check makes a later use safe only if it appears on all paths reaching the dangerous operation. Checklist: 1. Memory and resource checks Flag use of a pointer or resource without a required NULL or errorreturn check. 2. Buffer and bounds checks Flag unsafe access if the index, length, or pointer offset is not constrained by the actual capacity. 3. Integer safety Flag arithmetic that can overflow or underflow and then influence allocation, indexing, or loop bounds. 4. Lifetime safety Flag use-after-free and double-free on reachable paths. 5. Path sensitivity Only output 0 if all reachable paths are safe. Output only 0 or 1. |
References
- Chakraborty, S.; Krishna, R.; Ding, Y.; Ray, B. Deep Learning Based Vulnerability Detection: Are We There Yet? IEEE Trans. Softw. Eng. 2022, 48, 3280–3296. [Google Scholar] [CrossRef]
- Feng, Z.; Guo, D.; Tang, D.; Duan, N.; Feng, X.; Gong, M.; Shou, L.; Qin, B.; Liu, T.; Jiang, D.; et al. CodeBERT: A Pre-Trained Model for Programming and Natural Languages. In Proceedings of the Findings of the Association for Computational Linguistics: EMNLP 2020, Online, 16–20 November 2020; pp. 1536–1547. [Google Scholar] [CrossRef]
- Wang, Y.; Wang, W.; Joty, S.; Hoi, S.C. 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, Online, 7–11 November 2021; pp. 8696–8708. [Google Scholar] [CrossRef]
- Ding, Y.; Fu, Y.; Ibrahim, O.; Sitawarin, C.; Chen, X.; Alomair, B.; Wagner, D.; Ray, B.; Chen, Y. Vulnerability Detection with Code Language Models: How Far are We? In Proceedings of the 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE), Lisbon, Portugal, 14–20 April 2025; pp. 1729–1741. [Google Scholar] [CrossRef]
- Shin, T.; Razeghi, Y.; Logan, R.L., IV; Wallace, E.; Singh, S. AutoPrompt: Eliciting Knowledge from Language Models with Automatically Generated Prompts. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP), Online, 16–20 November 2020; pp. 4222–4235. [Google Scholar] [CrossRef]
- Gao, T.; Fisch, A.; Chen, D. Making Pre-trained Language Models Better Few-shot Learners. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), Online, 1–6 August 2021; pp. 3816–3830. [Google Scholar] [CrossRef]
- Ma, Y.; Luo, S.; Shang, Y.M.; Zhang, Y.; Li, Z. Enhancing source code classification effectiveness via prompt learning incorporating knowledge features. Sci. Rep. 2024, 14, 20220. [Google Scholar] [CrossRef] [PubMed]
- Yang, C.; Wang, X.; Lu, Y.; Liu, H.; Le, Q.V.; Zhou, D.; Chen, X. Large Language Models as Optimizers. In Proceedings of the International Conference on Learning Representations, Vienna, Austria, 7–11 May 2024; Volume 2024, pp. 12028–12068. Available online: https://proceedings.iclr.cc/paper_files/paper/2024/file/3339f19c5fcee3ad74502947a32be9e6-Paper-Conference.pdf (accessed on 1 January 2026).
- Pryzant, R.; Iter, D.; Li, J.; Lee, Y.; Zhu, C.; Zeng, M. Automatic prompt optimization with "gradient descent" and beam search. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, Singapore, 6–10 December 2023; pp. 7957–7968. [Google Scholar] [CrossRef]
- Yuksekgonul, M.; Bianchi, F.; Boen, J.; Liu, S.; Lu, P.; Huang, Z.; Guestrin, C.; Zou, J. Optimizing generative AI by backpropagating language model feedback. Nature 2025, 639, 609–616. [Google Scholar] [CrossRef] [PubMed]
- Chang, S.; Geng, C.; Huang, H.; Wang, R.; Li, Q.; Zhang, Y. CodeSpeak: Improving smart contract vulnerability detection via LLM-assisted code analysis. J. Syst. Softw. 2026, 231, 112635. [Google Scholar] [CrossRef]
- Li, Z.; Zou, D.; Xu, S.; Jin, H.; Zhu, Y.; Chen, Z. SySeVR: A Framework for Using Deep Learning to Detect Software Vulnerabilities. IEEE Trans. Dependable Secur. Comput. 2022, 19, 2244–2258. [Google Scholar] [CrossRef]
- Zhou, Y.; Liu, S.; Siow, J.; Du, X.; Liu, Y. Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networks. In Proceedings of the Advances in Neural Information Processing Systems, Vancouver, BC, Canada, 8–14 December 2019; Wallach, H., Larochelle, H., Beygelzimer, A., d’Alché-Buc, F., Fox, E., Garnett, R., Eds.; Curran Associates, Inc.: Red Hook, NY, USA, 2019; Volume 32, Available online: https://proceedings.neurips.cc/paper_files/paper/2019/file/49265d2447bc3bbfe9e76306ce40a31f-Paper.pdf (accessed on 1 January 2026).
- Ahmad, W.; Chakraborty, S.; Ray, B.; Chang, K.W. Unified pre-training for program understanding and generation. In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Online, 6–11 June 2021; pp. 2655–2668. [Google Scholar] [CrossRef]
- Guo, D.; Lu, S.; Duan, N.; Wang, Y.; Zhou, M.; Yin, J. 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), Dublin, Ireland, 22–27 May 2022; pp. 7212–7225. [Google Scholar] [CrossRef]
- Fan, J.; Li, Y.; Wang, S.; Nguyen, T.N. A C/C++ Code Vulnerability Dataset with Code Changes and CVE Summaries. In Proceedings of the 17th International Conference on Mining Software Repositories, Seoul, Republic of Korea, 29–30 June 2020; pp. 508–512. [Google Scholar] [CrossRef]
- Chen, Y.; Ding, Z.; Alowain, L.; Chen, X.; Wagner, D. 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, Hong Kong, China, 16–18 October 2023; pp. 654–668. [Google Scholar] [CrossRef]
- Wagner, J.; Müller, S.; Näther, C.; Steghöfer, J.P.; Both, A. Towards Effective Complementary Security Analysis Using Large Language Models. In Proceedings of the 2025 IEEE International Conference on Intelligence and Security Informatics (ISI), Hong Kong, China, 12–13 July 2025; pp. 21–28. [Google Scholar] [CrossRef]
- Nazzal, M.; Khalil, I.; Khreishah, A.; Phan, N. PromSec: Prompt Optimization for Secure Generation of Functional Source Code with Large Language Models (LLMs). In Proceedings of the 2024 ACM SIGSAC Conference on Computer and Communications Security, Salt Lake City, UT, USA, 14–18 October 2024; pp. 2266–2280. [Google Scholar] [CrossRef]
- Zhou, X.; Cao, S.; Sun, X.; Lo, D. Large Language Model for Vulnerability Detection and Repair: Literature Review and the Road Ahead. ACM Trans. Softw. Eng. Methodol. 2025, 34. [Google Scholar] [CrossRef]
- Pearce, H.; Tan, B.; Ahmad, B.; Karri, R.; Dolan-Gavitt, B. Examining zero-shot vulnerability repair with large language models. In Proceedings of the 2023 IEEE Symposium on Security and Privacy, San Francisco, CA, USA, 21–25 May 2023; pp. 2339–2356. [Google Scholar] [CrossRef]
- Muske, T.; Serebrenik, A. Survey of Approaches for Handling Static Analysis Alarms. In Proceedings of the 2016 IEEE 16th International Working Conference on Source Code Analysis and Manipulation (SCAM), Raleigh, NC, USA, 2–3 October 2016; pp. 157–166. [Google Scholar] [CrossRef]
- Zhou, Y.; Muresanu, A.I.; Han, Z.; Paster, K.; Pitis, S.; Chan, H.; Ba, J. Large Language Models are Human-Level Prompt Engineers. In Proceedings of the Eleventh International Conference on Learning Representations, Kigali, Rwanda, 1–5 May 2023; Available online: https://openreview.net/forum?id=92gvk82DE- (accessed on 1 August 2026).
- Kwon, M.; Kim, G.; Kim, J.; Lee, H.; Kim, J. StablePrompt: Automatic Prompt Tuning using Reinforcement Learning for Large Language Model. In Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing, Miami, FL, USA, 12–16 November 2024; pp. 9868–9884. [Google Scholar] [CrossRef]
- Batorski, P.; Swoboda, P. PIAST: Rapid Prompting with In-context Augmentation for Scarce Training data. In Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), San Diego, CA, USA, 2–7 July 2026; pp. 11222–11242. [Google Scholar] [CrossRef]
- Dong, Z.; Shang, L.; Olinto, G. GreenTEA: Gradient Descent with Topic-modeling and Evolutionary Auto-prompting. In Proceedings of the First International KDD Workshop on Prompt Optimization, Toronto, ON, Canada, 4 August 2025; Available online: https://openreview.net/forum?id=eoJpYybmOH (accessed on 1 January 2026).
- Lee, J.; Seo, W.; An, H.; Lee, S.; Bu, Y. Better by Comparison: Retrieval-Augmented Contrastive Reasoning for Automatic Prompt Optimization. In Proceedings of the 2025 ACM/IEEE Joint Conference on Digital Libraries (JCDL), DeKalb, IL, USA, 15–19 December 2025; pp. 269–272. [Google Scholar] [CrossRef]
- Khattab, O.; Singhvi, A.; Maheshwari, P.; Zhang, Z.; Santhanam, K.; A, S.V.; Haq, S.; Sharma, A.; Joshi, T.T.; Moazam, H.; et al. DSPy: Compiling Declarative Language Model Calls into State-of-the-Art Pipelines. In Proceedings of the Twelfth International Conference on Learning Representations, Vienna, Austria, 7–11 May 2024; Available online: https://openreview.net/forum?id=sY5N0zY5Od (accessed on 1 January 2026).
- Yang, Y.; Zhou, X.; Mao, R.; Xu, J.; Yang, L.; Zhang, Y.; Shen, H.; Zhang, H. DLAP: A Deep Learning Augmented Large Language Model Prompting framework for software vulnerability detection. J. Syst. Softw. 2025, 219, 112234. [Google Scholar] [CrossRef]
- Ribeiro, M.T.; Singh, S.; Guestrin, C. “Why should i trust you?” Explaining the predictions of any classifier. In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, San Francisco, CA, USA, 13–17 August 2016; pp. 1135–1144. [Google Scholar] [CrossRef]
- Lundberg, S.M.; Lee, S.I. A unified approach to interpreting model predictions. In Proceedings of the 31st International Conference on Neural Information Processing Systems, Long Beach, CA, USA, 4–9 December 2017; pp. 4768–4777. Available online: https://dl.acm.org/doi/10.5555/3295222.3295230 (accessed on 1 January 2026).
- Sundararajan, M.; Taly, A.; Yan, Q. Axiomatic Attribution for Deep Networks. Proc. Mach. Learn. Res. 2017, 70, 3319–3328. Available online: https://proceedings.mlr.press/v70/sundararajan17a.html (accessed on 1 January 2026).
- Qiang, Y.; Pan, D.; Li, C.; Li, X.; Jang, R.; Zhu, D. AttCAT: Explaining Transformers via Attentive Class Activation Tokens. In Proceedings of the Advances in Neural Information Processing Systems, New Orleans, LA, USA, 28 November–9 December 2022; Koyejo, S., Mohamed, S., Agarwal, A., Belgrave, D., Cho, K., Oh, A., Eds.; Curran Associates, Inc.: Red Hook, NY, USA, 2022; Volume 35, pp. 5052–5064. [Google Scholar] [CrossRef]
- Song, L.; Cui, Y.; Luo, A.; Lecue, F.; Li, I. Better Explain Transformers by Illuminating Important Information. In Proceedings of the Findings of the Association for Computational Linguistics: EACL 2024, St. Julian’s, Malta, 17–22 March 2024; pp. 2048–2062. [Google Scholar] [CrossRef]
- Rabin, M.R.I.; Bui, N.D.; Wang, K.; Yu, Y.; Jiang, L.; Alipour, M.A. On the generalizability of neural program models with respect to semantic-preserving program transformations. Inf. Softw. Technol. 2021, 135, 106552. [Google Scholar] [CrossRef]
- Yefet, N.; Alon, U.; Yahav, E. Adversarial examples for models of code. Proc. ACM Program. Lang. 2020, 4, 1–30. [Google Scholar] [CrossRef]
- Pintore, M.; Piras, G.; Sotgiu, A.; Pintor, M.; Biggio, B. Evaluating line-level localization ability of learning-based code vulnerability detection models. Mach. Learn. 2026, 115, 94. [Google Scholar] [CrossRef]
- Cheng, B.; Zhao, S.; Wang, K.; Wang, M.; Bai, G.; Feng, R.; Guo, Y.; Ma, L.; Wang, H. Beyond Fidelity: Explaining Vulnerability Localization of Learning-Based Detectors. ACM Trans. Softw. Eng. Methodol. 2024, 33, 1–33. [Google Scholar] [CrossRef]




| CWE | Description |
|---|---|
| CWE-284 | Improper Access Control |
| CWE-416 | Use After Free |
| CWE-200 | Exposure of Sensitive Information |
| CWE-399 | Resource Management Errors |
| CWE-264 | Permissions, Privileges, and Access Controls |
| CWE-119 | Improper Restriction of Operations within the Bounds of a Memory Buffer |
| CWE-20 | Improper Input Validation |
| CWE-190 | Integer Overflow or Wraparound |
| CWE-189 | Numeric Errors |
| CWE-362 | Race Condition |
| CWE-787 | Out-of-bounds Write |
| CWE-125 | Out-of-bounds Read |
| CWE-476 | NULL Pointer Dereference |
| CWE-703 | Improper Check or Handling of Exceptional Conditions |
| CWE | Raw Pos | Raw Neg | Dedup Pos | Dedup Neg | Dedup Rate (%) |
|---|---|---|---|---|---|
| CWE-20 | 2766 | 49,627 | 1958 | 32,306 | 29.2 |
| CWE-119 | 4,64 | 59,514 | 2881 | 35,412 | 30.8 |
| CWE-125 | 2568 | 35,304 | 1675 | 23,539 | 34.8 |
| CWE-189 | 747 | 14,252 | 516 | 7419 | 30.9 |
| CWE-190 | 1081 | 15,013 | 806 | 10,217 | 25.4 |
| CWE-200 | 1450 | 25,231 | 986 | 14,961 | 32.0 |
| CWE-264 | 861 | 23,447 | 605 | 12,960 | 29.7 |
| CWE-284 | 542 | 9884 | 437 | 7173 | 19.4 |
| CWE-362 | 743 | 16,325 | 546 | 9477 | 26.5 |
| CWE-399 | 1354 | 25,872 | 1008 | 16,851 | 25.6 |
| CWE-416 | 1449 | 35,942 | 1141 | 25,159 | 21.3 |
| CWE-476 | 1248 | 24,429 | 905 | 16,358 | 27.5 |
| CWE-703 | 1004 | 19,247 | 884 | 15,599 | 11.9 |
| CWE-787 | 1874 | 26,315 | 1614 | 22,162 | 13.9 |
| Total | 21,851 | 380,402 | 15,962 | 249,593 | 27.0 |
| Method | Main Feedback Signal |
|---|---|
| Fine-CodeSpeak | Code-oriented feedback generated for validation samples |
| Fine-DLAP-simplified | Simplified validation-based prompt adaptation feedback |
| Fine-OPRO | Historical prompts and validation metrics |
| Fine-TextGrad | Natural-language textual gradients and error feedback |
| Fine-IGPO | IG-selected lines, FP/FN error types, LLM error diagnosis, and validation metrics |
| Setting | Count | Average Precision | Average Recall | Average F1 Score |
|---|---|---|---|---|
| Diagonal source–target pairs | 14 | – | – | 0.8601 |
| All non-diagonal transfer pairs | 182 | 0.6419 | 0.7358 | 0.6518 |
| Positive-transfer pairs | 159 | – | – | – |
| Negative-transfer pairs | 23 | – | – | – |
| Method | Avg. F1 Score | Avg. ΔF1 vs. Fine | Exceed Fine | Exceed Ratio | Avg. Rank | Pred. Degen. |
|---|---|---|---|---|---|---|
| Fine-IGPO | 0.7267 | 0.0487 | 151 | 94.97% | 1.3019 | 6/3.77% |
| Fine-TextGrad | 0.6975 | 0.0195 | 104 | 65.41% | 3.8931 | 4/2.52% |
| Fine-OPRO | 0.6974 | 0.0195 | 86 | 54.09% | 4.1164 | 5/3.14% |
| Fine-role-play | 0.6782 | 0.0007 | 41 | 25.95% | 5.7468 | 9/5.66% |
| Fine-ZS | 0.6780 | 0.0000 | – | – | 5.9403 | 9/5.66% |
| Fine-CWE-definition | 0.6772 | −0.0003 | 43 | 27.22% | 5.7405 | 10/6.29% |
| Fine-checklist | 0.6681 | −0.0094 | 29 | 18.35% | 6.3797 | 6/3.77% |
| Fine-CodeSpeak | 0.6546 | −0.0234 | 68 | 42.77% | 6.3113 | 0/0.00% |
| Fine-few-shot † | 0.6526 | −0.0253 | 72 | 45.28% | 6.8648 | 5/3.14% |
| Fine-few-shot ‡ | 0.6480 | −0.0295 | 63 | 39.87% | 6.7627 | 19/11.95% |
| Fine-DLAP-simplified | 0.6270 | −0.0510 | 24 | 15.09% | 8.7484 | 0/0.00% |
| Variant | Average Precision | Average Recall | Average F1 Score |
|---|---|---|---|
| Full error samples without IG attribution | 0.5794 | 0.7663 | 0.6598 |
| Random two code lines | 0.5444 | 0.3754 | 0.4243 |
| FN-only feedback | 0.5403 | 0.7950 | 0.6421 |
| FP-only feedback | 0.6443 | 0.5661 | 0.5987 |
| Without LLM error diagnosis | 0.6321 | 0.8059 | 0.7085 |
| Top-4 IG-selected lines | 0.6158 | 0.7211 | 0.6639 |
| Top-6 IG-selected lines | 0.6101 | 0.5230 | 0.5570 |
| IGPO full | 0.6664 | 0.8378 | 0.7267 |
| Indicator | All (182) | Positive (159) | Negative (23) |
|---|---|---|---|
| Val set size (samples) | 80 | 80 | 80 |
| Avg. optimization rounds | 10.0 | 10.0 | 10.0 |
| Mean val. F1 score std across rounds | 0.037 | 0.035 | 0.053 |
| Median val. F1 score std across rounds | 0.030 | 0.029 | 0.055 |
| Avg. peak round (0-indexed) | 3.58 | 3.45 | 4.48 |
| Best prompt in first half (%) | 59.3 | 59.7 | 56.5 |
| Best prompt at final round (%) | 8.8 | 5.7 | 30.4 |
| Avg. val–test F1 score gap | 0.033 | 0.028 | 0.071 |
| Avg. val F1 score improvement () | 0.044 | 0.040 | 0.069 |
| Round | Prompt Focus | Metric | IG-Based Diagnostic Feedback |
|---|---|---|---|
| R0 | Defines CWE-416 as alloc–free–use lifecycle tracing across execution paths. | F1 score: 0.5849; Precision: 0.5536; Recall: 0.6200 | High-attribution regions in FP cases are often associated with names, constants, and return statements; FN cases show relatively weak attribution on lifetime-related operations. |
| R1 | Adds positive and negative examples for direct UAF and safe reassignment after free. | F1 score: 0.8000; Precision: 0.7333; Recall: 0.8800 | Recall improves substantially. The remaining FP cases still show high attribution on unrelated names, getter-like functions, and reference-counting cues. |
| R2 | Adds a negative example where freeing followed by return is safe. | F1 score: 0.6458; Precision: 0.6739; Recall: 0.6200 | The prompt becomes more conservative. In FN cases, attribution is more frequently observed around cleanup or state-update operations rather than explicit use-after-free patterns. |
| R3 | Adds an alias-based positive example where one pointer is freed and another alias is later used. | F1 score: 0.7273; Precision: 0.5854; Recall: 0.9600 | Recall increases, but precision drops. The attribution pattern suggests that the detector may be over-sensitive to pointer-like names and benign return statements. |
| R4 | Adds a positive example where passing the address of a freed pointer is treated as unsafe use. | F1 score: 0.7218; Precision: 0.5783; Recall: 0.9600 | High recall is maintained, but FP cases continue to show high attribution on surface-level tokens and benign pointer-return patterns. |
| Error Type | IG Signal | Prompt Implication |
|---|---|---|
| FP | Surface tokens, such as names, constants, or return statements | Avoid treating superficial cues as sufficient vulnerability evidence |
| FP | Reference-counting or lifetime-related fields without unsafe access | Require complete alloc–free–use evidence |
| FN | Cleanup, nullification, or state-update operations | Track state changes after deallocation |
| FN | Deallocation followed by alias use | Strengthen cross-statement lifetime and alias reasoning |
| Line | Code Snippet | IG Score | Sem. Relevant |
|---|---|---|---|
| Sample: Vulnerable (target = 1) | |||
| IG-selected lines | |||
| 12 | return 0; | 3.145 | √ boundary logic |
| 17 | *data += 1 + len; | 2.640 | √ pointer arith. |
| Randomly selected lines | |||
| 6 | (empty line) | — | × no semantics |
| 20 | } | — | × no semantics |
| Sample: Patched (target = 0) | |||
| IG-selected lines | |||
| 17 | *data += 1 + len; | 19.401 | √ pointer arith. |
| 14 | *buffer = p_malloc(pool, len); | 6.556 | √ memory alloc. |
| Randomly selected lines | |||
| 6 | (empty line) | — | × no semantics |
| 20 | } | — | × no semantics |
| Method | Optimizer Calls | Time (s) | Main Cost Source |
|---|---|---|---|
| CodeSpeak | 160 * | 1536 | Per-sample feedback generation |
| DLAP-simplified | 160 * | 1937 | Per-sample prompt-adaptation feedback |
| OPRO | 4 | 110 | Iterative prompt generation and validation |
| TextGrad | 17 | 180 | Textual-gradient feedback and prompt revision |
| IGPO | 17 | 922 | Integrated-gradient computation and prompt revision |
| Outcome | Number of Pairs | Ratio (%) |
|---|---|---|
| Fully recovers to Base-ZS level | 4 | 17.4 |
| Partially stabilizes degradation | 10 | 43.5 |
| Marginally aggravates degradation | 9 | 39.1 |
| Base-ZS outperforms IGPO | 19 | 82.6 |
| CWE Type | Number of Pairs | Ratio Among Negative-Transfer Pairs (%) |
|---|---|---|
| CWE-787 | 14 | 60.9 |
| CWE-703 | 6 | – |
| CWE-119 | 5 | – |
| Detector Backbone | Optimizer Model | Pairs | Fine-ZS F1 Score | Fine-IGPO F1 Score | Avg. ΔF1 | Win Rate |
|---|---|---|---|---|---|---|
| Qwen2.5-Coder-7B | DeepSeek-V4-Flash | 20 | 0.6612 | 0.7114 | 0.0502 | 100.00% |
| Qwen2.5-Coder-7B | GPT-5.5 | 20 | 0.6612 | 0.7036 | 0.0424 | 100.00% |
| DeepSeek-Coder-6.7B | DeepSeek-V4-Flash | 20 | 0.6537 | 0.7006 | 0.0469 | 100.00% |
| DeepSeek-Coder-6.7B | GPT-5.5 | 20 | 0.6537 | 0.7213 | 0.0676 | 100.00% |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.
Share and Cite
Xie, X.; Lu, Z.; Yao, N. Attribution-Guided Prompt Optimization for Cross-CWE Vulnerability Detection. Information 2026, 17, 762. https://doi.org/10.3390/info17080762
Xie X, Lu Z, Yao N. Attribution-Guided Prompt Optimization for Cross-CWE Vulnerability Detection. Information. 2026; 17(8):762. https://doi.org/10.3390/info17080762
Chicago/Turabian StyleXie, Xudong, Zhimao Lu, and Nianmin Yao. 2026. "Attribution-Guided Prompt Optimization for Cross-CWE Vulnerability Detection" Information 17, no. 8: 762. https://doi.org/10.3390/info17080762
APA StyleXie, X., Lu, Z., & Yao, N. (2026). Attribution-Guided Prompt Optimization for Cross-CWE Vulnerability Detection. Information, 17(8), 762. https://doi.org/10.3390/info17080762

