# CN

> Write ownership and correctness specifications as comments in C code; CN checks them with an SMT solver, or turns them into runtime checks for testing.

- Kind: toolchain
- Verifies: C (Sequential C; specifications are written in /*@ ... @*/ comments.)
- Effort: Auto-active — You write specifications and hints; a solver does the proving.
- Stage: 0 (Research)
- Trust: Checker partial, Semantics partial, Frontend partial, Binary gap weak, Escape hatches partial
- Licence: open-source, BSD-2-Clause (with listed exceptions)
- Latest release: main@4b4c33c (2026-11-26) https://github.com/rems-project/cn/commits/main
- Links: [repo](https://github.com/rems-project/cn), [docs](https://rems-project.github.io/cn-tutorial/), [paper](http://www.cl.cam.ac.uk/users/pes20/cn-draft.pdf), [tutorial](https://rems-project.github.io/cn-tutorial/)

## Use it if
- You want to prove existing systems C code free of undefined behavior and correct against specifications, with mostly automatic proofs.
- You want the same specifications to drive runtime checking and random testing (Fulminate) before you attempt a proof.

## Look elsewhere if
- Your code uses threads, unions, floating point or variadic functions; CN rejects or does not support these.
- You need a production-ready tool; its authors describe it as research tooling.

## How it works (pipeline)

| Step | Component | Assurance | Note |
|---|---|---|---|
| frontend | Cerberus C front end (`cerberus`) | trusted | Cerberus's own parser and type checker turn C into its Core language. C files are first run through the system preprocessor. |
| semantics | Cerberus Core semantics with the VIP memory model (`cerberus`) | trusted | CN works on a simplified form of Cerberus Core. By default it uses the VIP memory object model for pointer provenance. |
| translation | CN type checker | trusted | Infers ownership (resources) and reduces checks to SMT queries. Soundness of type checking was proved for a formalised core of the system (POPL 2023); the implementation is not verified. |
| checker | Z3 (`z3`) | trusted | Default SMT solver. |
| checker | cvc5 (`cvc5`) | trusted | Alternative solver, chosen with --solver-type cvc5. |
| compiler | GCC or Clang | trusted |  |

## Trust

| Axis | Level | Summary | Note |
|---|---|---|---|
| Checker | Partial (amber) | Z3 or cvc5 decides each check; no proof certificates by default. | An experimental option (--coq-proof-log) exports a proof log to Rocq; it is not on by default. Lemmas CN cannot prove can be exported as Rocq statements to prove by hand. [source](https://github.com/rems-project/cn/blob/4b4c33c/bin/verify.ml) |
| Semantics | Partial (amber) | Built on the Cerberus C semantics; CN's own model on top is tested by its suite. | Cerberus has published validation (GCC torture tests, Csmith). CN uses a simplified form of it plus the VIP memory model, and the 2023 paper notes it ignores C's loose evaluation order. [source](http://www.cl.cam.ac.uk/users/pes20/cn-draft.pdf) |
| Frontend | Partial (amber) | Cerberus's own C front end, separate from the compiler that builds the binary. |  |
| Binary gap | Weak (red) | The binary comes from GCC or Clang, which are not verified. | A 2023 MSc thesis (CN2Islaris) explored carrying CN specifications to compiled code with Islaris; this is research, not part of CN. [source](https://github.com/rems-project/CN2Islaris) |
| Escape hatches | Partial (amber) | Functions and lemmas marked trusted are not checked; findable by grep, not listed. | A trusted annotation makes CN accept a function's or lemma's specification without proof, and --skip leaves functions unchecked. The checker collects trusted functions but does not report them in its result. [source](https://github.com/rems-project/cn/blob/main/manual/manual.md) |

## What it can prove

| Property | Support |
|---|---|
| No undefined behavior | Supported — CN checks that code is free of undefined behavior as defined by the Cerberus semantics of ISO C. ([source](https://github.com/rems-project/cn)) |
| Functional correctness | Supported — Functions are checked against pre- and postconditions over ownership and values. ([source](http://www.cl.cam.ac.uk/users/pes20/cn-draft.pdf)) |
| Equivalence | Not supported — No built-in way to compare two programs. You can prove that both meet the same specification. |
| Information flow | Not supported — No support for secrecy or timing properties was found in the documentation. |
| Concurrency | Not supported — The 2026 PLDI paper says the specification language and tools do not yet support concurrency. ([source](https://www.cl.cam.ac.uk/~pes20/pldi2026-paper155-supplementary.pdf)) |
| Termination and liveness | Not supported — Specifications have preconditions, postconditions and loop invariants but no termination measures, so proofs say nothing about termination. ([source](https://github.com/rems-project/cn/blob/main/manual/manual.md)) |

## Common features

| Feature | Support |
|---|---|
| Machine integers | Supported — Signed overflow and other integer undefined behavior are rejected. ([source](https://rems-project.github.io/cn-tutorial/getting-started/tutorials/verif-numeric/)) |
| Floating point | Not supported — The type checker reports floats as unsupported. ([source](https://github.com/rems-project/cn/blob/4b4c33c/lib/check.ml#L157)) |
| Heap and pointers | Supported — Ownership of heap cells is tracked in separation logic. Allocation uses cn_malloc and cn_free_sized in place of malloc and free. ([source](https://rems-project.github.io/cn-tutorial/getting-started/tutorials/alloc/)) |
| Arrays and buffers | Supported — Iterated ownership over array ranges, with automatic inference for common access patterns. ([source](http://www.cl.cam.ac.uk/users/pes20/cn-draft.pdf)) |
| Loops | Partial — Loop invariants can be given only on for and while loops. ([source](https://github.com/rems-project/cn/blob/main/manual/manual.md)) |
| Recursion | Supported — Recursive C functions are checked against their specifications. Recursive specification functions are not unfolded automatically; you unfold them or state lemmas by hand. ([source](https://github.com/rems-project/cn/blob/main/manual/manual.md)) |
| Higher-order code | Partial — The test suite checks calls through function pointers to known functions; the tutorial does not cover them. ([source](https://github.com/rems-project/cn/blob/main/tests/cn/fun_ptr_three_opts.c)) |
| Threads and shared memory | Not supported — Not supported; locks had to be commented out in the pKVM case study. ([source](http://www.cl.cam.ac.uk/users/pes20/cn-draft.pdf)) |
| I/O and system calls | Unknown — No documentation found on specifying I/O or system calls. |
| Standard library | Partial — The tutorial covers allocation (cn_malloc, cn_free_sized). No general specifications of the C standard library were found. ([source](https://rems-project.github.io/cn-tutorial/getting-started/tutorials/alloc/)) |

## C-specific features

| Feature | Support |
|---|---|
| Pointer casts and provenance | Partial — Uses the VIP provenance model, which allows integer-pointer casts. The repo's VIP test notes list round-trip casts and provenance through bytes as still to do. ([source](https://github.com/rems-project/cn/blob/main/tests/cn_vip_testsuite/README.md)) |
| Unions and type punning | Not supported — Programs with union types are rejected ("unsupported union types"). ([source](https://github.com/rems-project/cn/blob/main/tests/cn/unsupported_union.error.c.verify)) |
| Bit-fields | Not supported — The Cerberus front end that CN uses rejects bit-fields as not yet supported. ([source](https://github.com/rems-project/cerberus/blob/master/frontend/model/cabs_to_ail.lem)) |
| Variadic functions | Not supported — Variadic functions are rejected as unsupported. ([source](https://github.com/rems-project/cn/blob/4b4c33c/lib/core_to_mucore.ml#L1203)) |
| setjmp / longjmp | Not supported — Not supported by the underlying Cerberus semantics. ([source](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-981.pdf)) |
| volatile and MMIO | Not supported — The underlying Cerberus semantics does not model volatile beyond syntax checks. ([source](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-981.pdf)) |
| Inline assembly | Not supported — Not supported by the underlying Cerberus semantics. ([source](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-981.pdf)) |

## Stage

**Stage 0: Research.**

| Stage | Criterion | Met | Evidence / note |
|---|---|---|---|
| 0 | Publicly available | yes | [evidence](https://github.com/rems-project/cn) |
| 0 | At least one published verification uses it | yes | [evidence](http://www.cl.cam.ac.uk/users/pes20/cn-draft.pdf) Verification of the buddy allocator of Google's pKVM hypervisor (POPL 2023). |
| 1 | Released or updated in the last 12 months | yes | [evidence](https://github.com/rems-project/cn/commits/main) Latest release: main@4b4c33c, 2026-11-26. |
| 1 | Installs and runs on current platforms | yes | [evidence](https://github.com/rems-project/cn#installation) Install from source with opam, or use Docker images built by CI for amd64 and arm64. |
| 1 | User documentation or tutorial | yes | [evidence](https://rems-project.github.io/cn-tutorial/) Tutorial and reference documentation, marked as work in progress. |
| 1 | Used by a group other than its authors | unknown | Papers so far are by the CN team (Cambridge, Penn, Oxford). No published use by an outside group was found. |
| 2 | Verified code in production at two or more independent organizations | no | None recorded. |
| 2 | Checker axis is not red | yes |  |
| 2 | Semantics axis is not red | yes |  |
| 2 | Public channel for soundness bugs | yes | [evidence](https://github.com/rems-project/cn/issues) Public GitHub issue tracker. |

Missing for Stage 1: Used by a group other than its authors.

## Projects
- [pKVM buddy allocator (POPL 2023)](http://www.cl.cam.ac.uk/users/pes20/cn-draft.pdf)
- [pKVM hyp allocator, testing and proof (PLDI 2026)](https://www.cl.cam.ac.uk/~pes20/pldi2026-paper155-supplementary.pdf) — Found four bugs in the hypervisor code, which the pKVM team fixed.

## Sources
- [CN repository and README](https://github.com/rems-project/cn)
- [CN manual](https://github.com/rems-project/cn/blob/main/manual/manual.md)
- [CN tutorial](https://rems-project.github.io/cn-tutorial/)
- [CN: Verifying Systems C Code with Separation-Logic Refinement Types (POPL 2023)](http://www.cl.cam.ac.uk/users/pes20/cn-draft.pdf)
- [Code-Specify-Test-Debug-Prove (PLDI 2026)](https://www.cl.cam.ac.uk/~pes20/pldi2026-paper155-supplementary.pdf)
- [CN license](https://github.com/rems-project/cn/blob/main/LICENSE)

---
Last checked 2026-11-26. Data: [JSON](/toolchains/cn.json) · Page: [HTML](/toolchains/cn/) · Methodology v0.1: [/methodology/](/methodology/) · Corrections: [/contribute/](/contribute/)
