TL;DR
MulVul is a novel multi-agent framework that significantly improves automated code vulnerability detection by breaking the task into a coarse-to-fine pipeline consisting of a Router agent and specialized Detector agents. To scale this across hundreds of vulnerability types without manual effort, it introduces Cross-Model Prompt Evolution, an optimization technique that decouples prompt generation from evaluation using two distinct LLMs. The framework achieves state-of-the-art accuracy on fine-grained vulnerability types, showing massive improvements in data-scarce (few-shot) scenarios.
What Problem Does This Paper Address?
Large Language Models (LLMs) show promise in security auditing, but they struggle with real-world vulnerability detection due to two main bottlenecks:
- Vulnerability Heterogeneity: Vulnerability patterns vary wildly. Detecting a buffer overflow requires reasoning about pointer arithmetic and memory bounds, whereas detecting an injection attack requires tracking untrusted data flows. A single, unified LLM struggles to master all these diverse patterns simultaneously.
- Prompt Scalability: While a multi-agent system with specialized "expert" agents for different vulnerability types makes sense, manually engineering high-quality prompts for hundreds of Common Weakness Enumeration (CWE) categories is completely unscalable. Furthermore, if these agents communicate freely, a hallucination from one can cascade and ruin the final consensus.
Methods
MulVul addresses these challenges using a multi-agent, retrieval-augmented architecture combined with an automated prompt optimization loop.
1. Coarse-to-Fine Router-Detector Architecture
Instead of querying every specialized agent for every piece of code (which is computationally prohibitive), MulVul uses a hierarchical approach:
- Router Agent: First analyzes the code and predicts the top-$k$ coarse vulnerability categories (e.g., Memory Safety, Injection).
- Detector Agents: Only the specialized detectors corresponding to the top-$k$ categories are activated to perform fine-grained identification of the exact CWE type. Crucially, detectors operate in isolation to prevent error cascading.
2. Retrieval-Augmented Generation (RAG)
To ground the LLMs and mitigate hallucinations, both the Router and Detectors use a structured code representation called SCALE (Structured Comment Tree) to query a vulnerability knowledge base. The detectors employ a contrastive retrieval strategy, pulling in-category positives, clean examples, and out-of-category hard negatives to establish sharp decision boundaries.
3. Cross-Model Prompt Evolution
To automate prompt engineering, the authors design an evolutionary algorithm that decouples prompt generation from execution across two different LLMs:
- Generator LLM (e.g., Claude): Proposes and mutates candidate prompts.
- Executor LLM (e.g., GPT-4o): Runs the prompts on training data and provides performance feedback.
By separating these roles, MulVul eliminates the "self-correction bias" inherent in single-model optimization setups (where a model struggles to objectively evaluate and improve its own instructions).
Datasets
The framework was evaluated on PrimeVul, a large-scale dataset containing:
- 6,968 vulnerable C/C++ functions.
- 229,764 benign C/C++ functions.
- Coverage across 10 broad categories and 130 distinct fine-grained CWE types, featuring a severe long-tail class imbalance typical of real-world software.
Key Insights and Ideas
- The Power of Cross-Model Feedback: LLMs have distinct internal biases. When Claude generates a prompt mutation and GPT-4o evaluates it, the resulting prompts are less likely to exploit superficial patterns, leading to instructions that generalize much better.
- Negative Constraints Reduce Hallucinations: Through the evolutionary process, the prompts naturally learned to incorporate strict negative constraints (e.g., "Do NOT infer vulnerabilities beyond these patterns", "If no strong pattern match, default to Benign"). This significantly curbed the LLM's tendency to hallucinate flaws in clean code.
- RAG Enables Cross-CWE Knowledge Transfer: Even when a specific CWE type has very few training examples, retrieving semantically similar patterns from related categories allows the model to make accurate predictions.
Key Results
MulVul was evaluated against state-of-the-art baselines, including fine-tuned models (LLM×CPG, LLMVulExp) and Graph Neural Networks (VISION).
- Type-Level Detection: MulVul achieved a 34.79% Macro-F1 score, outperforming the best baseline by 41.5% relatively. It also dramatically improved Macro-Precision to 27.90% (compared to GPT-4o's baseline of 4.76%).
- Category-Level Detection: MulVul achieved 50.41% Macro-F1, leading the pack in balancing precision and recall.
- Evolution vs. Manual Prompts: The Cross-Model Prompt Evolution mechanism boosted detection performance by 51.6% over manually designed baseline templates.
- Few-Shot Performance: For rare CWEs with fewer than 100 samples, MulVul achieved approximately 48% F1, nearly doubling the performance of the best baseline (25%), demonstrating exceptional data efficiency.
Limitations and Future Work
- Language Constraints: MulVul was evaluated exclusively on C/C++ code. Its effectiveness on memory-safe or dynamically typed languages (like Java or Python) remains untested.
- Inference Cost: Operating a multi-agent pipeline with RAG requires multiple LLM API calls ($1 + k$ calls per sample online), which might limit its adoption in large-scale, real-time batch processing or resource-constrained environments.
- Dual-Use Risks: As with any automated vulnerability detection tool, there is a risk that malicious actors could repurpose the framework to discover zero-day vulnerabilities for exploitation.
Summary updated