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
- The base is the set of named document versions: a line, named by
its name and owner (
sheaf:<name>:<owner>, wherever it is kept), and a document version number. Its open sets are the sets closed under earlier versions of the same object (the Alexandrov topology of the order of deposit). - The value at a named document version is its content: its files, and for a collection its member list.
- Collections. A named document version also comes after the versions its member list pins, so that below a selection version lies the selection together with what it vetted, and the earlier versions of those, which its pins fix too.
- The sections come from object versions. Each object version of a copy of a line, wherever the copy is kept, says what every document version up to it holds: a section over an open set.
- The theorem. In every world built from nothing by the model's valid steps and takedowns, the sections of all copies of all lines are compatible, and glue into exactly one section, when every owner signs one history: one content for each named document version, whichever copy and whichever object version it is read from. When they do not glue, a fork of a line is the reason, signed with keys of its owner's key log as the world holds it.
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:
- within one object, the rule of section 4.2, which gives each document version one content, and which the verifier checks (section 14.4): the pieces of an object version glue because of it, and a history that breaks it has pieces that do not glue;
- between copies kept in different archives, or in different worlds, the owner's signatures (section 7): the head of every copy is signed by the owner, and an owner that signs one history ("one writer per line", section 7.4) makes any two copies prefixes of one another;
- between any copies, found anywhere, a pin: two objects that resolve the same pin give the same section, unless digests collide (section 8.5).
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
- Sheaves on an order: the mathematics, without Mathlib: sections, the sheaf condition, and local conditions, which glue on an Alexandrov space;
- 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;
- 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);
- 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;
- 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;
- 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;
- 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);
- 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;
- 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);
- 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;
- 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;
- Verification is local: restricting a world restricts its sheaf, and a collection verifies in its support as in the whole world;
- 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;
- 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;
- 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
- Worlds that refer to each other. In the model, a pin or a copy is checked against the world in which it is written. Two worlds built independently, with pins from one found only through copies in the other, checked when they are combined, need a step relation across worlds, which the model does not have; chapter Separate worlds shows that such worlds agree on the lines they share, when owners are honest.
- Takedowns in the order with pins. That the order with pins is a partial order, and that nothing new comes below a point, are proved for worlds built by valid steps. With takedowns, a line may come back after every copy of it was taken down, and the proof would need the history of the world, not only its state (chapter The order with pins).
- A base that does not depend on the world. The order with pins (chapter 6) is defined from where pins resolve in a world: a takedown removes edges. A base fixed once and for all would take pins themselves as points, with their digests, which fix what they pin unless digests collide.
-
Collisions. Theorems that need digests not to collide assume it for the inventories they compare, or for the copies a world holds and the histories owners sign, never for the digest function as a whole.
-
References of documents. The pins of member lists are in the order (chapter 6): below a collection version lies what it pins. The pins of a document's references (issues #21 and #28 of the specification) are not: in the model a description-only version may change them, so they belong to object versions, not to document versions. They would join the order if references became part of the content (issue #28).
- Completion. A document version deposited without its sources may be completed later, keeping its number (section 4.2). Its content then grows, and the values would be partial maps from paths to digests, compatible when they agree where both are defined. The model does not represent completion, and neither does this program.
- Branches as one base. Version 0.2 has lines and branches (section 9), and a fork of a line is, as foreseen, a family that does not glue (chapter The sections of a world glue). A branch is another line, so another part of the base; reading a work with all its branches as one tree, or a graph once a branch point moves, would glue a branch's first version to its parent's (chapter Pins and accepted copies relates the two values), and is left for later.
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