# The soundness case

Status: Draft 1 (2026-11-06, T33 G13). This document sets out why a program Verada accepts
behaves as its contracts say: the claim, the argument, what the argument trusts, and the
evidence for each step. It is also the basis of a qualification kit, whose plan closes the
document.

## 1. The claim

For a program that `veradic prove` (or a default `build`, `run` or `emit`, which prove first)
accepts without errors:

1. **Safety.** No execution from a state that satisfies a subprogram's precondition, and its
   parameters' and globals' subtypes, fails a language check (overflow, range, index,
   division, discriminant, tag, null, length, accessibility, predicate, ownership) or reaches
   a `raise` that its `Exceptional_Cases` do not allow.
2. **Correctness.** Every normal return satisfies the postconditions, every propagated
   exception the exceptional cases covering it, every program exit the `Program_Exit`
   condition, and every end the case of `Exit_Cases` whose guard held on entry.
3. **Freedom from interference.** Flow analysis's contracts hold (`Global`, `Depends`,
   initialisation), no two tasks or interrupt handlers race on a variable outside a
   protected object, and ownership leaves no alias through which a proved value could change.
4. **Termination** where it is asked for: every function, and every procedure with
   `Always_Terminates` or a variant.

The claim is conditional on the trusted base (section 3) and on the assumptions the program
itself makes, all of which `veradic trust` lists: each `pragma Assume`, each contract of a
subprogram imported from C, each trusted enclave, each `Logical_Equal` function, each check
justified by review, each proof made outside Verada, and each raised proof budget.

## 2. The argument

Verada's pipeline is one program: the front ends (Vada, Varc, Vibe) produce one typed tree;
`Lower` produces Verada Core (BIR, `docs/plans/verada-core.md`); the prover, the code generator
and the reference interpreter all read Core. The argument has four parts, each small because
Core is small (a handful of type formers, expression and statement forms, and a catalogue
of primitives, verada-core.md section 6) and has a written reference semantics (verada-core.md appendix A).

| Part | Statement | Evidence |
| --- | --- | --- |
| A. Lowering is faithful to Ada | Core's meaning of a program is Ada's (RM 2022 and SPARK RM) for the language Verada accepts | GNAT differential corpora: every corpus is built by GNAT and must print what Verada's three engines print; GNATprove proves the same corpora, a second prover on the same source |
| B. The VC generator is sound for Core | If every obligation of a subprogram holds, the subprogram is safe and correct under appendix A (one case per form and per primitive) | Appendix A's wp rules, one per form, as `Verada.Proof.VC` applies them; the catalogue's three-way property; counterexample replay; the soundness regression tests (section 5) |
| C. The interpreter is the semantics | `Verada.BIR.Interp` computes appendix A's rules | Appendix A is written from it; its departures are listed in A.7, each fixed or settled |
| D. Code generation refines the semantics | On an execution that fails no check, native code produces the interpreter's outputs; only proved checks are elided | Corpora built **with proof** must print the interpreter's output (an unsound proof would elide a check the interpreter then fails); in-memory (JIT) and native runs must agree; generated arithmetic tests compare native code with the interpreter |

Part B carries the weight: a proof is only as good as its obligations. Its design keeps each
obligation local (a subprogram is proved from its callees' contracts, never their bodies,
unless a body is published, D156), monotone (adding a declaration or a check changes no other
obligation's text, D157, `test/Verada/Proof/MonotonicitySpec.hs`) and stable (each library
proof holds under another seed, renamed symbols and reordered facts, D158, the release gate).

## 3. The trusted base

What the argument assumes rather than checks:

- **The SMT solvers' `unsat` answers.** Z3, cvc5 and Yices decide each obligation; any one's
  `unsat` is accepted. Certificates (D92) record the unsat cores Z3 found and are rechecked by
  Z3 against regenerated obligations. `prove --check-proofs` (G12, D170) has cvc5 write an
  Alethe proof of each proved check and Carcara check it: a check so checked rests on Carcara
  and the rewrite rules given to it (cvc5 1.4.2's, and a few of Verada's checked by Z3), not on
  the solvers. Today that covers integer and array obligations (the gold corpus 312 of 325),
  not those over records, floats or division by a possible zero, which cvc5 writes no Alethe
  proof of; those stay trusted.
- **The float theory's encoding.** Floating-point obligations are decided in the solvers'
  IEEE theory; the error model over the reals (`Verada.Proof.ErrorModel`) is a faster route
  whose facts (monotone rounding, exact whole numbers, rounding to integers) are each IEEE
  theorems, and only its proofs are taken, never its counterexamples.
- **The tools that build Verada and its output**: GHC, LLVM (code generation and the JIT), the
  C compiler for the run-time, and the operating system's threads, signals and clock.
- **The run-time's C code** (`rt/`): heap, secondary stack, images, tasking, interrupts. It is
  small and reviewed; its behaviour is exercised by the run tests.
- **The predefined library's contracts**, which clients trust. Its bodies are proved by the
  release gate (`gorelease.sh`: every body in `lib/` by a prove test), except the C run-time's.

## 4. Process controls

