NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Learning to Quantize Vulnerability Patterns and Match to Locate Statement-Level Vulnerabilities

Michael Fu, Trung Le, Van Nguyen, Chakkrit Tantithamthavorn, Dinh Q. PhungarXiv 2023 · DOI

Abstract

Software vulnerability detection remains a critical challenge, particularly at the statement level. Traditional static analysis tools are precise but brittle, while deep learning models often struggle with long sequences and precise localization. This paper introduces OPTIMATCH, a framework that bridges this gap by learning a "codebook" of quantized vulnerability patterns. By utilizing RNN-based statement embeddings to bypass Transformer token limits and Optimal Transport to cluster vulnerable scopes into representative centroids, OPTIMATCH achieves a 94% F1-score in function-level detection and an 82% F1-score in statement-level localization—a 19% improvement over previous state-of-the-art methods.

Introduction

The rapid increase in software vulnerabilities necessitates automated detection tools. Current methodologies generally fall into two categories: static analysis and deep learning. Static analysis tools rely on predefined patterns, making them precise but unable to generalize to different coding styles. Conversely, deep learning models learn implicitly from data but often fail at statement-level detection and suffer from input length constraints. Standard Transformers, for instance, are limited by a strict token count, often truncating long functions and losing vital context.

Methods

The OPTIMATCH framework employs a two-phase approach to address these limitations.

Phase 1: RNN-based Statement Embedding

To handle long code sequences, the model uses a Recurrent Neural Network (RNN) to compress tokens into statement-level embeddings. This hierarchical approach allows the model to process up to 3,100 tokens per function—six times the capacity of standard models like CodeBERT—ensuring comprehensive representation for 99% of functions in the Big-Vul dataset.

Phase 1: RNN-based statement embedding and Transformer encoding process.

Phase 2: Vulnerability Codebook and Explicit Matching

The core innovation is the creation of a "Vulnerability Codebook." The model extracts "vulnerable scopes" (groups of statements known to be buggy) from training data and uses Optimal Transport (OT) with Wasserstein distance to cluster these into 150 representative centroids, or "codewords."

Phase 2: Learning the Vulnerability Codebook and the explicit matching mechanism.

During inference, the model explicitly matches input code against these centroids. If a code segment aligns closely with a vulnerability centroid, it is flagged. This quantization allows the model to ignore superficial noise (e.g., variable names) and focus on the underlying structural vulnerability patterns.

Datasets and Results

The framework was evaluated using Big-Vul, comprising 188,000 C/C++ functions from 348 GitHub projects across 91 CWE types. The dataset maintains a realistic 1:20 ratio of vulnerable to benign functions. OPTIMATCH demonstrated significant performance gains:

  • Function-Level Detection: 94% F1-score (6% improvement over previous SOTA).
  • Statement-Level Detection: 82% F1-score (a staggering 19% improvement).

Furthermore, integrating the RNN-based embedding into existing models like CodeBERT and CodeGPT resulted in a 30% performance boost for statement-level tasks, highlighting the importance of effective code representation over architecture alone.

Discussion and Limitations

OPTIMATCH demonstrates that explicit pattern matching, combined with hierarchical neural representations, significantly enhances vulnerability localization. However, the authors note several areas for future work:

  • Hyperparameter Tuning: The number of centroids ($k$) in the codebook currently requires manual tuning.
  • Scalability: Future iterations may require "adaptive quantization" to automatically determine the necessary number of patterns for larger datasets.
  • Zero-day Vulnerabilities: As a supervised method, the model may struggle with entirely new vulnerability patterns not represented in its codebook.

The research team has open-sourced their training code and pre-trained models to encourage the community to build upon this matching paradigm.

Summary updated

BibTeX
@misc{fu2023learning,
  author = {Michael Fu and Trung Le and Van Nguyen and Chakkrit Tantithamthavorn and Dinh Q. Phung},
  title = {{Learning to Quantize Vulnerability Patterns and Match to Locate Statement-Level Vulnerabilities}},
  year = {2023},
  eprint = {2306.06109},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.06109},
}
Figure