skills/smt-verify/SKILL.md
Convert VDM-SL proof obligations (POs) to SMT-LIB and verify them with the Z3 solver. Triggered by "prove POs", "verify with SMT", "check with Z3", "auto-verify proof obligations", "prove the spec is correct", or "find counterexamples". Also responds to Japanese: 「POを証明して」「SMTで検証して」「Z3で確認して」等。 Used as the next step after PO generation with verify-spec, or for end-to-end PO generation + SMT verification.
npx skillsauth add kotaroyamame/formal-agent-contracts smt-verifyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Convert proof obligations (POs) generated by VDMJ into SMT-LIB format and verify them with Z3.
VDMJが生成した証明責務(PO)をSMT-LIB形式に変換し、Z3で自動検証する。
which z3 || pip install z3-solver --break-system-packages
If Z3 is not available, guide the user through installation.
Z3がない場合はユーザーにインストールを案内する。
Locate the VDMJ JAR using the same method as the verify-spec skill.
verify-specスキルと同じ方法でVDMJ JARを特定する。
Generate POs using the verify-spec procedure. Skip if PO output already exists.
verify-specの手順でPOを生成する。すでにPO出力がある場合はスキップ。
java -jar <VDMJ_JAR> -vdmsl <files...> -p 2>&1
For each generated PO, perform the following conversion steps.
各POについて以下の手順で変換する。
Scan all types appearing in the PO and declare them in SMT-LIB.
Follow conversion rules in references/type-mapping-rules.md.
Key mappings:
nat → Int + (>= x 0) constraintnat1 → Int + (>= x 1) constraintdeclare-datatypes + constructors/selectorsseq1 of char → String + (> (str.len s) 0) constraintmap K to V → uninterpreted sort + map_apply/map_dom functionsset of T → (Array T Bool) characteristic function representationPOに出現する全型をSMT-LIBで宣言する。変換ルールは references/type-mapping-rules.md に従う。
Define invariants, pre-conditions, and post-conditions referenced by the PO using define-fun:
POが参照する不変条件・事前条件・事後条件を define-fun で定義する:
(define-fun inv_TypeName ((x TypeSort)) Bool ...)
(define-fun pre_funcName ((arg1 Sort1) ...) Bool ...)
Include type constraints (nat/nat1 bounds, seq1 non-empty constraints) in invariant definitions.
Convert PO expressions following references/expression-mapping-rules.md.
PO式を references/expression-mapping-rules.md に従って変換する。
Key patterns:
forall x:T & → (forall ((x T_smt)) (=> type_constraint ...)) — type constraint as antecedentexists x:T & → (exists ((x T_smt)) (and type_constraint ...)) — type constraint conjunctedmk_R(f1,f2):R pattern → single variable + let-bind fieldslet x = e in body → (let ((x e_smt)) body_smt)is_(e, bool) → usually true (trivial for total functions)SMT-LIB verification uses refutation: "if the negation is unsatisfiable (unsat), the original proposition is valid":
SMT-LIBの検証は反駁法:「否定が充足不能(unsat)なら元の命題はvalid」:
(assert (not <PO_smt>))
(check-sat)
Save the converted SMT-LIB file and verify with Z3:
変換したSMT-LIBファイルを保存し、Z3で検証する:
# Save to file
cat > /tmp/po_N.smt2 << 'SMTEOF'
<SMT-LIB content>
SMTEOF
# Verify with Z3
z3 /tmp/po_N.smt2
Interpret Z3 output and report to the user in a clear manner.
Z3の出力を解釈し、ユーザーにわかりやすく報告する。
| Z3 Output | Meaning | User Explanation (EN) | ユーザー向け説明 (JA) |
|------------|---------|----------------------|---------------------|
| unsat | Negation unsatisfiable → PO is valid | Proved: This property is logically derived from the spec | 証明成功: この性質は仕様から論理的に導かれます |
| sat | Negation satisfiable → counterexample exists | Counterexample found: A case violating this property exists | 反例発見: この性質を満たさないケースがあります |
| unknown | Z3 cannot decide | Undecidable: Z3 cannot automatically decide. Consider simplifying the spec | 判定不能: Z3では自動判定できません。仕様の簡略化を検討してください |
| timeout | Time limit exceeded | Timeout: Verification did not complete in time | タイムアウト: 検証が時間内に完了しません |
For sat results, have Z3 output the model (counterexample):
(check-sat)
(get-model)
Explain the counterexample in natural language. Example:
Counterexample: When name = "", email = "[email protected]", age = 200, the invariant
age <= 150is violated. 反例: name = "", email = "[email protected]", age = 200 のとき、不変条件 age <= 150 に違反します。
Summarize all PO results:
全PO結果をまとめて報告する:
## SMT Verification Summary / SMT検証サマリー
| # | Definition | PO Type | Z3 Result | Verdict |
|---|------------|---------|-----------|---------|
| 1 | User | invariant satisfiability | unsat | Proved / 証明成功 |
| 2 | findUser | map apply | unsat | Proved / 証明成功 |
| 3 | RegisterUser | state invariant | sat | Counterexample / 反例あり |
Proved: X/N
Counterexample found: Y/N
Undecidable: Z/N
Process POs in priority order rather than all at once:
すべてのPOを一度に変換するのではなく、優先度順に処理する:
is_(e, bool) pattern is usually trivial / 通常自明Abandon conversion and report for these cases:
以下のケースでは変換を断念し、報告する:
card requires approximation even for finite sets高階関数、再帰関数の停止性、無限集合の基数、パターンマッチの網羅性は変換不可。
When conversion is impossible:
references/type-mapping-rules.md — Complete type conversion rulesreferences/expression-mapping-rules.md — Complete expression conversion rulesreferences/conversion-examples.md — Real PO conversion examples (verified with Z3)testing
VDM-SL仕様の型チェック、構文検証、証明責務生成を実行するスキル
development
Orchestrate the full reverse engineering pipeline: Extract provisional spec from existing code, refine through dialogue to uncover the true spec, then reconcile code with the confirmed spec. Optionally connects to the forward pipeline (verify → prove → generate → test). Triggered by: "reverse workflow", "extract and refine spec from code", "formalize existing code", "reverse engineer the specification", 「リバースワークフローで」「既存コードから仕様を起こして」「コードの仕様を明確にしたい」 「このプロジェクトを形式仕様で整理したい」「既存コードをリバースエンジニアリングして」
testing
Refine a provisional VDM-SL specification through dialogue with the user, uncovering the true specification that exists in the user's mind. The provisional spec (from extract-spec) serves as a scaffold for questions. Triggered by: "refine the spec", "review the provisional spec", 「仕様を磨きたい」「仮仕様をレビューして」「コードの意図を確認したい」「仕様を確認して」
development
Reconcile existing code with the confirmed VDM-SL specification. Compare spec vs code item-by-item, generate a diff report, produce code fixes prioritized by Finding category, and auto-generate tests. Triggered by: "reconcile code with spec", "fix code to match spec", 「仕様とコードを照合して」「コードを仕様に合わせて」「差分を出して」「コードを直して」