논문 해설
Towards AI-Assisted Synthesis of Verified Dafny Methods
Dafny 메서드의 검증된 합성을 향한 AI 보조 방식
- 연구 문제 LLM은 Dafny처럼 사양과 검증 주석을 함께 요구하는 언어에서 검증 가능한 메서드를 얼마나 합성할 수 있는지 평가합니다.
- 연구 방법 GPT-4와 PaLM-2에 Contextless, Signature, 검색 증강 CoT의 세 가지 프롬프트를 적용하고 Dafny 검증기로 판정합니다.
- 주요 결과 검색 증강 CoT 프롬프트에서 GPT-4가 k=5 기준 64.04%의 검증 성공률을 보였으며, 시그니처 추가는 이 설정에서 Contextless보다 낮았습니다.
검증 가능한 Dafny 코드 합성의 어려움
LLM은 일반 프로그래밍 언어에서는 인상적인 코드를 만들지만, Dafny처럼 사전조건·사후조건·루프 불변식을 함께 요구하는 검증 지향 언어에서는 문법 오류와 잘못된 사양이 자주 나타납니다. 이 논문은 이 한계를 줄이기 위해 두 pre-training 모델이 Dafny 메서드를 합성하는 능력을 측정합니다. 연구 범위는 GPT-4와 PaLM-2, MBPP 기반 178개 문제, 세 가지 프롬프트 방식으로 제한됩니다. 핵심 질문은 단순한 문제 설명만으로도 검증된 메서드가 나오는지, 시그니처와 테스트 또는 단계별 분해와 검색 증강 예시가 그 결과를 바꾸는지입니다.
세 가지 프롬프트와 검색 증강 파이프라인
Contextless 프롬프트는 언어 이름, 문제 설명, 응답 형식만 담아 Dafny 메서드를 한 번에 생성하도록 합니다. Signature 프롬프트는 여기에 메서드 시그니처와 세 개의 테스트 케이스를 추가합니다. Dynamic Few-Shot 방식은 두 단계로 구성됩니다. 첫 단계에서 LLM이 메서드 시그니처와 사후조건을 먼저 생성하고, 두 번째 단계에서 그 결과를 임베딩하여 MBPP-DFY-50에서 의미적으로 가까운 상위 다섯 개 예시를 고릅니다. 이 예시들과 단계별 분해 지시를 담은 Chain of Thought 프롬프트로 사양과 구현을 합성합니다. 여기서 검색 증강 생성은 의미적으로 유사한 예시를 프롬프트에 붙이는 방식으로 사용되며, 저자들은 사후조건의 유사성이 적절한 해법을 찾는 단서가 된다고 보았습니다.

