Skip to main content
QUICK REVIEW

[Paper Review] Laurel: Generating Dafny Assertions Using Large Language Models

Eric Mugnier, Emmanuel Anaya Gonzalez|arXiv (Cornell University)|May 27, 2024
Topic ModelingComputer Science3 citations
TL;DR

Laurel is a tool that uses large language models (LLMs) to automatically generate helper assertions in Dafny programs, improving verification success by inserting assertion placeholders based on SMT error messages and selecting relevant in-context examples using a novel lemma similarity metric. Evaluated on DafnyGym, Laurel successfully generates 52.4% of real-world helper assertions with minimal attempts, demonstrating LLMs as a viable, low-cost solution for automating proof engineering in formal verification.

ABSTRACT

Dafny is a popular verification language, which automates proofs by outsourcing them to an SMT solver. This automation is not perfect, however, and the solver often requires guidance in the form of helper assertions creating a burden for the proof engineer. In this paper, we propose Laurel, a tool that uses large language models (LLMs) to automatically generate helper assertions for Dafny programs. To improve the success rate of LLMs in this task, we design two domain-specific prompting techniques. First, we help the LLM determine the location of the missing assertion by analyzing the verifier's error message and inserting an assertion placeholder at that location. Second, we provide the LLM with example assertions from the same codebase, which we select based on a new lemma similarity metric. We evaluate our techniques on a dataset of helper assertions we extracted from three real-world Dafny codebases. Our evaluation shows that Laurel is able to generate over 50% of the required helper assertions given only a few attempts, making LLMs a usable and affordable tool to further automate practical program verification.

Motivation & Objective

  • To address the burden of manual helper assertion authoring in Dafny, which is essential for guiding SMT solvers but often requires guesswork.
  • To improve LLM success in generating correct Dafny assertions by incorporating domain-specific prompting strategies tailored to verification workflows.
  • To develop a method for selecting relevant in-context examples from large codebases without overwhelming the LLM’s context window.
  • To create and release DafnyGym, a benchmark dataset of real-world helper assertions extracted from industrial-strength Dafny codebases.
  • To demonstrate that LLMs, when guided by domain-aware prompting, can effectively automate a key bottleneck in practical formal program verification.

Proposed method

  • Laurel uses static analysis of Dafny’s SMT error messages to infer the precise location where a helper assertion is missing and inserts a placeholder at that position in the prompt.
  • It employs a novel hierarchical edit distance metric to compute structural similarity between lemmas, enabling effective selection of relevant example assertions from the same codebase.
  • The tool retrieves the top-m most similar lemmas based on this metric and includes their assertions as in-context examples to guide the LLM.
  • The LLM is prompted with the code snippet containing the placeholder and the selected example assertions, with instructions to generate a correct assertion that resolves the verification failure.
  • The approach is evaluated on a new dataset, DafnyGym, extracted from three real-world Dafny codebases: the standard library, Cedar, and DafnyVMC.
  • Success is measured by whether the generated assertion, when inserted, allows the Dafny verifier to prove the program without further user intervention.
Figure 2 . Overview of Laurel .
Figure 2 . Overview of Laurel .

Experimental results

Research questions

  • RQ1Can LLMs be effectively guided to generate correct helper assertions in Dafny programs using domain-specific prompting techniques?
  • RQ2How effective is error-based assertion placeholder insertion in improving LLM localization of missing assertions?
  • RQ3Can lemma similarity based on hierarchical edit distance improve the relevance of in-context examples and thus LLM generation accuracy?
  • RQ4What is the success rate of LLM-based assertion generation on real-world, industrial-strength Dafny codebases?
  • RQ5Can a low-resource, symbolic similarity metric outperform neural embedding-based example selection in this verification context?

Key findings

  • Laurel successfully generates 52.4% of the 1,045 helper assertions in the DafnyGym dataset, demonstrating strong practical viability.
  • The use of assertion placeholders based on SMT error messages significantly improves localization accuracy, reducing the LLM’s guesswork.
  • Lemma similarity based on hierarchical edit distance enables effective retrieval of relevant in-context examples, improving generation quality.
  • The approach reduces the number of LLM attempts needed per assertion, making the process efficient and scalable.
  • The DafnyGym dataset, comprising assertions from three real-world codebases, provides a valuable benchmark for future research in assertion synthesis.
  • The results show that with proper prompting, LLMs can be a reliable, affordable, and practical tool for automating a major bottleneck in Dafny program verification.
Figure 4 . Percentage of verified lemmas vs inference cost, by codebase.
Figure 4 . Percentage of verified lemmas vs inference cost, by codebase.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.