← All papers
First page of VeriPy Source-Preserving Verification and Compatibility Checking for Python Components

VeriPy Source-Preserving Verification and Compatibility Checking for Python Components

Naing Oo Lwin

cs.SE Oct 2, 2026 · v1 cs.LO cs.PL
Annotated Python components are translated into Lean 4 (and Dafny) artifacts, and all 25 proof units are checked in Lean 4.33.1.
Keeping a Python program and its formal guarantees aligned is a continuing maintenance problem. Specifications must describe the implementation that actually runs, and updates must preserve the behavior on which existing callers depend. VeriPy brings these obligations into a common workflow for annotated Python components. Developers and agents express contracts, invariants, and proof hooks as Python comments, then refine checked auxiliary lemmas using source-located diagnostics. Direct encoders produce Dafny or Lean artifacts while retaining admitted executable bodies and explicit models of their dependencies. A relational product checks whether an updated component still admits old inputs and preserves returned values and modeled exceptions. The resulting workflow connects source-level proof development with functional verification and backward compatibility, recording the assumptions under which each guarantee applies. The code is available at https://github.com/astrio-labs/veripy.

Formal guarantees about Python components drift as the code is maintained. Specifications must match the implementation that actually runs, and updates must preserve the behavior existing callers rely on.

VeriPy reads contracts, invariants, termination measures and proof hooks written as #@ comments in Python. It checks types with basedpyright and admits a supported fragment with explicit dependency models. Separate encoders emit Dafny or Lean artifacts while keeping the executable Python bodies available to native callers. A relational product program then checks backward compatibility: every input the old version admits must be admitted by the new one, with equal returned values and modeled exceptions.

Figure 2: VeriPy verification workflow. VeriPy parses Python and #@ specifications, checks types with basedpyright, and admits a supported fragment. Dafny or Lean checks the translated program and any proof sidecars supplied by a human or LLM. CrossHair searches executable contracts for violations. Guards enforce admitted input conditions. Generated guards and the generic Hypothesis harness target

All 25 dual-backend proof units, drawn from seven repositories (including Django, PyTorch, Black, vLLM and CPython), verified in both Dafny 4.11.0 and Lean 4.33.1. On historical compatibility checks, some updates were proved compatible, Packaging yielded a counterexample, and several cases were inconclusive or unsupported.

ComponentPy LOCTime D / L (s)Property
Black range composition988.98 / 12.48Exact ordered output
PyTorch shard validation9422.66 / 110.76Overlap and errors
Django base36115.37 / 6.84Exact digits/errors
CPython time parser3712.73 / 163.59Exact fields/errors
Selected components verified in both backends (times in seconds, Dafny / Lean)