TL;DR
This paper introduces a neuro-symbolic framework that automatically generates and validates memory-aware formal function specifications for C programs from natural language descriptions. By combining LLM-based generation with automated theorem proving (Coq) to actively refute incorrect candidates, the system bypasses traditional verification bottlenecks and successfully filters out false positives that fool LLM-only judges.
What Problem Does This Paper Address?
As large language models (LLMs) are increasingly used to generate low-level systems code, ensuring the correctness and memory safety of this code has become a critical challenge. Formal verification offers a mathematically rigorous solution, but it relies heavily on precise formal specifications (preconditions and postconditions) written in complex frameworks like separation logic.
Writing these specifications requires rare, specialized expertise, creating a massive bottleneck. Furthermore, traditional verification pipelines often get bogged down trying to synthesize complex loop invariants. This paper addresses this scalability bottleneck by focusing exclusively on generating and validating function-level specifications for memory-manipulating C code, making the verification process more tractable.
Methods
The authors propose a two-phase neuro-symbolic pipeline:
- Initial Specification Generation: The system uses an LLM prompted with natural language descriptions of predefined predicates from QCP (a state-of-the-art C verifier), carefully curated few-shot examples, and common error patterns to generate an initial candidate specification.
- Iterative Refinement with Symbolic Feedback: If the generated specification contains syntax or type errors, the system collects diagnostics from the Coq compiler and QCP checker, feeding them back into the LLM alongside repair patterns to iteratively fix the code.
To ensure semantic correctness, the framework introduces a novel Counterexample-Guided Refutation workflow. Instead of trying to prove a specification correct (which is highly complex), it attempts to disprove it. The system negates the generated postcondition and uses a structured LLM-to-Python pipeline to generate concrete test cases (heap configurations). Coq’s automated hammer tactic then attempts to discharge the proof for this negated goal. If it succeeds, a concrete counterexample has been found, and the incorrect specification is definitively rejected.
Datasets
The authors introduce LEETCODE-C-SPEC-200, a new benchmark consisting of 200 C programming problems sampled from LeetCode. Unlike prior verification benchmarks that focus on trivial algorithms (like simple list copying), this dataset introduces substantial algorithmic complexity, including dynamic programming over arrays, graph algorithms on tree structures, and complex string manipulations. The benchmark spans five data structure categories: integers, arrays, strings, trees, and linked lists.
Key Insights and Ideas
- The Asymmetry of Proof vs. Refutation: Proving a specification correct requires reasoning over all possible inputs, which is incredibly difficult to automate. However, refuting an incorrect specification only requires finding one concrete input-output pair that violates the postcondition.
- LLMs as Generators, Symbols as Judges: LLMs struggle to accurately judge the intricate logical relationships in separation logic, frequently accepting flawed specifications. However, they excel at generating structured test cases when guided by a strict pipeline, leaving the rigorous judging to symbolic provers.
- Decoupling Loop Invariants: By deliberately leaving loop invariant generation out of scope, the framework simplifies the problem space, allowing test-case execution to act as a reliable ground truth for function boundaries.
Key Results
- Improved Syntactic Validity: The iterative refinement loop guided by compiler feedback significantly reduced trivial syntax and type errors in the generated QCP annotations.
- Effective False Positive Filtering: The Coq-based refutation mechanism successfully caught and filtered out subtle semantic errors—such as incorrect memory aliasing assumptions or overly weak postconditions—that LLM-only judges routinely missed.
Limitations and Future Work
The authors explicitly leave loop invariant generation out of scope for this work, noting it as a separate, harder problem. Additionally, the iterative refinement pipeline is currently limited by its error taxonomy; errors falling outside of predefined annotation syntax or predicate import categories are treated as unrecoverable, leading to generation failure.
Summary updated