arrow
Return

ClassInvGen: Class Invariant Synthesis Using Large Language Models

delete2026-01-01
delete0
PRE
AI
C
Chuyue Sun *
V
Viraj Agashe
S
Saikat Chakraborty
J
Jubi Taneja
C
Clark Barrett
D
David L. Dill
X
Xiaokang Qiu
S
Shuvendu K. Lahiri
DOI:10.1007/978-3-031-99991-8_4delete
deleteOriginal
deleteOriginal request for help
deleteShare
deleteSave
Abstract

Abstract

En 中文
Formal program specifications in the form of preconditions, postconditions, and class invariants have several benefits for the construction and maintenance of programs. They not only aid in program understanding due to their unambiguous semantics but can also be enforced dynamically (or even statically when the language supports a formal verifier). However, synthesizing high-quality specifications in an underlying programming language is limited by the expressivity of the specifications or the need to express them in a declarative manner. Prior work has demonstrated the potential of large language models (LLMs) for synthesizing high-quality method pre/postconditions for Python and Java, but does not consider class invariants. In this work, we describe ClassInvGen, a method for co-generating executable class invariants and test inputs to produce high-quality class invariants for a mainstream language such as C++, leveraging LLMs' ability to synthesize pure functions. We demonstrate that ClassInvGen outperforms a pure LLM-based technique for generating specifications (from code) as well as prior data-driven invariant inference techniques such as Daikon. We contribute a benchmark of standard C++ data structures along with a harness that can help measure both the correctness and completeness of generated specifications using tests and mutants. We also demonstrate its applicability to real-world code by performing a case study on several classes within a widely used and high-integrity C++ codebase.
Keywords:
Program Synthesis
Large Language Models
Class Invariants
Formal Verification

Journal

A
AI VERIFICATION, SAIV 2025
IF:
0
Papers:
16
Citations:
0

Organization

Purdue University System cover
Purdue University System
Scholars:
3.9W
Papers: 3.6W
Citations: 66
M
microsoft
Scholars:
376
Papers: 181
Citations: 17
S
stanford university
Scholars:
1.0W
Papers: 4.1K
Citations: 0
researcher View more organizations