# Structure-Enhanced Prompt Learning for Graph-Based Code Vulnerability Detection
## 3 Methodology
### Structure-Enhanced Prompt
#### 3.3.1 Generation of Structured Prompt  
To facilitate knowledge-driven generation of structured prompts, we first identify key structural features in graph data and encode them effectively. Since graphs differ from Euclidean data, their structure is best captured using adjacency matrices. Extracting structure-specific knowledge from class-associated graphs enables the creation of task-specific prompts. In our approach, we utilize graphons to efficiently model task-related knowledge within graph structures. A graphon [44] is a continuous representation of large-scale networks, capturing generalized structural properties. It defines probabilistic node relationships as random functions over the unit square. Graphon estimation typically employs spectral methods, singular value decomposition or smoothing techniques on observed graph data. It is a continuous, bounded, and symmetric function:  
\[W:[0,1]^{2}\rightarrow[0,1] \tag{4}\]  
which can be interpreted as the weight matrix of a graph with an infinite number of nodes [45]. In this work, we define a graphon as a two-dimensional matrix of the form:  
\[W=[w_{kk^{\prime}}]\in[0,1]^{K\times K} \tag{5}\]  
where \(w_{kk^{\prime}}\) denotes an element of matrix \(W\), representing the probability of an edge between nodes \(k\) and node \(k^{\prime}\). When treating a class of graphs as a set, the corresponding graphon captures its generalized structural characteristics and adjacency patterns. Leveraging the generative properties of graphons, we construct new topological structures as prompts for further analysis. Building on the previous analysis, we extract class-specific knowledge for downstream tasks by using graphons [46] as templates. These graphons, which represent innovative topological structures, form the foundation for generating class-specific subprompts at the graph level. The process involves a series of well-defined steps, as outlined below:  
* Given a dataset with two types of graphs, we divide the training set \(G_{train}\) by class to obtain two types of graph sets \(\{G_{c}|C=0,1\}\), representing robust and vulnerable. * The degree of the nodes serves as the metric for each graph set \(G_{c}\). The alignment procedure begins by sorting the nodes in descending order of degree, then reorganizing the adjacency matrix accordingly. * The graphon \(W^{c}\in\mathbb{R}^{K\times K}\) is estimated from the aligned graphs in \(G_{c}\) using \[W_{c}=Estimation(G_{c}^{{}^{\prime}})\] (6) where \(Estimation(\cdot)\) denotes the graphon estimation operator and \(G_{c}^{{}^{\prime}}\) represents aligned graph sets. \(K\) is the number of nodes that account for 80% of the total nodes in the graph set \(G_{c}^{{}^{\prime}}\). We adopt Universal Singular Value Thresholding (USVT) [47] for graphon estimation. This method stacks adjacency matrices of aligned graphs and applies Singular Value Decomposition (SVD) to extract dominant structural features. The resulting graphon \(W^{c}\) captures the generalized structural characteristics of the graphs in \(G_{c}\), providing a distribution that can generate topological structures. The topology of a graph-level structured prompt, consisting of \(K^{{}^{\prime}}\) nodes, is generated through the following sampling process:  
\[v_{1}...v_{K^{{}^{\prime}}}\sim Uniform_{[0,1]},\text{for }n=1,\dots K^{{}^{ \prime}} \tag{7}\]\[a_{m^{\prime}}\sim Bernoulli(W^{c}(i,j)),\forall_{i,j}\in[K^{{}^{\prime}}] \tag{8}\]  
First, \(K^{{}^{\prime}}\) nodes are independently sampled from a uniform distribution \(Uniform_{[0,1]}\) over the interval \([0,1]\). Next, an adjacency matrix \(A_{c}=[a_{i,j}]\in 0,1^{K^{{}^{\prime}}\times K^{{}^{\prime}}}\) is constructed using a Bernoulli distribution parameterized by \(W^{c}\). Since the estimated graphon captures the common structural patterns and adjacency relationships across a family of graphs, the subprompts generated via the Bernoulli distribution are expected to reflect these shared structures.