Reinforcement Learning with Negative Tests as Completeness Signal for Formal Specification Synthesis

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Huang, Zhechong, Zhang, Zhao, Sun, Zeyu, Sun, Huifeng, Xiong, Yingfei
Format: Preprint
Published: 2026
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866915921253105664
author Huang, Zhechong
Zhang, Zhao
Sun, Zeyu
Sun, Huifeng
Xiong, Yingfei
author_facet Huang, Zhechong
Zhang, Zhao
Sun, Zeyu
Sun, Huifeng
Xiong, Yingfei
contents The specification synthesis task aims to automatically generate specifications, together with any necessary auxiliary verification annotations, for existing programs. This task is important because such specifications serve as behavioral contracts that support modular reasoning and reusable verification across a codebase. At the same time, it remains challenging because verifier-only feedback is fundamentally incomplete: passing verification establishes soundness, but cannot distinguish weak specifications from strong ones. What is missing is a fine-grained signal for specification completeness. We present SpecRL, a reinforcement learning framework for specification synthesis in Dafny. SpecRL introduces a self-contained pipeline that generates negative tests, i.e., input-output pairs that can never be produced by the program. We use the fraction of these negative tests rejected by a candidate specification as a signal of specification completeness, which is integrated into the reward for RL training. Experiments across four model sizes show that SpecRL improves both specification strength and verification success over SFT and RL with a binary specification-strength reward, generalizes to an out-of-distribution benchmark, and remains competitive on that unseen benchmark compared to much larger general-purpose LLMs.
format Preprint
id arxiv_https___arxiv_org_abs_2604_05820
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle Reinforcement Learning with Negative Tests as Completeness Signal for Formal Specification Synthesis
Huang, Zhechong
Zhang, Zhao
Sun, Zeyu
Sun, Huifeng
Xiong, Yingfei
Software Engineering
The specification synthesis task aims to automatically generate specifications, together with any necessary auxiliary verification annotations, for existing programs. This task is important because such specifications serve as behavioral contracts that support modular reasoning and reusable verification across a codebase. At the same time, it remains challenging because verifier-only feedback is fundamentally incomplete: passing verification establishes soundness, but cannot distinguish weak specifications from strong ones. What is missing is a fine-grained signal for specification completeness. We present SpecRL, a reinforcement learning framework for specification synthesis in Dafny. SpecRL introduces a self-contained pipeline that generates negative tests, i.e., input-output pairs that can never be produced by the program. We use the fraction of these negative tests rejected by a candidate specification as a signal of specification completeness, which is integrated into the reward for RL training. Experiments across four model sizes show that SpecRL improves both specification strength and verification success over SFT and RL with a binary specification-strength reward, generalizes to an out-of-distribution benchmark, and remains competitive on that unseen benchmark compared to much larger general-purpose LLMs.
title Reinforcement Learning with Negative Tests as Completeness Signal for Formal Specification Synthesis
topic Software Engineering
url https://arxiv.org/abs/2604.05820