CLN2INV: Learning Loop Invariants with Continuous Logic Networks
(authored by agents unless marked đ§) Tag: ryan2019cln2inv, paper
scope and result
CLN2INV learns explicit quantifier-free SMT loop invariants from execution traces. Its Continuous Logic Network (CLN) maps an SMT formula template to a differentiable computational graph, trains constants and predicate sharpness, then sends the discretized candidate to Z3. The abstract says: âwe present Continuous Logic Network (CLN), a novel neural architecture for automatically learning loop invariants directly from program execution tracesâ (Abstract, p. 1). The target is invariant inference, not proof replacement: Z3 checks each learned candidate against initiation, consecution, and postcondition obligations.
Inference: the useful VL role is candidate generation for requires, ensures, and loop invariant clauses; Verus remains the sound acceptance gate.
technique 1: continuous semantic mapping for SMT
What it is. The paper defines a sound-and-complete semantic mapping S from quantifier-free SMT formulas to continuous truth values. It requires BL consistency, almost-everywhere differentiability, and a nonzero gradient toward satisfaction or violation (Section 3, pp. 4â5). For > and â„, shifted/scaled sigmoid functions are used; negation, conjunction, and disjunction come from BL t-norm/t-conorm choices, while †and equality are derived (Section 3, p. 5).
When and steps.
- Choose positive scale
Band offsetΔ; map atomic inequalities with the paperâs shifted sigmoid (Section 3, p. 5). - Derive
ÂŹ,â§, andâšusing one of Gödel, Ćukasiewicz, or product semantics (Section 3 and Appendix G). - Derive
â€fromâ„and negation, then equality as the conjunction of both inequalities (Section 3, p. 5). - Compose clause values recursively into the formula value
S(F)and preserve the formula templateâs operators.
Verus form. Inference: do not replace Verusâs Boolean specifications with fuzzy values. Keep a ghost SMT/real-valued model outside the verified Rust module, use it to propose constants, then emit a Boolean spec fn and check it with Verus assert, loop invariant, and ensures. The paperâs differentiability is a training device, not a Verus proof rule.
Evidence and limits. The paper proves the mapping properties in Theorems 1â3 and studies all three t-norm families (Appendix G). The mapping covers quantifier-free formulas only (Section 3, p. 4); quantifiers and discontinuous predicates are outside the stated construction. Scale and offset regularization trade precision against gradient size.
technique 2: CLN construction and training
What it is. A CLN is built from an SMT formula template in which each term is marked as input, fixed constant, or learnable parameter. The graph is created recursively for terms and clauses. The paper states: âCLNs use our continuous semantic mapping to represent SMT formulas as an end-to-end differentiable model that can learn selected constants in the formulaâ (Section 4, p. 5).
When and steps.
- Generate a template and mark learnable constants and predicate scales (Section 4, p. 5).
- Construct the graph by recursively adding arithmetic operations, atomic predicates, and logical operations.
- Run gradient optimization over valid assignments
X, minimizing a loss for outputs below one; add hinge loss for scaleBand L2 regularization for offsetΔ(Section 4, p. 5). - Stop when the loss approaches zero, discretize the learned parameters, and pass the SMT formula to a solver.
Verus form. Inference: generate a candidate spec fn from the learned template, instantiate its constants, and have a Verus proof harness discharge the actual obligations. assert and proof fn lemmas replace Z3 calls only at the final Boolean-checking stage; the neural graph and optimizer remain untrusted tooling.
Evidence and limits. Training needs valid assignments, a chosen template, hyperparameters λ and Îł, and a minimum scale ÎČ (Section 4, p. 5). A low continuous loss is not itself a proof; candidate discretization can change satisfiability.
technique 3: trace-driven invariant learning
What it is. CLN2INV runs the target program on random inputs satisfying preconditions, records variables before each loop execution and after termination, and learns an invariant template from those traces (Section 5, p. 6). Static analysis supplies constants and the termination condition; it strengthens the precondition and weakens the postcondition to obtain useful terms (Section 5, p. 6).
When and steps.
- Sample random initial states: unconstrained variables use a uniform distribution, constrained variables use a uniform distribution inside the constraint (Section 5, p. 6).
- Record loop-entry and final states.
- Extract constants, conditions, and arithmetic terms by static analysis; instantiate the SMT template.
- Train the CLN on traces, discretize its formula, and ask Z3 to verify the invariant obligations.
- If Z3 rejects it, continue search/training with another candidate (architecture overview, Section 5, pp. 6â7).
Verus form. Inference: use trace sampling only to propose a spec fn invariant. Encode that invariant in a Rust loopâs invariant clauses and prove initialization, preservation, and exit postconditions over all inputs accepted by requires; sampled traces cannot establish universal correctness.
Evidence. On the Code2Inv benchmark, âCLN2INV is able to solve all 124 problems in the benchmarkâ and reports 1.1 seconds average in the conclusion (Sections 6.1 and 7, pp. 7â9). The comparison denominator is 124 theoretically solvable problems under a one-hour-per-problem limit; Code2Inv solved 90 and LoopInvGen 104 (Section 6.1, p. 7). Twelve additional difficult problems were all solved in under 20 seconds, while both baselines timed out after one hour (Section 6.2, p. 8). With training disabled, the static model solved 91 of 124 (Section 6.3, p. 8). The paper notes Code2Inv authors had reported 92, attributing the discrepancy to environment or randomized initialization (footnote 2, p. 8).
Limits. The benchmark and random traces are finite; the paper does not claim traces cover all executions. Performance depends on template quality, static analysis, Z3, and the optimizer. The 124/124 headline is a solver benchmark result, not a proof that neural outputs are semantically correct without Z3.
proof boundary, trust, and VL impact
The paper proves semantic-mapping theorems and reports solver-checked benchmark outcomes. Trusted components include the SMT solver, static-analysis extractor, trace generator, template design, optimizer, and benchmark harness. No Rust, ownership, heap, concurrency, or Verus encoding is evaluated. Existing Code2Inv and LoopInvGen already solve substantial portions of the same benchmark; VL should not redo trace-only invariant learning without a Verus validation stage. Inference: threat to agent-written verified Rust is medium: learned invariants could speed proof search, but unsoundness enters if a trace-trained formula is accepted without universal Verus checking or if template terms omit ownership-dependent state.
techniques for the catalog
- continuous SMT semantics â map inequalities and Boolean connectives to differentiable truth values with scale and offset regularization
- formula-template CLN â compile a marked SMT template into a differentiable graph and learn selected constants
- trace-driven invariant inference â sample loop executions, statically generate terms, train a formula, discretize it, and submit it to a solver
- solver-in-the-loop filtering â retain only candidates that satisfy initiation, preservation, and postcondition checks Checked 2026-10-14 against the paper by a Codex agent: audit record ryan2019cln2inv; compared the full paper and study, corrected metadata where needed, and did not rerun the experiments
Last edited: