[Paper Review] Finding Inductive Loop Invariants using Large Language Models
The paper investigates using large language models (LLMs) to generate inductive loop invariants for C programs, combining LLM outputs with symbolic verification tools to verify Hoare triples, and showing improved verification performance over a symbolic baseline in many cases.
Loop invariants are fundamental to reasoning about programs with loops. They establish properties about a given loop's behavior. When they additionally are inductive, they become useful for the task of formal verification that seeks to establish strong mathematical guarantees about program's runtime behavior. The inductiveness ensures that the invariants can be checked locally without consulting the entire program, thus are indispensable artifacts in a formal proof of correctness. Finding inductive loop invariants is an undecidable problem, and despite a long history of research towards practical solutions, it remains far from a solved problem. This paper investigates the capabilities of the Large Language Models (LLMs) in offering a new solution towards this old, yet important problem. To that end, we first curate a dataset of verification problems on programs with loops. Next, we design a prompt for exploiting LLMs, obtaining inductive loop invariants, that are checked for correctness using sound symbolic tools. Finally, we explore the effectiveness of using an efficient combination of a symbolic tool and an LLM on our dataset and compare it against a purely symbolic baseline. Our results demonstrate that LLMs can help improve the state-of-the-art in automated program verification.
Motivation & Objective
- Curate a dataset of verification problems on C programs with loops to study invariant generation by LLMs.
- Develop a toolchain that prompts LLMs to generate loop invariants and validates them with symbolic verifiers.
- Evaluate different LLMs and a hybrid LLM-symbolic approach against a symbolic baseline on the dataset.
- Propose and assess a repair-enabled pipeline that tolerates LLM inaccuracies while ensuring inductiveness.
Proposed method
- Construct a two-component toolchain with an LLM (L) and an oracle/symbolic verifier (O).
- Use a prompt M and target program P to generate candidate invariants I via L.
- Annotate P with I as A(P,I) and verify inductiveness with O.
- Apply Loopy: accumulate I across completions, then use Houdini to extract an inductive subset, or Repair to improve I.
- Houdini prunes non-inductive or syntactically invalid candidates and seeks a subset that is inductive.
- Repair iteratively prompts L to repair error-informed invariants and re-checks with O.

Experimental results
Research questions
- RQ1RQ1 How often can LLMs generate a correct set of loop invariants for a C program?
- RQ2RQ2 How often can LLMs generate elements of a correct set of loop invariants needed to verify a C program?
- RQ3RQ3 How do different foundational models compare in their ability to find inductive invariants?
- RQ4RQ4 How often can LLMs fix incorrect invariants using error messages from the oracle?
- RQ5RQ5 What are the program features where LLMs fail to generate correct invariants?
- RQ6RQ6 How does the performance of Loopy compare with state-of-the-art symbolic verifiers?
Key findings
- Loopy's success increases with more completions, with diminishing returns after about 8 completions.
- Including nudges in prompts (M2) improves success by about 23% over simpler prompts (M1).
- Houdini significantly boosts performance by leveraging partial invariants generated by LLMs.
- GPT-4 generally outperforms other LLMs, but Houdini helps other models catch up; using multiple LLMs can be beneficial.
- Repair further increases verification reach, yielding 398 solved benchmarks versus 383 with Houdini alone in the reported setup.
- Compared to the symbolic baseline Ultimate, Loopy solves some benchmarks that Ultimate cannot, while Ultimate solves more overall (430 vs 398 on the 469 benchmarks).

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.