@h2loop/hydron-formal-verification
v1.0.3
Published
Formal verification for Hydron: requirements to ACSL contracts to Frama-C/WP proofs, with per-requirement evidence for regulated embedded C
Maintainers
Readme
Hydron formal verification
Prove that your C code meets its requirements, with Frama-C, from one Hydron command.
/prove docs/requirements.mdHydron reads the requirements, finds the functions that implement each one, writes the
pre- and postconditions (ACSL contracts) for them, runs the Frama-C/WP prover, explains every
goal it could not prove, confirms real defects by running them, and gives you a per-requirement
report. Your source files are never modified: contracts go into proof copies under fv/proofs/,
and the prover refuses a copy whose code differs from yours.
Quick start
- Install:
hydron plugin add @h2loop/hydron-formal-verification(orhydron plugin add <path>). /fv-setup: finds Frama-C (native, or a Docker image it can pull or build for you), readscompile_commands.jsonfor include paths and defines, and picks the target machine model (ARM Cortex-M/R, PowerPC, AVR, x86). Writesfv/hydron-fv.json./prove <what>: any of- a requirements file or Doorstop folder:
/prove reqs//prove docs/srs.csv - requirement IDs:
/prove REQ-003 REQ-007 - a source file or functions:
/prove src/pid.c/prove pid_update - nothing: Hydron looks for the requirements itself.
- a requirements file or Doorstop folder:
- Read the reply, or
fv/REPORT.mdat any time (/fv-reportrefreshes it). - Review each contract against its requirement (the report shows both, plus the contract in
plain words). When it says what the requirement means:
/fv-approve REQ-003. CI (script/fv-ci.ts) passes a proved requirement only once its current contract is approved;--allow-unreviewedrelaxes that while a project is being set up. - For a requirement in the
assumingstate, accept each remaining check you take responsibility for:/fv-accept <goal> because <reason>.
Optional checks (off unless you say yes)
A proof shows that the code agrees with its contract. It does not show that the contract says
everything the requirement says. Two optional checks help with that. In fv/hydron-fv.json, set each
to ask (the default: Hydron asks you at the start of /prove), on (always) or off (never, and
Hydron does not ask).
| Setting | What it does | What it costs |
|---|---|---|
| "mutation" | After the proofs, changes the code of each proved requirement in small ways (< to <=, == to !=, + to -, a constant plus one), one at a time on a scratch copy, and proves again. A change that no proof notices shows behaviour the contract does not state. Results in fv/REPORT.md and fv/mutation.json. Run it any time with /fv-mutate. | About one proof run per change; 10 changes per requirement by default. |
| "contractFirst" | You approve each requirement's contract (requires, ensures, assigns) before Hydron proves it and writes loop annotations. After that, any change to the approved contract makes the requirement failed. | Your review time during the run. |
{ "mutation": "ask", "contractFirst": "off" }Headless runs (hydron run) cannot ask, so there both checks run only when set to on.
What a result means
| Status | Meaning |
|---|---|
| proved | Every contract clause for the requirement and every runtime-safety goal (overflow, out-of-bounds, invalid pointer, shift, division) in its functions is proved, and no dead code was found. |
| partial | Proved, but the contract states only part of the requirement; the report says which part is not covered. |
| conditional | Proved, but only for callers that respect a precondition no proved call checks (an entry point's input ranges, for example). The report lists each one; your approval of the contract confirms who guarantees them. |
| assuming | The requirement's own contract clauses are proved, but other checks in its functions are not (a Frama-C limit, a prover timeout, a runtime goal no test reproduced). The report lists each one under "Holds only if these unproved checks hold". Fix the cause, or accept each check by name with /fv-accept <goal> because <reason>; CI passes it only when all are accepted. |
| failed | A runtime defect reproduced by a witness program on the original code, a code/requirement mismatch, dead code, or (contract-first mode) a contract changed after you approved it: triggering values, the witness output and a proposed fix are in the findings. An unreproduced runtime goal never makes a requirement failed. |
| open | Goals remain unproved: the requirement's own clauses, or checks with no explanation yet. |
| stale | The code, proof copy, fv/assumptions.h or settings changed after its functions were last proved, or a function has not been proved yet. Re-run /prove. |
| unformalizable | Not expressible as a function contract (timing, scheduling, hardware behaviour). Verify by test. |
A proof is only as good as its contract, which is why contracts need your sign-off, and why
the sign-off is tied to the exact contract text (editing a contract later shows
changed-since-approval).
What it does not prove
Read this before you use a report as certification evidence.
- Only what the contract states. "Proved" means: for every input that meets the function's preconditions, there is no runtime error and every postcondition holds. The report shows each contract in full, preconditions included, and needs your approval.
- Preconditions are assumed. A precondition counts as checked only where Frama-C proved it at a
call, in a function it proved. Where no proved call checks it (an entry point, or callers in code
that was not proved), the requirement shows as
conditional. - Not covered: timing and scheduling, concurrency and interrupts (the analysis is sequential),
hardware behaviour, the compiler and linker, and functions with no body in the analysed files
(their contracts in
fv/assumptions.hare assumed and listed in the report). - Target approximation. Integer sizes and alignment come from a machine model
(
arm_eabi_32,ppc_32_eabi, ...) that approximates your cross-compiler. Check that it matches your target. - C only. Frama-C proves C99/C11. C++ files are refused with a message.
- Tool qualification. Frama-C, Alt-Ergo, Why3 and this plugin are not qualified under DO-330
or ISO 26262-8. Use the results as supporting evidence (for example under DO-333) with your
own tool confidence assessment. The report records the exact tool versions and command for
each proof, and
script/fv-ci.tsre-runs every proof in CI without any AI.
What it needs
- Frama-C 32.1 with Alt-Ergo, either on
PATHor through Docker (hydron-fv:32.1built fromdocker/Dockerfile, or the officialframac/frama-c:32.1). Air-gapped sites: build or pull once elsewhere,docker save,docker load. - Requirements in Doorstop, CSV (DOORS/Polarion/Jama/Excel exports), Markdown/text, JSON or YAML.
- Tested on macOS (arm64) with Docker. Linux and Windows (x64, arm64; Windows through Docker Desktop) use the same code paths but have not been tested yet.
Files it writes (all under fv/, commit them)
hydron-fv.json settings · assumptions.h contracts for library/RTOS/HAL code that is not
proved (you review these) · requirements.json · plan.json · proofs/ · results/ ·
findings.json · approvals.json · mutation.json (optional mutation check) · REPORT.md · status.json (machine-readable, for
traceability) · .runs/ raw prover logs (gitignored).
For developers
- Design and every decision: DECISIONS.md.
- Library:
lib/(requirements parsing, ACSL identity/line mapping, Frama-C runner, status). Tools:handlers/fv_*.ts, registered inplugins/index.ts. Agent:agents/formal-verifier.md. Skill:skills/acsl-contracts/. - Tests:
bun test test. Typecheck:tsgo --noEmit -p tsconfig.json. - Benchmarks: in h2loop/hydron-fv-benchmarks, which pins this plugin as a submodule and runs and grades it.
