Few-Shot Code-Change Prompts for LLM Vulnerability Repair
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing methods struggle to efficiently detect and remediate software vulnerabilities in source code due to their subtle nature and the lack of clear fail-stop symptoms, which complicates resource management and security in complex software systems.
Innovation Solution
A system that generates a prompt for a large language model using few-shot examples of code changes to correct specific software vulnerabilities, clustering similar changes and selecting representative examples for the prompt to guide the model in generating accurate repair code.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Measurement precision
If traditional vulnerability detection methods are used, then detection capability is limited, but computational resources and time consumption increase
Solution Approach 1:
The system performs preliminary actions by pre-processing vulnerability data and organizing it into structured formats before the actual detection process. Code changes related to vulnerabilities are collected, cleaned, and prepared in advance, allowing the large language model to work with pre-organized information during real-time detection, thus reducing operational time consumption.
Solution Approach 2:
The system creates simplified copies of vulnerability information by generating structured representations of code changes and vulnerability relationships. Instead of analyzing raw, complex codebases directly, the system uses copied and structured vulnerability data that preserves essential information while reducing computational complexity, enabling faster detection without sacrificing accuracy.
2Reliability
If fine-tuning the large language model is performed, then model accuracy improves, but computational resources and training time increase
Solution Approach 1:
The system introduces an intermediary layer between the large language model and the vulnerability detection task. Instead of fine-tuning the model directly on vulnerability data (which consumes大量 computational resources), the system uses structured vulnerability information and code change representations as intermediaries that guide the model's detection process, achieving high accuracy without extensive fine-tuning.
Solution Approach 2:
The system changes the parameters of the detection approach by using structured vulnerability data formats and organized code change representations instead of raw data. This parameter change allows the large language model to achieve high detection accuracy by working with pre-processed, well-structured information rather than requiring extensive fine-tuning on raw vulnerability datasets.
3Measurement precision
If comprehensive code analysis is performed, then vulnerability detection accuracy improves, but system complexity and processing time increase
Solution Approach 1:
The system segments the vulnerability detection process into distinct components: code change collection, data cleaning, structured representation generation, and model inference. By dividing the comprehensive code analysis into these manageable segments, the system maintains high detection accuracy while reducing overall system complexity and making each component easier to manage and optimize independently.
Data Source
AI summary
A source code repair system generates a prompt including a few-shot examples of code changes made previously to correct a particular source code vulnerability. The prompt is given to a large language model to generate repair code for a source code snippet having the same vulnerability. Code changes made for a particular source code vulnerability, in the form of code diffs, are clustered into groups of closely related code change embeddings. A select few of the code diffs in each group having a closest mean of the cluster are used as the few-shot examples for the corresponding source code vulnerability.


