Vulnerability detectors miss the patch, not the bug: PatchCon weights vulnerable–patched pairs as hard negatives and lifts pairwise accuracy from 0.2060 to 0.3264
Synopsis
PatchCon treats a vulnerable function and its patched version as a hard negative pair in contrastive learning, giving that pair a larger weight and training it jointly with vulnerability classification. Most detectors had treated functions as independent samples and were scored mainly with accuracy and F1, which do not show whether a model can separate a vulnerable function from a minimally changed fix. On PairVul-Linux, built from Linux kernel CVEs and their patches, PatchCon raises pairwise accuracy from 0.2060 for the strongest reproduced baseline to 0.3264, and keeps the highest pairwise accuracy among reproduced models on CVEs unseen in training and on vulnerabilities disclosed after the training cutoff.
Interpretation
A vulnerability detector is now asked a finer question: given the vulnerable and patched versions of the same function, can it label the first vulnerable and the second safe. Earlier detectors classified functions as independent samples and were evaluated mainly with accuracy, precision and F1, which do not directly show whether a model gives a vulnerable function higher vulnerability confidence than its fix. On PairVul-Linux, PatchCon reaches a pairwise accuracy of 0.3264 against 0.2060 for the strongest reproduced baseline, DELTA, and its mean confidence gap rises to 0.1838 from near zero.
The method trains vulnerability classification and weighted supervised contrastive learning together on a CodeBERT encoder, pushing a vulnerable function away from its patched version in representation space. Supervised contrastive learning had been applied to vulnerability detection, but existing designs either did not use vulnerable–patched pairs or treated them like ordinary negatives. Training builds four pair types, same-safe, same-vulnerable, random negative and patch, and patch pairs receive a larger pair-level weight in the negative penalty; removing patch pairs in ablation drops pairwise accuracy to 0.0718, close to the CodeBERT baseline of 0.0486.
Perspective
The demonstrated scope is function-level detection on Linux kernel C code: the main experiments run on PairVul-Linux, and the generalization test uses the Linux kernel subset of VentiVul, 111 vulnerable–patched pairs from 96 CVEs, without retraining, fine-tuning or threshold adjustment.
VentiVul contains only 111 pairs, so differences among PatchCon, SCL-CVD and DELTA should be read with caution; bootstrap intervals show PatchCon's MCC gain over DELTA is not significant; each configuration is trained once with a fixed random seed, so variance across training runs is not captured.
