The library format¶
These pages specify the on-disk format of a judgment proof library: a
directory of content-addressed files that holds declarations, theorems and
the proof-DAG rows that prove them, and that any conforming reader in any
language can check again. They are written for implementers. With them and
the row and stream layouts of ST9, and without the Mojo
sources, an engineer can write a reader that parses and validates every byte,
and a writer whose libraries the judgment_store loader accepts.
The format's design and its proofs are on the design pages (ST1, ST7, ST8, ST9) and the theory pages (identity, libraries). These pages restate the file, manifest and metadata layouts and every check so that they stand alone, and link to ST9 for the rows, which they do not repeat. For what a library is for and how to use it from Mojo, start with the Store guides and concepts.
The pages¶
| Page | Contents |
|---|---|
| Primitive encodings | integers, varints, zigzag, strings, UTF-8, identities, SHA-256, raw DEFLATE |
| The container | the JDGB envelope shared by manifests and partitions: header, sections, digest, refusals |
| Declarations and terms | the canonical serialization of types, terms, and every declaration form |
| Identities | declaration identities, statement keys, statement identities, canonical names |
| Partitions | the ten sections of a proof-DAG partition, sub-partitions and chains |
| The manifest and the directory | the manifest's sections, the directory, publication, collection |
| Loading a library | the loader's ordered checklist and what acceptance establishes (Theorem L-6) |
Terms¶
| Term | Meaning |
|---|---|
| library | a directory: CURRENT, manifests/, parts/ (directory) |
| manifest | a container of kind 4 that lists a version's partitions, statements, names and declarations |
| partition | a container of kind 6 that holds a consecutive part of the library's theory: its declarations and the rows that prove its theorems |
| container | the JDGB envelope: a header, tagged sections, a SHA-256 digest |
| row | one record of the writer's termbank.dag bank: a term node, a pool entry, a local, a context frame, a set, a theory, a declaration, a reference to a declaration, or a proof node (ST9.2) |
| chain | partitions whose rows are numbered consecutively, so that a later one references an earlier one's rows by number (ST9.1) |
| DAG block | a run of a partition's rows, written as sixteen compressed streams (ST9.4) |
| block | a declaration as one unit, with its parts (a type definition's abs, rep, and theorems, for example); the identity pages use the word in this sense |
| reference | a pair (identity, part) naming a block (part 0) or one of its parts |
| identity | the 32-byte SHA-256 of a block's canonical bytes under a domain prefix |
| statement identity | the 32-byte SHA-256 of a statement's key, the same for statements equal up to renaming type variables |
| provider | the one declaration that provides a statement in a library: a theorem, an axiom, a definitional statement, or a statement of the profile |
| profile | the theory a library extends (none, classical or isabelle); its declarations are not in the library's files |
| core | the declarations every bank holds (core.Prop, core.and, …); they are named, never serialized |
| checker | the trusted stateless checker of judgment_core, which checks every row a loader commits; see what a loader checks |
| export-table entry | a Proven declaration's name, statement identity, and the row number of the PROOF row that proves it (partition section 10) |
| closed-form entry | the shape of a theorem whose proof row concludes an open sequent (partition section 9) |
Normative words¶
MUST, MUST NOT, REQUIRED, SHALL, SHALL NOT, SHOULD,
SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL have the meanings of
RFC 2119 and
RFC 8174 when they are in capitals.
Byte offsets are zero-based. "Refuse" means reject the whole input with the
named error kind; the error kinds are those of the
API reference (FORMAT, DIGEST,
IDENTITY, VERSION, LIMIT, MISSING_DEPENDENCY, KERNEL, REPLAY,
CONFLICT, LOCKED, IO, LIBRARY).
Conformance¶
The format has four conformance classes. Each includes the one before it.
| Class | What it does | What it can claim |
|---|---|---|
| Parser | reads a library's files and decodes every structure, without a checker | nothing about truth: the bytes are well formed |
| Validating reader | a parser that also makes every check that needs no checker, with the stated error kinds and offsets | the files are a well-formed library version; nothing about truth |
| Loader | a validating reader with a checker of the judgment logic that commits every row, rebuilds every declaration, checks every row, and makes every check of Loading a library |
Theorem L-6: every theorem it declares was checked |
| Writer | produces files that every loader accepts | determinism (below) |
A conforming parser MUST read every field described on these pages and in ST9.3 to ST9.6, MUST NOT read past the end of any input, section, stream, or list, and MUST bound every count by the bytes that remain before it allocates for the count. It SHOULD refuse with the error kinds these pages give.
A conforming validating reader MUST make every check that needs no checker: those of Primitive encodings and The container; the grammar, position, and category checks of Declarations and terms (checks 1 to 5); the framing, directory, digest and row checks of Partitions; and manifest checks 1 and 2 (reader checks). When these pages give an error kind and an offset, it SHOULD report them. Two inputs that the reference implementation refuses with different error kinds MAY be refused by another reader with either, but a reader MUST NOT accept an input the reference refuses or refuse one the reference accepts.
A conforming loader MUST do everything Loading a library lists and MUST NOT declare anything from a library that it has not checked. A load is atomic: it builds a fresh bank and either returns it complete or discards it.
A conforming writer MUST produce files that the reference loader accepts: the section contents the loader recomputes, minimal varints, the block and stream layouts of ST9.4, correct identities and digests, and file names that are the SHA-256 of their contents.
Deterministic writer output¶
Declarations and statements are canonical: their bytes, and so their identities and statement identities, depend only on their content (identities). A partition's rows are the rows the writer's bank committed, in its commit order (ST9.2): the producer fixes them, and two producers that prove a theorem differently write different rows. For given rows, every byte outside the DEFLATE streams is determined: the field encoding, the block boundaries, the directory, and the metadata sections, which a loader recomputes from what it loaded and compares byte for byte.
DEFLATE is the one place where many encodings are valid. A reader MUST accept every valid stream that inflates to the stated length (raw DEFLATE). A writer chooses its streams, so its file hashes, which name the files, depend on its encoder:
- A conforming writer MAY use any encoder. Its libraries load, and their
declarations and statements have the identities any other writer would give
them; only the file hashes (the
.jlpand.jlmnames, the manifest's file hashes,CURRENT) and the block digests and Merkle roots differ. - A reproducing writer uses the Store's own encoder at level 6, specified
bit for bit in compression, Determinism.
Its files are byte-identical to the reference writer's for the same rows.
tests/store/reference/store_deflate.pyis a Python reference of that encoder, andtests/store/reference/st9_dag.pyencodes partition sections 5, 8 and 10 with it, byte for byte as the Mojo writer does.
The reference writer is a reproducing writer: a publication of the same changes on the same base writes the same bytes on every platform, in every run, and at every worker count (ground rules G1 and SG6). Nothing hashed contains a timestamp, a process id, or a hash-table order. The kernel commit in every container header is the writer's revision, and it is hashed like any other content, so a reproducing writer writes the same commit as the files it reproduces.
Versions and compatibility¶
| Version | Where | Value | A reader that does not know it |
|---|---|---|---|
| container format version | container bytes 4–7 | 2 | refuses with FORMAT at byte 4 |
termbank format |
container bytes 8–11 | 2 | refuses with VERSION at byte 8 |
| library format version | manifest section 1, first four bytes | 4, format 2.2 | refuses with VERSION at byte 73 |
| identity domains | the prefixes judgment/decl/1, judgment/core/1, judgment/stmt/1 |
version 1 of each | (a new serialization takes a new prefix, so identities never collide across versions) |
| container kinds | container byte 56 | 4 manifest, 6 partition | refuses with FORMAT at byte 56 |
| row tags and proof-node kinds | the TAG stream of every DAG block | ST9.2, TD1.8 | refuses with FORMAT |
Only library format 2.2 is supported. A LOCAL row is keyed by its binding
site, parent frame, type and name
(ST9.3). There is no format migration
path; an unsupported library must be written again from its articles or sessions.
The policy:
- Identities are permanent. The domain prefixes fix the serialization of
version 1. A change to the declaration, statement, or core serialization
takes a new prefix (
judgment/decl/2, …), so an identity of one version is never an identity of another. - The
termbankformat is part of every identity. Canonical forms, and so serializations and identities, depend on the term bank's hash functions and structural order (termbank T1.2 and T1.6). A library is readable only by a checker of the sametermbankformat; a reader refuses another withVERSION. - Formats change only with their version. A change to the container envelope increments the container format version; a change to the manifest or to a partition's sections or rows increments the library format version. Readers refuse versions they do not know; there are no optional extensions, unknown sections, or skippable fields.
- The kernel commit is informational. It records the writer's kernel revision, as 40 hexadecimal digits, and a reader never compares it with its own: every row is checked again by the reader's checker.
- Proof-node kinds are appended, never changed. A
PROOFrow names its kind by its tag, 0x80 plus the TD1.8 code; an existing kind's operand layout never changes, and a new kind gets a new code. A reader refuses a tag it does not know. - A changed checker or profile does not reinterpret a library. A version
that stops checking under a new checker or profile is refused whole by a
load and by
Library.recheck; its statements are withdrawn, or their proofs replaced, by an explicit change published as a new version (changing a library).
The OpenTheory article dialect (judgment.extended.6,
ST6) is an input format the Store
imports from; it never occurs in library files.
Test vectors¶
The byte layouts of the container, the core identities, DEFLATE and the DAG
sections have fixtures in tests/store/corpus/, generated by independent
Python references in tests/store/reference/. The references use only
Python's standard library (struct, hashlib, zlib) and import no Store
code. With --check each one verifies the checked-in fixtures without
rewriting them. They are a second implementation of the format to test
against.
| Reference | Fixtures | Covers |
|---|---|---|
sha256_vectors.py |
reference/sha256_vectors.txt |
SHA-256, the NIST vectors |
container_vectors.py |
container_*.bin |
the container: every refusal and its offset |
identity_vectors.py |
reference/identity_vectors.txt |
the identities of the core declarations and of the empty declaration |
deflate_vectors.py |
deflate_* |
raw DEFLATE: accepted, refused, and the encoder's pinned output |
store_deflate.py |
deflate_*.mojo-<level>.deflate |
the Store's deterministic encoder, reimplemented from compression |
st9_dag.py |
st9_* |
partition sections 5, 8 and 10: the field encoding, the blocks and streams, the directory, the Merkle root and the export table (ST9.3 to ST9.6) |
Each .bin fixture of a refusal has an .expect file holding ok, or the
error kind and the zero-based offset the reference reader reports. To check
them all:
python tests/store/reference/sha256_vectors.py | diff - tests/store/reference/sha256_vectors.txt
python tests/store/reference/container_vectors.py --output tests/store/corpus --check
python tests/store/reference/identity_vectors.py --check
python tests/store/reference/deflate_vectors.py --check
python tests/store/reference/store_deflate.py
python tests/store/reference/st9_dag.py --check
A new implementation is tested by reading every fixture and comparing its
outcome with the .expect file, and by encoding the st9_*.rows inputs and
comparing its sections 5, 8 and 10 with the fixtures.