- **The freeze rule** (D134): Core's forms change only for a genuinely new primitive at the
  lowest level, with appendix A updated in the same change. Changes since: the place step
  `StepAs` (D192, 2026-11-11, Luke: "OK, let's do the Core primitive then"); a record's layout
  in `RecordInfo`, printed `at B range F .. L`, the one layout for storage, `'Size`,
  `Unchecked_Conversion` and overlays (D196, 2026-11-11, Luke: "Yes, make that Core change");
  an enumeration representation clause's codes in `EnumInfo`, used by storage, `'Enum_Rep`,
  `'Enum_Val` and `Unchecked_Conversion` (D196, 2026-11-11, Luke: "Also, yes, you can count the
  enumeration thing as part of my 'yes'"); value snapshots in `BSubprogram`, `F (...)'Old` of
  a function that reads globals taken as an expression on entry (D197, 2026-11-12, Luke: "I'm
  fine with the Core change"); a variable's `atomic` mark, an atomic load or store for each
  access, which lets tasks share it (D199, 2026-11-12, Luke: "OK, yes, that sounds important
  (atomic flag). Please continue per recommendation."); an array's `componentBits`, a
  `Component_Size` clause's stride, the components padded to it in storage, `'Size` and
  `Unchecked_Conversion`, and a variable's `alignment`, where it is placed (D196, 2026-11-12,
  Luke: "On the array component size, yes, this should be added to Core.").
- **One regression test per soundness fix**, kept in the suite (section 5).
- **The release gate** (`gorelease.sh`): the full suite, every library body proved, the
  library's proofs stable under three mutations, the manuals' coverage and publication
  checks, the third-party notices.
- **The ledger** records every decision and every defect found, with its fix.

## 5. Soundness defects found and fixed

Each was found by review, by writing the reference semantics, or by a proof that went through
too easily; each has a regression test. They show where the risk lies: in rules that assume
facts (frames, contracts of what is not proved), not in the arithmetic.

| Date | Defect | Fix and test |
| --- | --- | --- |
| 2026-10-30 | A call through an access-to-subprogram value was taken to use no globals, unchecked | A designated subprogram may use none (B3003); `test/ui/b3003-designated-global` |
| 2026-10-31 | An object's index constraint was not checked against the index subtype (RM 3.6.1(7)) | Checked; ledger T32a |
| 2026-11-04 | An instance of a generic subprogram inside a covered generic instance was never proved | Proved where it is made; ledger E4 (Vibe enclaves) |
| 2026-11-05 | A null procedure was never lowered, so its postcondition was never proved | It is its own empty body; ledger G1 |
| 2026-11-06 | A loop's frame assumed every fresh cell outside the footprints freed, a contradiction when a local held one: the hash map's growth proved anything | The frame is relative to the loop's entry; `test/programs/prove/library-verada-containers-hash_maps` |
| 2026-11-06 | Array ordering: an ill-sorted query in the prover, a crash in code generation, `False` in the interpreter for static arrays | Lexicographic in all three; `test/programs/run/array-ordering` |
| 2026-11-06 | Binary32 literals were rounded twice by the interpreter | Rounded once, as the prover and code generation do |
| 2026-11-06 | A private type's default value was not checked against its `Type_Invariant`, which every operation assumes: a default `Count := 5` under `Count <= 3` let a proved program index outside an array (found by the GNATprove comparison) | Checked where the package is elaborated; `test/ui/b5110-invariant-default` |
| 2026-11-06 | A concatenation's last index was not checked against its index subtype (RM 4.5.3(8)) | A range check on each chain of `&`; `test/programs/prove/concat-bounds` |
| 2026-11-06 | A library subprogram with a separate spec (`twice.vads`, `twice.vadb`) was lowered from its spec alone, its body dropped as a duplicate: never proved, "proved 0 of 0" (found by the SPARK benchmark) | Lowered from its body; a spec named on the command line brings its body; `test/programs/prove/library-subprogram-separate-spec` |

## 6. The conformance suite

The tests that tie the engines to the semantics and to Ada, all in `./gotest.sh`:

- `test/Verada/BIR/PrimSpec.hs`: about 1,400 primitive operations computed by the interpreter
  and natively, equal, and each proved equal to the interpreter's value.
- `test/Verada/Codegen/NativeSpec.hs`: every corpus built with proof, run natively and in
  memory, printing what the interpreter prints and what GNAT's build prints.
- `test/Verada/Proof/EnginesSpec.hs`: Z3 and cvc5 give the counterexample cases the same values.
- `test/Verada/Proof/MonotonicitySpec.hs`: canonical obligations are unchanged by unrelated
  declarations.
- `test/programs/prove/*`: the library and the soundness regressions, each with its expected
  outcome (proved, or the exact checks that fail).

## 7. Toward a qualification kit (after 1.0)

A verification tool used to claim credit under DO-178C (DO-330 TQL-5) or IEC 61508 (T2) needs:
tool operational requirements (the claim of section 1, per language feature); a verification
case per requirement (this document's tests, indexed by requirement); the configuration index
(the versions `veradic --version` reports, G15); known problems (the ledger's open items); and
the evidence that the tool's own development follows this process. The pieces exist; the kit
is their indexing, plus independent proof checking (G12) to take the solvers out of the trusted
base.
