Skip to content

Commit c2188c1

Browse files
committed
proofs: added AutoCorrode/C proofs of a subset of poly.c functionality
AutoCorrode is a separation logic framework developed by AWS for use in the verification of the Nitro Isolation Engine. Originally targetting Rust, a new frontend for C11 has recently been added using an established Isabelle library, Isabelle/C, for parsing. C code can be embedded both in Isabelle theory files for reasoning about, or code can be loaded from .c files, parsed, and processed into Isabelle definitions automatically (post preprocessing with cpp). The C frontend is still a work-in-progress, but has sufficiently advanced enough that material from the poly.c file from mlkem-native can now be verified using an abstract specification and weakest-precondition style reasoning. In this initial commit: We define a pipeline which takes MLKEM .c and .h files and autogenerates AutoCorrode/C definitions. Setting this up correctly requires some care: C11 files must first be preprocessed using the C preprocessor, the relevant definitions and supporting types that we are interested in verifying must be filtered out from the resulting generated code, and any feature that we cannot support (e.g. __darwin_builtin types, when running on an Apple machine) must be filtered out. To do this we use a series of "manifest" files which identify the functions we are interested in working with, which is processed by dedicated Python script files and the `micro_c_translate` command in Isabelle. Using the pipeline above, we extract all of the functions and supporting types from `poly.{c, h}` and the supporting `verify.{c, h}` file, specify them, and verify them with respect to a series of pre/postcondition specifications using Weakest Precondition-style reasoning. To do this, we define a machine "locale" or "interface" setting up the memory model of the AutoCorrode/C library. This presents a bit of a chicken-and-egg situation, as the AutoCorrode/C memory model requires knowledge of any types that will be mutated, however translated C functions must be defined within the scope of the machine model in order to constrain the types of memory addresses and memory values. As a result of this, extraction of C code proceeds in two stages, with the first stage extracting types alone, prior to the definition of the machine and used to define it, which is then used further when extracting C functions. The machine model is instantiated with a concrete model, demonstrating that the axioms describing the machine are consistent, and opening the door to execute the translated C code via Isabelle's code-generation mechanism for conformance testing. Note that the more complex functions in this changeset are still a work-in-progress, including the NTT. Signed-off-by: Dominic Mulligan <dominic.p.mulligan@gmail.com>
1 parent 152b23e commit c2188c1

26 files changed

Lines changed: 4374 additions & 1 deletion

.github/workflows/all.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ jobs:
5151
needs: [ base, nix ]
5252
uses: ./.github/workflows/cbmc.yml
5353
secrets: inherit
54+
isabelle:
55+
name: Isabelle
56+
permissions:
57+
contents: 'read'
58+
id-token: 'write'
59+
needs: [ base ]
60+
uses: ./.github/workflows/isabelle.yml
61+
secrets: inherit
5462
oqs_integration:
5563
name: libOQS
5664
permissions:

.github/workflows/isabelle.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) The mlkem-native project authors
2+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
3+
4+
name: Isabelle
5+
permissions:
6+
contents: read
7+
on:
8+
workflow_call:
9+
workflow_dispatch:
10+
11+
jobs:
12+
isabelle-proofs:
13+
name: proofs/isabelle
14+
runs-on: ubuntu-latest
15+
container:
16+
image: makarius/isabelle:Isabelle2025-2
17+
options: --user root
18+
19+
steps:
20+
- name: Checkout mlkem-native
21+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
22+
with:
23+
submodules: recursive
24+
25+
- name: Checkout AFP mirror
26+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
27+
with:
28+
repository: isabelle-prover/mirror-afp-2025-1
29+
path: AutoCorrode/dependencies/afp
30+
31+
- name: Install build tooling
32+
run: apt-get update -qq && apt-get install -y -qq make > /dev/null
33+
34+
- name: Build Isabelle proofs
35+
run: make -C proofs/isabelle build ISABELLE_HOME=/home/isabelle/Isabelle/bin

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "AutoCorrode"]
2+
path = AutoCorrode
3+
url = https://github.com/awslabs/AutoCorrode

AutoCorrode

Submodule AutoCorrode added at b80b3ac

BUILDING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,24 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to setup and use
102102
### Running the HOL-Light proofs
103103

104104
Once you are in the `nix` shell or have all tools setup by hand, use `./scripts/tests hol_light` (or just `tests hol_light` in the `nix` shell) to re-check the HOL-Light proofs. Note that depending on the function, they will take a long time. See `tests hol_light --help` for details on the command line options, and [proofs/hol_light](proofs/hol_light) for more details on the HOL-Light proofs in general.
105+
106+
## Isabelle (AutoCorrode)
107+
108+
### Prerequisites
109+
110+
To run the Isabelle proofs in [`proofs/isabelle`](proofs/isabelle), you need Isabelle2025-2 and the AFP mirror used by AutoCorrode (containing `Word_Lib` and `Isabelle_C`).
111+
112+
### Running the Isabelle proofs
113+
114+
From the repository root:
115+
116+
```bash
117+
make -C proofs/isabelle setup-afp # optional helper to clone mirror-afp-2025-1
118+
make -C proofs/isabelle build
119+
```
120+
121+
To open jEdit with all required session directories configured:
122+
123+
```bash
124+
make -C proofs/isabelle jedit
125+
```

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ relevant parts of the Arm and x86 architectures). See [proofs/hol_light](proofs/
7171
**NOTE:** Formal Verification is never absolute. See [SOUNDNESS.md](SOUNDNESS.md) for a detailed analysis of the scope, assumptions and risks of the formal verification
7272
efforts around mlkem-native.
7373

74+
Selected C/functional components are also verified in [Isabelle/HOL](https://isabelle.in.tum.de/) using AutoCorrode. See [proofs/isabelle](proofs/isabelle).
75+
7476
## Security
7577

7678
All AArch64 and x86_64 assembly in mlkem-native is formally proved in [HOL Light](https://github.com/jrh13/hol-light) to be free of secret-dependent control flow,

proofs/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ We use the [C Bounded Model Checker (CBMC)](https://github.com/diffblue/cbmc) to
1010

1111
## Assembly verification: HOL-Light
1212

13-
We use the [HOL-Light](https://github.com/jrh13/hol-light) interactive theorem prover alongside the verification infrastructure from [s2n-bignum](https://github.com/awslabs/s2n-bignum) to show the functional correctness of all AArch64 and x86_64 assembly in mlkem-native at the object-code level. See [proofs/hol_light](hol_light).
13+
We use the [HOL-Light](https://github.com/jrh13/hol-light) interactive theorem prover alongside the verification infrastructure from [s2n-bignum](https://github.com/awslabs/s2n-bignum) to show the functional correctness of all AArch64 assembly and all x86_64 ML-KEM arithmetic assembly in mlkem-native at the object-code level. See [proofs/hol_light](hol_light).
14+
15+
## C/functional verification in Isabelle (AutoCorrode)
16+
17+
We use [Isabelle/HOL](https://isabelle.in.tum.de/) together with [AutoCorrode](https://github.com/awslabs/AutoCorrode) to translate and verify selected C implementations and their refinement lemmas. See [proofs/isabelle](isabelle).

0 commit comments

Comments
 (0)