Local Success Does Not Compose: Benchmarking Large Language Models for Compositional Formal Verification

Xu Xu, Xin Li, Xingwei Qu, Jie Fu, Binhang Yuan

TL;DR

While Large Language Models (LLMs) have become remarkably proficient at generating code, they fail significantly when asked to formally prove that multiple functions work together correctly. This paper introduces DAFNYCOMP, a new benchmark showing that even frontier models collapse from ~60% success on single-function verification to near-zero success when programs require "compositional reasoning" across function boundaries.

The Specification Bottleneck

A major hurdle in software engineering is the "specification bottleneck": writing formal proofs (contracts like preconditions and postconditions) is often as difficult and time-consuming as writing the code itself. While researchers hoped LLMs could automate this, current benchmarks primarily test isolated, single functions.

In the real world, software is a web of interacting components. If Function A calls Function B, their formal specifications must align perfectly; a slight mismatch in what Function A promises and what Function B requires will cause the entire verification process to fail. Current LLMs lack this compositional reasoning—the ability to coordinate interdependent contracts across a call graph.

Building the DAFNYCOMP Benchmark

To systematically study this gap, the authors developed a two-stage pipeline to create a rigorous benchmark:

  1. Program Assembly: Independent Python functions (sourced from LeetCode) were systematically combined into complex call graphs—either "chains" (A calls B calls C) or Directed Acyclic Graphs (DAGs). These were validated using unit tests to ensure functional correctness.
  2. Formal Translation: Using Claude-3.5-Sonnet and an iterative refinement process, these Python programs were translated into Dafny, a verification-aware programming language. This resulted in a "ground truth" set of programs where every function and interaction is mathematically proven to be correct.
The two-stage synthesis pipeline: (1) Assembly of Python functions and (2) Translation into verified Dafny code.

To evaluate other LLMs, the authors stripped away the formal annotations (the requires and ensures clauses) and asked the models to reconstruct them based only on the implementation code.

The resulting dataset, DAFNYCOMP, consists of 400 mechanically verified multi-function programs:

  • 300 Chain-structured instances: Programs with 2–5 functions in a linear calling sequence.
  • 100 Non-chain DAG instances: Programs using 10 different topology templates to test branching and merging data dependencies.

Key Insights: The Formal Verification Gap

The results reveal a massive disconnect between a model's ability to follow language syntax and its ability to reason logically across boundaries.

  • Near-Zero Success: While frontier models achieve ~58-67% verification on single-function benchmarks (like DafnyBench and MBPP-DFY), they experience a total collapse on DAFNYCOMP.
  • The 2% Ceiling: Even the strongest model evaluated reached only 2% verification (at Pass@8) on the chain split. Most models remained below 1%.
  • Scaling Limits: Increasing the number of samples (test-time scaling) or providing verifier feedback (multi-turn refinement) helped slightly but did not come close to saturating the benchmark.
The formal verification gap: Models maintain high syntax success (blue) but experience a total collapse in verified rates (orange) on DAFNYCOMP compared to prior benchmarks.

The authors identified three primary failure modes driving this collapse:

  1. Specification Fragility (The Domino Effect): If a model fails to propagate a constraint (e.g., forgetting to specify that a result is non-negative), it invalidates the entire calling chain. One "local" omission leads to a "global" proof failure.
  2. The Independence Assumption: LLMs often generate code and specifications as if they are independent entities rather than coupled constraints, leading to "hallucinated" invariants that contradict the actual implementation.
  3. Reasoning Instability: Models struggle with induction. They can handle the "base case" of a proof but lose track of how program state evolves through loops or recursive calls across function boundaries.

Limitations and Future Work

The benchmark currently focuses on acyclic graphs and functional correctness properties (pre/post-conditions). It does not yet cover cyclic dependencies, mutual recursion, complex shared-state scenarios, or liveness/security policies.

A major reason for the observed failure is likely the lack of high-quality, multi-function verified code in the models' training data. Future work will likely focus on synthetic data generation—using pipelines like the one introduced here to create massive amounts of verified compositional data to teach models how to reason across component boundaries.

Summary updated

BibTeX
@inproceedings{xu2026local,
  author = {Xu Xu and Xin Li and Xingwei Qu and Jie Fu and Binhang Yuan},
  title = {{Local Success Does Not Compose: Benchmarking Large Language Models for Compositional Formal Verification}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=y4kAMUBqLq},
}
Figure