VeCoGen: Automating Generation of Formally Verified C Code With Large Language Models

Large language models have demonstrated impressive capabilities in generating code, yet they often produce programs with flaws or deviations from intended behavior, limiting their suitability for safety-critical applications. To address this limitation, this paper introduces VeCoGen, a novel tool that combines large language models with formal verification to automate the generation of formally verified C programs. VeCoGen takes a formal specification in ANSI/ISO C Specification Language, a natural language specification, and a set of test cases to attempt to generate a verified program. This program-generation process consists of two steps. First, VeCoGen generates an initial set of candidate programs. Secondly, the tool iteratively improves on previously generated candidates. If a candidate program meets the formal specification, then we are sure the program is correct. We evaluate VeCoGen on 15 problems presented in Codeforces competitions. On these problems, VeCoGen solves 13 problems. This work shows the potential of combining large language models with formal verification to automate program generation.

Authors

Institutions

Publication Details

Published
2025-04-27
DOI
https://doi.org/10.1109/formalise66629.2025.00017
Citations
7
Primary Topic
Software Testing and Debugging Techniques
Type
article
Field-Weighted Citation Impact
16.16
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

VeCoGen: Automating Generation of Formally Verified C Code With Large Language Models

Khashayar Etemadi, Mattias Nyberg, Merlijn Sevenhuijsen
7 citations
Software Testing and Debugging Techniques
16.16
article

VeCoGen: Automating Generation of Formally Verified C Code With Large Language Models

Khashayar Etemadi, Mattias Nyberg, Merlijn Sevenhuijsen
article en
7 citations

Abstract

Large language models have demonstrated impressive capabilities in generating code, yet they often produce programs with flaws or deviations from intended behavior, limiting their suitability for safety-critical applications. To address this limitation, this paper introduces VeCoGen, a novel tool that combines large language models with formal verification to automate the generation of formally verified C programs. VeCoGen takes a formal specification in ANSI/ISO C Specification Language, a natural language specification, and a set of test cases to attempt to generate a verified program. This program-generation process consists of two steps. First, VeCoGen generates an initial set of candidate programs. Secondly, the tool iteratively improves on previously generated candidates. If a candidate program meets the formal specification, then we are sure the program is correct. We evaluate VeCoGen on 15 problems presented in Codeforces competitions. On these problems, VeCoGen solves 13 problems. This work shows the potential of combining large language models with formal verification to automate program generation.

Scania (Sweden) (SE), KTH Royal Institute of Technology (SE)
Openalex Percentile: Top 1%
Software Testing and Debugging Techniques
16.16
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.