Keep It Simple: Towards Accurate Vulnerability Detection for Large Code Graphs

Xin Peng, Shangwen Wang, Yihao Qin, Bo Lin, Liqian Chen, Xiaoguang MaoarXiv 2024 · DOI

Abstract

Detecting vulnerabilities in large software projects is a significant challenge due to the complexity and noise inherent in large code graphs. This paper introduces ANGEL (hierarchicAl and coNtext-aware Graph rEpresentation Learning), a novel approach that prunes irrelevant code structures and combines Graph Neural Networks (GNNs) with Transformers. This hybrid architecture captures both local logic and long-distance dependencies, leading to substantial accuracy improvements, particularly in complex, large-scale codebases where traditional models typically fail.

Introduction

Modern vulnerability detection has moved toward representing code as complex graphs, such as Code Property Graphs (CPGs). While Graph Neural Networks (GNNs) have shown promise, they face two primary bottlenecks when processing large functions:

  1. The Noise Problem: In a large function, only a few lines usually cause a vulnerability. Standard models treat the entire graph equally, allowing irrelevant code to drown out the actual signal.
  2. The Long-Distance Problem: Vulnerabilities often involve dependencies between distant code elements. Standard GNNs, which primarily focus on immediate neighbors, struggle to connect these dots.

Methodology: The ANGEL Pipeline

ANGEL addresses these issues through a four-stage pipeline designed to simplify and encode code graphs effectively:

  • Parsing: Code is converted into a CPG using the Joern analysis tool.
  • Hierarchical Graph Refinement (SAPool): This "simplification engine" uses a self-adaptive pooling mechanism to score node importance and iteratively prune the least relevant nodes. This process reduces graph size by an average of 75.9%, effectively denoising the code.
  • Context-aware Graph Encoding: To solve the distance problem, ANGEL uses a hybrid architecture that alternates between GNN layers (for local syntax) and Graph Transformer (GT) layers (for global multi-head self-attention), bridging distant nodes regardless of their position.
  • Classification: The refined representation is fed into a standard MLP to predict if the code is vulnerable.

Experimental Evaluation

The researchers evaluated ANGEL on three widely recognized C/C++ benchmarks: Devign (~22k samples), Reveal (~18k samples), and Big-Vul (~188k samples).

The Long-Tail Challenge

Analysis of these datasets reveals a "long-tail" distribution of graph sizes. While most functions are small, real-world vulnerabilities are frequently distributed across very large functions. Models that perform well on average often fail on these large, critical samples.

Fig. 1: Statistics on the distribution of graph sizes and accuracy comparison across the Devign, Reveal, and Big-Vul datasets.

Key Results and Insights

ANGEL consistently outperformed state-of-the-art baselines like Devign, Reveal, and AMPLE across all metrics:

  • Massive Gains on Large Graphs: In functions with over 100 nodes, ANGEL improved accuracy by 34.27% to 161.93% compared to the previous state-of-the-art method, AMPLE.
  • F1 Score Superiority: Across the three datasets, ANGEL achieved F1 score improvements ranging from 14.0% to 43.4% over the best-performing baselines.
  • Efficiency: Despite its performance, ANGEL uses a "narrow while deep" architecture with a hidden dimension of only 64, resulting in fewer total parameters than older models.
  • Synergy of Architectures: The GNN acts as a local feature extractor, while the Transformer acts as a global bridge, preventing the "over-smoothing" issue common in deep GNNs.

Conclusion

ANGEL demonstrates that "keeping it simple" through intelligent pruning and hybrid encoding is highly effective for large-scale vulnerability detection. While challenges remain regarding data imbalance and support for complex semantic vulnerabilities (like type conversion bugs), ANGEL represents a significant step forward in making automated vulnerability detection practical for real-world software development.

Summary updated

BibTeX
@misc{peng2024keep,
  author = {Xin Peng and Shangwen Wang and Yihao Qin and Bo Lin and Liqian Chen and Xiaoguang Mao},
  title = {{Keep It Simple: Towards Accurate Vulnerability Detection for Large Code Graphs}},
  year = {2024},
  eprint = {2412.10164},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.10164},
}
Figure