2026-11-26 15:40 UTC

okcontract releases Zean, a Lean verification toolkit for supported Zig programs

state: seedheat: mediumuncertainty: mediumrelevance: highformal-verification zig leanokcontract

What is this?

Zean is an Apache-2.0 open-source toolkit from okcontract, developed from the team’s formal-verification work on oksolc, a Solidity compiler written in Zig. Announced on November 16, 2026, and surfaced in a Show HN post on November 24, it captures Zig’s analyzed intermediate representation (AIR) and translates selected supported programs into executable Lean models. Developers write specifications, contracts and, where needed, loop invariants in Lean; the project provides examples and reusable rules for proving properties including memory safety. Its documentation emphasizes that support is limited to admitted AIR fragments and that source admission, compiler frontend, capture and native code generation remain trust boundaries. The supplied evidence is chiefly the project’s own repository, with search results pointing to an announcement by okcontract; independent validation or adoption evidence is not provided.

Why it matters

Zean makes machine-checked reasoning about real Zig code more approachable by connecting compiler representations to Lean proofs, with examples spanning memory safety, loops, calls and atomic publication. If the approach proves useful beyond its examples, it could help developers verify low-level systems code and compiler components without rewriting them in a proof assistant. The immediate significance is a practical open-source experiment, not general verification of Zig: coverage is restricted, proof obligations still require developer input, and important parts of the source-to-model chain remain trusted.

Current assessment

New development: okcontract has made Zean available as an Apache-2.0 project. The repository says it captures Zig AIR and emits Lean definitions, keeping generated models separate from handwritten specifications and proofs so models can be regenerated after source changes. Its supplied tutorials describe checked properties for counters, buffers, copy loops, calls and an atomic dispatch-table example; it also documents intentionally failing proof clients and unsupported compatibility cases. The project claims its examples can be run with pinned Zig and Lean toolchains, while generating new AIR captures requires an instrumented Zig compiler. These are first-party project descriptions, not independent evaluation. Crucially, proofs establish properties of the selected Lean model and stated contracts, not whole-compiler correctness: source admission, the Zig frontend, capture instrumentation and native backend are identified as trusted boundaries. Some translation routes offer Lean-checked AIR-to-model correspondence, but the documentation still leaves source capture and other stages trusted. Thus the release demonstrates a concrete workflow for formal verification of supported Zig fragments, not broad Zig-language coverage or an end-to-end proof that native binaries are safe. The announcement is dated November 16 in search results; the Show HN item is dated November 24. No supplied source establishes wider adoption, independent benchmarks or external proof of the project’s claims.

Measured heat

now 0 pts/hpeak 6 pts/hcomments 0/hpeers p10momentum: steady2 platformsage 74h
points/hour across evidence · reading as of 2026-11-27 02:23:58.509736+11:00 · deterministic, not a model opinion

How the heat travelled

11-23 14:25 (minted)⭐ origin echo-reconstructedThe repository README is the original project announcement/content and does not cite an earlier post, paper, or social-media artifact. It de
okcontract on github (echo) · attributed from hn.story.50611274 · published time unknown
—
11-23 13:29first on hacker news · published · lag ?Show HN: Zean Transpiles Zig to Lean
hbbio
—
11-23 13:29amplified on hacker news 👑hn.story.50611274
hbbio
peak 7 · 1 comments · 99% of case engagement
11-23 14:20our radar first saw it · lag ?discovery anchor: hn.story.50611274—
pace: p58 vs 2088 stories at the 72h mark (now 74h old) — ahead of advocacy-groups-sue-ai-companies-to-halt-model-development (1.1x), behind amd-rocm-hrx-loom-v01-release (0.9x)

Evidence (2) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnShow HN: Zean Transpiles Zig to Lean
Retrieved article excerpt

Open article · Retrieved 2026-11-23T14:22:52.626063+00:00

# Zean

**Translate Zig functions into executable Lean models and prove their behavior.**

Zean captures Zig's analyzed intermediate representation (AIR) and emits
Lean program definitions. You write specifications and proofs in separate
files, then regenerate the model when the Zig code changes. Our model is
currently incomplete and translation is restricted to supported operations.

For memory safety, a reusable verification library generates proof obligations
from the translated program using Lean 4.35's `Std.WP` and `vcgen`. You supply
contracts and loop invariants, then discharge the remaining obligations in Lean.

