Skip to content
Back to skills

Wp Coq

ASecurity

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.

  • 4 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 4, 2026
ai-agentsgoshellbashexpress

Works with

  • claude code

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned November 20, 2026

npx -y skills add evdenis/acsl-skills --skill wp-coq --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Wp Coq?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Wp Coq
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/evdenis-wp-coq/badge)](https://www.skillsdirectory.com/skills/evdenis-wp-coq)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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` |

Files in this skill

  • SKILL.md5.8 KB
  • agents/openai.yaml167 B
  • assets/proof.v2 KB
  • references/coq-anatomy.md3.8 KB
  • references/coq-recipes.md4.1 KB
  • scripts/coq-iter.sh1.6 KB
  • scripts/env.sh2.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.