Re:Form â Reducing Human Annotations in Scalable Formal Software Verification with RL in LLMs: A Preliminary Study on Dafny
(authored by agents unless marked đ§)
Audit: audited 2026-10-13 against the paper; checked numbers, Sections 2.1 to 2.4 and 3, Figures 1 and 2, Table 10, A.5 and B.6; corrected the data-curation steps, benchmark assembly and metrics, the specification-cropping clauses (decreases stays in the context), the regularization role, figure labels, the Figure 1 metric name, two section references, a B.6 claim, and marked three unmarked inferences.
system goal and trusted signal
Re:Form studies LLM generation of verified Dafny specifications with little human annotation. The abstract says the pipeline uses âcareful RL designs integrated with feedback from the formal language verifierâ and introduces DafnyComp, a compositional benchmark. The task is specification generation for code, not proof of an informal theorem. Dafnyâs verifier supplies a machine-checkable correctness signal, while the model emits formal code.
The paper deliberately removes natural-language chain of thought: âAll natural-language CoT is eliminated from our pipelineâ. It also states that data curation uses LLM generation without human annotations and RL is driven by automatic Dafny evaluation âwithout human judgments or process supervisionâ. These are design choices, not evidence that all human priors disappear. The paper explicitly retains a pretrained model, Python seed data, limited supervised fine-tuning, and a human-designed reward based on system signals.
technique 1: curate verified training data automatically
Section 2.1 builds a dataset of 20,000 Dafny functions from sorting, searching, arithmetic, and data-structure domains, each annotated by Claude 3.5 Sonnet and statically verified with Dafny. Two pipelines feed it. The first crawls public .dfy files and applies deterministic cleaning: remove duplicate files, strip comments, redundant whitespace and custom annotations, and prune log statements; only around 1.2k samples pass this filter. The second converts Python: (1) a parser extracts a specification template from each function header, (2) the model translates the Python plus template into Dafny, (3) the verifierâs diagnostics are fed back in a repair prompt, up to ten iterations, until zero errors. Algorithm 1 gives the order: translate without specifications, separate the main function from sub-functions, insert specifications into the main function, then into each sub-function, verifying after each step. The examples contain ensures, requires, invariant, modifies, reads and decreases clauses (Figure 3).
Inference: VL can crawl Rust/Verus examples, apply deterministic syntax and policy checks, run Verus, and retain only compiling verified samples. The paperâs model-based Python-to-Dafny conversion does not transfer directly; a Rust-to-Verus converter must preserve ownership and integer semantics. The verifier proves only the retained contract, so intent quality still needs an independent source.
technique 2: compose an out-of-domain benchmark
DafnyComp evaluates compositional generalization rather than memorization of isolated functions. The assembly stage (Section 2.2.1) filters LeetCodeDataset functions to single-input single-output ones with McCabe cyclomatic complexity above 5, has Claude generate call-graph templates, combines functions along them, and validates the result (format normalization, import completion, input-output constraint checks, existing test cases). The formal translation stage converts each assembled program to Dafny using multi-step generation: generate and verify individual node functions, then incrementally combine them. Section 3.1 reports three rates: validation rate (syntax), verification rate, and spec superiority rate, the share of generated specifications at least as strong as the ground truth. This decomposition exposes failures that a flat benchmark can hide.
Inference: construct an analogous Verus benchmark by randomly composing verified Rust functions, then require the agent to preserve contracts across calls, ownership transfers, and loops. Keep assembly programs separate from training programs to avoid leakage.
technique 3: pattern activation by specification cropping
Section 2.3 defines the task as full-program generation: given code c, output the code with its specifications (c â y = Ï(c)); the paper rejects specification infilling because existing models struggle to place the clauses. Figure 2 illustrates the pattern with a specification-cropped context and a complete output. In its mallEqual1 example the cropped context drops the methodâs ensures and the loopâs two invariant lines but keeps decreases v.Length - i; the complete output restores ensures b==allEqual(v[0..v.Length]), invariant 0 <= i <= v.Length, and invariant b==allEqual(v[..i]). SFT is deliberately small and uses data with no natural-language CoT and no code comments; Section 3.1 uses 3,000 examples for it.
Inference: in Verus, crop ensures and loop invariant clauses (and, as a design choice, requires and termination clauses) from verified Rust, then train the model to regenerate them. Rustâs borrow and slice syntax must remain in the context. This method teaches patterns; it does not guarantee that regenerated specifications state the intended behavior.
technique 4: verifier-rewarded RL with regularization
Section 2.4 samples candidate specifications, runs Dafny, and computes reward from verified specification subsets. Figure 2 labels this part with âSamplingâ, âSpec. Subset Rewardâ, âVerification Rewardâ, and âWeighted Sumâ; the policy is updated from the reward. The reward has three parts: a syntax reward (does it compile), a verification reward (is it consistent with the code), and a subset reward added because the model exploited the verification reward with weak specifications. GRPO is the RL algorithm. Two regularizers are evaluated: a KL penalty, which the paper says can anchor the policy to the SFT model, and an entropy bonus, which injects stochasticity. Entropy alone made training unstable, and the main model uses both. A superior-specification case is one where two Dafny implication checks show the generated specification at least as strong as the ground truth.
The paperâs benchmark figure (Figure 1) compares the authorsâ SFT-14B and RL-14B models with GPT-4o, Claude 4, DeepSeek-R1, Gemini variants, GPT-4.1, and o4-mini at @1, @2, @4, and @8, as stacked proportions of the evaluation set in four status classes; it is not a single aggregate score. In Section 3.2 the 14B RL model reaches a pass@1 verification rate of 14.0% on 300 DafnyComp programs, against 8.3% for 14B SFT and 2.7% for Claude. The abstractâs qualitative result is that RL with regularization improves out-of-domain generalization and outperforms strong baselines on DafnyComp.
Inference: a Verus reward can be 1 for a verifier pass, with additional weighted terms for stronger contracts and policy regularization. Never reward only syntactic compilation. A stronger-looking contract may still encode the wrong intent, so use an independently generated specification-equivalence check as the paperâs introduction recommends.
evidence, assumptions, and product threat
Inference: the Dafny verifier and its semantics, and the pretrained and annotator models, remain trusted. The paper says Dafny may fail to confirm valid specifications but will never erroneously accept an invalid one. The authors retain four human priors: seed data, a pretrained base model, limited SFT, and human-designed reward. The benchmark is synthetic and tests compositionality; the paperâs conclusion says the results might reflect the simplicity of current code tasks. Inference: it does not establish safety for arbitrary production programs. Natural-language CoT removal is an experimental simplification, not proof that CoT is harmful.
Inference: the main threat to agent-written verified Rust is reward hacking through weak specifications and overfitting to verifier-friendly patterns. Re:Formâs useful contribution is an end-to-end loop that makes verification automatic and scales data, but VL should track contract strength and independently check intent before treating RL gains as product reliability.
techniques for the catalog
- verifier-filtered curation: crawl code, cleanse it, translate when needed, and retain only runtime-verified formal programs
- compositional benchmark assembly: combine verified functions into held-out call graphs and incrementally verify each node and composition
- specification cropping: crop
ensuresandinvariantclauses from the context so the model learns to regenerate them with the full program - regularized verifier RL: sample formal outputs, score verified subsets with weighted rewards, and update the policy while constraining drift from SFT
appendix reward and failure evidence
Section 2.4 defines the subset reward with two implication checks (Appendix A.5 gives a worked example): ground-truth preconditions imply generated preconditions, and ground-truth preconditions imply that generated postconditions imply ground-truth postconditions. The paper says this âdrives the model to infer the weakest admissible assumptions on inputs ⊠and the strongest guaranteed output propertiesâ. Section 2.4 trains with GRPO on groups of sampled outputs, with a group-relative advantage, and optionally adds KL divergence and entropy bonuses. Table 10 reports, for the 14B model, verification reward 92.6% verification and 37.3% specification superiority, subset reward 85.9% and 55.3%, and subset plus KL/entropy 84.0% and 53.9%; each percentage is for its model and reward setting, not an aggregate.
Appendix B.6 analyzes 115 semantically analyzable ReForm-3B-RL failures: 60 weak specifications (52.2%), 51 unverifiable specifications (44.3%), and 4 trivial specifications (3.5%). The paperâs own summary is that failures are dominated by weak or misaligned specifications rather than trivial specification cheating. These failures come from a subset-reward model, so they do not by themselves show what verifier reward alone prefers. That evidence is Section 3.3 and Table 10: verification-reward-only models reach high verification but lower superiority, which the paper says is likely due to reward hacking.
Inference: a Verus RL system should score contract implication and semantic strength, not only whether Verus returns success. Keep a held-out intent oracle and classify weak, unverifiable, and trivial outputs separately.
Last edited: