Agentic Separation Logic Specification Synthesis

Tarun Suresh, David korczynski, Julien Vanegue

TL;DR

Spec-Agent is a new agentic framework that automatically generates formal specifications (preconditions and postconditions) for large-scale C++ codebases. By combining LLMs with separation logic and fuzz-driven validation, it achieves an 85% success rate in synthesizing valid specifications, outperforming frontier models like Claude Code Opus 4.6 at one-tenth the cost.

What Problem Does This Paper Address?

Ensuring software correctness is a monumental challenge, especially in systems-level C++ code where manual memory management and complex data structures are the norm. Formal specifications—mathematical descriptions of what a function should do—are the "gold standard" for verification, but they are notoriously difficult and tedious for humans to write.

While Large Language Models (LLMs) have shown promise in "automatic programming," they often hallucinate or fail to capture the nuances of low-level memory behavior. Existing automated tools struggle with three main issues:

  1. Scalability: They can't handle repositories with millions of lines of code.
  2. Expressivity: They lack the logical vocabulary to describe heap-allocated memory and pointers.
  3. Validation: They have no robust way to prove that a generated specification is actually correct.

Methods

The authors introduce Spec-Agent, which treats specification synthesis as an iterative, agentic loop. Its architecture consists of four key stages:

  • Code Mining & Feature Extraction: The system uses static analysis (via Tree-sitter) and dynamic heap tracing to determine a function's complexity—specifically, whether it uses loops or touches the heap.
  • Adaptive Language Selection: Instead of using a "one size fits all" logic, Spec-Agent selects the simplest appropriate language from a "ladder" of four program logics: Propositional Logic, First-Order Logic (FOL), Propositional Separation Logic, and First-Order Separation Logic (FOSL).
  • Fuzz Harness Generation: To validate the specs, Spec-Agent transforms existing unit tests into "fuzz harnesses." This allows the system to stress-test the code with thousands of automatically generated inputs rather than just a few hand-written cases.
  • Counterexample-Guided Refinement: This is the "agentic" core. An LLM generates a candidate specification, which is then compiled into a runtime assertion. The fuzzer tries to break that assertion. If it finds a failing input (a counterexample), that input is fed back to the LLM to help it "fix" the specification in the next iteration.

Datasets

The researchers evaluated Spec-Agent on two massive, real-world C++ repositories:

  • BDE (Bloomberg Development Environment): A foundational library suite used by thousands of developers.
  • BlazingMQ (BMQ): A high-performance, low-latency message-queue library.
  • CPPEVAL: A newly introduced benchmark created for this paper, consisting of 100 expert-reviewed specifications per repository to serve as a ground-truth comparison.

Key Insights and Ideas

  • Fuzzing as a "Pseudo-Oracle": Since a full formal verifier for C++ is practically non-existent, the authors repurposed fuzz testing. While fuzzing can't prove a spec is 100% correct, it is incredibly effective at disproving incorrect ones, providing a scalable "guardrail" for LLM outputs.
  • The Power of Separation Logic: Standard logic struggles with pointers. By adopting Separation Logic, Spec-Agent can explicitly reason about "disjoint" memory locations, which is essential for verifying functions that swap variables or manipulate linked lists without causing memory corruption.
  • The "Logic Ladder" Efficiency: By forcing the LLM to use the simplest logic necessary for a given function, the system reduces the search space and prevents the model from over-complicating the specification, leading to higher accuracy and lower token usage.

Key Results

  • High Accuracy: Spec-Agent synthesized valid specifications for 85.87% of functions in the BDE repository and 77.73% in BMQ.
  • Superior Performance: It consistently outperformed Claude Code Opus 4.6, which achieved only ~81% and ~66% on the same datasets, respectively.
  • Cost Efficiency: Spec-Agent achieved these results at 10x lower token cost than the Claude Code baseline.
  • Zero False Positives: Under both automated fuzzing and manual review by experts, the specifications accepted by the system showed no false positives, demonstrating high reliability.

Limitations and Future Work

  • Fuzzing vs. Formal Proof: The authors acknowledge that fuzzing is a "strong proxy" but not a mathematical proof. A specification might pass a fuzzer but still contain a subtle logical error that only a theorem prover could catch.
  • The "Strongest" Spec Problem: While the system finds valid specifications, it doesn't always find the strongest (most general) one. Some generated specs might only describe a subset of a function's behavior.
  • Complexity Ceiling: The system still struggles with the most complex functions requiring First-Order Separation Logic (FOSL), suggesting that even more advanced algorithmic insights are needed for high-level memory reasoning.

Summary updated

BibTeX
@inproceedings{suresh2026agentic,
  author = {Tarun Suresh and David korczynski and Julien Vanegue},
  title = {{Agentic Separation Logic Specification Synthesis}},
  booktitle = {AI4Math @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=OJN0jbUn52},
}
Figure