Figure 3 : A high-level architecture of the RAG prompt-chaining pipeline for Dynamic Few-Shot Prompting. MBPP-DFY-50 dataset. We select these examples based on the semantic similarity of the problem descriptions. Figure 4 (top) shows an example of a first phase specification prompt. In the second phase, we search for semantically similar Dafny methods in our MBPP-DFY-50 dataset, incorporating the LLM’s first phase response. We use the OpenAI embedding API to compute semantic similarity based on cosine distance. For the specification generated in the first phase, we select the top five Dafny similar examples from our MBPP-DFY-50 dataset. We use five examples so that the whole prompt fits inside the LLMs’ context length. With these examples, we then prepare a CoT prompt that first instructs the LLM to synthesize the specifications according the problem decomposition steps, and then synthesize a Dafny method that satisfies these specifications — see Figure 4 (bottom).
원문 · CC BY 4.0 · Md Rakib Hossain Misu, Cristina V. Lopes, Iris Ma, James Noble · Towards AI-Assisted Synthesis of Verified Dafny Methods · 원문 그림 인용 · 원본 PDF 9쪽에서 그림 영역을 추출했습니다.검증 기준과 데이터 구성
평가는 Dafny 검증기가 코드를 구문적으로 올바르게 판정하고 검증에 성공했는지를 기준으로 합니다. 지표 verify@k는 문제마다 k개의 샘플을 만들고, 그중 하나라도 검증되면 그 문제를 성공으로 셉니다. 데이터셋 MBPP-san-DFY는 MBPP-san에서 Python 전용 문제를 제외한 뒤 표본을 추린 178개 문제이며, 각 문제의 설명, 시그니처, 테스트를 Dafny로 옮겨 구성했습니다. MBPP-DFY-50은 검증된 예시를 만드는 별도의 50개 데이터셋이며 검색 증강 예시로 사용됩니다. 온도는 0.0부터 0.75 사이에서 조정했고, 조정은 178개 중 무작위 50개 문제에서 수행했습니다.
프롬프트별 검증 성공률 비교
GPT-4는 Contextless 프롬프트에서 k=5일 때 178개 문제 중 104개(58.42%)를 검증했습니다. Signature 프롬프트에서는 95개(53.37%)로 오히려 낮아져, 시그니처와 테스트를 추가해도 이 설정에서는 개선되지 않았습니다. Dynamic Few-Shot CoT 프롬프트에서는 114개(64.04%)로 가장 높았습니다. PaLM-2는 Contextless에서 검증된 메서드를 만들지 못했고, Signature에서 12개(6.74%), Dynamic Few-Shot에서 52개(29.21%)를 얻었습니다. 따라서 검증 성공률만 보면 검색 증강 CoT 프롬프트가 두 모델 모두에서 가장 좋은 결과를 보였습니다.

Table 1 : Summary of verified Dafny method synthesis on 178 problems. For each prompt, LLMs responses were generated with their tuned temperature (T) at verify@k (where 𝑘∈{ 1, 3, 5})
원문 · CC BY 4.0 · Md Rakib Hossain Misu, Cristina V. Lopes, Iris Ma, James Noble · Towards AI-Assisted Synthesis of Verified Dafny Methods · 원문 그림 인용 · 원본 PDF 12쪽에서 그림 영역을 추출했습니다.검증 성공과 사양 품질의 차이
검증에 성공했다는 사실이 사양이 의미 있다는 뜻은 아닙니다. Contextless 프롬프트에서 GPT-4의 검증 메서드 104개 중 사후조건을 가진 것은 56개였고, 나머지 48개는 사후조건이 없어 실질적인 검증으로 보기 어렵다고 논문은 설명합니다. Dynamic Few-Shot 프롬프트에서는 검증된 메서드 114개 모두 사후조건을 가졌으며, 수동 검토에서 강한(Strong) 사후조건은 103개로 집계되었습니다. 이 점수는 두 저자의 수동 태깅 결과로, 코헨 카파 93.91%의 일치도가 보고되었습니다. 이 검토는 사양의 의미적 정확성을 자동 지표가 대신하지 못한다는 한계를 보여 줍니다.

