Statement-Level Vulnerability Detection: Learning Vulnerability Patterns Through Information Theory and Contrastive Learning
Van Nguyen, Trung Le, Chakkrit Tantithamthavorn, Michael Fu, John Grundy, Hung Nguyen, Seyit Camtepe, Paul Quirk, Dinh Phung
TL;DR
This work tackles statement-level vulnerability detection in large code sections where vulnerabilities are sparse within functions. It introduces LEAP, an end-to-end framework that selects vulnerability-relevant statements via a learnable Bernoulli selector and optimizes this selection by maximizing the mutual information $\mathbb{I}(\tilde{F},Y)$, where $\tilde{F}$ is the selected subset; it additionally imposes a clustered spatial contrastive learning term to capture reusable vulnerability patterns across functions. Empirical results on real-world datasets CWE-399, CWE-119, and Big-Vul show that LEAP achieves higher vulnerability coverage proportion (VCP), vulnerability coverage accuracy (VCA), and Top-10 accuracy than baselines, with improvements of about 3–14 percentage points, and benefits further from semi-supervised labeling. Ablation studies demonstrate the contributions of mutual information and CSCL, while additional experiments and auxiliary metrics highlight stability and interpretability; the authors also release code to support reproducibility and practical adoption.
Abstract
Software vulnerabilities are a serious and crucial concern. Typically, in a program or function consisting of hundreds or thousands of source code statements, there are only a few statements causing the corresponding vulnerabilities. Most current approaches to vulnerability labelling are done on a function or program level by experts with the assistance of machine learning tools. Extending this approach to the code statement level is much more costly and time-consuming and remains an open problem. In this paper, we propose a novel end-to-end deep learning-based approach to identify the vulnerability-relevant code statements of a specific function. Inspired by the specific structures observed in real-world vulnerable code, we first leverage mutual information for learning a set of latent variables representing the relevance of the source code statements to the corresponding function's vulnerability. We then propose novel clustered spatial contrastive learning in order to further improve the representation learning and the robust selection process of vulnerability-relevant code statements. Experimental results on real-world datasets of 200k+ C/C++ functions show the superiority of our method over other state-of-the-art baselines. In general, our method obtains a higher performance in VCP, VCA, and Top-10 ACC measures of between 3% to 14% over the baselines when running on real-world datasets in an unsupervised setting. Our released source code samples are publicly available at \href{https://github.com/vannguyennd/livuitcl}{https://github.com/vannguyennd/livuitcl.}
