hn.today

Zean: Write Zig, prove it in Lean

okcontract.com8 points0 comments
Screenshot of Zean: Write Zig, prove it in Lean

Zean is an open-source toolkit that lets developers write supported functions in Zig, translate them into executable Lean models, and prove specified properties of those functions. Its proposed workflow keeps early design and iteration in Zig, then adds formal contracts once a component is stable. In the copy-loop example, the caller must provide initialized source data and writable destination space of sufficient size; disjoint ranges are also required for the source-preservation guarantee. Lean proofs establish that execution avoids invalid accesses and uninitialized reads, copies the source into the destination on success, and preserves the source and memory outside the destination. Allocation exhaustion is allowed, while termination requires a separate proof. The guarantees apply to all inputs meeting the stated assumptions, rather than only to tested examples.

Zean captures supported functions from Zig’s analyzed intermediate representation, AIR, and translates them into Lean definitions. Developers write specifications, loop invariants, and remaining mathematical arguments; the verification library generates obligations involving memory access, initialization, permissions, arithmetic, control flow, and calls. Unsupported operations are rejected, and unresolved obligations remain visible. After code changes, developers regenerate the model and replay proofs, so a boundary error such as changing a loop condition from “less than” to “less than or equal” can invalidate the original contract. The initial release supports a restricted set of AIR operations and includes examples such as buffer updates, copy loops, helper calls, and a specialized standard-library replacement function. Proofs cover the translated model, not the final binary or the entire compiler pipeline, which remain trust boundaries.

Read on okcontract.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Solid 2.0

Solid 2.0

Solid 2.0 is now stable, five years after version 1.0, with a smaller API and diagnostics designed for AI agents. Its reactive graph now handles asynchronous computations, while built-in server functions support RPC calls and persistent Server-Sent Events connections. (solidjs.com)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.