OpenSheaf in Lean
Two literate programs about the OpenSheaf specification (version 0.2, a draft), checked by Lean 4. Both are non-normative: where they and the specification differ, the specification holds.
A formal model
Lines and their versions, owners and their key logs with pre-rotation, signatures, archives and copies, pins, catalogues and selections, branches and drafts, and the steps that change archives; then the properties the specification states in prose, proved for every world: pins stay valid, only an owner's keys add to its lines, current keys cannot change a key log nor block an exposure, a fork freezes its owner for ever, copies agree while owners sign one history, takedowns are reported, selections move only by their curator, and the use cases hold; the residual risks of the specification, shown by example; and what a reader who checks one copy, from any host, can trust.
OpenSheaf as a sheaf
An application of the model. Named document versions of lines, ordered by deposit, are the base; each object version, wherever it is kept, is a section. In every world built from nothing by valid steps and takedowns, the sections of all copies glue into one when owners sign one history: one content for each document version, whichever copy it is read from; and a fork of a line, which only keys of its owner's key log can sign, is exactly what stops them gluing. Every copy that holds a pinned version gives the same verdict on it, and verification needs only what lies below.
The source of both, and the issues found by the model, are in opensheaf/opensheaf-lean.