- The paper introduces a hybrid pipeline that combines neural embeddings with structural graph representations to effectively match verification artefacts.
- It details a multi-stage process including source-to-graph translation, semantic enrichment via LLM embeddings, and cosine similarity based matching.
- The study demonstrates robust cross-language reuse and improved precision in matching formal specifications from diverse programming languages.
Graph-Based Construction and Matching of Imperative Programs via Neural and Structural Methods
Introduction
This work presents a comprehensive, specification-aware pipeline for constructing and matching graphs from imperative programs, integrating both neural and symbolic program representations. The focus is on enabling scalable reuse of software verification artefacts—including specifications, contracts, and proofs—across heterogeneous code bases written in C (annotated with ACSL), Java (JML), and C# (Dafny). The pipeline constructs attributed, typed graphs from annotated program sources, subsequently enriching these structures with semantic embeddings derived from LLMs such as SentenceTransformer and CodeBERT. The approach facilitates similarity-based artefact retrieval and cross-language adaptation, ultimately supporting practical verification artefact reuse.
The central insight is that code-level and specification-level semantic content can be captured as hybrid, language-agnostic graphs, which are subsequently mapped to high-dimensional vector spaces for efficient approximate matching. Structural information alone is insufficient for robust alignment of artefacts due to syntactic divergence and abstraction differences; neural embeddings provide an orthogonal semantic signal, significantly boosting the discriminative power of the matching process.
Figure 1: Workflow for verification artefact reuse via hybrid graph matching and LLM-based semantic enrichment.
Pipeline Architecture
The proposed workflow for artefact reuse is methodically partitioned into (i) source-to-graph translation, (ii) semantic node enrichment via LLM embeddings, and (iii) joint structural-semantic graph matching.
- Source-to-Graph Translation: Source code and its specifications are parsed using AST extraction tools (Clang for C, javalang for Java, and regex-driven extractors for Dafny). The pipeline generates node- and edge-labeled, typed, attributed graphs—capturing both control/data flow and embedded formal contracts. Specification elements (e.g., ACSL pre/postconditions, JML invariants, Dafny ensures/variants) are preserved as explicit nodes, linked to language-level constructs.
- Semantic Node Enrichment: Subtree, node, or graph-level textual representations are aggregated and passed through transformer-based models (SentenceTransformer for ACSL/JML, CodeBERT for Dafny), generating dense, contextualized embeddings. These embeddings capture domain semantics not evident in syntax, improving the fidelity of graph similarity computations.
- Similarity-Based Matching: Matched artefacts are identified using cosine similarity atop embedding vectors, computed across pairwise program instances to yield a ranked similarity matrix. This matrix serves as the basis for artefact clustering, code search, cross-language alignment, and retrieval for reuse.
Cross-Language Multi-Specification Dataset Construction
The primary experimental dataset consists of C programs with varying algorithmic complexity, systematically translated into parallel Java and C# (Dafny) corpora. Specification injection is performed as follows:
- C → ACSL: Automated specification synthesis using Python and LLM-guided (GPT-5.2) rules generates preconditions, postconditions, inductive loop invariants, and variants.
- Java → JML: JML contracts are injected via static analysis and type-based heuristics, generating class and method invariants, assignable clauses, and nullness/refinements.
- C# → Dafny: Dafny contracts are synthesized by extracting control structure and inferred ensures clauses, augmented with loop invariants and termination arguments.
Language-specific and domain-specific idiosyncrasies are systematically mapped to maintain specification continuity across representations.
Graph Construction: Methodological Rigor
Graph construction leverages AST traversal to produce edge-annotated, attributed digraphs where:
- Nodes correspond to syntactic and semantic elements—e.g., function declarations, statements, predicates, contracts.
- Edges encode parent-child, control/data-flow, and logical dependencies.
- Node labels retain textual content for textual and semantic embedding.
- Specification nodes are injected explicitly to ensure that formal properties are not marginalized during subsequent neural embedding and matching.
- Graph serialization is managed via NetworkX’s native GraphML interface.
Graphs constructed from quicksort and merge (ACSL-annotated C, JML-annotated Java) illustrate the uniformity and expressiveness achieved, demonstrating how control-flow, data access, and specification artifacts are centrally represented.
Figure 2: Graphs constructed for ACSL annotated C programs of quicksort and merge.
Figure 3: Graphs constructed for JML annotated Java programs of quicksort and merge.
Semantic Enrichment and Matching
Node label aggregation produces a textual linearization for each graph, subsequently embedded using pre-trained transformer models. For C/Java, all-MiniLM-L6-v2 SentenceTransformer is employed; for Dafny, CodeBERT is used to accommodate specification-heavy, verification-oriented data. Cosine similarity between embedding vectors enables global, dataset-wide comparison, supporting:
- Clustering of algorithmic families
- Discovery of near-duplicate or semantically related functions/modules
- Cross-language artefact retrieval for specification transfer and contract-level alignment
High-similarity pairs ($0.8$–$1.0$) consistently reveal semantically equivalent or closely related program logic, despite surface syntactic differences, demonstrating the utility of hybrid graph+embedding representations for robust matching.
Output Analysis: Quantitative Similarity
The output matches.json encodes a dense pairwise similarity matrix. Fine-grained analysis reveals:
- Inter-algorithm class separation (low similarity for divergent routines, e.g., search vs. sort)
- Intra-family clustering (high similarity for structural or contract-preserving variants)
- Typical similarity score stratification: [0.35,0.6] (unrelated), [0.6,0.8] (partial overlap), [0.8,0.95+] (near-equivalence)
This output supports downstream tasks: semantic clustering, specification recommendation, plagiarism detection, and verification condition alignment.
Implications and Future Directions
Practical Implications
- Cross-language Reuse: The pipeline enables transfer and adaptation of formal contracts across diverse programming and specification frameworks—facilitating more scalable verification, and lowering barriers to specification authoring in industry.
- Augmented Program Analysis: Integrating structure (graphs) and semantics (embeddings) provides orthogonal signals, dramatically improving artefact matching precision over symbolic or neural-only methods.
- Specification Mining and Repair: The approach establishes a foundation for automated mining, adaptation, and even repair of formal annotations, poised to leverage LLM-based program understanding in future verification pipelines.
Theoretical Implications
- Uniform Artefact Representation: The approach supports a shared, language-agnostic representation of programs, contracts, and proofs, which dovetails with modern views of unifying theories of programming and multi-level program logics.
- Extension to Verification Workflows: As the representations are compatible with graph transformation and approximate matching, the system is extensible to automated adaptation scenarios (e.g., graph rewriting for contract migration).
Open Challenges
- Robustness is currently limited by rule-based syntax extraction and the out-of-domain nature of available embedding models, which are not explicitly trained for code + verification artefact alignment.
- The current similarity metric (global embedding cosine) may miss locality and relational nuances achievable with full graph kernels or compositional neural graph matching.
Conclusion
This work demonstrates that specification-driven program representations, formulated as attributed, typed graphs and semantically enriched using LLMs, can serve as a robust substrate for scalable verification artefact reuse across languages and specification frameworks (2604.26578). The hybrid approach supports expressive matching, algorithm clustering, and transfer of correctness annotations, moving verification workflows toward modular, automated, and reusable foundations. The methodology aligns with and advances current trends advocating the integration of symbolic structures, neural models, and retrieval-augmented matching in program analysis.
Future research should explore domain-adapted neural embedding models, integrate compositional graph matching (e.g., graph kernels, GNNs), and augment local semantic alignment techniques. Such advances will enable more precise, scalable, and context-sensitive reuse and adaptation of formal artefacts—driving next-generation verification tooling for modern, multi-language software ecosystems.