verif 0.2.0

In-code formal verification for Rust: an embedded bit-blasting SMT decision procedure, a symbolic DSL, contracts and a machine-checked proof kernel. SPARK-inspired, no_std, no external dependencies.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# CI for the `verif` crate.
#
# The first job runs `scripts/gate.sh` -- the same script a human runs -- so "the gates are
# green" means the same thing locally and in CI, and there is no second copy of the commands
# to drift. The rest install one oracle each and run it as a hard gate, because each is a
# large download (a pinned nightly plus CBMC for Kani; a self-contained bundle with its own
# z3 for Verus; elan for Lean; apt for Coq) that a normal `gate.sh` run should not pay for,
# but that CI can. The `ferrocene` job is the one that cannot run without a secret -- the
# qualified toolchain is commercial -- so it reports and skips when `FERROCENE_TOKEN` is
# absent, exactly as `gate.sh` does.
#
# No job adds a dependency to the crate: z3, Kani and Verus are oracles, invoked as
# subprocesses, and `gate.sh`'s zero-dependency check would fail if that ever changed.
#
# Every third-party action is pinned to a full commit SHA, not a movable tag, so a
# compromised or retagged release cannot change what CI runs. The tag is kept in a trailing
# comment because a bare SHA does not tell a reader which version it is.

name: CI

on:
  push:
    branches: [master, main]
  pull_request:

env:
  CARGO_TERM_COLOR: always

# The workflow reads a public release (Verus) and checks out the repo; it needs no write
# access at all. Declaring that turns the default token into a read-only one, so a
# compromised step has nothing to push with -- least privilege on the same `github.token`
# the Verus download authenticates with.
permissions:
  contents: read

