Skip to content

C4: Contract verifier — Z3-backed verification#10

Merged
aallan merged 1 commit into
mainfrom
contract-verifier
Feb 23, 2026
Merged

C4: Contract verifier — Z3-backed verification#10
aallan merged 1 commit into
mainfrom
contract-verifier

Conversation

@aallan

@aallan aallan commented Feb 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Z3-backed contract verification for requires/ensures clauses — Tier 1 (decidable fragment: QF_LIA + Boolean logic + length) proved automatically, Tier 3 (unsupported constructs) warned gracefully
  • Counterexample generation — when a contract is violated, the diagnostic shows concrete input values that break it, with an LLM-oriented fix suggestion
  • New modules: vera/smt.py (AST→Z3 translation layer), vera/verifier.py (verification orchestration)
  • New CLI command: vera verify <file> — type-checks then verifies contracts, prints tier summary
  • 51 new tests (335 total), all 13 examples verify clean, mypy clean (11 source files)
  • Version bump to 0.0.8
  • LICENSE converted to Markdown (user change, sneaked in)

What it verifies

Example Tier 1 (Z3 proved) Tier 3 (warning)
safe_divide.vera 2 0
absolute_value.vera 3 0
modules.vera (clamp) 5 0
factorial.vera 1 2 (recursive body + decreases)
generics.vera 6 2 (generic functions)
increment.vera 1 1 (effect ops in ensures)
All others trivial contracts 0

Test plan

  • pytest tests/ -v — 335 passed
  • mypy vera/ — no issues (11 source files)
  • python scripts/check_version_sync.py — 0.0.8 consistent
  • python scripts/check_examples.py — all 13 examples pass (check + verify)
  • python scripts/check_spec_examples.py — 154 spec blocks valid
  • Pre-commit hooks pass (mypy, pytest, examples, trailing whitespace, yaml/toml)

🤖 Generated with Claude Code

Implements Tier 1 contract verification using Z3 SMT solver. Functions
with decidable contracts (linear integer arithmetic, comparisons,
Boolean logic, if/else) are proved automatically. Unsupported constructs
(match, effects, recursion, quantifiers) fall back to Tier 3 with a
warning. Counterexample generation shows concrete inputs that break
violated contracts.

New modules: vera/smt.py (AST→Z3 translation), vera/verifier.py
(verification orchestration). New CLI command: vera verify <file>.
51 new tests (335 total). Version 0.0.8.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aallan aallan merged commit 88eb65a into main Feb 23, 2026
10 checks passed
@aallan aallan deleted the contract-verifier branch February 23, 2026 15:16
aallan added a commit that referenced this pull request May 12, 2026
…ecks

The four `in`/`not in` substring assertions on mono-suffix
strings in `TestGenericMonoSuffixFromSlotRef604` could pass on
longer symbol variants (e.g. `$option_map$Int_Int_X` would
satisfy `"$option_map$Int_Int" in wat`).  No current code path
produces longer variants, but the assertions weren't precise
about what they were pinning.

Replaced each substring check with a boundary-safe regex using
a negative lookahead: `re.search(r"\$option_map\$<suffix>(?![A-Za-z0-9_])", wat)`.
The pattern rejects any continuation character that would
indicate a longer variant.  `re` was already imported at top of
file.

Two test methods updated:
- `test_mono_suffix_correct_for_slotref_fn_alias_arg` —
  positive `$option_map$Int_Int` + negative `$option_map$Int_Bool`
- `test_parameterised_alias_substitutes_type_args` —
  positive `$option_map$Int_Int` + negative `$option_map$T_T`

Validation: all 4 tests in `TestGenericMonoSuffixFromSlotRef604`
pass against current compiler output.

Refs #604 #655 #659

Co-Authored-By: Claude <noreply@anthropic.invalid>
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