Files
sisi/verifiers/prove/frama-c-wp.md
T
swaitsandClaude Fable 5.2 2fc1fe9c2d
ci / tests (macos-latest, python 3.11) (push) Canceled after 0s
ci / tests (macos-latest, python 3.13) (push) Canceled after 0s
ci / tests (macos-latest, python 3.9) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.11) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.13) (push) Canceled after 0s
ci / tests (ubuntu-latest, python 3.9) (push) Canceled after 0s
sisi 0.1.0: a shared rulebook and verification tool for AI coding agents
Contracts with a ladder of checks, an end-of-turn gate, retrospectives and
shared lessons, time-to-delivery measurement, a library of 140 verification
techniques and 20 recipes, personal data kept outside the clone, and
releases with rollback. Standard library only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 22:29:02 -07:00

2.9 KiB

id, title, answers, rung, section, languages, kinds, cost, detect, ran_here, verified
id title answers rung section languages kinds cost detect ran_here verified
frama-c-wp Frama-C WP for C with ACSL contracts Does this C function meet its contract and avoid undefined behaviour for all inputs? 1 prove c general, parsing high frama-c -version no docs

Use when

  • Small, critical C functions (parsers, buffers, arithmetic, drivers) need a proof that holds for all inputs, with no unwinding bounds.
  • You can write ACSL contracts (requires, ensures, assigns, loop invariants) in comments.

Do not use when

  • You only need a bounded check with minimal effort. Use cbmc.
  • The code relies on heavy pointer aliasing, floating point, or concurrency without a plan.

Set up

Install with opam (the Frama-C site's recipe: opam init --compiler 4.14.1, eval $(opam env), opam install frama-c). Per the WP manual (written for Frama-C 33.0 "Arsenic", July 2026), the WP plug-in ships with Frama-C, needs the Why3 platform and at least one external prover, and opam installs Alt-Ergo and Why3 automatically; WP finds provers on $PATH and in the Why3 configuration. Not installed here, so nothing below was run.

Minimal example

abs.c:

#include <limits.h>
/*@ requires x > INT_MIN;
    assigns \nothing;
    ensures \result >= 0 && (\result == x || \result == -x);
*/
int my_abs(int x) { return x < 0 ? -x : x; }

Run

frama-c -wp -wp-rte -wp-timeout 20 abs.c

Passing looks like: a line [wp] Proved goals: N / N (the manual shows [wp] Proved goals: 4 / 4; a run with a failure shows Proved goals: 6 / 7 and an Unknown: count). -wp-rte adds the no-undefined-behaviour obligations (overflow, bounds) and -wp-timeout is the per-goal prover timeout in seconds (default 2). The manual does not document an exit status for unproved goals, and Frama-C is commonly seen exiting 0 with unproved goals, so the contract tests the text. Real output may pad the numbers with extra spaces, so the pattern allows them: frama-c ... | grep -E 'Proved goals: +([0-9]+) / \1$' (the backreference is GNU grep).

As a contract check

{"id": "prove-abs-framac", "claim": "my_abs meets its contract and has no runtime errors when x > INT_MIN", "kind": "general", "rung": 1, "cmd": "bash -c \"frama-c -wp -wp-rte -wp-timeout 20 abs.c | tee /dev/stderr | grep -E 'Proved goals: +([0-9]+) / \\\\1$'\"", "expect": {"exit": 0}, "timeout_s": 900, "tier": "deep"}

What a pass does not prove

  • Only the written contract, under a memory model that assumes no aliasing the contract does not allow. assigns clauses must be right.
  • All goals proved means none were skipped by -wp-timeout; a timeout counts as unproved, which the N / N test catches.
  • Not run here; the output format is from the WP manual's examples. Confirm the exit status and spacing of the Proved goals line on your version, and check the check by weakening the ensures so a goal fails.