opensheaf-lean · sheaf

OpenSheaf as a sheaf

The name OpenSheaf says that archives kept and verified separately glue into a whole, as the local pieces of a sheaf do. This literate program makes the claim precise and proves it in Lean 4. It is an application of the formal model of the specification, OpenSheaf in Lean, kept in the same repository as a separate document: it adds no rule to the model, and only reads the model's worlds as sheaves.

Like the model, it is non-normative. Where it and the specification differ, the specification holds.

The claim

Precisely: the sections over a set, with values in the contents, form a sheaf for general reasons (chapter 1), whatever the protocol. What the theorem says about OpenSheaf is that the data of a world form a compatible family of sections. So a world defines one section of that sheaf, over the open set of what it holds, and every copy and every object version is a restriction of it. That is all that "a world is a sheaf" means here: the theorems are about which sections a world gives, not about the sheaf, which is the same for every world.

A name carries no digest, so this is not automatic. Two copies could hold different content under the same name, and then nothing glues. The proof shows which rules of the specification make the pieces agree:

Version 0.1 of the specification had no owners: an object lived in its own archive and mirrors copied it, so every world built by events glued with no hypothesis. Version 0.2 lets an owner write a line in several archives, and its keys, or a thief's, sign what they sign. The hypothesis that owners are honest is therefore part of the theorems now, and the program shows where: a fork of a line is exactly what stops gluing. Honesty is stated of a world and of an account of the histories owners sign (Honest E H w): every signature of an owner's keys signs a prefix of its history, and no copy the world holds collides with that history. It assumes nothing of the digest beyond those pairs, so SHA-512 can satisfy it, and so can the toy digest of the story, whose world is shown honest (chapter A story, as a sheaf). Signatures count whoever made them: a thief's version signed with keys the key log lists belongs to the history too.

How to read it

  1. Sheaves on an order: the mathematics, without Mathlib: sections, the sheaf condition, and local conditions, which glue on an Alexandrov space;
  2. Named document versions: the base, the order of deposit, the content of a document version, and the rule "one number, one content" in both directions;
  3. An object version is a section: its set is open, and is what its pieces hold (no gaps), it glues its pieces (section 4.2), and a later object version restricts to an earlier one (versions are fixed);
  4. The sections of a world glue: copies agree in every world built by events when owners are honest, so the sections of a world glue, uniquely; otherwise a fork signed by an owner is the reason; a condition checked one object version at a time holds of the whole;
  5. Pins and accepted copies: a pin names a section, in any world; an accepted copy, a branch, holds the vetted content at another point, and every branch in a world built by events holds, at its first version, the files of its parent, unless inventories collide;
  6. Collections and what they pin: the pins of member lists added to the order; below a collection version lies each member it pins, with the content its pin fixes, unless its line was taken down at the pin's hints;
  7. The order with pins: later steps keep its edges, and in every world built by valid steps with honest owners the order with pins is a partial order (with takedowns, open);
  8. A story, as a sheaf: the story of the model, read as a sheaf and checked by computation (the accepted copy holding what the journal vetted, descriptions that do not glue), and two broken worlds that do not glue: a forged copy, written outside the protocol, and a number reused;
  9. Names are eternal: a named document version has the same content in any two worlds built by events, when owners are honest, and the glued sections of any two worlds agree; a name held nowhere may be held again (version 0.1 said it could not);
  10. What lies below is fixed: once a named document version is held, no later valid step adds or removes anything below it in the order with pins, and the values below agree;
  11. Verification is lifting: pins are points of a sheaf of digests, verification lifts them to the sheaf of inventories, the lift is unique without collisions, and every copy that holds the pinned version gives the same verdict, when owners are honest;
  12. Verification is local: restricting a world restricts its sheaf, and a collection verifies in its support as in the whole world;
  13. Separate worlds: two worlds built by events glue when owners are honest, though they may share lines, and on separate archives each keeps its section;
  14. Descriptions are the fibres: two maps from object versions to named document versions; the fibres of the first lie within the contents, but it is not monotone; the second, the top, is monotone, and its fibres are runs of description-only versions; descriptions do not glue;
  15. The citable section: the worlds of a run glue over time into one section over everything ever held, when owners are honest.

Each chapter writes one module of the library, Sheaf/*.lean, which imports the modules of the model it needs. The root of the library imports every module:

import Sheaf.Order
import Sheaf.Base
import Sheaf.Object
import Sheaf.World
import Sheaf.Pins
import Sheaf.Collections
import Sheaf.Acyclic
import Sheaf.Eternal
import Sheaf.Below
import Sheaf.Lifting
import Sheaf.Local
import Sheaf.Federation
import Sheaf.Fibres
import Sheaf.Citable
import Sheaf.Story

What does not glue

Descriptions. Two object versions may describe the same document version differently: a description-only version adds a DOI, corrects a stage or a title, or adds a withdrawal or a notice (section 4.2). A notice or the reason of a withdrawal kept as a file is new content in the model, so a new document version (chapter Named document versions). Their descriptions do not agree, and are not meant to. The specification settles them by authority, not by agreement: the latest signed version of the line describes it (section 7.3), and earlier object versions keep the description as it was known when they were made. So descriptions are values of object versions, ordered by time, not values of named document versions, and the sheaf leaves them out. Chapter Descriptions are the fibres shows where they vary, along the fibres of the maps from object versions to named document versions, and shows on the story that they do not glue. This is a feature of the design: what is fixed (the content) glues, and what may be corrected (the description) has an owner instead.

The reading order. The history of a document (history in object.json) orders its document versions for readers, and a later object version may correct it. It is not the order of the base, which is the order of deposit, fixed by the inventories.

What is left out

The tools

The chapters are in literate-sheaf/, beside the model's in literate/. They are tangled into the library Sheaf by the literate tools, naming the documents, and the library is built with the model's:

literate tangle literate-sheaf/*.md   # write Sheaf.lean and Sheaf/*.lean
lake build --wfail                    # check every proof, of both libraries