Flex: A Foundational Proof-Producing Horn Solver
Jam Kabeer Ali Khan, Petros Markopoulos, Niki Vazou, Nico Lehmann, Ranjit Jhala
cs.PL
Jul 14, 2026 · v2
cs.LO cs.SE
TL;DR
Implements Flex, a proof-producing CHC solver, as Lean metaprogram tactics (zap, fix) emitting kernel-checked proofs for Flux Rust verification.
Abstract
Constrained Horn Clauses (CHCs) are a versatile intermediate representation for program verification, but leading CHC solvers rely on SMT-based reasoning over supported background theories. Specifications involving user-defined recursive functions or bespoke operators can require additional semantic encodings and reasoning beyond these theories. We observe that CHCs are existentially quantified propositions in a foundational logic, and so can be proved within an interactive theorem prover, where specifications can use native definitions, and users can complete proofs when automation stalls. However, in a foundational setting, every Horn variable solution must be justified by a kernel-checked proof. We present Flex, a proof-producing CHC solver implemented as a Lean metaprogram, that combines predicate synthesis with proof construction. Flex comprises a suite of tactics: Zap, which synthesizes strongest predicates for acyclic Horn variables and exploits their structure to construct elimination proofs without any proof search; Fix, which uses predicate abstraction over templates built from arbitrary Lean terms, discovered by scraping the CHCs and associated definitions, to infer inductive invariants for cyclic Horn variables; and a certifying pipeline that keeps external SMT-based solvers like Spacer and Eldarica outside the trusted computing base. We use Flex to verify the functional correctness of sorting algorithms, hash tables, ring buffers from the Tock OS kernel, and Rust std library challenges. We show that Zap constructs elimination proofs 28.2x and 44.6x faster than grind and aesop, respectively. With Zap and Fix, Flex automatically proves 98.0% of the refinement-typechecker CHCs in our evaluation.
Problem
CHC solvers used for program verification rely on SMT reasoning over fixed background theories. This makes specifications with user-defined recursive functions hard to handle, and it places large SMT engines in the trusted computing base.
Approach
CHCs are treated as existentially quantified Lean propositions and solved by Flex, a Lean metaprogram of about 2700 lines. The Zap tactic synthesizes strongest solutions for acyclic Horn variables and builds elimination proofs without proof search. The Fix tactic infers inductive invariants for cyclic variables by predicate abstraction over templates scraped from Lean terms. External solvers such as Spacer and Eldarica are used only through a certifying pipeline. The Flux Rust verifier is extended with a backend that emits Lean propositions, and foundational verifiers are built for Imp and a refinement-typed lambda calculus.
Results
Flex verifies sorting algorithms, hash tables, Tock OS ring buffers and Rust std challenges. Zap is 28.2x faster than grind and 44.6x faster than aesop at constructing elimination proofs. Zap and Fix together automatically prove 98.0% of the evaluated refinement-typechecker CHCs.
| Case study | Flux LoC | #CHCs | Spec LoC | Proof LoC |
|---|
| Sorting | 316 | 15 | 96 | 620 |
| RingBuffer | 257 | 10 | 75 | 501 |
| TickTock | 15 | 5 | — | 302 |
| HashTable | 562 | 22 | 245 | 1361 |
Case studies: verified Rust LoC, number of CHCs, Lean spec LoC, and proof LoC