Fun2spec: Code Contract Synthesis At Scale

ICLR 2026 Conference Submission21405 Authors

19 Sept 2025 (modified: 08 Oct 2025)ICLR 2026 Conference SubmissionEveryoneRevisionsBibTeXCC BY 4.0
Keywords: Specification, LLM, Code Contracts, Postconditions, Software
Abstract: Specification synthesis -- the problem of inferring program specification from program implementation -- is an undecidable problem. Therefore, machine learning and more specifically, autoregressive large language models (LLMs) are a good fit for solving this problem. We demonstrate that code contracts, the most widespread software specification mechanism, can be generated by LLMs and validated using a software testing oracle on large real-world codebases. This oracle acts as an approximate code contract verifier. It only selects LLM-generated contracts that are test-valid, guaranteeing that the obtained contracts are at least as good as the test suite provided by the program. Our tool Fun2spec is the first code contract synthesis tool applied to real-world large-scale low-level C and C++ programs of millions of lines of code, raising the state-of-the-art of automated software verification using LLMs.
Primary Area: neurosymbolic & hybrid AI systems (physics-informed, logic & formal reasoning, etc.)
Submission Number: 21405
Loading