Skip to content

Embed symbolic Fin indices as bounded integers with proof reconstruction - #5

Open
dranov wants to merge 7 commits into
mainfrom
codex/fin-embedding-reconstruction
Open

dranov wants to merge 7 commits into
mainfrom
codex/fin-embedding-reconstruction

Conversation

@dranov

@dranov dranov commented Nov 21, 2026 •

Copy link
Copy Markdown

Veil generates obligations over fields such as coverage : Fin maxId → Nat, where maxId is a parameter and may be zero. This PR embeds Fin n as the integers satisfying 0 ≤ i ∧ i < n and reconstructs proofs for reads, writes, and frame conditions over those fields. It targets the fork’s main. The motivating example is verse-lab/veil#173.

What this fixes over #4

We ran identical Lean examples on #4 at ecf8e34 and on this implementation. Two examples give closed proofs of False under +trust on #4. This branch rejects both.

  • Nonstandard casts. Embed functions over Fin n with a symbolic bound #4 accepts @Nat.cast Int c 0 = 0 for arbitrary c : NatCast Int. Choosing the cast that always returns one gives 1 = 0. This implementation uses proved rewrites for the casts introduced by the embedding.
  • Empty function domains. Embed functions over Fin n with a symbolic bound #4 derives False from f : α → Fin 0 and h : ∀ a, (f a).val = 0. Both hypotheses hold when α := Empty. The new output rule checks inhabitation before introducing a range constraint over an abstract SMT argument sort.

Six true obligations that failed on #4 reconstruct here: reflexivity of a quantified field read, (∃ _ : Fin n, True) ↔ 0 < n, positivity from an aliased index, preservation of a bound after a whole-field write, wraparound from 3 to 0 in Fin 4, and the extracted weakest-precondition obligation from Veil ufmg-smite#173. The simpler result bound for f : Nat → Fin n passed on both revisions. Fin regression suite

Veil proof reconstruction

We tested Veil at 18a1c985 with a temporary port to its no-mathlib dependency and veil.smt.trust false.

Example Result
Two-action ufmg-smite#173 reproducer, four-action variant, indexed routing All 6, 25, and 6 checks passed, respectively. The extracted weakest-precondition and transition-relation proofs use only propext, Classical.choice, and Quot.sound.
Work queue, mirrored journal, three-server protocol Reconstructed mutual exclusion, the publish and synchronization invariants, and all 12 three-server safety checks. The queue also passed explicit model checking over 27 reachable states.
Finite quorum 19/20 at the default 60-second timeout. Ratification preserving the single-vote invariant timed out. With veil.smt.finiteModelFind false, all 20 passed at four seconds per query.

EWD840 still had six undischarged conditions. The deliberately buggy circular buffer failed its put-safety condition. Fin-indexed counterexamples can also fail to render because the returned field interpretation expects an integer index.

The Lean SMT regression suite passed 121/122 files. The sole mismatch, Test/BitVec/Rewrites.lean, produced the same diagnostics as the parent.

Veil symbolic verification benchmarks

Across all 25 existing symbolic examples, Veil’s pinned Lean SMT (b528077) and the no-mathlib port of this PR (0579b2c) both verified all 1,653 invariant obligations. Total wall time was 900.2 s on the pin and 906.6 s with the PR (+0.7%). This comparison uses the second pass plus a longer run for Distributed Reliable Broadcast, which exceeded the three-minute cap on both builds. Across the 23 examples that completed in both passes, the PR averaged 3.0% more wall time on the shared host.

With proof reconstruction enabled (veil.smt.trust false), the three Fin-indexed examples improved from 17/37 to 37/37 obligations proved. Two-action coverage went from 4/6 to 6/6, four-action coverage from 9/25 to 25/25, and indexed routing from 4/6 to 6/6.

Trusted-mode blockers for separate PRs

Default proof reconstruction rejects both statements below. With +trust, each can still be accepted on this branch.

  1. SMT binder capture. Given a global def x : Int := 0, the tactic accepts ¬ ∃ i : Fin 2, (i.val : Int) ≠ x. The witness is 1. The generated query binds another x and compares (distinct x x). A test merge of the fork’s name-capture fix emitted (distinct x_1 x) and rejected the example.
  2. Custom integer order. For arbitrary rel : LT Int and i : Fin 1, the tactic accepts @LT.lt Int rel (i.val : Int) 1. Taking rel to be always false refutes it. The integer translator needs to check the supplied instance before emitting SMT’s built-in <.

The regression file checks default-mode rejection and records the two trusted-mode failures so each follow-up can clear its expected diagnostic. Blocker reproducers

Represent quantification, function arguments and function results with proved equivalences. Normalize Fin.mk projections and Nat-to-Int round trips during embedding, including the generated weakest-precondition and transition-relation obligations from Veil ufmg-smite#173.

Check domain inhabitation when adding a quantified result bound, and refuse residual finite sorts and aliases at the SMT boundary. Cover empty Fin, symbolic bounds, custom cast instances and unsupported function spaces in trust mode.
Select the finite normalization and embedding rules from the original goal, supplied facts and relevant context. Retain real witnesses of function domains and send mixed Fin/user-sort UNSAT results through proof reconstruction even in trust mode.

Check aliases, constructor fields and type arguments before declaring uninterpreted sorts. Report unsupported Fin function arity during embedding. Add regressions for aliases, explicit inhabitation, context relevance and empty carriers.
dranov added a commit that referenced this pull request Nov 21, 2026
Backport #5 (0579b2c) to veil-no-mathlib. Preserve the configurable Bool embedding and local Nonempty evidence used by Veil. Include the finite-sort regression suite and its trusted-mode blocker cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant