LLM vulnerability detection relies on safety-pattern attention heads, not direct vulnerability signatures
The model detects vulnerable code mainly via safety detectors rather than explicit vulnerability features
AI/ML arXiv 28 May 2026 Measurement Prototype evidence
Published as “Dissecting the Black Box: Circuit-Level Analysis of LLM Vulnerability Detection”
Why it matters
Understanding the sparse safety-detector circuit enables targeted improvements and explanations for LLM-based security tools.
Summary
The model’s vulnerability detection hinges on safety detectors: attention heads that fire on safe code patterns, and a small set of MLP neurons; when these fail, the model flags code as vulnerable. Ablating Layer 11 drops detection accuracy from 100% to 6%, and removing just 20 neurons in Layer 7 cuts it by 50%, showing a sparse 16% circuit. Evidence comes from mechanistic tracing on 472 balanced C/C++ samples from the PrimeVul benchmark, with statistical tests confirming distinct activation patterns.
What they found 4
- Ablating Layer 11 destroys detection ability
“removing Layer 11 drops vulnerability detection accuracy from 100% to 6%”
- Ablating 20 neurons in Layer 7 halves detection performance
“ablating just 20 neurons in Layer 7 reduces it by 50%”
- Only a small fraction of the model is active during detection
“only 16.1% (1,597 out of 9,944) of the probed nodes were active during the inference of the vulnerable sample.”
- Top attention heads act as safety detectors
“Negative scores indicate the head is more active in safe code (Safety Detectors).”
Caveats 3
- Layer 10 ablation dropped TP to 19.3% but kept TN at 96.9%
- removing Layer 11 resulted in a 94% drop in TP accuracy (from 100% to 6.02%)
- Future work should extend this analysis to other model architectures
What’s new here 4
- First mechanistic interpretability study of LLM vulnerability detection.
- Discovery that detection relies on safety-detector attention heads rather than direct vulnerability signatures.
- Quantification of a sparse circuit using only 16.1% of model capacity.
- Causal ablation showing that a handful of neurons and a single layer dominate detection performance.