jobs:
  # Runs first and alone: a job that contains an unpinned action dies at "Set up
  # job" before any step runs, so the check cannot live only in the job it is
  # meant to police. This job holds one pinned action, so it survives to report
  # the real reason. The `gate` job runs the check too, for the case where the
  # unpinned action is added here.
  pinned:
    name: actions pinned to a SHA
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
      - run: python3 scripts/check_actions_pinned.py

  gate:
    name: gates (clippy, tests, no_std, zero deps, z3 oracle)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

      # `--emit=mir` works on stable, so a stable `rustc` is enough for the MIR suite;
      # CI names a nightly anyway, out of caution, because a dump-format change is exactly
      # what the `rustc_public` oracle in step 10 exists to catch. Without a compiler named,
      # every test in `tests/mir.rs` skips itself -- and a skipped test still reports `ok`, so
      # the suite count is identical whether the MIR frontend was exercised or not. That is how
      # the per-kind discharge polarity (`Obligation::is_discharged`) came to have no teeth
      # in CI. The in-module oracle in `src/mir/exec.rs` covers that logic ungated; this
      # makes the end-to-end tests run too.
      - name: Install Rust (stable, nightly, MSRV, bare-metal target)
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup toolchain install nightly --profile minimal --no-self-update
          # The MSRV gate in `scripts/gate.sh` builds with the oldest compiler the manifests
          # promise to support. It is installed here so the gate *runs* rather than skipping:
          # a floor that is never exercised is the claim this gate exists to stop trusting.
          # It must match `rust-version` in `Cargo.toml` and `verif-arithmetic/Cargo.toml`.
          rustup toolchain install 1.85 --profile minimal --no-self-update
          rustup default stable
          rustup target add thumbv7em-none-eabihf
          # The bare-metal target has to be present for the MSRV toolchain too, or the
          # gate's no_std half skips and the floor is only half-checked.
          rustup target add thumbv7em-none-eabihf --toolchain 1.85

      # `gate.sh` treats an absent z3 as a failure, on purpose: an oracle that did not run
      # is not evidence about the exporter. setup-python gives a pip that is not externally
      # managed, so `pip install z3-solver` works without --break-system-packages.
      - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
        with:
          python-version: '3.x'
      - name: Install the z3 oracle
        run: python3 -m pip install z3-solver

      # The org rejects unpinned actions, and the failure is a red workflow rather
      # than a clear message, so catch it here too (the `pinned` job is what
      # survives an unpinned action in this file).
      - name: Check every action is pinned to a commit SHA
        run: python3 scripts/check_actions_pinned.py

      # Packaging hygiene: a manifest missing `readme`, a crate directory with no
      # LICENSE, a project credited in the source but absent from NOTICE. None of
      # those fail a build, which is why the check exists.
      - name: Packaging hygiene
        run: sh scripts/check_package.sh

      # `VERIF_RUSTC` must be a path to a `rustc`, not a toolchain name: the frontend
      # runs it as a subprocess (`Command::new(rustc)`), so a bare `nightly` would look for
      # a binary by that name and fail.
      - name: Run scripts/gate.sh
        run: |
          VERIF_RUSTC="$(rustup which --toolchain nightly rustc)"
          export VERIF_RUSTC
          sh scripts/gate.sh

  ferrocene:
    name: ferrocene (qualified toolchain) build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

      - name: Install Rust (stable)
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup default stable

      # Ferrocene is commercial: a subscription plus a customer-portal token, and its release
      # archives "require authentication through the customer portal, and don't allow
      # programmatic access" (Ferrocene User Manual 3.2.1). So this job can only run when a
      # `FERROCENE_TOKEN` secret is configured. It is checked *before* anything is installed,
      # and the job reports and exits cleanly when the secret is absent -- a skipped oracle is
      # not evidence, and it must never be confused with a passing one. `tools/ferrocene/run.sh`
      # keeps the same distinction with its exit codes, which is what lets this job be honest
      # about which of the two happened.
      - name: Is a Ferrocene subscription configured?
        id: have_token
        env:
          FERROCENE_TOKEN: ${{ secrets.FERROCENE_TOKEN }}
        run: |
          if [ -n "$FERROCENE_TOKEN" ]; then
            echo "present=true" >> "$GITHUB_OUTPUT"
          else
            echo "present=false" >> "$GITHUB_OUTPUT"
            echo "No FERROCENE_TOKEN secret; skipping the qualified-toolchain build."
            echo "This is reported, not passed: the gate did not run."
          fi

      # CriticalUp is Ferrocene's rustup-like installer. It installs the *tool*; the toolchain
      # itself is fetched on first use against the token, from `tools/ferrocene/criticalup.toml`.
      - name: Install CriticalUp
        if: steps.have_token.outputs.present == 'true'
        run: |
          set -e
          curl --proto '=https' --tlsv1.2 -LsSf \
            https://github.com/ferrocene/criticalup/releases/latest/download/criticalup-installer.sh | sh
          echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"

      # The token goes in on stdin rather than as an argument. CriticalUp accepts either
      # (`criticalup auth set [TOKEN]`), but an argument would put the token in the process
      # table, where any process on the runner can read it; on a non-TTY stdin CriticalUp
      # reads a single line, which is what the pipe provides. Nothing echoes the token, and
      # `set -x` is deliberately not used anywhere in this job.
      - name: Authenticate CriticalUp and build with the qualified toolchain
        if: steps.have_token.outputs.present == 'true'
        env:
          FERROCENE_TOKEN: ${{ secrets.FERROCENE_TOKEN }}
        run: |
          set -e
          printf '%s\n' "$FERROCENE_TOKEN" | criticalup auth set
          sh tools/ferrocene/run.sh

      # The skip is announced rather than left implicit: a job that quietly did nothing is
      # the failure mode this whole pattern exists to avoid. A warning annotation shows up on
      # the run summary, so "Ferrocene did not run" is visible without reading the log.
      - name: Report the skip explicitly when no token is configured
        if: steps.have_token.outputs.present != 'true'
        run: |
          echo "::warning::The Ferrocene qualified-toolchain build did not run (no FERROCENE_TOKEN)."
          echo "The crate's no_std builds were checked by the stable toolchain in the 'gate' job,"
          echo "but the *qualified* toolchain was not exercised."

  kani:
    name: kani differential oracle
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

      - name: Install Rust (stable)
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup default stable

      # Cache the Kani install: `cargo kani setup` fetches a pinned nightly and CBMC, and
      # re-downloading them on every run is most of the job's wall time.
      #
      # The key is versioned because the first version of this job cached `~/.cargo/bin/cargo-kani`
      # and then unconditionally ran `cargo install`, which *refuses* to overwrite an existing
      # binary ("binary `cargo-kani` already exists in destination"). A restored cache therefore
      # turned the install step into a hard failure on every run after the first, which is what
      # broke this job. The install below is now conditional, so a warm cache is a fast path
      # rather than a trap; the versioned key drops any cache left in the broken state.
      - name: Cache Kani's toolchain download
        uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
        with:
          path: |
            ~/.cargo/bin/cargo-kani
            ~/.cargo/bin/kani
            ~/.cargo/registry
            ~/.cargo/git
          key: kani-${{ runner.os }}-0.68.0-v2

      - name: Install Kani
        run: |
          # `cargo install` is not idempotent -- it errors instead of replacing -- so skip it
          # when the cached binary is already there. The cache key pins the version, so a hit
          # means the right Kani.
          if [ ! -x "$HOME/.cargo/bin/cargo-kani" ]; then
            cargo install --locked kani-verifier
          else
            echo "cargo-kani already installed (cache hit); skipping install"
          fi
          cargo kani setup

      # The oracle is a hard gate here: if it disagrees with the engine, CI fails. It exits
      # non-zero on any mismatch, on a refuted identity, or on a harness that produced no
      # verdict, so a green run means every generated case was actually checked.
      - name: Run the Kani oracle
        run: cargo run -q --features std --example kanidiff -- 64

  verus:
    name: verus differential oracle
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

      - name: Install Rust (stable)
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup default stable

      # Verus ships a self-contained release bundle (its own `z3`, and it needs one pinned
      # rustc toolchain of its own). We take the latest release rather than pinning a tag,
      # because the point of this job is "does the engine agree with an *independent*
      # verifier", and the interesting failures are Verus changing its mind, not ours.
      #
      # The release lookup is *authenticated*. An unauthenticated call to api.github.com is
      # limited to 60 requests an hour *per IP*, and GitHub's runner IPs are shared, so the
      # call intermittently returns 403 before anything is built -- a red job that says
      # nothing about the crate (it happened here: the job failed at this `curl` with
      # `curl: (22) ... 403`, and a re-run on the same commit passed). `github.token` raises
      # the limit to 5000 an hour and is already available to the workflow, so the download
      # is a check of Verus rather than a lottery on the runner's IP. Only the API call is
      # authenticated; the asset itself is fetched from the redirect target, which does not
      # take the header.
      #
      # The token is fed to `curl` on *stdin* (`-H @-`), never as a `-H` argument: an
      # argument is readable from `/proc/<pid>/cmdline` by any process on the runner, which
      # is a secret leak (CWE-214). The Ferrocene step below pipes its secret the same way.
      - name: Download the Verus release
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          set -e
          url=$(printf 'Authorization: Bearer %s\n' "$GH_TOKEN" \
                | curl -fsSL -H @- \
                https://api.github.com/repos/verus-lang/verus/releases/latest \
                | python3 -c "import sys,json; print([a['browser_download_url'] for a in json.load(sys.stdin)['assets'] if a['name'].endswith('x86-linux.zip')][0])")
          curl -fsSL -o verus.zip "$url"
          python3 -c "import zipfile; zipfile.ZipFile('verus.zip').extractall('.')"
          chmod +x verus-x86-linux/verus verus-x86-linux/rust_verify verus-x86-linux/z3
          echo "$PWD/verus-x86-linux" >> "$GITHUB_PATH"
          # Verus needs its own pinned rustc; install it so the driver can find it.
          rustup install "$(verus-x86-linux/verus --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+-x86_64-unknown-linux-gnu' | head -1)"

      # Hard gate, same as the Kani job: a disagreement, a refuted identity, or a missing
      # verdict all fail the run.
      - name: Run the Verus oracle
        env:
          VERUS_BIN: ${{ github.workspace }}/verus-x86-linux/verus
        run: cargo run -q --features std --example verusdiff -- 64

  mir-oracle:
    name: rustc_public MIR oracle
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

      # This job is the whole reason `tools/mir-oracle` exists: it links `rustc_public`,
      # which needs a nightly plus the `rustc-dev` component. Neither may leak into
      # `verif` -- the crate builds on stable with no dependencies -- so the oracle is a
      # separate, excluded workspace member and only this job pays for the nightly.
      #
      # `llvm-tools-preview` is required too, and its absence is not obvious from the error.
      # It is the component that ships `libLLVM` next to `rustc`; without it `rustc` cannot
      # even start under the `LD_LIBRARY_PATH` cargo sets for build scripts, so the oracle's
      # `build.rs` silently fails to read the sysroot and the link dies later with
      # `unable to find library -lLLVM-...`. `rustc-dev` alone is not enough.
      #
      # `clippy` is installed onto the *nightly* rather than the stable toolchain because the
      # lint step must run the nightly's `clippy-driver`; see the note there.
      - name: Install Rust (stable + nightly with rustc-dev, llvm-tools and clippy)
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup toolchain install nightly --profile minimal --no-self-update
          rustup component add rustc-dev --toolchain nightly
          rustup component add llvm-tools-preview --toolchain nightly
          rustup component add clippy --toolchain nightly
          rustup default stable

      # The frontend reads *textual* MIR; this checks that reading against rustc's own typed
      # MIR, function by function. A rustc release that reprints the dump would otherwise
      # break the parser silently, because the parser is the only thing that reads the dump.
      # `run.sh` exits 2 if the toolchain is missing and 1 on a real disagreement; only the
      # latter should fail CI, so a missing nightly is surfaced by the component step above
      # rather than being swallowed here.
      - name: Run the MIR oracle
        run: |
          VERIF_RUSTC="$(rustup which --toolchain nightly rustc)"
          export VERIF_RUSTC
          sh tools/mir-oracle/run.sh

      - name: Run the oracle's own tests
        run: |
          cd tools/mir-oracle
          RUSTC="$(rustup which --toolchain nightly rustc)" cargo test

      - name: Lint the oracle
        run: |
          cd tools/mir-oracle
          # `RUSTC=<nightly> cargo clippy` is not enough, and fails in a way that looks like a
          # missing component: `cargo clippy` runs the *default* toolchain's `clippy-driver`
          # and ignores `RUSTC` for that choice, so it tries to check a `rustc_private` crate
          # with the stable driver and reports `can't find crate for rustc_driver`. Selecting
          # the nightly for the whole command is what picks up the matching driver.
          cargo +nightly clippy --all-targets -- -D warnings

  lean:
    name: lean differential oracle
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

      - name: Install Rust (stable)
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup default stable

      # Lean via elan, the official installer. It is pinned to a release rather than
      # tracking latest because `bv_decide` and `native_decide` are the interface this job
      # depends on, and a nightly that renames or moves them would look like a disagreement
      # with the engine rather than a toolchain change. Bumping this pin is the deliberate
      # act of moving the oracle.
      - name: Install Lean 4 (elan)
        run: |
          set -e
          curl -fsSL https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh \
            -o elan-init.sh
          sh elan-init.sh -y --default-toolchain leanprover/lean4:v4.35.0
          echo "$HOME/.elan/bin" >> "$GITHUB_PATH"

      # Hard gate, same as Kani and Verus: a disagreement, a refuted identity, a missing
      # verdict, or a case Lean could not decide all fail the run.
      - name: Run the Lean oracle
        run: cargo run -q --features std --example leandiff -- 64

  coq:
    name: coq differential oracle
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

      - name: Install Rust (stable)
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup default stable

      # Coq from the distribution rather than opam: the oracle needs only `coqc` and the
      # standard library, and the apt package is a fraction of an opam switch's install time.
      - name: Install Coq
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends coq

      # Hard gate. This one enumerates the 8-bit domain, so it takes a selected subset of
      # the corpus (see `SELECTED` in examples/coqdiff.rs) and is the slowest job here.
      - name: Run the Coq oracle
        run: cargo run -q --features std --example coqdiff

  comparison:
    name: comparison fixtures (contracts, teeth, degenerate check)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

      # This job runs `tools/comparison/run.sh`, which needs all three of: a nightly
      # `rustc` (the `verif` half reads real MIR), `coqc`, and Lean. It is a separate
      # job rather than a step in `gate` because `gate` installs none of Coq or Lean, so
      # the comparison gate would *skip* there and a skipped gate is not evidence.
      - name: Install Rust (stable + nightly)
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup toolchain install nightly --profile minimal --no-self-update
          rustup default stable

      - name: Install Lean 4 (elan)
        run: |
          set -e
          curl -fsSL https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh \
            -o elan-init.sh
          sh elan-init.sh -y --default-toolchain leanprover/lean4:v4.35.0
          echo "$HOME/.elan/bin" >> "$GITHUB_PATH"

      - name: Install Coq
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends coq

      # Hard gate: the script exits 1 on a real failure and 2 only when a tool is absent,
      # and the two are never conflated. All three tools are installed above, so exit 2
      # here would itself be a failure worth seeing.
      - name: Run the comparison gate
        run: |
          VERIF_RUSTC="$(rustup which --toolchain nightly rustc)"
          export VERIF_RUSTC
          sh tools/comparison/run.sh

  # The crates.io half: a crate that builds and passes every gate can still be
  # unpackagable, and the failure only shows up at `cargo publish` -- the worst
  # moment, because an upload cannot be undone. This job packages both crates and
  # dry-runs the publish in dependency order.
  #
  # `cargo publish` resolves the parent's `verif-arithmetic` dependency against
  # the registry, so the parent's dry-run verdict is a fact about what the
  # registry holds at that moment, not about this tree. `scripts/publish.py`
  # keeps the two apart: a dependency this repository owns but the registry
  # cannot resolve is reported as *blocked* and exits 0 -- the sibling's version
  # is uploaded before its dependent's, on every release, so that is release
  # ordering and not a manifest fault -- while a manifest that is genuinely
  # broken (a typo'd dependency name, a missing `readme`, an unpackageable
  # crate) is *failed* and turns the job red. So the dry-run step below is the
  # gate on the manifest. The strict run after it is informational: it escalates
  # *blocked* to a non-zero exit, and whether a crate is blocked is a fact about
  # the registry rather than about the commit under test, so it is surfaced as a
  # notice rather than enforced. The maintainer runs `--strict` by hand as the
  # pre-upload check.
  package:
    name: package (dry-run publish, in dependency order)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

      - name: Install Rust (stable)
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup default stable

      # A crate directory with no LICENSE, or a manifest missing `readme`, is a
      # `.crate` that is legally or practically unusable. No compiler sees it.
      - name: Packaging hygiene
        run: sh scripts/check_package.sh

      # `cargo package` on the sibling, which has no in-repo dependency, must
      # succeed outright -- there is nothing for it to wait on. The parent's
      # verdict is a fact about the registry: `publish.py` exits 0 when the only
      # problem is an unresolvable sibling dependency (the dependency is uploaded
      # before its dependent, on every release) and non-zero when a manifest is
      # genuinely broken. So this step is a gate on the manifest, not on registry
      # state, and it prints each crate's verdict either way.
      - name: Dry-run the publish, in dependency order
        run: python3 scripts/publish.py

      # The maintainer's pre-upload check, surfaced as a notice rather than
      # enforced: `--strict` exits non-zero while a crate is *blocked*, and
      # whether it is blocked is a fact about what the registry can resolve for
      # the required version, not about the commit under test. Reporting it keeps
      # the signal without making a red job out of release ordering.
      - name: Report the strict publish verdict
        run: |
          if python3 scripts/publish.py --strict >/dev/null 2>&1; then
            echo "The strict publish check passes: every crate is publishable."
          else
            echo "::notice::The strict publish check reports a crate as blocked on its sibling version."
            echo "That is release ordering (a dependency is uploaded before its dependent), not a manifest fault."
          fi