opensheaf-lean

OpenSheaf in Lean

This is a formal model of the OpenSheaf specification (version 0.2, a draft) in Lean 4, written as a literate program. It defines lines and their object versions and document versions, owners and their key logs, signatures, archives and copies, pins, catalogues and selections, branches and drafts, and the ways archives change. It then proves the properties that the specification states in prose: that pins, once valid, stay valid; that a takedown is detected; that only an owner's keys add to its lines, wherever they are kept; that whoever holds only current keys cannot change a key log, nor block an exposure, and that a key log never forks at its first version; that a fork freezes its owner for ever; that copies of a line agree as long as its owner signs one history; that a selection does not move unless its curator moves it; that drafts can be rewritten without breaking any pin; and that a reader who checks a copy against a copy of the owner's key log, from any host, reads the history the owner's keys signed.

The model is non-normative. Where it and the specification differ, the specification holds, and the difference is a bug of one or the other, to be reported. Its purpose is to make the semantics precise, to find the ambiguities and corner cases of the text, and to check design proposals before they are written into the specification. An earlier version modelled version 0.1 of the specification, in which archives owned their objects; version 0.2 names works by their genesis records, makes owners keyed identities with key logs, and lines signed versions wherever they are stored, and the model follows.

How to read it

The chapters build the model from the bottom up:

  1. Basic notions: names, owners and lines, pins with their hints, member lists, keys and signature files, branch points and object versions;
  2. Objects and their history: genesis records, objects, inventories (exact, with the inventory chain of section 4.3), the environment (digests, names, which signatures verify), and the counting of document versions (section 4.2);
  3. Archives and pins: archives and the owners they host, resolution at an archive and through the hints of a pin, the steps that change archives, immutability, and takedown;
  4. Owners and key logs: pre-rotation (section 6.1): the rules on keys.json, the computed first version, rotation keys (counted by the digests committed), ending versions and fork records; a key log never forks at its first version, and current keys cannot change it;
  5. Lines and signatures: signed versions, vouching, exposed keys, fork points and contested versions (section 7.3);
  6. Catalogues and selections: what updating a collection does to each type;
  7. Well-formed worlds: the valid steps, the model's reading of what the specification allows (identity, signatures against the archive's copy of the key log, mirrors that only copy, branch points), and what they guarantee; then takedowns among the events (of lines, not of key logs), after which every pin held is found or reports removed;
  8. Owners sign, places host: the head of every copy of every line is signed by its owner, every key log is valid; forgery needs an owner's key; mirrors only copy, a fork freezes an owner, an ended owner deposits nothing, and exposed keys add nothing (section 7.5); every copy keeps the identity of its line, so copies hold one genesis record unless the names of the two records collide;
  9. Copies, mirrors and branches: copies of a line agree when its owner signs one history, and a fork of a line was signed with the owner's keys; a pin authenticates any copy, unless digests collide; resolution through hints; branches hold their parents' files, and accepted copies survive the parent and are never taken for it;
  10. Drafts and sealing: drafts may be rewritten or deleted, and nothing about any line changes;
  11. Use cases as theorems: the promises of the use cases (a journal issue does not change, a co-author's catalogue follows a paper, a withdrawal keeps what was vetted, only the owner adds to a member, a takedown is reported, a mirror is a receipt, a record deleted at the end of its retention), proved for every world;
  12. What cannot happen: breaks of the protocol, shown impossible or detected: a pin changing its meaning, history rewritten, identifiers reused, document versions ambiguous or with gaps, cycles of pins, a pin naming a key log, a withdrawal undone;
  13. What keys can do: the promises of sections 6.3 and 15.1 about keys: only rotation keys of the version before decide a new version of a key log, so whoever holds current keys cannot block an exposure; a fork freezes the owner for ever; keys of the other side of a fork never count; signatures stay good and contested versions stay contested against a longer copy of the key log; rotation keys of the latest version take the owner over, and the owner's only answer is a fork; a retired key never exposed still signs;
  14. A story, checked by computation: three owners with key logs, a paper sealed and revised after a key rotation, a journal issue and accepted copy, a co-author's catalogue and mirror, a takedown and a draft, with the verifier's reports checked by decide; and attempts that fail: a signature that is not the owner's, a rewrite in place, a fresh pin into a line taken down, a reinstatement, a branch posing as its parent, bad member lists, a mirror that does not copy, a version signed with an exposed key, a key log changed with current keys, a fork that freezes the owner and makes contested, where it is known, the versions signed from the fork point on;
  15. Residual risks, checked by computation: the residual risks of section 15.1 in the story's worlds: an archive served a key log without the exposure adds what the author's archive refuses; a thief's fork that exposes the owner's key makes the owner's own versions contested, and adds nothing; a retired key still signs; a takeover without a fork, and the owner's answering fork;
  16. A learning record, checked by computation: a student's thesis and the department's receipt of it, comments tied by a reference to the version commented on, a rewrite caught by the receipt, and the record deleted at the end of its retention;
  17. References between documents: pinned references from one document to an exact version of another (the proposals of issues #21 and #28): they are found and travel with copies, a pin fixes what its version refers to, a takedown behind a reference is invisible to a verifier that knows only the core; the use case of a short account and its detailed argument, computed;
  18. A reader's check: what a reader that checks one copy of a line against one copy of its owner's key log knows, whatever host served them: the head is signed by a current key, which comes from the owner's genesis record through rotation keys, and the copy is the history the owner's keys signed, unless inventories collide: no host forges a version.

Each chapter writes one module of the library, OpenSheaf/*.lean. The code is given in chunks, with the prose that explains it; the literate tools tangle the chunks into the Lean files, which Lean then checks. The root of the library imports every module:

import OpenSheaf.Basic
import OpenSheaf.Object
import OpenSheaf.Archive
import OpenSheaf.Owners
import OpenSheaf.Lines
import OpenSheaf.Collection
import OpenSheaf.Worlds
import OpenSheaf.Acts
import OpenSheaf.Copies
import OpenSheaf.Drafts
import OpenSheaf.Patterns
import OpenSheaf.Impossible
import OpenSheaf.Security
import OpenSheaf.Story
import OpenSheaf.Risks
import OpenSheaf.Record
import OpenSheaf.References
import OpenSheaf.Reader

Modelling choices

The specification describes files on disk, JSON documents, signatures and web servers. The model keeps only what the properties depend on.

An application: OpenSheaf as a sheaf

A second literate program in the same repository, OpenSheaf as a sheaf, reads the worlds of this model as sheaves: named document versions, ordered by deposit, are the base, and each object version, wherever it is kept, is a section. It proves that, in every world built by the events of this model, the sections of all copies of a line glue into exactly one when its owner signs one history, and that a fork of a line, which only the owner's keys can make, is a failure of gluing.

Building

Install Lean with elan and the literate tools (pip install -r requirements-literate.txt), then

literate tangle   # write OpenSheaf/*.lean from these chapters
lake build        # check every proof

The model has no dependencies beyond Lean's standard library.