blob: 35556313f6c1528af1a41b032d060d4982eb5a8e [file] [view]
<img src="https://raw.githubusercontent.com/google/anneal/main/docs/images/logo.svg" alt="Anneal logo" width="100%">
<p align="center"><em>logo by <a href="https://www.instagram.com/tinyneonspark">tinyneonspark</a></em></p>
**Anneal** is an experimental formal verifier for Rust. Where `rustc` proves
that safe Rust is memory safe, Anneal aims to let you prove that `unsafe` Rust
is free of undefined behavior and obeys explicit contracts.
> [!WARNING]
> **Alpha software:** Anneal is under active development and has not yet
> undergone an independent security audit. Today's default profile verifies a
> pointer-free scalar subset of Rust on x86-64 Linux; an experimental second
> profile adds borrowed slices and raw pointers without a pointer aliasing
> model. Automated reporting of the complete human review surface is still in
> progress. Do not rely on alpha runs as a production soundness guarantee, and
> expect breaking changes. See the [alpha guide][alpha-guide] and
> [threat model][threat-model].
## Why safe Rust is not enough for `unsafe` code
Rust promises that all safe Rust code is memory safe. It does this by encoding
the requirements for memory safety in the type system, ensuring that if a
program type checks, then it is memory safe.[^1] The same is not true of unsafe
Rust code.
[^1]: Barring compiler and platform bugs, which do exist.
One way to understand this distinction is that a safe Rust function must be
memory safe *no matter what value is passed in*. Consider
[`usize::strict_div`](https://doc.rust-lang.org/std/primitive.usize.html#method.strict_div):
```rust
impl usize {
/// # Panics
///
/// This function will panic if `rhs` is zero.
pub fn strict_div(self, rhs: usize) -> usize;
}
```
A safe implementation of `strict_div` is forced to handle *all possible values*
of `self` and `rhs`, including `rhs == 0`. It can choose to return an arbitrary
`usize` or, as it does in practice, panic—but it cannot exhibit a memory safety
bug, because `rustc` will reject any safe implementation that could.
By contrast, consider the unsafe
[`usize::unchecked_div_exact`](https://doc.rust-lang.org/std/primitive.usize.html#method.unchecked_div_exact):
```rust
impl usize {
/// # Safety
///
/// This results in undefined behavior when `rhs == 0` or `self % rhs != 0`.
pub unsafe fn unchecked_div_exact(self, rhs: usize) -> usize;
}
```
The Rust type system has no way to express *and enforce* "a pair of `usize`s
such that `rhs != 0` and `self % rhs == 0`". The type signature of
`unchecked_div_exact` is therefore *too permissive*. While the type system still
rules out some invalid inputs (for example, `-1`), other illegal values compile
cleanly and trigger undefined behavior at runtime:
```rust
let res: usize = unsafe { 1usize.unchecked_div_exact(0) };
```
In this view, unsafe Rust differs from safe Rust in that **some type-safe values
are still illegal**, while in safe Rust **all type-safe values are legal**
(where "illegal" means "will trigger undefined behavior").
Anneal's goal is to extend Rust's compile-time promise to `unsafe` code—and
beyond memory safety to developer-defined contracts—by making those contracts
machine-checked alongside `cargo check` and in CI.
| | Rust (`rustc`) | Anneal (target model; scalar alpha today) |
| :--- | :--- | :--- |
| **Command** | `cargo check` | `cargo anneal verify` |
| **Contract surface** | Rust types | Rust types + formal specifications[^2] |
| **Guarantee** | Safe code is memory safe | Verified code is UB-free and obeys its stated specifications[^3] |
| **Boundary** | `unsafe` code is unchecked | Code outside the Rust Abstract Machine (FFI, inline asm) is unchecked and must be axiomatized; alpha refuses unsupported constructs rather than failing open |
| **Human review surface** | All `unsafe` blocks and their safety invariants | Stated specifications + TCB audit log (not proofs or verified implementation bodies) |
[^2]: In the current alpha, specifications live out-of-line in Lean modules
(with an untrusted Rust-syntax lowering tool in `tools/anneal-spec/`);
first-class inline Rust specification syntax is roadmap work.
[^3]: Anneal's conditional promise: *if* the code in the TCB audit log is
correct, its assumptions are valid, *and* Anneal emits no errors in an
uncompromised environment, *then* the verified code is UB-free and satisfies
its stated specifications. See [Principles][principles] and the
[threat model][threat-model].
## How Anneal earns your trust
Most of Anneal is generated by AI agents, which begs the question: ***why should
you trust Anneal at all?***
Our answer is this: Anneal's architecture, development infrastructure, and team
practices follow three core principles:
1. **Keep the TCB simple, small, and auditable**: Anneal separates *finding* a
proof from *checking* it. Every verification obligation is stated in
[Lean 4][Lean 4], a proof assistant whose small typechecking kernel checks
proof terms from first principles. Untrusted tactics, proof libraries, and
AI-written proof scripts do the heavy lifting, while Anneal enforces strict
isolation so a buggy or adversarial proof can make verification fail, but
cannot smuggle a false theorem past the kernel. That confines
soundness-critical code to a small Trusted Computing Base (TCB) under
[`trusted/`][trusted-dir] with four components:
- **Compiler-to-MIR capture**: translates `rustc`'s Mid-level Intermediate
Representation (MIR) faithfully and records the exact compilation flags,
target layout, and scope.
- **Boundary and specification auditing**: ensures untrusted Lean code cannot
exploit macros, elaborators, namespaces, or compiler overrides to bypass
the kernel.
- **Orchestration and receipt integrity**: binds source inputs, compiler
configuration, specifications, and verification results into an auditable
receipt so human review can stay bounded to stated specifications and the
TCB audit log (automated complete review-surface reporting is still in
progress).
- **Mechanized Rust MIR semantics**: defines a semantics for MIR syntax that
has been mechanically lowered to Lean data types.
2. **Ground semantics in existing semantic authorities**: Rather than judging
our Rust MIR model solely by tests or definitions we wrote ourselves, we
anchor it against established compilers, interpreters, and formal
specifications:
- **Formal refinement proofs against reference semantics (`lean-miri` and
`MiniRust`)**: in blocking CI on `main`, Anneal proves kernel-checked
refinement and fault-equivalence theorems showing that its MIR semantics
soundly abstract a pinned `lean-miri` reference model, complemented by
correspondence proofs anchored to a pinned `MiniRust` specification.[^4]
- **Differential testing and fuzzing against real `rustc` and Miri**: we
execute real and generated Rust programs through `rustc`, Miri, and
Anneal's MIR semantics to surface semantic divergences that no internal
proof can catch.[^5]
3. **Continuously check meaningfulness**: No model or boundary check is
perfect, so we deploy continuous testing and structural defenses to surface
bugs quickly and rule out whole classes of mistakes by construction:
- **Mutation testing and adversarial red-teaming**: we deliberately mutate
`trusted/` guards, semantic rules, and real `zerocopy` verification
targets, and run red-team campaigns against the capture, sandbox, and audit
boundaries to verify that broken code and hostile inputs fail closed rather
than silently passing.
- **Structural containment and non-oracle invariants**: we enforce dependency
boundaries that align with our model of the TCB, isolate Lean elaboration
inside OS sandboxes, enforce default-deny syntactic pre-flight checks
before Lean elaboration, check proofs across independent kernels, and run
structural lints to eliminate classes of bugs by construction.[^6]
[^4]: On `main` today, universal `lean-miri` refinement and fault-equivalence
proofs cover the default pointer-free scalar profile (Profile v1). The
experimental Profile v2 semantics (adding borrowed slices, arrays, and raw
pointers without a pointer aliasing model) are not yet universally bridged;
extending correspondence to Profile v2—starting with concrete canary proofs
and progressing toward per-primitive lemmas—is active work.
[^5]: Today's differential harnesses (`tests/differential` and
`tests/itree_diff`) compare scalar return values, observable call and branch
traces, panics and aborts, divergence, and coarse UB/fault verdicts across
`rustc` (`-O0` and `-O2`), Miri (with Tree Borrows), and Anneal's MIR
semantics. Ongoing hardening extends these comparators to verify full
provenance-aware caller memory images and exact fault classifications.
[^6]: In blocking CI on `main` today, `anneal-audit` enforces the Cargo
workspace zone boundary (`trusted/` cannot depend on `tests/` or `tools/`),
runs default-deny syntactic pre-flight checks, compiles and replays proofs
through Lean's standalone kernel, and enforces repository hygiene and pin
lints, while `cargo-anneal` sandboxes target Lean elaboration on Linux
(`bwrap` or Landlock+seccomp). Out-of-process proof replay across independent
external kernels (`nanoda` and `con-ron`) is implemented on `main` for newer
Lean toolchains (`v4.35.0+`, opt-in via `--allow-unpinned-lean`), and
additional structural lints—such as exhaustive wildcard-match enforcement
across `trusted/` and split spec/model cone hashing—are in progress.
For the full explanation of our assurance model—what does not need to be
trusted, where trust lives, and how we ground and test our trusted
components—read **[How Anneal Earns Your Trust][how-anneal-earns-trust]**.
## Trying the alpha and documentation map
You can find installation commands, local toolchain setup, and `cargo anneal`
CLI usage alongside CI-tested workflows in the [alpha guide][alpha-guide].
Anneal's verification core also supports
[out-of-tree specification and proof modules][extensibility-quickstart] so
downstream projects can add custom models and witness checkers without
expanding the trusted computing base.
### Agent skills
Run `cargo anneal skill` to print the bundled `cargo-anneal` `SKILL.md`
without setting up the Anneal toolchain, or `cargo anneal skill list` to list
all bundled skills (including `spec-authoring`, `proof-scaling`, and
`boundary-audit`). To install the skill into a project repository with
[GitHub CLI][gh-skill], set `ANNEAL_REV` to your release tag or source commit:
```sh
gh skill install google/anneal \
trusted/cargo-anneal/skills/cargo-anneal/SKILL.md \
--agent codex --scope project --pin "${ANNEAL_REV:?set the source revision}"
```
See the [Anneal skills index][skills-index] for the companion
[spec-authoring][spec-authoring-skill], [proof-scaling][proof-scaling-skill],
and [boundary-audit][boundary-audit-skill] skills.
### What to read next
| Document | What it covers |
| :--- | :--- |
| **[How Anneal Earns Your Trust][how-anneal-earns-trust]** | Complete account of our assurance model, the four `trusted/` components, and external grounding vs. internal checks. |
| **[Project Principles][principles]** | Anneal's mission, conditional correctness promise, and design priorities. |
| **[Threat Model][threat-model]** | Adversarial assumptions, bounded two-surface human review, and explicit assumptions vs. total defenses. |
| **[Alpha Guide][alpha-guide]** | Supported vs. refused Rust constructs (Profile v1 and experimental Profile v2), installation, CLI usage, and receipt inspection. |
| **[Out-of-Tree Extensibility][extensibility-quickstart]** | Adding project-specific specification models, witness checkers, and rewrite rules outside `trusted/`. |
| **[Contributor & Architecture Docs][developing-anneal]** | Building from source, repository layout, CI checks, and deep architecture references. |
[alpha-guide]: https://github.com/google/anneal/blob/main/docs/alpha.md
[boundary-audit-skill]: https://github.com/google/anneal/blob/main/skills/boundary-audit/SKILL.md
[developing-anneal]: https://github.com/google/anneal/blob/main/docs/README.md
[extensibility-quickstart]: https://github.com/google/anneal/blob/main/docs/extensibility-quickstart.md
[gh-skill]: https://cli.github.com/manual/gh_skill_install
[how-anneal-earns-trust]: https://github.com/google/anneal/blob/main/docs/how-anneal-earns-trust.md
[principles]: https://github.com/google/anneal/blob/main/PRINCIPLES.md
[proof-scaling-skill]: https://github.com/google/anneal/blob/main/skills/proof-scaling/SKILL.md
[skills-index]: https://github.com/google/anneal/blob/main/skills/README.md
[spec-authoring-skill]: https://github.com/google/anneal/blob/main/skills/spec-authoring/SKILL.md
[threat-model]: https://github.com/google/anneal/blob/main/THREAT_MODEL.md
[trusted-dir]: https://github.com/google/anneal/tree/main/trusted
## Acknowledgments
Anneal builds on decades of research and engineering in formal verification,
programming languages, proof checking, and systems isolation, and is only
possible thanks to the work of countless researchers and software engineers.
For the full list of external papers, tools, and libraries that have shaped
Anneal, see [`ACKNOWLEDGMENTS.md`](ACKNOWLEDGMENTS.md).
## Security
If you discover a security vulnerability in Anneal, please follow the reporting
instructions in [`SECURITY.md`](SECURITY.md).
Google's Open Source Software Vulnerability Rewards Program (OSS VRP) rules and
eligibility criteria are described at
[https://bughunters.google.com/about/rules/open-source-software-vulnerability-reward-program-rules](https://bughunters.google.com/about/rules/open-source-software-vulnerability-reward-program-rules).
## License
Anneal is distributed under the terms of the 2-Clause BSD license
([`LICENSE-BSD`](LICENSE-BSD)), the Apache License, Version 2.0
([`LICENSE-APACHE`](LICENSE-APACHE)), or the MIT license
([`LICENSE-MIT`](LICENSE-MIT)), at your option (`BSD-2-Clause OR Apache-2.0 OR
MIT`).
All contributions to Anneal are governed by Google's Contributor License
Agreement; see [`CONTRIBUTING.md`](CONTRIBUTING.md).
Committed third-party components and static assets (including
[`vendor/lean-miri/`](vendor/lean-miri/),
[`vendor/minirust/`](vendor/minirust/), and
[`site/static/fonts/baskervville/`](site/static/fonts/baskervville/)) retain
their upstream open source licenses; see
[`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md).
[Lean 4]: https://lean-lang.org/papers/lean4.pdf