Write manual Coq proofs for Frama-C/WP goals that no SMT solver can close. Covers -wp-interactive update/batch, the edit contract for the generated .v proof file in the session's interactive directory, ACSL-to-Coq name mangling (L_ logic functions, P_ predicates, Q_ lemmas and axioms), the Typed memory-model vocabulary, fast headless coqtop iteration, and the known printing gotchas. Use only after the SMT, assertion, lemma-function and tactic tiers have failed.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Wp Coq?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/evdenis-wp-coq)
---
name: wp-coq
description: Write manual Coq proofs for Frama-C/WP goals that no SMT solver can close. Covers -wp-interactive update/batch, the edit contract for the generated .v proof file in the session's interactive directory, ACSL-to-Coq name mangling (L_ logic functions, P_ predicates, Q_ lemmas and axioms), the Typed memory-model vocabulary, fast headless coqtop iteration, and the known printing gotchas. Use only after the SMT, assertion, lemma-function and tactic tiers have failed.
license: MIT
allowed-tools: Bash(${CLAUDE_SKILL_DIR}/scripts/coq-iter.sh *)
---
# Manual Coq proofs for WP goals
**Requires** Frama-C with the WP plugin, Why3 with its Coq library (`why3-coq`) and Coq,
reachable through opam or on `PATH`, plus bash. A Frama-C installed from the binary bundle
brings a Why3 without that library, and `-wp-prover coq` then stops with `Unknown prover coq`
(`references/coq-anatomy.md`).
## Try the cheaper route first
Most goals that "need Coq" do not. A **lemma function** encodes the induction in C and lets
WP's loop-invariant machinery do it — verified: 20/20 goals proved automatically on exactly
the property that, written as a plain `lemma`, times out on every SMT prover and needs a
hand-written Coq script. See `frama-c-wp/references/auto-active.md`.
Before concluding that you need a label-quantified lemma, check whether the contract needs one
at all. A function that writes to the buffer it reads looks like it requires a two-state frame
lemma proved by induction; usually it does not. State the postcondition over `\at(x, Pre)` and
carry a pointwise *untouched* loop invariant, and the frame fact follows from `\separated`
directly. Eight kernel string functions came off this ladder that way — see
`acsl-spec/references/patterns.md` `## Pointer-walking code, specified over indices`.
Come here when the goal genuinely needs induction over a recursive definition **and** a lemma
function cannot express it — typically because the lemma quantifies over ACSL labels, which a
C function has no way to take as parameters.
## The loop
Paths here are relative to this skill's own directory, which is normally **not** your
shell's working directory. Resolve them against the skill directory and run the absolute
path (in Claude Code, `${CLAUDE_SKILL_DIR}` expands to it).
```sh
# Without this the commands below are not found. Auto-detects the opam switch
# holding frama-c; override with FRAMAC_SWITCH=<name>.
. scripts/env.sh
S=.wp-session
# 1. generate (or refresh) the .v file
frama-c -pp-annot -wp -wp-prover coq -wp-interactive update -wp-session $S file.c
# 2. edit ONLY between Proof. and Qed. in $S/interactive/<goal>.v
# 3. iterate fast -- about 1s per attempt instead of 15s
scripts/coq-iter.sh $S/interactive/<goal>.v
# 4. confirm through WP
frama-c -pp-annot -wp -wp-prover coq -wp-interactive batch -wp-session $S file.c
```
Success looks like `Coq <version>: 1` in the prover summary.
`update` regenerates the preamble and keeps your proof. `batch` checks without creating
anything — use it in CI. `edit`/`fix` open an editor and are not usable headlessly.
## The edit contract
The file says `Beware! Only edit allowed sections below`. **Only the `Proof. … Qed.` block is
yours.** Everything above is regenerated by `update` and edits there are lost — including
`Require Import`. Put imports inside the proof:
```coq
Proof.
Require Import Psatz.
Require Import ZArith.
intros K L a m n L32 K32.
```
## Reading the goal
Goals are stated in the Typed memory model, not in C terms:
- `t : addr -> Z` is a **memory chunk**; two program states appear as two chunks `t` and `t1`.
- `base`, `offset`, `shift` are pointer decomposition and arithmetic.
- `is_sint32 v` / `is_sint32_chunk t` say values fit in `int` — `lia` usually needs these, so
`intros` them with names.
- `valid_rd`, `valid_rw`, `separated`, `included` are the ACSL memory predicates.
Your ACSL names arrive mangled: `logic` → `L_`, `predicate` → `P_`, `lemma`/`axiom` → `Q_`,
with `_1_`, `_2_` suffixes for overloads. **Every ACSL lemma already in scope is usable as
`Q_<name>`** — that is what keeps these proofs short.
## The shape of a real proof
`auto with zarith`, `rewrite`, `lia`, `intros`, `replace`, `assert`, `apply` and
`natlike_rec2` cover almost everything. The job is mostly rewriting with lemmas you already
proved, plus integer arithmetic; genuine induction is rarer than it looks. Worked skeletons:
`references/coq-recipes.md`, and `assets/proof.v` to start from.
## Gotchas that cost the most time
- **Coq prints `-1` as `- (1)`.** `replace (-1 + ...)%Z` silently fails to match; write
`replace (- (1) + ...)%Z`. A `replace` that matches nothing may not error — it just leaves
the goal untouched and a later `lia` fails for no visible reason.
- **`Tactic failure: Cannot find witness.`** is `lia` saying a hypothesis is missing. Insert
`Show.` before it and read the context.
- **Check the exact mangled name in the preamble** before using a `Q_` lemma; `_1_` suffixes
are easy to get wrong.
- **`.v` files are source.** Commit `<session>/interactive/*.v`. `<session>/cache/` is generated:
leave it out by default, and commit it only as a deliberate choice to make the proof
replayable without provers, pruned first — `verifiable-c/references/project-layout.md`.
## If the proof is hard
Stop and add another ACSL `lemma` instead, then prove that separately. A long Coq proof
usually means a missing intermediate lemma, not a hard theorem.
## Closing the loop
Once the goal is discharged, return to the `acsl-verify` skill and re-run the full loop —
one Coq proof landing does not mean the file is done.
## Reference
| Need | Read |
|---|---|
| the goal's symbols make no sense | `references/coq-anatomy.md` |
| you know the goal and need the tactic | `references/coq-recipes.md` |
| the cheaper route you should try first | `frama-c-wp/references/auto-active.md` |
| prover setup, session layout, `-wp-interactive` modes | `frama-c-wp/references/toolchain.md` |
| starting point | `assets/proof.v` |