Note: This initial release of this project was written with AI assistance mostly
using GPT-6 Astra over the course of two months. It is extracted from our formal
verification work for [oksolc](https://github.com/okcontract/oksolc), a Solidity
compiler written in Zig.

## Try the Ziglings memory-safety demo

With **Zig 0.17.1** and **elan** installed, run from the repository root:

```
elan toolchain install leanprover/lean4:v4.35.0
zig build ziglings
```

The [tutorial](https://github.com/okcontract/zean/blob/main/examples/ziglings/README.md) follows two familiar Ziglings lessons:

| Exercise | Checked property of the derived runtime kernel |
| --- | --- |
| 038: initialize both characters | Reading either gold slot is safe after both writes, without assuming initial contents |
| 054: give a many-pointer a length | Reads stay within the caller's initialized byte region and preserve memory |

You supply the caller contracts; reusable verification rules discharge the
memory obligations. Broken variants demonstrate an uninitialized read and an
invented slice extent. The command checks the proofs, requires false claims to
fail, and runs the two officially corrected upstream exercises on Zig 0.17.1.

The formal proofs cover the captured runtime kernels described in the tutorial.
The original exercises, including their printing code, receive separate native
compatibility checks. Retained captures let you run the demo without building
an instrumented compiler.

## More demos

When can one thread safely read a dispatch table that another thread is filling
in? The writer sets a flag with a release store after it fills both entries.
The Lean proof shows that a reader can use either entry once its acquire load
sees that store. Run `zig build atomic-publication` to check the proof and see
what goes wrong if the writer sets the flag too soon.
[Dispatch-table example](https://github.com/okcontract/zean/blob/main/examples/atomic_publication/README.md)

Continue with the [buffer update](https://github.com/okcontract/zean/blob/main/examples/buffer/README.md), or follow the
[copy-loop tutorial](https://github.com/okcontract/zean/blob/main/examples/copy/README.md) for initialization, framing and
helper contracts. The [verification guide](https://github.com/okcontract/zean/blob/main/docs/verification.md) explains how
to apply the same machinery to another supported function.
The [manifest-based client](https://github.com/okcontract/zean/blob/main/examples/client/README.md) captures and verifies
your own function without adding a new tutorial command or changing the verifier.
Its [caller/helper variant](https://github.com/okcontract/zean/blob/main/examples/client/calls/README.md) uses the explicit
call-stack interpreter and verifies a caller from a separately checked helper
contract, with readable generated function tables.
The [byte-scanning client](https://github.com/okcontract/zean/blob/main/examples/client/scan/README.md) adds a loop invariant,
early returns, and a helper call inside the loop.
For runtime helper calls, the [call-chain example](https://github.com/okcontract/zean/blob/main/examples/calls/README.md)
shows a caller reusing checked callee contracts across actual runtime calls.
The [standard-library example](https://github.com/okcontract/zean/blob/main/examples/stdlib_replace/README.md) goes beyond
the tutorials: it verifies an unchanged `std.mem.replaceScalar(u32)` specialization,
with a separately checked AIR-to-model correspondence certificate.
The [compatibility probes](https://github.com/okcontract/zean/blob/main/examples/compatibility/README.md) also show examples
that still reject, so these results should not be read as general Zig support.

## Follow a small program update

Start with a counter that advances without overflowing:

```
pub export fn advance(value: u8) u8 {
    return if (value < 255) value + 1 else 255;
}
```

The [handwritten proof](https://github.com/okcontract/zean/blob/main/lean/Compiler/Tutorial/Counter/V1/Proofs.lean) establishes
that, for every valid byte input `x`, the generated model returns
`min(x + 1, 255)` successfully. A second theorem proves that the result never
decreases and never exceeds 255.

```
zig build counter-run
zig build counter
```

`counter-run` runs the working Zig examples. `counter` checks their native
results, generated-source identities, Lean proofs, and expected proof failures.
The example includes generated models from real native AIR captures, so these
commands need no instrumented compiler.

The [counter tutorial](https://github.com/okcontract/zean/blob/main/examples/counter/README.md) follows the complete lifecycle:

1. Write the byte counter and prove its behavior.
2. Change the step to two and see an incomplete edit overflow at input 254.
3. Fix the guard, regenerate the model, and update the proof.
4. Apply the same reasoning to a `u32` counter, proving the contract for all
   2³² inputs without enumerating them.

## Prove a buffer update safe

The [buffer tutorial](https://github.com/okcontract/zean/blob/main/examples/buffer/README.md) takes the next step: prove that
a Zig function updates exactly one element of a writable buffer and preserves
surrounding memory. Its Lean proofs cover arbitrary valid caller heaps, buffer
contents and 64-bit indices under explicit storage contracts.

```
zig build buffer-run
zig build buffer
```

An off-by-one edit demonstrates both an invalid access and a write outside a
smaller logical buffer that still lies inside allocated memory. A repaired
version restores the contract. Like the counter, it includes real captured
models, separate handwritten proofs, and automated fresh capture and proof
replay. These are memory-safety proofs for the supported models; caller storage
assumptions and source/compiler correspondence remain explicit.

The [copy example](https://github.com/okcontract/zean/blob/main/examples/copy/README.md) uses the same verifier for a loop
over a readonly source and an initially uninitialized destination. Its contract
proves memory safety at every execution prefix; successful completion copies
the contents and preserves the source and surrounding memory. Run `zig build copy`
to check the proofs, native controls and three intentionally false proof clients.

## What a proof establishes

```
Zig source → captured AIR → generated Lean model → handwritten Lean proofs
```

Lean checks proofs about execution in the selected model, including its explicit
failure outcomes. The counter's successful-return theorem rules out arithmetic
faults for every input in its stated domain.

Source admission, the Zig frontend, capture instrumentation, and the native
backend remain trusted boundaries. Model proofs and matching native object
bytes do not establish whole-compiler correctness. See
[architecture and trust](https://github.com/okcontract/zean/blob/main/docs/architecture.md) for the exact boundaries.

## Capture and translate a program

To generate a new model, first build an instrumented Zig compiler using the
[toolchain guide](https://github.com/okcontract/zean/blob/main/docs/toolchain.md). An ordinary Zig installation can run the
examples and tests; producing AIR records requires the instrumented compiler.
Native capture tooling supports macOS and Linux.

For example, capture and translate the original counter:

```
zig build capture -- \
  --toolchain /path/to/instrumented-build/report.json \
  --source examples/counter/v1/counter.zig \
  --root counter.advance \
  --output /tmp/counter-capture

zig build run -- translate \
  --capture /tmp/counter-capture/report.json \
  --root counter.advance \
  --profile scalar \
  --namespace MyCounter.Generated \
  --output /tmp/counter-model
```

The output bundle contains:

| File | Purpose |
| --- | --- |
| `Generated.lean` | Executable program data; regenerated by the translator |
| `manifest.json` | Source, AIR, capture, producer and model identities, plus verification scope |

Translation validates every selected root before publishing the bundle. Use a
new output directory for each run, and keep captures and compiler builds in a
separate working directory. Repeat `--root` to select more functions; their
final name components must be unique.

For `scalar`, `memory` and `loops`, add `--certify /tmp/certificate-evidence` to check
AIR-to-model correspondence in Lean before publication. The generated theorem
compares an independent Lean interpretation of the captured data with the emitted
program. This checks the lowering step; source capture, JSON lifting and native
code generation remain trusted. See the [admission specification](https://github.com/okcontract/zean/blob/main/docs/admission.md).

Build the reusable model library and check the generated module:

```
zig build lean-framework
elan run leanprover/lean4:v4.35.0 lake env lean /tmp/counter-model/Generated.lean
```

Add your specification and proofs in separate Lean files. The tutorial shows
how to organize those files and update them after a source change.

## Supported fragments

| Translation profile | Supported operations |
| --- | --- |
| `scalar` | Selected integer/Boolean operations, casts and structured control |
| `memory` | Typed pointers, allocation, loads/stores and retained slice guards |
| `loops` | Memory operations with resumable loops |
| `aggregate` | Complete aggregate declarations, fields and aggregate operations |
| `word-bytes` | Restricted initialized `u32` byte views with checked provenance |
| `word-byte-loops` | Word-byte access with resumable loops |
| `calls` | Finite memory programs with an admitted direct-call closure |
| `call-loops` | Looping callers with finite, separately verified callees |
| `nested-calls` | Acyclic calls to looping callees, with safety over all finite observation budgets |
| `recursive-calls` | Direct recursion over a checked call table, including mutual calls |

These profiles describe admitted AIR, rather than general Zig language support.
Standalone translation currently admits ReleaseFast AIR. Memory profiles
have additional target and contract restrictions; see the
[supported routes](https://github.com/okcontract/zean/blob/main/docs/architecture.md#supported-routes).

The [native tooling guide](https://github.com/okcontract/zean/blob/main/docs/native-tooling.md) describes capture, source-owner
validation, certified translation, and proof replay. The repository includes
the inputs needed for its portable examples and regression checks. New captures
require an instrumented build of the public, pinned Zig release.

## Build and contribute

Versions are pinned in [.zigversion](https://github.com/okcontract/zean/blob/main/.zigversion) and
[lean-toolchain](https://github.com/okcontract/zean/blob/main/lean-toolchain). The build uses elan by default; select an
existing matching Lake executable with `-Dlake=/path/to/lake`.

| Command | What it does |
| --- | --- |
| `zig build` | Build and install the native CLI |
| `zig build test` | Run native translation, admission, process, and tutorial regressions |
| `zig build lean-core` | Check the core verification API and its dependencies |
| `zig build lean-framework` | Check reusable semantics, optional verification domains and correspondence |
| `zig build lean-examples` | Check tutorial and component proof clients |
| `zig build lean-regressions` | Check retained 
hbbio71
🟧 echo.github ⭐The repository README is the original project announcement/content and does not cite an earlier post, paper, or social-media artifact. It deokcontract——

Interpretation history

Decision trace