Skip to content

fix: preserve module params in counterexamples - #197

Draft
dranov wants to merge 3 commits into
codex/binding-shadowing-testsfrom
codex/fix-symbolic-counterexample-params
Draft

dranov wants to merge 3 commits into
codex/binding-shadowing-testsfrom
codex/fix-symbolic-counterexample-params

Conversation

@dranov

@dranov dranov commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #192. Addresses the counterexample reconstruction bug reported in #120.

Observed problem

With param f : Nat → Nat, #check_invariants reports that step violates def_y but fails to reconstruct the counterexample. The violation is real. With f := id, initialization gives (x, y) = (0, 0). The second assignment reads the incremented x, so one step gives (1, 2) and violates y = f x. One-step trace and Lean proof

Wider problem

Ordinary module value parameters can prevent Veil from turning a satisfying solver model into a counterexample or symbolic trace. A scalar param bound : Nat suffices. With x := 0 at initialization and x := bound + 1 in a step, #check_invariants can refute x ≤ bound but loses the counterexample, and sat trace finds the violating execution but fails to render it.

Root cause

Veil supplied only the module’s sort arguments when rebuilding the generated Lean terms. Instantiation, FieldAbstractType, Theory, and Label also expect value parameters in declaration order. This can leave a constructor partially applied or pass a state-field label where a value parameter belongs. Looking up the missing values by source name alone is ambiguous when a quantified variable shadows a module parameter.

Fix

  • Give module value binders reserved solver names after elaboration. The model decoder can identify the parameter even when another binder uses the same source name.
  • Rebuild the full argument list in declaration order and use it for both invariant counterexamples and symbolic traces. Specialize dependent parameter types as earlier arguments are recovered, rebuild structured values from solver projections, and use defaults for omitted unconstrained arguments.

Other changes

  • Share the declaration-order parameter list across binder generation and reconstruction, and render marked assignments under param.<name> to distinguish them from same-named locals.
  • Make the discharger’s binder metadata optional for existing callers. Custom proof tactics keep their source binder names, and their unmarked models skip structured reconstruction for modules with value parameters.
  • Add regression coverage for the function parameter, Boolean shadowing, a dependent Fin trace, and a class-valued parameter whose sort may be omitted.

The cvc5 parser error reported for the larger model still needs a separate reproducer.

Validation

lake build VeilTest Examples passed locally (1,621 jobs).

@dranov
dranov added this pull request to stack #198 November 21, 2026 04:39
@dranov
dranov force-pushed the codex/fix-symbolic-counterexample-params branch from 834917f to 3436770 Compare November 21, 2026 05:23
@dranov dranov changed the title Preserve module parameters in symbolic counterexamples fix: preserve module params in counterexamples Nov 21, 2026
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.

immutable function / param of type Nat → Nat: #check_invariants refutes a preserved invariant with an empty counterexample

1 participant