# Structure-Enhanced Prompt Learning for Graph-Based Code Vulnerability Detection
###### Abstract  
Recent advances in prompt learning have opened new avenues for enhancing natural language understanding in domain-specific tasks, including code vulnerability detection. Motivated by the limitations of conventional binary classification methods in capturing complex code semantics, we propose a novel framework that integrates a two-stage prompt optimization mechanism with hierarchical representation learning. Our approach leverages graphon theory to generate task-adaptive, structurally enriched prompts by encoding both contextual and graphical information into trainable vector representations. To further enhance representational capacity, we incorporate the pretrained model Code-BERTScore, a syntax-aware encoder, and Graph Neural Networks, enabling comprehensive modeling of both local syntactic features and global structural dependencies. Experimental results on three public datasets--FFmpeg+Qemu, SVuID and Reveal--demonstrate that our method performs competitively across all benchmarks, achieving accuracy rates of 64.40%, 83.44% and 90.69%, respectively. These results underscore the effectiveness of combining prompt-based learning with graph-based structural modeling, offering a more accurate and robust solution for automated vulnerability detection. vulnerability detection; syntax aware; prompt learning; graphon; code property graph 2025  
24 April 202524 April 202524 May 202524 May 202524 April 202524 April 2025  
Although task-specific knowledge integration via prompts has proven effective in the NLP and CV domains [2; 3], particularly through knowledge-aware designs [4; 5], its application to graph-structured code representations remains challenging. In theory, graph-level prompts could enhance vulnerability detection by encoding structural task knowledge. However, the highly abstract nature of graph data complicates explicit alignment between prompt structures and code semantics. This gap highlights the need for systematic approaches to evaluate and optimize graph-aware prompt adaptability in code vulnerability analysis. Furthermore, Graph Neural Networks (GNNs) suffer from long-term dependency issues [6], particularly in large code property graphs (CPGs), where distant nodes struggle to exchange information effectively. As the node count increases, this limitation becomes more pronounced. Recent studies [7] indicate that the performance of CPG-based vulnerability detection methods degrades dramatically under these conditions. Figure 1 illustrates a typical Use-After-Free (UAF) vulnerability, where the variable VARS is prematurely released at line 6 and subsequently reused at line 7. Detecting this vulnerability requires propagating taint information across eight-hop neighbors in the CPG (highlighted in Figure 2), which exceeds the effective receptive field of conventional GNNs. Although prior studies [8; 9] employ coarse-grained program dependence graphs (PDGs) to extract vulnerability features, such statement-level embeddings often fail to capture fine-grained local semantics, which are crucial for identifying subtle vulnerabilities. To address these challenges, we design a prompt optimization for vulnerability detection as a two-stage process: (1) generating graph-level prompts enriched with task-specific knowledge derived from downstream task samples, and (2) making predictions by integrating these prompts with text semantic labels. In the prompt generation phase, we introduce graphon theory [10] to systematically model structural knowledge. Figure 1: Example of a UAF vulnerability, where the variable VARS is freed and then reused. Figure 2: The simplified CPG of the vulnerable function. To further improve vulnerability detection, we propose a hierarchical representation learning strategy. This approach synergizes Convolutional Neural Networks (CNNs) with graph-based neural networks to perform syntax- and semantic-aware embeddings at multiple granularities.