Table 2 : Summary of specifications synthesis result, in both verified and unverified methods. The number in the denominators represents the total number of verified and unverified methods respectively. For each prompt, LLMs responses were generated with their tuned temperatures at verify@k (k=5).
원문 · CC BY 4.0 · Md Rakib Hossain Misu, Cristina V. Lopes, Iris Ma, James Noble · Towards AI-Assisted Synthesis of Verified Dafny Methods · 원문 그림 인용 · 원본 PDF 13쪽에서 그림 영역을 추출했습니다.
Table 3 : Summary of qualitative analysis of specifications synthesis in verified methods. The number in the denominator represents the total number of verified methods containing specifications. For each prompt, LLM responses were generated with their tuned temperatures at verify@k (k=5).
원문 · CC BY 4.0 · Md Rakib Hossain Misu, Cristina V. Lopes, Iris Ma, James Noble · Towards AI-Assisted Synthesis of Verified Dafny Methods · 원문 그림 인용 · 원본 PDF 14쪽에서 그림 영역을 추출했습니다.
Table 4 : Examples of LLMs synthesis Strong, Weak and Wrong postconditions; Required and Optional preconditions; invariants subsuming postconditions, and auxiliary definitions.
원문 · CC BY 4.0 · Md Rakib Hossain Misu, Cristina V. Lopes, Iris Ma, James Noble · Towards AI-Assisted Synthesis of Verified Dafny Methods · 원문 그림 인용 · 원본 PDF 15쪽에서 그림 영역을 추출했습니다.적용 범위와 남은 한계
이 결과는 GPT-4와 PaLM-2, MBPP 기반 178개 문제, Dafny 4.0.0이라는 특정 조건에서 얻은 것입니다. 논문은 모델과 언어의 버전이 빠르게 바뀌므로 결과가 다른 모델이나 버전에서 그대로 재현되지 않을 수 있다고 밝힙니다. 또한 Signature 프롬프트의 하락은 이 설정의 결과이며, 모든 명세 추가가 불리하다는 결론으로 확장할 수는 없습니다. 검증 성공률은 자동으로 측정되지만, 사후조건의 강도와 의미는 수동 검토에 의존했습니다. 따라서 이 연구는 검증된 메서드 생성의 가능성을 보여 주지만, 실제 프로그램 전체의 정확성을 보장하지는 않습니다.
논문 정보
- 저자
- Md Rakib Hossain Misu, Cristina V. Lopes, Iris Ma, James Noble
- 학회·저널
- arXiv · 프리프린트
- 최초 공개일
- 2024년 2월 1일
- 등록일
- 2026년 11월 6일
- 수정일
- 2024년 6월 10일
- 버전
- v2
- arXiv
- 2402.00247
- DOI
- 10.1145/3643763
- 분류
- cs.SE · cs.PL
- 원문 이용 조건
- CC BY 4.0
- 제공 범위
- 논문 정보, 해설, 허용된 원문 그림
AI 해설은 논문 원문과 별개의 설명이며 오류가 있을 수 있습니다. 원문과 그림은 각 출처의 이용 조건과 따로 표시된 권리를 따릅니다.
초록
Large language models show great promise in many domains, including programming. A promise is easy to make but hard to keep, and language models often fail to keep their promises, generating erroneous code. A promising avenue to keep models honest is to incorporate formal verification: generating programs' specifications as well as code so that the code can be proved correct with respect to the specifications. Unfortunately, existing large language models show a severe lack of proficiency in verified programming. In this paper, we demonstrate how to improve two pretrained models' proficiency in the Dafny verification-aware language. Using 178 problems from the MBPP dataset, we prompt two contemporary models (GPT-4 and PaLM-2) to synthesize Dafny methods. We use three different types of prompts: a direct Contextless prompt; a Signature prompt that includes a method signature and test cases, and a Chain of Thought (CoT) prompt that decomposes the problem into steps and includes retrieval augmentation generated example problems and solutions. Our results show that GPT-4 performs better than PaLM-2 on these tasks and that both models perform best with the retrieval augmentation generated CoT prompt. GPT-4 was able to generate verified, human-evaluated, Dafny methods for 58% of the problems, however, GPT-4 managed only 19% of the problems with the Contextless prompt, and even fewer (10%) for the Signature prompt. We are thus able to contribute 153 verified Dafny solutions to MBPP problems, 50 that we wrote manually, and 103 synthesized by GPT-4. Our results demonstrate that the benefits of formal program verification are now within reach of code generating large language models...
원문 인용
Md Rakib Hossain Misu, Cristina V. Lopes, Iris Ma, James Noble (2024). Towards AI-Assisted Synthesis of Verified Dafny Methods. arXiv:2402.00247v2. https://doi.org/10.1145/3643763
BibTeX
@article{misu2024towards,
title = {{Towards AI-Assisted Synthesis of Verified Dafny Methods}},
author = {Md Rakib Hossain Misu and Cristina V. Lopes and Iris Ma and James Noble},
year = {2024},
eprint = {2402.00247},
archivePrefix = {arXiv},
doi = {10.1145/3643763},
url = {https://arxiv.org/abs/2402.00247v2}
}