diff --git a/README.md b/README.md index 7e10df50..e023f26f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Lean statements](https://img.shields.io/badge/Lean-328_statements_judged-blue)](formal/README.md) [![sorry](https://img.shields.io/badge/sorry-0-brightgreen)](formal/sorry-budget) [![kernels](https://img.shields.io/badge/kernel_replay-6_checkers-6f42c1)](formal/check.sh) -[![attacks](https://img.shields.io/badge/attacks-178_with_controls-blue)](formal/PalaceTest) +[![attacks](https://img.shields.io/badge/attacks-227_with_controls-blue)](formal/PalaceTest) [![tests](https://img.shields.io/badge/tests-3633-brightgreen)](docs/runbook.md) [![coverage](https://img.shields.io/badge/coverage-77%25-green)](pyproject.toml) [![mypy](https://img.shields.io/badge/mypy-0_errors_in_core-brightgreen)](pyproject.toml) @@ -121,12 +121,12 @@ A law has one row in [`docs/LAWS.md`](docs/LAWS.md): its statement, the structur | | | |---|---| | toolchain | Lean `v4.36.0-rc2`, Mathlib; Plausible for the attacks | -| the library | 37 proof modules, 36 models, 26 statement files; 23,101 lines of models and proofs, 3,460 of statements, 4,990 of attacks | -| theorems | 1,345 proved in `formal/Palace`; 328 statements in `formal/Spec` judged identical by the comparator | +| the library | 38 proof modules, 37 models, 26 statement files; 25,426 lines of models and proofs, 3,460 of statements, 5,705 of attacks | +| theorems | 1,520 proved in `formal/Palace`; 328 statements in `formal/Spec` judged identical by the comparator | | the ledger | 100 rows in 15 families, 334 cited declarations, 87 law markers checked against the rows | -| attacks | 178 Plausible attacks and 161 negative controls over 32 modules, fixed seeds | +| attacks | 227 Plausible attacks and 203 negative controls over 33 modules, fixed seeds | | axioms | `propext`, `Classical.choice`, `Quot.sound`; `sorry` 0 | -| the replay | 55,746 declarations accepted by all six checkers on the run of `formal/check.sh` this commit was built with | +| the replay | 56,188 declarations accepted by all six checkers on the run of `formal/check.sh` this commit was built with | | families | memberships · Laplacian, balance and spectral · cut and conductance · curvature · the global event clock · the shared prose plane · capability scopes · the abstraction ultrametric σ* · bridges · the retrieval curve · the query sentence algebra · the ingress · stored vectors · the growth readout · the utility field | ## The mathematics diff --git a/docs/TRACKS.md b/docs/TRACKS.md index fb2124c5..ee9b126f 100644 --- a/docs/TRACKS.md +++ b/docs/TRACKS.md @@ -170,6 +170,7 @@ - QL-2 the executor — clause evaluators over the existing stores, the mask/column/product/threshold operators, the product-automaton walker, the overlay for assume - QL-3 the surface — palace query, a /context skill, the resolution ledger, the query log as a sensor - QL-4 the falsifier battery run — composed sentences against flat search on owner-endorsed answers, a finding either way + - SN-0 the temporal snapshot's design proved: dn-temporal-snapshot with SNP-1 to SNP-10 machine-checked in formal/Palace/Snapshot.lean (append invariance, monotonicity, composition, idempotence at the head, derived views as functions of the prefixes, grant restriction, erasure dominance, the resolution of a frontier to a consistent cut, certified cuts, the horizon), attacks and controls green, the measurements on synthetic fixtures - **Reference bookkeeper** (active): - the async F-consistency agent designed (a FABLE design-pass) — bookkeeper still unbuilt - the reference-sensor gap closed (finding-0145) diff --git a/docs/design-notes/dn-temporal-snapshot.md b/docs/design-notes/dn-temporal-snapshot.md new file mode 100644 index 00000000..bba4177e --- /dev/null +++ b/docs/design-notes/dn-temporal-snapshot.md @@ -0,0 +1,2165 @@ +--- +type: design-note +id: dn-temporal-snapshot +track: query-language +status: draft # provenance description, never a gate; the merge is ratification +implementation: design-only # nothing built in the store; the laws are machine-checked in formal/Palace/Snapshot.lean +created: 2026-11-10 +updated: 2026-11-11 +links: + - papers/2026-11-10-temporal-snapshot/paper.tex # the article: the same theorems, with proof sketches and the references + - docs/design-notes/global-event-clock.md # N, its generators, the cut as a certified frontier (§2.4) + - docs/brainstorms/limits-of-the-algebra.md # L7: the snapshot as the clock's cut on the version chains + - docs/design-notes/dn-query-sentence-algebra.md # `as of` as the index of the reading; §2.9 what is not in the universe + - docs/design-notes/dn-ingress.md # the one writer, the landing order, the key written last (ING-7) + - docs/design-notes/dn-two-phase-ingestion.md # an item complete without its vector; the pending report (ING-19 to ING-21) + - docs/design-notes/vector-membership-store.md # atoms, occupancies per class, purge (A3.7) + - docs/design-notes/dn-utility-field.md # the use log and the field as its fold (UTL-4); its open question 1 + - docs/design-notes/dn-graph-dynamics.md # GD-4: velocity over a window of cuts, which waits on the snapshot + - docs/design-notes/dn-mathematical-foundations.md # the ladder; design theorems before code + - formal/Palace/Snapshot.lean # the theorems (Snapshot/Defs.lean the model; PalaceTest/Snapshot.lean the attacks) +supersedes: null +superseded_by: null +warrant: null +--- + +# The temporal snapshot: the palace as of a cut + +> Composed on the snapshot session (Fable 5.2, 2026-11-10 and 2026-11-11), on the standing +> direction that the design and its proofs come first and the build follows a licence given at +> the merge. Agent-drafted, filed `draft` on a branch; the merge is ratification. Nothing is +> built: `core/` is untouched and no store of any instance was read. Every nontrivial claim +> carries a grade: `[THEOREM]` is machine-checked in `formal/Palace/Snapshot.lean` and names its +> declaration; `[ESTABLISHED]` is a ratified note's, a fact of the code read at the line cited, +> or a figure of the repository's own experiment records, cited by file and line; `[DERIVED]` is +> argued here from those; `[MEASURED]` is a figure taken for this note on a synthetic fixture, by +> a probe that is not in the repository (§11 says how, and which stage commits its harness); +> `[INFERENCE]` is a design call with a named falsifier; `[HYPOTHESIS]` is a claim nothing here +> checks, with what would check it named. Code claims were read on +> `origin/main` at `e3e3ee47`. The article `papers/2026-11-10-temporal-snapshot/paper.tex` +> states the same theorems with proof sketches and the references. + +## 1. Purpose and scope + +### 1.1 The requirement + +A sentence of the query language can carry `as of ""`. Today it moves one relation: the +citation graph, which the stores index by commit, is read at the cut, and a file of the repository +is read as git's blob there when git holds the commit. Every other verb reads the stores as they +are now, and the answer says so. The requirement is the rest: the palace as of a cut. A read at a cut must be the same +whenever it is asked, since the store only grows above the cut; it must never return what was +erased since; it must respect the grant the asker holds today; and where it cannot read a store at +the cut it must say so instead of answering from the present. + +The same object serves three needs the record already names: a generic integrator, whose +checkpoint is a cut and whose input is the delta between two cuts; the velocity of an identity +over a window of cuts (dn-graph-dynamics GD-4, which waits on the snapshot); and the utility field +as of a cut (dn-utility-field, open question 1). + +### 1.2 Decisions + +1. **A cut is one position per chain, about a dozen positions for an instance, not one per + document (§3.1, §3.3).** The chains are the stores' own append orders. A chain has an id that + never changes and carries a provenance class as a label, so clearances that separate rows + separate chains. `[DERIVED from global-event-clock §2.4; INFERENCE, falsifier SNF-2]` +2. **The missing ledger is a landing log (§3.2).** The catalog is rewritten in place, and no + ledger records which digest a path held when, except the version chains of one place. One + append-only, hash-chained log, written by the catalog's own methods in the transaction of the + row they write, makes the catalog its fold and gives every landed stratum a past. + `[ESTABLISHED for the gap; INFERENCE for the log, falsifier SNF-1]` +3. **A name resolves to a frontier, and the read is at the greatest consistent cut under it + (§3.4, §3.5).** Every frontier resolves to exactly one such cut. That consistent cuts are + closed under meet and join is CLK-2's, already in the ledger. Wall time selects a frontier by + lookup in the bookmarks and orders nothing. `[THEOREM: SNP-8, CLK-2]` +4. **A cut is certified by the digest of each hashed chain's prefix, recorded on a chain of records + that no other chain reads (§3.3, §3.6).** A certificate verifies on every later state of the + store and, under a collision-free digest, pins the prefix it digests. For the landing log that + prefix is the commitments, so under a binding commitment it pins the events. It attests no + erasure, no seal and no grant: those are the present's, and an answer at a certified cut is the + same on two stores for one erasure, one grant and one set of seals. `[THEOREM: SNP-9]` +5. **Derived data is a function of the prefixes, held store by store in the cheapest of the + equal ways (§5):** version-keyed rows selected by the log for vectors and lexical units, + recomputation for the causal fiber and for the relations a note declares, kept generations + for model output. `[THEOREM: SNP-5; INFERENCE per store]` +6. **The grant and the erasure are the present's (§6).** A narrower grant's snapshot is the + restriction of a wider one's; nothing erased is visible at any cut, and a read by path returns + a hole where the version at the cut is erased; a retired identity is sealed at every earlier + cut, its versions with its value. `[THEOREM: SNP-6, SNP-7]` +7. **A read under `as of` holds no event from after the cut it names (§7).** Where a store + cannot serve the cut asked, the cut read is the greatest consistent cut among the positions + the stores serve, and the answer names it chain by chain. A chain that no other chain reads is + lowered alone; a chain that others read takes its readers down with it, which is why a + recorded cut is kept off the chains that content reads, and why a row that reads a landing + without being a landing's own record, a pass attestation or a row of model output, is + withheld by a filter of the read and lowers no position (§3.5). `[THEOREM: SNP-8, SNP-10; + INFERENCE for the surface, falsifier SNF-4]` +8. **History is exact from the horizon, and the horizon is an event of the chain (§8).** A + store that drops old generations reads every cut from its horizon on exactly, and a cut under + the horizon is not served. `[THEOREM: SNP-10]` +9. **Retention is counted in positions and drops derived rows before ledgers (§9).** + `[INFERENCE, falsifier SNF-9]` +10. **The build is eight stages, each a pull request with its tests and its rollback; the first + is the landing log (§12).** `[INFERENCE, falsifier SNF-11]` + +### 1.3 Out of scope + +Any change to `core/` (code is licensed at the merge); the storage engines (a study of storage at +scale is under way and none of its figures is in the repository, so this note cites none, measures +what it needs on fixtures of its own, and names for each choice the evidence that would change +it); the spine's reachability index; a second embedder identity held beside the first +(dn-two-phase-ingestion, open question 4); backups and migration archives, which a purge does +not reach today and which this note does not design. + +Not in a snapshot, each for its reason. The job queue, the task list and the telemetry are +operational state and not content. So are the launcher's run ledger (`ops/lifecycle/runs.py:27`, +whose rows are updated at a stop, `:117`), the self-modification proposal ledger +(`ops/ledger.py:294`) and the effect ledger (`ops/effect_ledger.py:294`): they record the +system's own runs and acts, and no sentence reads them. The eval results +(`eval/harness/store.py:164`) are measurements of the system; the spine cuts them as a stratum +of its own (`core/temporal/spine.py:279`, `:346`) and no sentence reads them either. The spools +and state files hold what is in flight: the ingress spools with their receipts +(`core/ingest/ingress.py:1-27`), the dialogue handoff documents and their `.synced` marks +(`core/ingest/table.py:276`, `ops/heartbeat.py:298`), the two sensing handoffs +(`ops/code_sensor.py:862`, `ops/self_sensor.py:345`), a stream source's cursor +(`core/ingest/stream.py:30`) and the heartbeat's tick files (`ops/heartbeat.py:76`). A recorded +cut does not certify that these are empty. Its handoff certificate, as the spine sources it, is +that the `requests/` and `observations/` directories of the one sensing handoff it is given +hold nothing (`core/temporal/spine.py:218`, `:283-286`, `:1090-1103`), and its trough +certificate that no job is queued or running (§3.3). The code and agent sensing handoffs are +other directories, and the ingress spools and the dialogue handoff are not looked at. A cut +does not need them to be empty: what a spool or a handoff holds has not landed, so it is an +event of no chain, no sentence reads it, and when it lands it lands at a position after the +cut. One of them keeps text, the rejected requests, and §6.1 names it for the purge. + +### 1.4 What is proved, what is measured, what is open + +Proved, in `formal/Palace/Snapshot.lean` over `formal/Palace/Snapshot/Defs.lean`: SNP-1 to SNP-10 +as §10 states them, 175 theorems, eighteen of them the controls; attacked in +`formal/PalaceTest/Snapshot.lean` (seeds 430 to 520: forty-nine attacks, every one surviving +all 500 instances, and forty-two negative controls, each refuted). They are design theorems: no +code relies on them, so they have no row in `docs/LAWS.md` and no statement in `formal/Spec/`; +§12 says when they enter the ledger. Some of what §6 and §7 require holds by the construction of +the model and not by a theorem about the code: §10 says which, law by law. + +Measured, on synthetic fixtures only (§11): the landing log's size and the cost of its reads; what +a kept version costs in the lexical index; what a purge leaves behind today; that the causal store +depends on the order of two jobs; that the events of a transcript's prefix are not always the +prefix of its events, and what re-deriving a session costs; what `as of` accepts and when; that a +position taken from a store's row numbering is given again after a delete. + +Open, stated where it bites: the attestation ledger's own content hashes under an erasure +(decision D9); the cadence of recorded cuts (§3.3); a repository history that is not one line +(§3.1); rows written to the curated store outside the catalog (§5.6). + +## 2. What exists + +### 2.1 `as of` today + +`as of ""` is an adjective of the grammar (`core/sentence/grammar.py:253-256`, +`core/sentence/ast.py:205-210`): the index of the reading, never a letter of a chain +(dn-query-sentence-algebra §2.3). `[ESTABLISHED]` + +- **One cut a sentence.** The universe's builder keeps the cut of the `as of` it meets + (`core/sentence/universe.py:125-127`), and the executor refuses a clause whose cut is not the + universe's (`core/sentence/execute.py:713-718`). `[ESTABLISHED]` +- **The names it accepts.** A commit's sha, whole, or a prefix the reference store resolves to + one commit (`universe.py:466-477`, `core/stores/reference_edges.py:381-388`). When the store + holds some reading, a name it has no reading for falls back to the newest reading + (`universe.py:478-484`, taken only when `latest_commit()` is not `None`) and the clause is then + refused; so are `HEAD` and a date. When the store holds no reading at all, as on an instance + with no repository or one just reset, the string asked becomes the universe's cut as it is, the + executor's prefix check passes (`execute.py:714`), and `as of "HEAD"`, a date and any other + string are answered: a walk over `F` over an empty graph with no note, another verb with the + note that it read the present. `[ESTABLISHED; MEASURED §11]` +- **What is read at the cut.** The citation graph (`universe.py:485-486`), and a file of the + repository, as git's blob in the tree at the commit (`execute.py:249-302`, called with the + universe's cut at `universe.py:787-788`), when git resolves the cut. When it does not, a + reading whose commit the checkout lacks, the read tries the cut and then `HEAD` + (`execute.py:266-270`) and returns `HEAD`'s blob. `[ESTABLISHED; MEASURED §11]` +- **What is read as it is now.** Everything else, and the answer carries a note naming the verbs + (`execute.py:503-521`, `:719-725`). The note lists `read` among them, though a `read` of a + repository path is at the cut where git holds it: on a file that changed since the cut the text + returned is the cut's blob and the note says the present. `[MEASURED §11]` The record of such a + read carries the commit it was read at, and the hit built from the record drops it + (`execute.py:296-299`, `:1121-1126`), so the answer does not show which commit the text is + from, the cut's or, after the fallback, `HEAD`'s. A note's `read` opens + the vault file when its reference is a path under the vault, and the raw object of the catalog's + digest otherwise (`execute.py:342-350`): the present, in the first case newer than the catalog. + `[ESTABLISHED]` +- **The cut the spine certifies.** `Spine.cut_at` (`core/temporal/spine.py:1004-1029`) builds a + `CertifiedCut` from the frontier the stores have now: one position per chain, a chain per + document for the versions (`spine.py:222-234`, `:805-816`), with the quiescence certificates of + the event clock's §2.4 as evidence strings. No past cut can be named through it, nothing in it + lets a later reader check that a store still holds the prefix that was cut, and the catalog + enters the spine with no chain at all (`spine.py:549-556`). `[ESTABLISHED]` + +### 2.2 The inventory + +Every store an instance writes that holds content a sentence can read, by what a past state of +it is. The clock is the order that positions its rows; wall-time columns are bookmarks and +position nothing (event clock, Law C4). The operational stores, the eval results, the spools and +the state files are left out, each with its reason (§1.3). + +**Ledgers: a past state is a prefix.** + +| store | clock | what names a position | what a rewrite loses today | +|---|---|---|---| +| raw objects (`core/kernel/stores/rawstore.py:28-40`) | none of its own; an object is ordered by the events that name its digest | the digest | nothing is rewritten; a purge deletes the object (`rawstore.py:51-61`); a transcript that grew is retained whole again under a new digest (`ops/chat_sensor.py:289-333`) | +| version chains (`core/stores/versions.py:77-86`) | `version_seq` per document | `(doc_id, version_seq)` | nothing (one admitted relabel of `doc_id`, `versions.py:132`); kept by one place only, `mirror_authored` (`core/ingest/table.py:241-251`) | +| attestations (`core/attestation/store.py:27-36`) | insertion order and the parents' graph; read back `ORDER BY timestamp, id` (`store.py:130`) | the content-addressed id | nothing; one per (action, digest), and one more for a landing that appended a version (`core/ingest/landing.py:77-86`), so not one a landing outside the place that keeps chains, and no path | +| chat utterances (`core/stores/chatlog.py:77-92`) | `turn_index` per session | `(session_id, turn_index)` | nothing: the first write of a turn stands (`chatlog.py:161`); the store is wiped by a reset and filled again from the raw store (`chatlog.py:41-45`) | +| citation readings (`core/stores/reference_edges.py:134-148`) | the commit of the reading; git orders the commits | `commit_sha`, part of every edge's identity (`reference_edges.py:164-174`) | no row: the store is append-only (`reference_edges.py:289-302`). What is lost is which projection wrote an edge: a deliberate re-projection under a later extractor (`ops/code_sensor.py:827-845`, through `_project`, `:473-490`) adds edges under the old `commit_sha`, the rows carry no extractor version, and one is owed (`code_sensor.py:83-91`). So a commit's reading is the union of every projection of it so far, not a function of its tree | +| commit ledger (`ops/code_snapshot.py:44-58`) | git's ancestry: the ledger keeps no parent, and the sensor reads the commits of one branch in `rev-list` order (`ops/code_sensor.py:404-418`) | `commit_sha` | nothing | +| code and agent observations, current readings (`core/stores/code_observations.py:246`, `core/stores/agent_observations.py:205`) with their history (`core/stores/observation_history.py:46-56`) | the interpreter's generation per identity | (store, identity, interpreter) | nothing: a superseding write archives the old generation first, and it is never dropped (`code_observations.py:211-254`); a reset wipes the current readings and keeps the history (`ops/lifecycle/launcher.py:1765`, `:1776`, `:111-118`). This is generations as built, the form §5.4 takes | +| run ledger, verdicts (`core/stores/runledger.py:140`, `:161`; `core/stores/verdicts.py:145`) | insertion order | the row's id | nothing; a dream claim keeps the digests it rests on and its surface text (`runledger.py:90-97`) | +| structural snapshots (`core/complex/temporal.py:41-58`, `:208`) | a sequence of its own, one row a dream pass (`core/dreaming/dreamer.py:288`) | `snapshot_id` | nothing: invariants of the graph as it stood at the pass, appended | +| claim ops (`core/stores/claim_ops.py:40-48`) | none: `at` is wall time | a hash of (kind, claim, related, text) (`core/kernel/recursion_ops.py:134-135`) | nothing but the bookmark: a row is keyed by its whole content, so the `INSERT OR REPLACE` of a second application (`claim_ops.py:73`) only stamps `at` again. An append-only set with no position. The store calls no model (`claim_ops.py:14-15`), and its rows are by design a model's proposals: extracting the operations from a dialogue is a model task behind an injected analyzer whose default proposes none (`core/kernel/recursion_ops.py:44-46`), and at `e3e3ee47` no caller outside the tests applies an operation. A supersede names the conclusion artifact the same call writes (`claim_ops.py:45`, `:161-163`) | +| verdict dispositions (`core/verdict/dispositions.py:59-64`) | the verdict's sequence number | `verdict_seq` | nothing but the bookmark: append-only, one row a verdict, the latest winning by subject (`dispositions.py:4-6`); a second application of one verdict replaces the row with the same subject and effect and stamps `at` again (`dispositions.py:82-87`) | +| authored supersessions (`core/stores/authored_supersession.py:112-120`) | none: `at` is wall time | the pair (superseded, superseding) | the bookmark and the note of an earlier declaration of the same pair (`authored_supersession.py:159-161`); owner-declared, never model output (`:150-157`). An append-only set with no position | +| staging (`core/stores/staging.py:118-138`) | its own generation clock | the generation | a sweep stamps `tombstoned_at_gen` and the row stays; `read_at(g)` exists (`staging.py:232-244`) | +| query log (`core/sentence/surface.py:93`) | line order | the line | nothing | + +**Version-keyed derived stores: every version's rows are kept and a flag marks the head.** + +| store | clock | what names a position | what a rewrite loses today | +|---|---|---|---| +| plane occupancies (`core/stores/plane.py:268-278`) | none: `landed_at` is wall time | (path, digest, chunk) | which version was the head when: only `current` flips, and flips back when a path returns to bytes it held before (`plane.py:466-487`) | +| the plane's supersession log (`plane.py:282-289`) | `seq` per path | (path, seq) | a purge deletes entries and the next entry takes the position again (`plane.py:491-495`, `:552-553`) `[MEASURED §11]`; a reset drops it (`plane.py:628-640`); an instance with no plane has none; under lazy embedding it is written by the drain, in the drain's order, and only for the versions still current then (`core/ingest/derive.py:85-118`) | +| atoms (the vector table) | none: content-addressed (`plane.py:113-115`) | the atom's id | the `held` and `current` cache columns; the table's own dataset versions, one a write, which a compaction drops (`core/stores/vectorstore.py:780-812`) | +| the curated store: a second vector table with a plane of its own (`core/stores/curated_store.py:30-38`, `core/stores/vectorstore.py:243`) | as the plane and the atoms | as the plane and the atoms | as the plane and the atoms. It has two writers. `ingest_curated` lands through the catalog (`core/ingest/curated.py:66-82`). `scripts/curate_local.py:96-108` writes rows with `store.add` and no catalog row, raw object or attestation, so nothing positions them. `near` seeds from it (`core/sentence/universe.py:378-393`) and `read` opens its rows (`core/sentence/execute.py:318-326`); the purge does not open it (`scripts/purge_raw.py:51-56`) | +| lexical units and postings (`core/stores/lexical.py:56-82`) | none: `landed_at` is wall time | (path, digest, chunk) | the head flag (`lexical.py:251-256`, `:260-265`); every unit, when the tokenizer changes (`lexical.py:180-194`) | +| code memberships (`core/stores/memberships.py:140-155`) | git: (path, blob) | the version's identity | the head flag; a purge leaves a recorded hole (`memberships.py:153`, `:491-497`) | + +**Stores rewritten in place: no past.** + +| store | clock | what names a position | what a rewrite loses today | +|---|---|---|---| +| catalog (`core/stores/catalog.py:36-45`) | none: `updated_at` is wall time | the path | which digest a path held before and whether it was active: an upsert (`catalog.py:113-121`), a tombstone that flips `active` (`catalog.py:167-170`), a purge that deletes the row (`catalog.py:254-258`) | +| chat events (`core/stores/chat_events.py:40-48`) | `ord` per session, on each row | (session, ord) | the session's rows are deleted and written again (`chat_events.py:72-88`); re-derivable from the retained transcript | +| causal edges (`core/stores/causal_edges.py:51-61`) | `event_order` and `witness_turn`, on each row | the edge's id, a hash that includes the transcript's digest (`causal_edges.py:71-76`) | the session's rows are deleted and written again (`causal_edges.py:130-154`), under new ids when the session grew; what they were before the commit ledger gained a commit | +| interpreted artifacts and hyperedges (`core/stores/derived.py:49-60`) | none: `created_at` is wall time | a hash of the kind, the subkind and the sorted subjects, which are note titles (`derived.py:55`, `:97-100`) | the artifact a later pass over the same titles replaced (`derived.py:209-216`), whatever versions of those notes each pass read: model output, not recomputable. What a row was built from is its `derived_from`, note digests or other artifacts' ids (`derived.py:186-189`); it records no run, only the attestation that produced it (`derived.py:59`) | +| relation edges (`core/stores/edges.py:37-46`) | none: `created_at` is wall time | hash of (u, v, relation), the two ends content digests | the weight, sign and provenance a re-assertion replaced (`edges.py:88-106`). Two producers, kept apart by provenance (`core/relations.py:7-16`): authored edges read off a note's own `supports::`, `contradicts::` and `contextualizes::` properties (`relations.py:140-158`), a function of the note's text and so recomputable; and interpreted edges from a model (`relations.py:192-210`) or a `link` request (`core/ingest/writer.py:521-535`), which never replace an authored one (`writer.py:526-530`) | + +### 2.3 What the two-class picture misses + +The picture this note started from has two classes: ledgers that only append, where a past state +is a prefix, and derived stores rewritten in place, which keep no past and are recomputed from the +ledgers. Read against the code it needs eight corrections. `[ESTABLISHED, each at the lines cited +in §2.2 unless given]` + +1. **The catalog is neither, and it is the gap.** It is the head of every landed item and the + idempotence key (ING-7), rewritten in place, and outside one place no ledger holds its past. + The version chains exist for `mirror_authored` only; for the dialogue, observed and curated + places the sequence of digests a path held is recorded nowhere. It has six writing methods: + `record` (`catalog.py:100-123`), `tombstone` (`:160-172`), `relabel_provenance` (`:195-208`), + `migrate_rekey_doc_id` (`:210-241`), `remove` (`:243-246`) and `remove_digest` (`:254-259`). + A seventh write is the migration's, which fills `doc_id` at open (`catalog.py:91`). The + callers are seven modules of `core/ingest/` (`writer.py:419`, `:433`, `:518`; `sync.py:201`, + `:238`; `founding.py:110`; `dialogue.py:75`; `curated.py:80`; `purge.py:61`; + `mint_ids.py:252`) and one script, the only caller of `relabel_provenance` + (`scripts/migrate_provenance_split.py:61`); `remove` has no caller. No statement outside + `catalog.py` writes the table. So a record of its past written inside the catalog misses + nothing, and one written by a caller would. +2. **The attestations do not fill it.** An attestation names a digest and no path. In the + dialogue, observed and curated places a landing attests once per (action, digest), so a path + that returns to bytes it held before, or bytes that land at a second path, leave no new + record. In `mirror_authored` both append a version and are attested again + (`core/ingest/landing.py:77-86`, `core/ingest/writer.py:409-418`), which is the one place + whose past is already kept. The ledger is read back in wall-time order. +3. **Lexical postings and a changed item's vectors are not rewritten.** The units and the + occupancies of a superseded version stay; only a `current` flag moves. They are generations in + all but the stamp. And a stamp on the row would be wrong: a path that returns to bytes it held + before makes the same rows current again (`plane.py:466-487`), so a version's rows are valid on + a set of intervals, not on one. What they lack is the position at which each version became the + head and stopped being it, which is the catalog's past again. +4. **The causal store is not a function of its inputs' present state.** The integrator skips a + session whose transcript digest is unchanged (`core/integrator.py:106-111`) and resolves a + commit against the ledger as it is at that pass (`integrator.py:148-164`), so two instances with + the same transcripts and the same ledger hold different edges when the two jobs ran in + different orders. `[MEASURED §11]` The extractor reads every tool result of the transcript + before it walks it (`core/chat_events.py:110-123`, `:153`), so the events of a prefix that ends + between a commit and its result are not the prefix of the events. `[MEASURED §11]` And an + edge's id is a hash over the transcript's digest (`integrator.py:134-137`), so every edge of a + session takes a new id when the session grows, and an id noted from an earlier answer names + nothing. +5. **`read` under `as of` is already at the cut for a repository path** (§2.1). +6. **An erasure does not reach every store.** `purge_raw` removes the vector rows, the raw object + and the catalog rows (`core/ingest/purge.py:58-62`). On a synthetic palace, after the purge of + both versions of a note: the lexical units and postings of the purged versions remain, with + their words; the version rows and the attestations still name the digests; and the purged text + is still returned by the vector table read at its earlier dataset versions, until a compaction + with no retention, which the purge does not call. `[MEASURED §11]` The relation edges whose + endpoint is the digest and the interpreted artifacts whose `derived_from` names it are not + touched either, nor are the curated store, the dream claims, the staging rows and the claim + ops (§6.1 lists each), and no deletion attestation is written, though the attestation store's + header says one is (`core/attestation/store.py:3-6`; no call in `purge.py` or + `scripts/purge_raw.py`). A snapshot that read those stores at a cut would return what the + purge left, so §6.1 states what an erasure must reach before any of them is read at a cut. +7. **A reset takes the ledgers with the derived stores.** Its targets are the raw store, the + vector store, the catalog, the attestations, the version chains, the chat log and the stores + derived from them (`ops/lifecycle/launcher.py:1748-1800`); the commit ledger and the + observation history are guarded (`launcher.py:111-118`). The raw store is the first target + listed (`launcher.py:1753`), while the comment beside the chat log's entry says it is not one + (`launcher.py:1779-1780`). The lexical index and the relation edges are not among the targets, + so they outlast a reset with rows about items that are gone. Whatever the intent, no chain of + an instance survives a reset with its positions, so a reset opens a new history (§8). +8. **A path written again after a delete continues the deleted note's history.** A re-record of + an existing path keeps the stored identity, and a tombstoned row stays in the catalog + (`catalog.py:103-121`, `:160-172`), so the version chain of the identity appends + (`core/stores/versions.py:109-119`): a new note written at a deleted note's path has the + deleted note's versions under it. §6.2 seals them. + +## 3. The cut + +### 3.1 Chains and positions + +A chain is an append order a store already records, or one this note adds; a position is a +prefix length of it. `[DERIVED from global-event-clock §2.2, generator g1]` + +| chain | store | position | today | +|---|---|---|---| +| `land`, one or more a provenance class | the landing log (§3.2), in the catalog's file | `seq`, from 1, never given twice | not built | +| `chat` | the chat log | a sequence number beside each row; within a session it is the turn order | the order is recorded, the number is not | +| `att` | the attestation ledger | a sequence number beside each row | the order is recorded, the number is not; the ledger is read in wall-time order | +| `repo` | git, mirrored by the commit ledger and the per-commit readings | a commit, standing for its ancestors | recorded | +| `interp`, one a store | interpreted artifacts with their hyperedges, interpreted relation edges, claim ops: rows of the class `interpreted` only | a sequence number a write (§5.4) | not built | +| `decl` | authored supersessions | a sequence number a declaration | not built | +| `staging` | the staging store | its generation | recorded | +| `runs` | the run ledger, with the structural snapshot of a pass | a sequence number | recorded as insertion order | +| `use` | the utility field's use log (dn-utility-field §3.1) | the tick | not built | +| `cuts` | the recorded cuts (§3.3) | `seq` | not built; it reads every chain it certifies, and no other chain reads it | + +Four choices are made here. + +**The position is the store's, not the document's.** The spine's frontier has a pair per version +chain and a pair per chat session (`spine.py:414-427`, `:428-445`). The version chains exist for +one place, so on a corpus instance, whose items land in `observed` +(`ingress/sync_corpus.palace:5`, `core/ingest/table.py:241-251`), today's frontier has no pair +for them at all. Giving every place a per-document chain, which is decision D1's first +alternative, is what would make a frontier of one pair an item, ten million at the scale the +repository's records plan for (`docs/experiments/corpus-measurements-2026-11-07.md:94-96`). One +position a store with the per-path order inside it says the same thing (CLK-2: a frontier cut +needs only its cross-store edges checked). `[DERIVED]` The version chains stay as they are: the +log carries each landing's document and version number, so a document's chain is the log's +sub-chain, and the versions store remains the primary record of supersession. + +**Where clearances separate rows the chain is per class.** A position counts every event before +it, so on a chain that mixes classes a reader of one class learns from its positions how many +landings the others made (`Witness.position_channel`), and a snapshot under a grant reads only the +chains the grant names and the cut on them (`snapshot_congr`). `[THEOREM: SNP-6]` So the `interp` +chains hold rows of the class `interpreted` only: the relations a note declares are of the +note's class and are recomputed from the note at the cut (§5.4), not numbered with the model's. + +**A chain is keyed by an id, and its class is a label.** A certificate and a recorded cut name +chains, and a certificate of a cut does not verify on a store whose chains were renamed +(`Witness.rename_breaks_certificate`). The catalog's whole-class relabel +(`catalog.py:195-208`) changes the class of every row at once, and its one use merges a class +into another that already has rows (`scripts/migrate_provenance_split.py:58-61`). So a landing +chain has an integer id that is never reused or changed, and a row of a `landing_chains` table +gives the class it holds now. A relabel rewrites that label and no row of the log; after a merge +a class has two chains, and the read of a class is the union of its chains' reads. `[THEOREM +for the control; INFERENCE for the id]` + +**A position is a number the store keeps, never the row numbering it happens to have.** The chat +log and the attestation ledger are keyed by text, and SQLite numbers their rows as the largest +number in use plus one, so a number is given again after the last row is deleted. `[MEASURED +§11]` Stage SN-2 adds a chain table beside each (an integer key, the row's own key, the running +hash of §3.6), written in the transaction of the append. + +On `repo` the order is git's ancestry, which is a chain only when the history read is one line. A +commit names the down-set of its ancestors, and CLK-2's laws are stated for down-sets of any +order (`Clock.IsCut.inter`, `Clock.IsCut.union`), so the meet of two cuts at two commits is the +down-set of their common ancestors and the join the down-set of both; a join of two commits +neither of which is the other's ancestor is not named by one sha. On an instance that reads one +branch whose history is a line, which is what this repository's merges by rebase produce, every +cut on `repo` is a commit and the model's chain applies as it stands. `[DERIVED from CLK-2; +INFERENCE for the line, parked as SN-f]` + +### 3.2 The landing log + +Two tables in the catalog's file, written by the catalog's own methods in the transaction that +writes the catalog's row, so the key and its log entry land together, no caller can write one +without the other, and ING-7's order is unchanged (the key last, now two rows of one +transaction): + +```sql +CREATE TABLE landing_chains ( + chain INTEGER PRIMARY KEY, -- the chain's id: never reused, never changed + class TEXT NOT NULL, -- the provenance class it holds now; a relabel rewrites this only + secret BLOB NOT NULL -- 32 random bytes: the key of path_key +); +CREATE TABLE landings ( + chain INTEGER NOT NULL, -- landing_chains.chain + seq INTEGER NOT NULL, -- the position in the chain, from 1, never given twice + kind TEXT NOT NULL, -- genesis | store | retire | move | unseal | horizon + path_key BLOB, -- hmac-sha256(secret, source_path): the key a hole keeps + source_path TEXT, -- NULL once purged + doc_id TEXT, -- the identity the event belongs to; NULL once purged + version INTEGER, -- the version number, where the place keeps a chain + digest TEXT, -- NULL for a retire, and once purged + title TEXT, -- NULL once purged + att_head INTEGER, -- the head of att when the row was written; NULL before SN-2 + ref_lo INTEGER, -- a horizon: the horizon; an unseal: the first retire it lifts + ref_hi INTEGER, -- an unseal: the last retire it lifts + salt BLOB, -- 16 random bytes; NULL once purged + commitment BLOB NOT NULL, -- sha256(salt, the row's fields): what the chain digests + hash BLOB NOT NULL, -- sha256(the previous row's hash, commitment) + closed_at INTEGER, -- the seq of the path's next event; NULL while it is the head + at TEXT, -- wall bookmark: lookup only, never an order; NULL once purged + PRIMARY KEY (chain, seq) +) WITHOUT ROWID; +CREATE INDEX landings_path ON landings (chain, path_key, seq) WHERE path_key IS NOT NULL; +CREATE INDEX landings_doc ON landings (chain, doc_id, seq) + WHERE doc_id IS NOT NULL AND doc_id <> source_path; +CREATE INDEX landings_closed ON landings (chain, closed_at) WHERE closed_at IS NOT NULL; +``` + +**The kinds** are the catalog's writes. `store` is a landing (`record`). `retire` is the +tombstone of an identity no other active path holds. `move` is a tombstone that leaves the +identity at another path (the second half of a rename, which the writer tells from a delete by +the catalog, `writer.py:409-413`), the owner-gated re-key of an identity (`catalog.py:210-241`), +and the row that closes a path in one chain when a `record` gives it another class, its `store` +then landing in a chain of the new class. `genesis`, `unseal` and `horizon` are below, §6.2 and +§8. A purge is not a kind: it empties rows (§6.1). A `record` that changes nothing, the same +path, digest, title, class and identity as the path's open row, appends nothing: the log is of +the changes of the map, and the catalog's `updated_at` is a bookmark (the curated lane re-lands +an unchanged digest after a plane reset, `core/ingest/curated.py:66-82`). + +**Which chain a landing goes to.** The chain that holds the path's last event; for a path with +no event, the newest chain of its class, opened if the class has none. So a relabel moves no row +and no position (§3.1), and after a merge both chains go on growing, each with the paths it +holds. + +**The commitment and the hash.** `commitment` is SHA-256 over the salt followed by the canonical +JSON (keys sorted, no white space, UTF-8) of the object with the fields `chain`, `seq`, `kind`, +`source_path`, `doc_id`, `version`, `digest`, `title`, `att_head`, `ref_lo`, `ref_hi` and `at`. +`closed_at` is out, since it is written later, and so is `path_key`, which is an index key. +`hash` is SHA-256 over the previous row's `hash` followed by the commitment; the first row's +previous hash is 32 zero bytes. No row is ever deleted, by a purge or by a history window: both +empty rows and keep their commitments and hashes (§6.1, §9.2), so the chain is hashed from its +first row for as long as it lives. The chain is hashed like the prediction ledger +(`eval/predictions/ledger.py:1-12`), with one difference that §6.1 needs: a row's hash covers a +commitment to the row and not the row, so a purge can empty the row and keep the chain +(`commitments_purge`, `verifies_purge`). `[THEOREM: SNP-9]` + +**The key of a hole.** `path_key` is a keyed hash of the path under the chain's secret. It is +what a read by path seeks on, and it is the one name a purged row keeps, so a hole still shadows +the path's earlier versions (§6.1). `version` and `att_head` are the two fields a caller +supplies: `record` gains a `version` argument, passed by the writer's last step from the version +it just appended or found (`writer.py:408-419`, `:433`; `sync.py:201`) and left out where the +place keeps no chain; `att_head` is the attestation ledger's head read inside the key's +transaction, after the landing's own attestation, and stays `NULL` until SN-2 numbers that +ledger, which reads as the end of the ledger's genesis (§8). + +**The genesis.** At the first open after the migration that fills `doc_id` +(`catalog.py:77-92`), each class the catalog holds gets a chain: a `genesis` row, then the +catalog's rows of the class in path order, an active path as one `store` and a tombstoned path +as a `store` of the digest it held followed by a `retire`, then a `horizon` row whose `ref_lo` +is its own position. The order inside the block is not history, so the positions before the +`horizon` are under it (§8). A class that first appears later opens its chain at its first +landing, with a `genesis` and a `horizon` and nothing between. + +The catalog is then the fold of the log: each path's last event (`stateOf`), an active row for a +`store`, a tombstoned row for a `retire` with the digest of the path's last `store`, and no row +when that `store` is a hole or the path's last event is a `move`. The state at a position is the +same fold of the prefix (`stateAt`), read by one seek as the path's last event at or under the +position (`stateAt_eq_lastWrite`), or for every path at once through the closing stamp: the rows +with `seq ≤ c` and `closed_at` absent or above `c` (`genRead_gens`). The stamp is the one field +written after a row is appended, and it is a function of the rows, the position of the path's +next event (`gens_append_singleton`), so it can be rebuilt and it changes no read at a cut inside +the chain (`genRead_gens_append`). At most one row of a path is alive at a cut +(`length_filter_selects_le_one`), which is L7's falsifier turned into a theorem. `[THEOREM: +SNP-5]` The store's own precedent is the staging store: a generation clock, an admission stamp +and a tombstone stamp on each row, and `read_at(g)` as exactly this predicate +(`core/stores/staging.py:232-244`). `[ESTABLISHED]` + +### 3.3 The cut and its record + +A cut is a position for every chain of §3.1: for an instance, about a dozen integers. +`[DERIVED]` The read at a cut is the prefix of every chain (`readAt`), and everything else in this +note is a function of that. A cut is worth recording when it is consistent (§3.5) and certified +in the event clock's sense. GC-N3 names three certificates +(`docs/design-notes/global-event-clock.md:175-186`): the commit, which certifies the strata the +repository backs; trough quiescence, an empty queue with no queued and no running job +(`core/temporal/spine.py:197-206`), which certifies that no causality of the core is in flight; +and the empty handoff, which certifies that nothing is in flight between the edge and the core. +A cut across strata composes the three, and the spine refuses a cut whose certificate it cannot +source (`spine.py:275-281`, `:1064-1084`). As the spine sources it, the handoff certificate is +the emptiness of the two directories of the one sensing handoff it is given (`spine.py:218`, +`:283-286`, `:1090-1103`); §1.3 says what that leaves unlooked at, and why a cut does not need +it. `[ESTABLISHED]` + +So a cut is recorded at a trough and at no other moment. Two things ask for one: the trough +itself, when the queue and the handoff are empty and the frontier moved since the last record; +and the owner's command, which is served at the next trough. With no daemon running that is at +once only when no job is queued. A landing through the writer enqueues jobs +(`core/ingest/writer.py:203`, `:555`), and the trough certificate needs none queued as well as +none running (`spine.py:197-206`), so with jobs queued and nothing running to take them the +spine refuses the cut: the command says so and records nothing until the queue is drained. The +sensor reading a commit does not record a cut: it reads inside its job +(`ops/code_sensor.py:404-418`), where the trough certificate is refused. A record names the +newest commit of the ledger as its `repo` position, so it covers every commit sensed since the +record before it, and §3.4 says what a commit's name resolves to. + +A recorded cut is a row of a chain of its own: + +```sql +CREATE TABLE cuts ( + seq INTEGER PRIMARY KEY, -- the position in the records' chain, from 1 + id BLOB NOT NULL UNIQUE, -- sha256 of the canonical bytes: the cut's name + prev BLOB, -- the previous record's id; NULL for the first + reason TEXT NOT NULL, -- trough | command + commit_sha TEXT, -- the newest commit of the ledger; NULL with no repository + frontier TEXT NOT NULL, -- JSON: [[chain, position, digest or null, horizon], ...] + certs TEXT NOT NULL, -- JSON: the commit, trough and handoff evidence strings + attestation BLOB, -- the attestation of action cut; NULL with no attestor + at TEXT NOT NULL -- wall bookmark: the key a date is looked up by +); +CREATE INDEX cuts_at ON cuts (at); +CREATE INDEX cuts_commit ON cuts (commit_sha) WHERE commit_sha IS NOT NULL; +``` + +The id is the hash of the record's canonical bytes: the JSON, keys sorted and no white space, of +the previous id, the reason, the commit, the frontier in chain order (each chain's name or id, +its position, the digest of its prefix where the chain is hashed (§3.6) and its horizon (§8)) +and the certificates as the spine sources them. The bookmark is not in the id. An attestation +has no field for a payload: it names an action, input and output hashes and its parents +(`core/attestation/record.py:51-62`). So the record's attestation, of action `cut`, names the id +as its output and the previous record's attestation as its parent, and it is built and signed +as any other is (`core/attestation/attestor.py:59-90`) but kept in the record's row and not +appended to the ledger that landings read. `[INFERENCE, falsifier SNF-3]` + +That last point is forced. A record reads from the prefix of every chain it certifies, and every +landing reads from the attestation ledger. If records sat on that ledger, a chain that could +serve only a position below one a record certified would exclude the record, the ledger's +prefix would stop before it, and every landing attested later would go with it: one chain read +low can take a landing chain to its empty prefix (`Witness.record_drags`). On a chain of +their own, which no event of another chain reads, a record takes no chain down. Its own chain +does go down with a chain it certifies: the chain of records is read at its last record every +position of which the cut read holds, and nothing follows it (`resolvesIn_of_followed`, +`Witness.record_follows`; §7.1). `[THEOREM: SNP-10]` + +Since each record is the head of every chain at some moment and chains only grow, the recorded +cuts are totally ordered. A record is about 2.7 kilobytes by arithmetic from its fields, not +measured: twelve chains at about 110 bytes each in the frontier, the certificates, and an +attestation at the 1,060 bytes a row of the attestation ledger takes in the repository's +records (`docs/experiments/corpus-measurements-2026-11-07.md:107`). A record at every trough +that moved is at most one a job. At the job rate those records show, 720 an hour +(`corpus-measurements-2026-11-07.md:94-95`), a record a job would be 47 megabytes a day; but +those were sync jobs of 0.07 s each, and a job that moves no chain asks for no record. +An instance with thirty troughs a day that moved writes 81 kilobytes a day. The cadence is +parked (SN-a). + +### 3.4 Names + +`as of` takes a string, and the string resolves to a frontier. The shapes do not overlap: + +| name | resolves to | exact | +|---|---|---| +| `head` | the head cut; the answer is the answer without `as of` (`view_head`) | yes | +| `cut:` and a recorded cut's id, or a prefix that names one | that record's frontier | yes, and checkable against its certificate on the chains it digests | +| a commit's sha or an unambiguous prefix, as today | the frontier of the first record that holds the commit, with `repo` lowered to the commit, resolved as §3.5 says. For a commit sensed before the first record: the commit on `repo` and the empty prefix elsewhere | on `repo` for the tree; elsewhere a consistent cut between two records, which the answer names. It carries the commit certificate and not the trough's | +| a date or a date and time | the last recorded cut whose bookmark is at or before it. A date after the newest record is the newest record, never the head | to the cadence of the records; the answer names the record, and says when the head has moved since | + +A commit's name needs the resolution because the sensor's attestation of a commit reads from the +commit (`code_sensor.py:413-418`): with `repo` lowered, the attestation of the next commit is +outside the cut, so `att` stops before it, and the landing chains stop at the last landing +attested before it. A chain that reads nothing, as `chat`, stands at the record. The cut read is +then no later than the record on any chain and holds nothing that read a later commit. +`[DERIVED]` + +Wall time enters in the last row only, as a lookup key into bookmarks, and the cut it selects is +ordered by the chains (Law C4; the staging store's sweep resolves wall time to a generation the +same way, `staging.py:26-30`). A branch or a tag is not a name: it moves. A name that resolves +to nothing is refused whether or not the stores hold a reading, which is not so today (§2.1). +The grammar does not change; the names it accepts do, and the answer always carries the cut +read. `[INFERENCE, falsifier SNF-3]` + +### 3.5 Consistency and resolution + +An event of one chain may read from an event of another: `R k i k' j` says the `i`-th event of +chain `k` reads from the `j`-th of chain `k'` (the event clock's generators g2 and g3). The +references between the chains of §3.1 are these. `[ESTABLISHED: read off the writers]` + +- a landing reads from its attestation and, where the place keeps chains, its version row, by + the order the writer lands them in (`core/ingest/writer.py:397-436`: the version, the + attestation, the key last); +- the attestation of a sensed commit, and of a projection of it, reads from the commit + (`ops/code_sensor.py:413-418`, `:498-499`); +- a citation edge reads from its commit and from the projection that wrote it; +- a recorded cut reads from the prefix of every chain it certifies and from the record before + it, and no row of another chain reads a recorded cut; +- the attestation of a pass reads from the landings of the notes the pass read. The dreamer's + and the curator's attestations sit on the ledger the landings' attestations sit on, name the + notes' digests as their inputs (`core/dreaming/dreamer.py:144-148`, `:223-227`; + `core/curator/curator.py:167-171`; `core/attestation/record.py:57`) and take as parents the + attestations that produced those digests (`core/attestation/attestor.py:64-69`); +- a dream claim of the run ledger reads from the landings of the digests it rests on + (`core/stores/runledger.py:90-97`); +- an interpreted artifact reads from the digests its `derived_from` names, through the artifacts + it names there, and from the attestation its `attestation_id` names + (`core/stores/derived.py:186-191`); an interpreted relation edge reads from the landings of its + two endpoint digests; +- a claim op reads from the note or the artifact its `claim_id` names, and a supersede from the + conclusion artifact the same call wrote, its `related_id` (`core/stores/claim_ops.py:45`, + `:161-163`); a verdict's disposition reads from the claim or artifact it is about + (`core/verdict/dispositions.py:59-64`). + +The first four are **resolved**: the resolver follows them, and the cut read is consistent for +them. Three of them join chains of §3.1. A citation edge is a row of no chain: it is read by its +stamps, which are positions on `repo` and `att` (§5.1), so a cut that holds its stamps holds its +sources. The last four are **filtered**: the resolver does not follow them, and a row that has one +is served at a cut only when its sources are. Both are taken up below, after the definition. + +A causal edge reads from the turn that witnessed it and, when it ends at a commit, from the +commit (`causal_edges.py:58-60`, `integrator.py:134-137`); it is recomputed at a cut (§5.5), so +it is a filter of a read and no row of a chain. + +A cut is **consistent** when every source of an event inside it is inside it (`Consistent`): no +fact whose sources lie after the cut, every cross-chain reference closed. `[THEOREM: SNP-8]` + +- Consistent cuts are the event clock's cuts among the frontier cuts: a cut is consistent + exactly when the events under its frontier are a down-set of the order the chains and the + references generate (`consistent_iff_isCut`, on CLK-2's `IsCut` and `frontierCut`). +- So they are closed under the pointwise meet and join, with the empty cut at the bottom: this + is CLK-2, which the ledger already states for frontiers (`docs/LAWS.md:114`, + `Clock.IsCut.frontier_inf`, `Clock.IsCut.frontier_sup`), read through that equivalence + (`Consistent.inf`, `Consistent.sup`, `consistent_zero`, `consistentCuts`). It is not a new law. + `[THEOREM: CLK-2]` +- What SNP-8 adds is resolution. Every frontier has exactly one greatest consistent cut under + it, and a later frontier has a later one (`exists_resolves`, `Resolves.unique`, + `Resolves.mono`); a consistent frontier is its own (`resolves_self`). This is what a name's + resolution is. +- Consistency is append invariant: the references a store gains by growing start at events at or + past its old head, so a cut inside the old head that was consistent stays consistent + (`Consistent.of_grown`). + +So ING-7's invariant, that a key implies its rows, holds at every consistent cut and not only at +the head: a cut that holds a landing holds its attestation and its version. `[DERIVED]` + +**Where the resolved references are recorded.** The resolver has to know, for an event, where +its sources lie. A landing records the head of `att` at its writing (`att_head`); an attestation +of a commit names the commit; a recorded cut carries its whole frontier. With one writer a row's +sources were all written before it, so the head at its writing bounds them, the bound rises +along the chain, and it is sound: a cut consistent for the recorded bounds is consistent for the +true references they bound (`Consistent.of_bound`). It can only make fewer cuts consistent. The +theorem's hypothesis is a recorded bound at or above every true reference, so it speaks of the +resolved references and of no other. `[THEOREM: SNP-8; DERIVED from the one-writer rule, +dn-ingress D3, for the bound]` + +**Rows that are filtered, not resolved.** The other references must not be given to the +resolver. A pass attestation sits on `att`, which every landing reads, and it reads landings. +Resolved, that reference would put `att` below the first pass that read a landing outside the +cut, and every landing chain attested after that pass would fall with it: a landing chain read +low behind a history window would take the other landing chains to the positions they had when +that pass ran, which is the cascade of a record kept on the ledger, through a pass +(`Witness.pass_drags`). So the closure of these references is kept row by row. A row is +**withheld** at a cut when it fails a test of its own, when a source of it lies outside the cut, +or when a source of it is withheld (`Withheld`); the read at a cut is the rows inside the cut +that are not withheld (`Kept`). `[THEOREM: SNP-8 for the control; INFERENCE for the choice, +falsifier SNF-16]` What a row's sources and its own test are, store by store: + +- **A pass attestation:** an attestation whose inputs name the digests of notes it did not itself + land, which today are the dreamer's and the curator's. Its chain-table row records, at its + writing, the landing chains that held its inputs and the head of each. It is withheld when the cut + read lies under one of those heads. The head stands for the landings the pass read, which lie at + or under it, so the bound can only withhold more; it is a position and names no digest, so a purge + or a history window, which empty rows and move no position, change nothing in what is withheld. + The ledger is read by sequence number with those rows left out. +- **A row of the run ledger.** A run's chain-table row records the same pairs, and a dream + claim is served when its run is. +- **An interpreted artifact and an interpreted relation edge.** §5.4: the attestation the row + names is kept at the cut, and every digest its sources reach is a head at the cut and is not + erased or sealed. +- **A claim op and a disposition.** The note or the artifact it names is served at the cut, + and for a supersede the conclusion artifact as well. + +What is proved of the filtered read, for any reads-from relation and any test. `[THEOREM: +SNP-8, with SNP-1 and SNP-2 for the last item]` + +- It is closed: every source of a kept row is kept, so it lies inside the cut (`Kept.source`, + `Kept.passes`). The read holds no fact whose sources lie after the cut, for every reference + of the list above, whatever cut the resolver returned. +- It withholds no more than it must: every set of rows inside the cut that pass their test and + that holds its own sources is kept (`kept_of_closed`). +- It never withholds a row all of whose references are resolved. The landings, the attestations + of landings and of commits, and the commits read only one another, by resolved references, so + at a cut consistent for those references every one of them inside the cut is kept + (`kept_of_resolved`). The filter takes rows out of `att`, `runs` and the `interp` chains and + takes no landing. +- At a cut consistent for every reference, where every row passes its test, it withholds + nothing and the read is the prefix (`kept_iff_of_consistent`). For the attestations and the + runs, whose test is empty, that is the case at the head, since a store holds the sources of + its own rows, and at a recorded cut every position of which is served. +- For a test that does not depend on the cut it is monotone, a row kept at a cut being kept at + every later one, and it is append invariant (`Kept.mono`, `kept_grown_iff`). + +So the cut read is consistent for the resolved references, and the read at it is filtered for +the rest. That read is a derived view of the prefixes (SNP-5), and on `att`, `runs` and the +`interp` chains it is not the prefix. The control is the store of `Witness.pass_drags` with the +pass's reference filtered: the landing chain behind its window is lowered alone, the prefix at +that cut holds a pass whose landing is outside it, and the filtered read withholds the pass and +keeps the attestation after it and the other class's landing (`Witness.pass_withheld`). + +**The resolver.** A name that selects a recorded cut needs none while every chain serves the +record's positions: the record is consistent. Otherwise it is two steps alternated until +nothing moves: + +1. the floor: each chain's position is lowered to the greatest position at or under it that the + chain serves (§7.1); +2. one pass of the descent: each chain's position is lowered to the first event inside the cut + whose recorded bound lies outside it. + +A round that moves anything lowers a position, so there are at most as many rounds as the +frontier has positions. Neither step alone is enough, in either order: the descent leaves the +served positions, and the floor breaks consistency again. The library proves that the cut +exists and is unique, with and without served positions. The attack module runs the descent +against the definition by enumerating every cut under the frontier (seed 461) and the +alternation against the greatest consistent served cut (seed 492), with each one-shot order as +a control that is refuted (493, 494). SN-2 transcribes the alternation. `[THEOREM for existence +and uniqueness; the resolver attacked, not proved]` + +### 3.6 Certificates + +The certificate of a cut is, for each chain, the digest of its prefix under the chain's hash +(`certify`). A store verifies a certificate when its own prefixes have those digests +(`Verifies`). `[THEOREM: SNP-9]` + +**Which chains have a hash.** A landing chain from SN-1, as the `hash` of the row at the +position. `repo` always: the commit's sha is git's own chain. `chat`, `att`, `staging` and +`runs` from SN-2, as the running hash of the chain table added beside each. The `interp` chains, +the claim ops among them, and `decl` from SN-6, which gives each a sequence number and a +running hash over its rows' content, the wall bookmark left out; and `use` with the stage that +builds the field. A record carries a digest +for each chain that has a hash when it is taken and a null for the others, and `verify` says +which chains it checked. Until a chain is hashed, a recorded cut fixes its position and nothing +about its rows, and the two conclusions below do not reach a view that reads it. `[INFERENCE]` + +- **Reproducible.** The certificate of a cut verifies on every extension of the store + (`verifies_certify_of_extends`): the same store later, a restored backup, a clone. +- **Checkable, for what it digests.** Under a collision-free digest, two stores that verify one + certificate have the same prefix of each digested chain at its cut (`Verifies.readAt_eq`), so + every derived view of those prefixes is the same on both (`Verifies.view_eq`). A landing chain + digests commitments, so what is pinned directly is the commitments. A commitment that is + binding, as a salted SHA-256 is under the same hypothesis, pins the events behind them: two + committed stores that verify one certificate were made from the same events at its cut + (`Verifies.readAt_eq_of_committed`), and under one erasure they read the same store with holes + (`Verifies.contents_eq`). The control is a digest with collisions, under which two different + chains of one length agree (`Witness.digest_collides`). +- **What it does not attest.** An erasure: a store verifies a certificate after a purge exactly + when it did before (`verifies_purge_iff`), so a backup taken before a purge and restored later + verifies every certificate and still holds what was purged. A restore therefore has to apply + again the purges recorded since, which §6.1's attestation of a purge makes listable. A seal: a + retire written after a certified cut changes what is served at it, and the certificate still + verifies (`Witness.seal_not_certified`). The grant, and the identity of the embedder and the + tokenizer (D5). So an answer at a recorded cut is the same on two stores that verify it for + one erasure, one set of seals, one grant and one derivation identity, and not otherwise; for + the grant and the erasure together that is `Verifies.shown_eq`. +- **Cheap.** A certificate extends over the events since an earlier one + (`certify_digest_readBetween`), and the meet and the join of two certified cuts are certified + from the two certificates alone, chain by chain the earlier or the later digest (`certify_inf`, + `certify_sup`). +- **Compatible with erasure.** A chain that digests commitments keeps every certificate when an + event's content is erased (`verifies_purge`), and what a reader then reads is the store with + holes (`contents_purge_committed`). + +Checking a certificate against a store is one seek a chain, the stored hash at the position +against the certified digest, 3 microseconds; recomputing a chain from its first row is the +audit, 0.7 to 0.8 s for a million rows. `[MEASURED §11]` + +## 4. Reads + +### 4.1 `read_at` and `read_between`, ledger by ledger + +`read_at(c)` is the prefix of a chain at a position and `read_between(a, b)` the events after `a` +and up to `b` (`readAt`, `readBetween`). The second composes with the first and with itself +(`readAt_append_readBetween`, `readBetween_append`), so nothing more is needed of a ledger than +these two. `[THEOREM: SNP-3]` For a ledger of keyed rows the read a caller wants is the state of +a key at a cut, which is a function of the prefix (`stateAt`); the table names it `state_at`. +For each ledger, the reads, the index each needs and the cost. A cost with no grade is an +estimate from the measured log, the same engine and the same shape of index, and is not +measured: + +| ledger | `read_at(c)` | `read_between(a, b)` | index | cost | +|---|---|---|---|---| +| landing log, a chain | the rows with `seq ≤ c`; `state_at` of one path: its last event at or under `c`, by its key; every head of a class: the `store` rows with `seq ≤ c` not closed at or under `c`, over the class's chains | the rows with `a < seq ≤ b` | the primary key, `landings_path`, `landings_closed` | one path 3 µs through `landings_path`, and 1.4 µs for its keyed hash; 1,000 positions 0.64 to 0.69 ms; every head §4.2 `[MEASURED §11]` | +| a document's version chain | the log's rows of the identity at or under `c`, after its last retire (§6.2) | the same rows in the range | `landings_path` where the identity is the path, `landings_doc` where it is not | 9 µs for seven versions through the index, and 49 to 57 ms when the planner takes the primary key, so the statement names the index `[MEASURED §11]` | +| raw objects | the object of the digest the log names at `c` | the objects the delta names | none: content-addressed | one file read, the object's bytes | +| chat log | a session's turns whose chain number is at or under `c` | the turns numbered in the range | the chain table's key and its `(session, turn)` | a range of an integer key: of the order of the log's 0.7 ms a thousand rows | +| attestations | by id, as today; in order, the chain table at or under `c` | a range of the chain table | the chain table | the same order, where `all()` sorts the ledger by wall time and `producers_of` decodes every record today (`core/attestation/store.py:127-132`, `:159-165`) | +| citation readings | the edges of the commit projected at or under `c` on `att` (§5.1) | the paths whose blob differs between the two commits, by the commit ledger's `files` rows (`ops/code_snapshot.py:59-69`), with their readings at each | exists: `(target_ref, commit_sha)` and `(source_ref, commit_sha)` (`reference_edges.py:149-156`); the projection's position is one integer column more | one indexed lookup a reference, as today | +| commit ledger | the commit and, through git, its ancestors | git's range | none: the ledger keeps no parent, so the range is git's | one `rev-list`, not measured | +| staging | `read_at(g)`, as built | the rows admitted or tombstoned in the range | `staged_rows_generation` exists; none on the tombstone stamp | a range of the generation index; a scan for the tombstones | +| run ledger, verdicts, structural snapshots, observation history | by key; in insertion order | a range | a sequence number, from SN-2 for the run ledger | no reader at a cut yet | + +The landing log's reads are the ones every other store's read at a cut goes through, since it +is the log that says which version of a path a cut holds (§5). + +### 4.2 Every head at a cut + +Reading the head of every path of a class at a cut is the `store` rows with `seq ≤ c` whose +`closed_at` is absent or above `c`. On a synthetic chain of a million events over 100,000 paths +it took 52 to 56 ms at a cut a tenth of the way in, 147 to 166 ms at the middle cut and 240 to +275 ms at and near the head. `[MEASURED §11]` The cost is the part of the log the statement +walks, about a quarter of a microsecond an event, and not the size of the answer. Two readers +need it: the universe, for the strata it loads whole (`core/sentence/universe.py:275-299`), and +the lexical statistics at a cut (§5.3). + +So the read from the log alone passes a tenth of a second at between a quarter and a third of a +million events in one chain, and the rule is by size. A chain under 250,000 events reads its +heads from the log. A chain over it keeps heads: the heads at some recorded cuts, continued +over the events since (`stateAt_eq_foldl`), which costs the distance to the nearest kept cut +instead of the prefix. That is built with SN-4 for an instance that has such a chain, and a +corpus instance has one from the start: ten million items are ten million events at the least. +An instance of a few thousand notes never needs it. `[THEOREM for the journal; INFERENCE for the +threshold, falsifier SNF-6]` + +### 4.3 What the reads cost in bytes + +On the fixture a landing is 434 bytes in the log with its indexes when the identity is the path +(the table 374, the key index 47, the closing index 13), and 396 when the identity is a short +id of its own (the table 315, the key index 47, the identity index 21, the closing index 13). +`[MEASURED §11]` The fixture's paths are 37 characters and its titles under twelve; a row grows +by the bytes of a longer path, twice where the identity is the path. A chain table's row is an +integer, the row's key and a 32-byte hash. A recorded cut is about 2.7 kilobytes by arithmetic +(§3.3). None of it is content: the log holds paths, digests and titles, which the catalog holds +already. + +## 5. Derived data as a function of a cut + +### 5.1 The rule and the four forms + +A derived view at a cut is a derivation applied to the prefixes (`view`), and a reader of a store +at a cut is append invariant exactly when it is one (`appendInvariant_iff_exists_view`). On a +store of keyed writes three ways of holding such a view agree: recomputed from the prefix +(`stateAt`), journaled from a checkpoint over the delta (`stateAt_eq_foldl`, +`foldAt_readBetween`), and kept by generation, a row valid from the cut that contains its write +up to the cut that contains the key's next one (`genRead_gens`). The store rewritten in place +determines no read at a past cut (`Witness.stateOf_forgets`). `[THEOREM: SNP-5]` So the choice +among the three is cost, store by store. A fourth form is a way of storing the third: immutable +segments under a versioned manifest, where the manifest's version is the position. The vector +table is built that way, and §5.2 says why its versions are not the snapshot. + +| derived store | a function of | held as | what it costs here | what would change the choice | +|---|---|---|---|---| +| vectors (atoms, occupancies), in the plane and in the curated store for what landed through the catalog | the chunk's text and the embedder's identity | version-keyed rows the plane keeps already; the log selects the version | no new bytes; a search over every version's rows, then a join with the heads at the cut. Not measured: the rows searched are the current ones over the current share, three times as many where two thirds are superseded, as on the lexical fixture | an instance that must drop superseded atoms (§9), after which a cut finds them pending | +| lexical units and postings | the chunk's text and the tokenizer's identity | version-keyed rows the index keeps already; the log selects the version; the statistics from the mask | no new bytes; 4,179 bytes a kept unit on synthetic text `[MEASURED §11]` | a query at a past cut over its budget at the instance's size: then statistics stored per class and per recorded cut | +| chat events, causal edges | the transcript as retained at the cut, and the commits inside the cut | recomputed at the cut, the present rows a cache of the head | 6 ms a session of 2,000 records `[MEASURED §11]`; no bytes | a sentence that walks the causal fiber at a past cut over a second on a real instance (SNF-5): then generations, written with a diff | +| interpreted artifacts with their hyperedges, interpreted relation edges | a model's output: of nothing that can be computed again | generations, the replaced row archived with its interval | one archived row a replacement, which is thrown away today; how often a row is replaced is not measured | a measured churn so low that declaring them outside the snapshot loses nothing | +| the relations a note declares | the note's text at a version, and the titles the catalog resolves at the cut | recomputed from the heads at the cut | one parse of a note's properties a head that has any, kept in a memo by digest; no bytes | nothing | +| claim ops, authored supersessions | nothing: they are appended, keyed by their content | a position a first insert; the read at a cut is the rows at or under it, a claim op served with what it names (§3.5) | one integer a row | nothing | +| verdict dispositions | nothing: one row a verdict, appended (§2.2) | the key is the position: the read at a cut is the rows whose `verdict_seq` is at or under the cut on the verdicts' own sequence, each served with the claim it is about (§3.5) | nothing new | nothing | +| the similarity backbone | the vectors of the support | recomputed, as today | nothing | nothing | +| citation readings | the tree at the commit and the extractor that projected it | append-only rows, as built, each stamped with the extractor's version and the position on `att` of the projection that wrote it; the reading of a commit at a cut is its rows stamped at or under the cut | one integer and a short string a row, on 3,029,562 rows over 1,487 commits at 567 bytes a row in the repository's records | the store's size: then a row valid over a range of commits (SN-b) | +| code memberships | git's blob at the path | version-keyed by blob; git's tree selects the version | nothing new | nothing | +| the utility field (not built) | the use log | a fold with kept checkpoints | a checkpoint a declared number of ticks | its own note's measurements | + +The figures for the citation readings are `docs/experiments/corpus-measurements-2026-11-07.md:106` +and `core/reference_view.py:15-16`. `[ESTABLISHED]` + +The stamp on a citation edge is what makes its reading a function of a cut. Today a commit's +reading is the union of every projection of it so far (§2.2), so `as of` a commit answers +differently after a re-projection though the cut did not move, which is the reader SNP-1's +control refutes; and the commit's sha does not pin it. With the stamp, the reading at a cut is +the edges projected at or under it, a later projection is a later event, and the head reads +every projection as it does today. The rows the store holds when the stamp is added are stamped +with the `att` genesis, so their history starts there (§8). `[DERIVED from SNP-1]` + +### 5.2 Vectors + +An atom is one chunk text under one embedder: its id is its layer and the hash of its text +(`core/stores/plane.py:113-115`), the plane records the embedder's identity and refuses another +(`plane.py:350-362`), and an occupancy says that a document at a version holds an atom at a +position (`plane.py:268-278`). So a vector is a function of a content digest and an embedder +identity, and a past version's vectors are still in the plane: a superseded version's occupancies +and atoms stay, and only `current` moves. `[ESTABLISHED]` The vectors at a cut are therefore the +atoms of the versions the landing log says were the heads at the cut: a read of the plane with +its superseded rows (`plane.py:772-821`) joined with the heads. `[DERIVED from SNP-5]` + +Three things follow. + +- **No stamp on the rows.** The interval a version's rows are valid on is read from the log. A + stamp on the rows would have to be a set of intervals (§2.3, item 3). +- **Not the table's own versions.** The vector table keeps a dataset version a write, and an + earlier version can be read. After a purge the purged text was still returned by eight and by + five of the table's ten versions, and the compaction that removes it leaves one version, so it + removes every earlier snapshot with it. `[MEASURED §11]` A manifest's version cannot be both + the position a snapshot is read at and something an erasure reaches. The cut is a predicate on + rows, taken from the log; the manifest stays a physical form. +- **The embedder's identity is the present's.** After a model change the plane is reset and the + drain derives the current versions only (`core/ingest/derive.py:85-118` lists the active + entries the plane does not hold current), so a superseded version has no vector. At a cut such + a version is pending, and a semantic clause ranks it by the lexical index or reports it, which + is ING-21's rule read at a cut. Deriving it is the same drain run over the versions a cut + holds. `[DERIVED from ING-19, ING-21]` A snapshot is of content, not of the geometry in force + when the content landed (decision D5, §13). + +### 5.3 The lexical index + +The index keeps every version's units and postings and marks the head +(`core/stores/lexical.py:56-82`, `:251-256`), and it computes its statistics at query time over +the current units of the reader's classes: the unit count and the mean length +(`lexical.py:316-321`) and each term's document frequency (`lexical.py:337-340`). +`[ESTABLISHED]` At a cut the arithmetic is the same with one predicate changed: a unit counts +when its version is its path's head at the cut, in place of `current = 1`. The collection size, +the mean length and the document frequencies are then the masked set's own, which is what makes +a score at a cut the score the index gave then under the same tokenizer. A clearance and a cut +are the same kind of thing to this index: a mask over units whose statistics must be the mask's. +`[DERIVED]` + +The other forms cost more here. Recomputing means tokenizing every item alive at the cut, since +the statistics are the collection's and not the support's: every unit of every head, where the +mask reads the units' stored lengths and postings. A journal of the changes to the document frequencies has an entry a term a unit, no +fewer than the postings (122 a unit on the synthetic text). An index with its statistics built in +cannot serve a cut, or a clearance, without a copy a mask; if the index moves to immutable +segments, a segment carries no statistics and they are computed from the mask, as they are +today, until a query at a past cut runs over its budget (SN-e). None of the three is measured +at a corpus's size. `[INFERENCE, falsifier SNF-7]` The tokenizer's identity is the +present's, as the embedder's is: a changed tokenizer resets the index (`lexical.py:180-194`) and +the backfill lands the active items, so a superseded version's units are derived again from the +raw store when a cut asks for them. + +### 5.4 Model output, and what is not model output + +Three stores were read as one kind, and they are three. + +**The relations a note declares** are not model output. The edge store has two producers kept +apart by provenance (`core/relations.py:7-16`): an authored edge is read off a note's own +`supports::`, `contradicts::` and `contextualizes::` properties and resolved by title through +the catalog (`relations.py:140-158`), so it is a function of the note's text at a version and of +the catalog. At a cut it is recomputed: for each head at the cut that has such a property, the +property parsed from the raw object the log names, the title resolved among the heads at the +cut. Nothing is stored and the edge has its note's class. `[DERIVED from SNP-5]` + +**Claim ops and authored supersessions** are not rewritten in place. Each row is keyed by its +whole content (§2.2), so a second write stamps a bookmark and changes nothing else. The +supersessions are the owner's declarations. The claim ops are appended by a store that calls no +model (`core/stores/claim_ops.py:14-15`), and what it appends is by design a model's proposal: +extracting the operations from a dialogue is a model task behind an analyzer whose default +proposes none (`core/kernel/recursion_ops.py:44-46`), and at `e3e3ee47` no caller outside the +tests applies one. So the claim ops are rows of the class `interpreted` (§3.1). The storage +choice does not depend on who proposes them: both stores are append-only sets that lack a +position, each gets a sequence number at a row's first insert, and the read at a cut is the +rows at or under it. A claim op is further filtered by what it names, the claim it acts on and, +for a supersede, the conclusion artifact the same call wrote (`claim_ops.py:45`, `:161-163`): +it is served when those are (§3.5). `[DERIVED]` + +**Interpreted artifacts and interpreted relation edges** are model output: written by a pass +that calls a model or by a `link` request (`core/relations.py:192-210`, +`core/ingest/writer.py:521-535`), each keyed by what it is about, so a later write replaces the +row (`core/stores/derived.py:209-216`, `core/stores/edges.py:88-106`). The output cannot be +computed again, so the two choices are to keep it by generation or to declare it outside the +snapshot. This note keeps it. `[INFERENCE, falsifier SNF-8]` + +The form is the one the observation stores use: archive, then replace +(`core/stores/code_observations.py:211-254`, `core/stores/observation_history.py:46-56`). Each +store gets a sequence number a write, its chain; each row the number it was written at; and a +replaced row goes to a history table with the number it was replaced at. The read at a cut is +the row whose interval holds the position (`genRead`), and at the head it is the present row +(`genRead_gens_length`). `[THEOREM: SNP-5, SNP-4]` + +A kept row is served at a cut only when its sources are there, and what a row's sources are +differs between the two stores. + +- A relation edge's two ends are content digests (`edges.py:39-40`), so the row is about two + particular versions. +- An artifact's key is not its sources. The key hashes the kind, the subkind and the sorted + `subjects`, which are note titles (`derived.py:55`, `:97-100`; the callers pass titles, + `core/curator/curator.py:98`, `core/dreaming/dreamer.py:153`), so one row is replaced by a + later pass over the same titles whatever versions of those notes the two passes read. Its + sources are its `derived_from`: note digests, or the ids of other artifacts + (`derived.py:186-189`; `curator.py:175`, `dreamer.py:160`). The artifact records no run. Its + link to the pass that wrote it is the attestation it names (`derived.py:59`). + +So a kept row is in the read at a cut when four things hold: it was written at or under the cut +on its own chain; the attestation it names, if any, is kept at the cut on `att`, which for a +pass attestation is more than lying under the cut (§3.5); every +digest its sources reach is some path's head at the cut, where an artifact's sources are +followed through the artifacts it names, each as it stood at the cut, down to digests (the +store refuses a cycle, `derived.py:186-189`); and none of those digests is erased or sealed +(`mem_serve_iff`). `[THEOREM: SNP-7 for the erasure, SNP-8 for the closure; DERIVED for the +rest]` This is the row filter of §3.5: it withholds a row and lowers no position. Until SN-6 +builds it the `interp` chains serve two positions, the empty prefix and the head (§7.1). +Lowering them moves no chain outside them but the chain of records, which follows (§7.1): the +other references into them are their own, a claim op's to an artifact and an artifact's to +another, and those are the filter's. + +### 5.5 The causal fiber + +The events of a session and its causal edges are a deterministic function of the transcript and +the commit ledger (`core/chat_events.py:136-176`, `core/integrator.py:118-164`), so recomputing is +exact, and it is the definition here. At a cut: for each session, the transcript is the raw +object the session's last turn inside the cut names (`core/chat_events.py:211` takes the last +row's digest the same way for the head); its events are extracted and kept when their turn is +inside the cut; a commit event resolves against the commits inside the cut on `repo`. `[DERIVED +from SNP-5]` + +This repairs three things the stored rows have today (§2.3, item 4). The result no longer depends +on the order in which the projector, the integrator and the code sensor ran. An event whose +result arrived after the cut is read without it, as it stood. And an edge is named by its session, +its event's order and its endpoint, which a session's growth does not change. + +The cost is an extraction a session: 6 ms for a synthetic session of 2,000 records and 0.79 MB. +`[MEASURED §11]` The builder reads the causal store whole once a sentence +(`core/sentence/universe.py:581-595`), so at a cut it would extract every session with a turn +inside the cut, and a memo keyed by the session and its transcript's digest makes each +extraction happen once a process. By arithmetic from that figure, not measured: the first +sentence of a process that walks the fiber at a past cut pays 6 ms and one transcript read a +session, so 6 s and 0.8 GB read for a thousand sessions of the fixture's size, and the memo's +price after that. Generations are the alternative: the rows kept, keyed by session and order, +each with the range of `chat` positions it was valid on, written with a diff so that a session's +growth adds its new events and closes only the rows that changed. They need the projector and +the integrator written again, which is not sized here, and are kept for the instance that needs +them (SNF-5). + +### 5.6 An instance with no embedder + +Nothing above reads the plane to learn what existed. The node set of a snapshot comes from the +landing log, which lives in the catalog's file; the lexical units, the version chains, the causal +fiber and the citation readings need no vector; and a semantic clause on such an instance ranks +by the lexical index and says so, at a cut as at the head (ING-21). The plane's own supersession +log could not carry this: an instance with no plane has none, and under lazy embedding it records +the order in which the drain reached the items, not the order in which they landed. Today the +universe takes the mirror's nodes from the plane's rows (`core/query.py:462-465`); at a cut it +takes them from the log. `[DERIVED; ESTABLISHED for the present reads]` + +One set of rows the log cannot give. The curated store is read by `near` and by `read` +(§2.2), and one of its two writers, `scripts/curate_local.py:96-108`, adds rows with no catalog +row, so no landing and no position. Such a row is outside the snapshot: at a cut it is not a +node, and the answer's note says how many curated rows have no landing and were not read. What +`ingest_curated` landed is in the log's `curated` chain and is read at a cut as a note is. The +repair is to route that script through the writer's `store`, as every other source is; it is +parked (SN-i) because it changes a writer and not a reader. `[INFERENCE]` + +## 6. Erasure and scope + +Two things are parameters of a read and no function of the cut, because they are the present's: +what has been erased, and what the asker may see. + +### 6.1 A purge leaves a hole + +No erased event is visible at any cut (`not_erased_of_mem_visible`), a larger erasure shows a +sublist (`visible_sublist`), and two stores that differ only in erased events give every +derivation of what is visible the same reading at every cut (`erased_invisible`). `[THEOREM: +SNP-7]` That is a statement about a reader that reads the visible events. It becomes a +statement about the code only when every reader of a store goes through the erasure, which is +what the table below is for. + +The erasure keeps positions. The store with a hole at each erased event has the head it had and +commutes with the cut (`head_redact`, `redact_readAt`); an erasure that deletes rows moves the +later ones up, and a read at a cut then holds an event from after it (`Witness.compact_moves`). +`[THEOREM]` The plane's supersession log is the second kind today: after a purge, a later landing +at the path took position 1 again. `[MEASURED §11]` + +**The hole keeps its key.** A purge is by digest, and it may take an old version of a path +that is still live, since only the digest's active references block it +(`core/ingest/purge.py:52`). If the emptied row lost its path, a seek by path would pass over it +and return the version before it as the path's head at a cut where the purged version was the +head; and a reader that dropped the holes before seeking would return a version from after the +cut (`Witness.keyless_hole`). So the row keeps `path_key`, the keyed hash of its path. On a +chain whose holes keep their keys, the read of a path at a cut is its last event at or under +the cut, returned as a hole when that event is erased, never an earlier version and never a +later one (`stateAt_holes`, `stateAt_holes_of_erased`, `not_erased_of_stateAt_holes`), and the +seek, the closing-stamp read and the fold still agree (`lastWrite_holes`, `genRead_gens_holes`). +`[THEOREM: SNP-7]` On the fixture, after the fifth of a path's ten versions was emptied, the +seek at a cut where it was the head returned the emptied row. `[MEASURED §11]` + +**What a purge empties in the log.** The path, the identity, the digest, the title, the salt +and the wall bookmark become null; the commitment and the hash stay. The certificates keep +verifying (`verifies_purge`), a reader reads a hole (`contents_purge_committed`), and since the +commitment was salted and the salt is gone, it can no longer be tested against a guess of the +content. `[THEOREM: SNP-9 for the chain; DERIVED for the salt]` What stays, and why: + +- `chain`, `seq` and `kind`: the position, which the erasure must keep. +- `path_key`: so that the hole shadows. It can be tested against a guess of the path only with + the chain's secret, which is in the same file as the rows. +- `closed_at` and `version`: positions and a count, no content. `closed_at` is a function of + the rows that keep their keys, so nulling it would hide nothing. +- `att_head`: a position on another chain. + +The hole is thus still tied to its path while another row of the path keeps the name, which is +the intent: the purge is of a digest, and the path with its other versions is not erased. When +every row of a path is emptied no row names the path. The bookmark goes because nothing looks a +landing up by its date, and a date on a hole says when the erased content arrived. + +That is a rule the record already has: no tombstone keeps a content hash of purged private text, +and for prose privacy outranks lineage (`docs/design-notes/vector-membership-store.md:810-813`). +A digest of purged bytes is a test for those bytes. What a purge has to reach, against what it +reaches today: + +| store | today, after a purge | what a snapshot needs | +|---|---|---| +| raw object, catalog row, plane occupancies and their freed atoms | removed `[MEASURED §11]` | the same, and the log's rows emptied | +| the vector table's earlier dataset versions | still return the text `[MEASURED §11]` | the purge ends with a compaction that keeps no earlier version | +| lexical units, postings and version records | remain, with the words `[MEASURED §11]` | removed with the plane's rows | +| the version chain's rows | still name the digest `[MEASURED §11]` | the digest nulled, the row and its number kept: a second owner-gated write beside the relabel (`core/stores/versions.py:132`) | +| the curated store's plane and atoms | not opened: the purge is given the main vector store only (`scripts/purge_raw.py:51-56`, `core/stores/curated_store.py:30-38`) | the same removal and compaction as the main store | +| relation edges and artifacts that name the digest | untouched (`core/ingest/purge.py:58-62` names neither store) | not served (`mem_serve_iff`), and removed by the purge, with the archived generations that name it | +| dream claims of the run ledger | keep the digests a claim rests on and its surface text (`core/stores/runledger.py:90-97`) | the claim's support and text nulled, the row kept | +| staging rows | keep the content digest and the payload (`core/stores/staging.py:130-131`) | the digest and the payload nulled, the row and its generation kept | +| claim ops | keep the warrant's text (`core/stores/claim_ops.py:40-48`) | the ops on a removed artifact removed | +| rejected requests of the ingress spools | keep the request's text (`core/ingest/ingress.py:20-27`, `:505-517`) | the files that hold the purged text removed | +| the attestation ledger | still names the digest `[MEASURED §11]` | decision D9 | +| a deletion attestation | none is written (`core/attestation/store.py:3-6` says one is) | one, of action `purge`, naming the positions emptied and no digest | + +Rows without a grade were read in the code and not measured. Until the stores of the middle +rows are reached, a read of them at a cut would return what a purge left. So the erasure's reach +is stage SN-3, and it lands before any of those stores is read at a past cut (§12). The +attestation of a purge lists the positions it emptied, which is what lets a backup restored from +before it be purged again (§3.6). + +### 6.2 A retire seals + +A vault delete is a tombstone: the catalog's row goes inactive and the raw object stays +(`catalog.py:160-172`). The requirement is that a tombstoned item does not come back through a +snapshot either. Two rules do that for the value served at a cut, both proved, and they are +ordered. + +- **The stricter seal** (`servedAt`). A retire among the events past the cut closes the cut for + that identity. Once the chain retires an identity, no cut before the retire serves it + (`servedAt_append_of_retire`); growth that does not retire it changes nothing + (`servedAt_append_of_no_retire`); so growth changes a served value only by removing it + (`servedAt_of_append`). +- **The looser seal** (`servedNow`). An identity is withheld at every cut exactly while it is not + live at the head. It serves everything the stricter one serves (`servedNow_of_servedAt`), keeps + an identity that is retired now out of every cut (`servedNow_of_not_live`), and is lifted by a + later landing, which brings the past back (`Witness.servedNow_restores`). `[THEOREM: SNP-7]` + +This note takes the stricter seal, keyed by identity, with an `unseal` event that only the owner +writes. `[INFERENCE, falsifier SNF-10]` The reason is in the code: a new row's identity is its +path unless it declares one, and a re-record of a path keeps the identity it has +(`catalog.py:103-121`), so a different note written later at a deleted note's path has the +deleted note's identity, and under the looser seal it would bring the deleted note's versions +back at the earlier cuts. + +**The seal covers the versions, at every cut.** Sealing the value is not enough. The new note's +identity is the deleted note's, so its chain of versions holds the deleted note's versions +(§2.3, item 8), and a read of the history would return them at the head and at every cut after +the new note landed, where no value is sealed. So the history served of an identity at a cut is +defined with the seal (`historyAt`): nothing where the identity is sealed, else its landings +inside the cut that no retire follows. It ends at the value served there +(`getLast?_historyAt`); a retire after the cut empties it (`historyAt_append_of_retire`); and at +every cut after a retire, the head included, it holds only versions landed after that retire +(`historyAt_of_retire_inside`, `sinceRetire_append_retire`). `[THEOREM: SNP-7]` This changes a +read at the head too: `trace` of a note written at a deleted note's path stops at the delete. +The versions store keeps its rows; the read withholds them. + +The seal is by identity and not by path so that a rename seals nothing: the old path's tombstone +is a `move` (§3.2). The cost of the stricter seal is also in the code. The sync retires every +stored path its source no longer lists (`ingress/sync_vault.palace:7-15`, +`core/ingest/writer.py:499-519`), and a source whose directory is missing lists no file +(`core/ingest/readers.py:126-137`), so a vault that is missing at a sync seals every note's +past. The owner lifts it with one `unseal` row, whose `ref_lo` and `ref_hi` name the range of +positions of the retires it lifts; an `unseal` of one identity carries the identity and the +position of its retire in both. + +The seal is read off the whole chain, the present, and off no prefix of it: one more seek, the +position of the identity's last retire that no later `unseal` names. At the head no value is +sealed (`servedAt_length`), and the history served is the identity's landings since that retire +(`historyAt_length`). + +### 6.3 The grant is the asker's now + +A snapshot under a grant is the read at the cut restricted to the chains the grant names and, +within them, to the events it may see named (`snapshot`). The grant is no function of the cut. +`[THEOREM: SNP-6]` + +- A narrower grant's snapshot is the restriction of a wider one's, at every cut + (`snapshot_narrow`): what a wider grant was shown at a cut bounds what a narrower one is shown + there. +- It reads only the chains the grant names and the cut's positions on them (`snapshot_congr`), + and it is append invariant (`snapshot_grow`). +- Restricting to whole chains commutes with the cut (`restrict_readAt`). Filtering events before + the cut does not: it moves the positions (`Witness.filter_before_cut`), and a position on a + chain counts the events a filter hides (`Witness.position_channel`). So an event filter is + applied after the read, and what must be hidden in number is hidden by chain, which is why a + landing chain holds one class. +- The grant and the erasure compose: what an asker is shown, the grant's snapshot with the + erased events masked (`shown`), is append invariant, holds no erased event, and under a + narrower grant and a larger erasure is the restriction of what the wider grant is shown under + the smaller erasure (`shown_grow`, `not_erased_of_mem_shown`, `shown_narrow`). + +**What these laws are about.** They are about the read: the rows a grant is shown. They pass to +an answer when the answer is a filter of the read, as the members of `reach`, `trace`, `read` +and `changed` are. They do not pass to a score. A lexical score uses the statistics of the +reader's own classes, the unit count, the mean length and each term's document frequency +(`core/stores/lexical.py:316-321`, `:337-340`), and §5.3 keeps it so; a rank depends on every +candidate. So for a sentence that scores or ranks, the narrower answer is not the wider one +masked, at the head today as at a cut, and nothing here claims it is. `[ESTABLISHED for the +statistics]` + +**The cut shown.** `snapshot_congr` holds for a fixed cut. The cut read is resolved over every +chain (§7.1), and its position on a chain the grant names can depend on a chain the grant does +not name, when the named chain reads it (`Witness.resolution_reads_unnamed`). On a set of +chains that read from no chain outside the set, the cut read is a function of that set alone +(`ResolvesIn.eq_on_of_closed`). `[THEOREM: SNP-6]` A landing chain reads `att`, and `att` reads +`repo`; both mix every class. So the cut shown to a grant is a function of its own chains, of +`att` and of `repo`. Landings of another class move the head of `att` and change none of that +at a recorded cut: the record's positions are fixed, `att` is never pruned, so it serves them, +and the references of the events inside the cut do not change as the store grows +(`Consistent.of_grown`). What a narrower grant can learn through the cut shown is only that +`att` or `repo` did not serve a position, which is a fact about the instance and no class's +data. The filtered references do not enter the cut shown, since the resolver does not follow +them. A row withheld because a chain the grant does not name was read low tells the asker that +that chain did not serve the cut, the same kind of fact. `[DERIVED]` + +Two consequences for the surface. An answer names the cut it read on the chains the asker's grant +names and on no other, and the bounds a row records (§3.5) are never shown: `att` mixes every +class, so its positions count other classes' landings. And a class is a row's class now: a +whole-class relabel changes the label of a chain, and a row moves between chains only by a +`move` and a `store` (§3.2), after which its earlier events stay under the class they had +(ING-17). `[DERIVED]` + +### 6.4 A reader that is shown only named endpoints + +Take a read-only principal that is shown a causal edge only when the edge ends at a commit or +at a file git tracks at `HEAD`. That rule is an event filter in the sense of §6.3, and at a cut +it is the present's filter applied to the edges inside the cut: an edge is shown when its +witness turn is inside the cut on `chat`, its commit, if it ends at one, is inside the cut on +`repo`, and its endpoint passes the list as the list stands now. The list is not taken at the +cut's tree. `[DERIVED from SNP-6]` Two reasons. The grant is the asker's now, so a file that left +the tracked tree since the cut is withheld at the cut as it is at the head, and no cut shows a +name the head withholds. And the filter is then applied after the read, which is the order +`restrict_readAt` and its control require. The principal's snapshot is the restriction of the +owner's at every cut (`snapshot_narrow`). The alternative, the list taken at the cut's tree, is +decision D11. + +## 7. The sentence surface + +### 7.1 The cut asked and the cut read + +A sentence has one cut, as today (§2.1). The name resolves to a frontier, the cut asked (§3.4). +Each chain serves some positions exactly: every position from its horizon to its head (§8), and +the empty prefix; a store that keeps no past serves the empty prefix and the head. The read is +taken at the greatest consistent cut under the frontier asked every position of which is served +(`ResolvesIn`). `[THEOREM: SNP-10]` + +- It exists and is unique whatever the stores serve (`exists_resolvesIn`, `ResolvesIn.unique`). +- It never passes the cut asked (`ResolvesIn.le_resolves`), so what is read is a prefix, chain by + chain, of what the cut asked holds (`readAt_mono`): a read under `as of` holds no event from + after the cut it names. +- It rises with the frontier, and with what is served while the served positions only grow + (`ResolvesIn.mono`): as the stages of §12 give stores a past, the cut read for one name climbs + toward the cut asked. +- When every position is served it is the resolution of the frontier (`resolvesIn_univ`), and at + the head, which is consistent because a store holds the sources of its own events, it is the + head (`resolvesIn_self`). + +**Which chains go down together.** The cut read is not a floor taken chain by chain. A chain +that others read takes its readers with it: where it is read low, every event that reads past +that position is outside the cut, and so is everything that reads those events +(`Witness.record_drags`). A chain that no other chain reads is lowered alone: from a consistent +cut asked, the cut read is the cut asked with each such chain at the greatest position it +serves at or under the one asked, and every other chain as asked (`resolvesIn_of_unread`, and +`resolvesIn_update_of_unread` for one chain). And a chain that reads a lowered chain, and that +nothing but itself reads, follows it and takes nothing with it: it is read at the greatest +position it serves whose events read the lowered chains inside their new positions +(`resolvesIn_of_followed`). `[THEOREM: SNP-10]` + +The design is arranged so that, among the references the resolver follows, the second and the +third case are the only ones that occur at a recorded cut. Those references are a landing's to +`att`, an attestation's to `repo` and a record's to every chain it certifies (§3.5). Neither +`att` nor `repo` has a horizon that moves: the attestation ledger is never pruned (§9.2) and +`repo` is git's. Every chain that can fail to serve a recorded position, a landing chain behind +a history window, a chain that keeps no past yet, the use log behind its horizon, is read +through a resolved reference by one chain only, the chain of records, which no other chain +reads (§3.3). So at a recorded cut each chain that cannot serve is lowered to the greatest +position it serves; the chain of records is lowered with them, to its last record every +position of which the cut read holds (`Witness.record_follows`); and every other chain is read +as recorded. `[DERIVED]` + +That is a statement about positions, and it holds for the resolved references only. A row that +reads a lowered chain through a filtered reference, a pass attestation, a dream claim, an +interpreted row or a claim op, leaves the read by the filter of §3.5 and moves no position: at +a cut where a landing chain is read at its empty prefix, every pass attestation that read a +landing of that chain is withheld, with the artifacts that name it, and `att` keeps its +position. Resolving those references instead would bring the cascade back through `att` +(`Witness.pass_drags`, against `Witness.pass_withheld`). `[THEOREM: SNP-8 for the two +controls]` + +**When the cut read falls.** The monotonicity needs the served positions to grow. They do not +always. A store that keeps no past serves its empty prefix and its head, and loses its old head +when it grows; a history window removes the positions under the new horizon. In both cases the +same name read later is read lower (`Witness.served_set_shrinks`). So an answer read at the head +of a store with no past names a position that store will not serve again. The answer's note +marks such a chain as served at its head only, and the same name asked after the store grew +reads that chain at its empty prefix and says so. `[THEOREM for the control; INFERENCE for the +note]` + +The answer is then exact for the cut it names: every law of §10 holds at the cut read. What the +answer says is that cut. It carries one note with the cut asked, the cut read on the chains the +asker's grant names (§6.3), and each chain on which the two differ with the reason: the store keeps +no past, the cut is under the chain's horizon, or the stage that reads the store at a cut is not +built. Where the filter withheld rows because a chain was read low, the note says of which store and +how many. For example, on an instance where the interpreted relation edges do not yet keep +generations: + +``` +as of "cut:4c1f09a2": land 3 (authored-solo) 412, chat 9318, repo 9de5325. Not read at the +cut: the interpreted relation edges keep no past and were read at their empty prefix. +``` + +This replaces what the executor does today, which reads those stores at the head and says so +(`core/sentence/execute.py:719-725`). The head is later than the cut asked, and a reader that +ignores the cut is not append invariant: the same sentence gives another answer after the store +grows (`Witness.present_not_appendInvariant`). `[THEOREM: SNP-1]` + +A store read at its empty prefix makes its clauses empty. That is the answer at the cut named, +and it is not a bound on the answer at the cut asked: `reach` and `relate` only lose members when +edges are missing, but `diffuse` normalizes by degree and `top` ranks, and both can move either +way (the executor says so of an assumption that removes weight, `execute.py:473-481`). So the +note is part of the answer's meaning. The alternative is to refuse such a sentence (decision D4). +`[INFERENCE, falsifier SNF-4]` + +### 7.2 Each mode and each edge species at a cut + +The mode of a clause follows from its scope (`core/query.py:273-281`). + +| mode | verbs | what it reads at the cut | exact from | +|---|---|---|---| +| semantic | `near`, `diffuse S`, `reach S`, `relate` | the heads of the clause's classes, from the log; their vectors by content address and the lexical index for the pending ones (§5.2, §5.3); the backbone recomputed among them | SN-4; `relate` SN-6 | +| structural | `reach F`, `diffuse F`, `walk` over `F` | the citation reading of the cut's commit, as projected at or under the cut (§5.1) | today for a commit projected once; SN-4 for one projected again | +| temporal | `trace`, `reach D`, `walk` over `D`, `changed` (§7.4) | the history served of the identity at the cut (§6.2): the log's rows of the identity at or under the cut, after its last retire | SN-4; `changed` SN-8 | +| causal | `reach C`, `walk` over `C`, `witness` | the causal fiber recomputed at the cut (§5.5); an attestation kept at the cut on `att` (§3.5) | SN-5 | + +| species | at a cut | +|---|---| +| `S`, similarity | recomputed from the vectors of the versions alive at the cut, within a stratum, as today (`core/sentence/universe.py:733-739`); no edge at a pending node | +| `F`, citation | the edges of the reading at the commit; a reading is whole, so nothing is inferred between commits | +| `D`, supersession | consecutive versions of the chain's prefix; at the node grain it is empty today and stays so (`universe.py:810`) | +| `C`, causal witness | an edge whose witness turn is inside the cut on `chat` and whose commit, if it ends at one, is inside the cut on `repo` | +| the signed relations (supports, contradicts, contextualizes) | an authored edge recomputed from the heads at the cut; an interpreted edge as a kept generation whose two endpoint digests are heads at the cut (§5.4) | +| an assumed edge (`assume`) | applied to the universe of the cut read; nothing is stored, and the result is a `Hyp` as today | + +### 7.3 The verbs + +- **`near`, `diffuse`, `reach`, `relate`, `walk`, `trace`, `witness`** read as their mode says. +- **`far`, `top`, `atleast`, `not`, `minus`, `and`, `or`, `then`, `within`, `over`** are the + algebra on whatever universe the clauses built. Their laws (QSA-1 to QSA-4, QSA-10) are stated + for any universe, so they hold at a cut with no change. `over` masks by a row's class, which is + its class now (§6.3). +- **`read`.** A repository path: git's blob at the cut's commit, with the commit shown on the + hit; when git does not hold the cut's commit the read is refused and says so, where today it + returns `HEAD`'s blob (§2.1). A note or a dialogue turn: the raw object of the digest the log + names for the path at the cut, never the vault file, which is the present and can be newer + than the catalog (§2.1). A path whose event at the cut is a hole reads as erased, and not as + the version before it (`stateAt_holes_of_erased`); a sealed identity reads as nothing (§6). A + transcript turn: the chat log's row when its number is at or under the cut. A curated row: + what landed through the catalog as a note is; a row with no landing is not read (§5.6). +- **`witness`.** The record when it lies inside the cut: an attestation by its number on `att`, + and a pass attestation only when the landings it read are inside the cut as well (§3.5); a + causal edge by its turn and its commit; a citation edge by its commit. +- **`assume`.** The overlay applied to the universe of the cut read: a hypothetical at a past cut. +- **`do`.** A request is a whole sentence and takes no adjective (`core/sentence/grammar.py:4-5`), + so it cannot be written under `as of`: a write has no past. + +**`as of "head"` is no `as of`.** At the head cut the read is the store (`readAt_head`), every +derived view is the derivation of the present (`view_head`), the generational store reads the +store rewritten in place (`genRead_gens_length`), a snapshot is the grant's restriction of the +store (`snapshot_head`), nothing is sealed (`servedAt_length`) and what is visible is the store +without the erased events (`visible_head`). `[THEOREM: SNP-4]` On the code this is the first test +of every stage: the same sentence with and without `as of "head"` returns the same hits. + +**Refusals.** An ambiguous prefix, as today (`universe.py:471-475`). A name that selects nothing: +a sha no chain knows, a cut id no record has, a date before the first record, `HEAD`, a branch; +the refusal says which names would resolve, and it does not depend on what the stores hold. A +date after the newest record is not refused and is not the head: it is the newest record +(§3.4), and the answer says the head has moved since when it has. + +### 7.4 Between two cuts + +One form is worth admitting, and it is a region: + +``` +changed between "" and "" changed since "" +``` + +Its members are the identities with an event in the delta, on the landing chains of the classes +the clause reads; `since` is `between` with `head`. `[INFERENCE, falsifier SNF-14]` + +- **It is sound for what did not change.** An identity outside the region has the same state at + both cuts (`stateAt_eq_of_not_written`). It over-approximates what did: a path that returned to + the bytes it had is a member. +- **It composes.** The region between `a` and `c` is the union of the regions between `a` and `b` + and between `b` and `c` (`readBetween_append`, `mem_readAt_iff`). `[THEOREM: SNP-3]` +- **It is cheap.** One range read of the log: 0.7 ms a thousand positions. `[MEASURED §11]` +- **It composes with the algebra.** A region masks a field or meets a region, so + `near "x" within (changed since "")` needs no new rule; its mode is temporal, since its + window is not a point (`core/query.py:277`). + +The general form, a sentence evaluated at two cuts with the difference reported as `assume` +reports its two universes (`execute.py:1045-1063`), is the `velocity of` that dn-graph-dynamics +designs as GD-4. This note supplies the two readings it needs and does not add a second way to +write it. + +## 8. The exactness boundary + +History is exact from the first retained generation and from no earlier. Each chain has a +**horizon**: the first position from which it serves every cut. Three things set one. + +- **The genesis.** The landing log opens with the catalog as it stood (§3.2). What a path held + before was never recorded, so the positions before the genesis block ends are under the + horizon. For the chat log and the attestation ledger the genesis is the rows they hold when + their chain tables are added, numbered in the order they were inserted and followed by a + horizon: within a chat session the turn order is exact, but the order across sessions and + across the two stores was not recorded, so no cut inside the block is served. The citation + edges held when their stamp is added are stamped with that genesis (§5.1). +- **Retention** (§9), which drops the generations closed at or under a declared position. +- **A reset**, after which every chain is a new chain with a new id (§2.3, item 7), and no + record taken before it names a chain that exists. + +The law is the same for the three. A generational store that drops the rows closed at or under a +horizon reads, at every cut from the horizon on, the state recomputed from the whole prefix +(`genRead_prune_gens`), though the prefix is no longer held, and landings after the pass leave +it so (`prune_landGen`). Under the horizon it is never wrong: a value it returns at a cut is the +value the key held (`stateAt_of_genRead_prune`). But what it lost it reads as absent +(`Witness.prune_forgets`), and nothing in the rows that remain tells a lost key from a key that +was never there: two chains can leave the same pruned store where, at one cut under the +horizon, a key held a value in the first and had never been written in the second +(`Witness.prune_indistinct`). Two horizons are the later one (`prune_prune`). `[THEOREM: +SNP-10]` The journal form says the same of a fold: continued from the state kept at the +horizon over the events since, it is the fold of the whole prefix (`foldAt_readBetween`), and +for a chain that drops its prefix whole, as the use log does, the chain's digest at the horizon, +kept as the seed, lets every certificate from the horizon on verify +(`certify_digest_readBetween`). `[THEOREM: SNP-3, SNP-9]` The landing log needs no seed: a +window empties its rows and keeps their commitments, so it is hashed from its first row (§9.2). + +So the horizon is recorded, and a cut under it is not served. + +- **Where.** As a `horizon` row of the chain, which the chain's hash covers, and in every + recorded cut (§3.3). It only advances. +- **What a question before it gets.** The chain is read at the greatest position it serves at + or under the one asked, which under a horizon is its empty prefix, and the answer says the cut + is under the chain's horizon and names the first cut the chain serves. Every other chain but + one is read as asked. Among the references the resolver follows, a chain that has a horizon + above a recorded position is read by the chain of records alone, so each such chain is + lowered alone and the chain of records with them, to its last record that the cut read holds + (§7.1, `resolvesIn_of_followed`). What else follows a lowered landing chain is the rows about + it, by the filter and not by position: a pass attestation, a dream claim, an interpreted row + or a claim op whose sources are not inside the cut read is withheld (§3.5, §5.4). A sentence + all of whose chains are under their horizons returns the note and no hit. +- **What that means today.** A commit read before the log exists resolves, on every chain but + `repo`, under the horizon: `as of` such a commit reads the citation graph and the repository's + files at the commit and nothing else. For a commit projected once, and held by the checkout, + that part is exact, and it is the lawful part of what `as of` does now; a commit projected + again has a reading that grew (§5.1), and a commit the checkout lacks is read at `HEAD` + (§2.1). The observation that the version store held one generation and so had nothing to + snapshot (limits-of-the-algebra, L7) is this boundary seen from the other side. `[DERIVED]` + +## 9. Retention and cost + +### 9.1 What grows + +A landing drops nothing today: a retired path's rows and a superseded version's rows stay in the +plane and in the lexical index (`core/stores/plane.py:497-499`, `core/stores/lexical.py:260-265`), +and rows go only with a purge or a reset. So the bytes of a past are mostly paid already, and +the snapshot adds three things. + +| what | a | bytes | source | +|---|---|---|---| +| the landing log | landing | 396 to 434 on the fixture | `[MEASURED §11]` | +| a recorded cut, with its attestation | record | about 2,700, by arithmetic | §3.3 | +| a chain table's row, for `chat`, `att`, `staging` and `runs` | appended row | under 100, by arithmetic: an integer, the row's key, a 32-byte hash | §3.1 | +| archived model output | replaced row | the row's; how often one is replaced is not measured | §5.4 | +| kept already: a lexical unit of a superseded version | unit | 4,179 on synthetic text, 122 postings a unit | `[MEASURED §11]` | +| kept already: a plane occupancy | row | 734 to 1,084 | `docs/experiments/corpus-stage1-2026-11-07.md:416`, `corpus-measurements-2026-11-07.md:104` | +| kept already: an atom | changed chunk | 2,215, of which the vector 1,536 | `corpus-measurements-2026-11-07.md:103` | +| kept already: a raw object | version | the version's bytes; a transcript's, whole, at each growth | §2.2 | + +By arithmetic, not measurement: an instance with a hundred landings a day adds 43 kilobytes a day +to the log, 16 megabytes a year, and thirty recorded cuts a day add 81 kilobytes. A corpus +instance at the ten million items the repository's records plan for +(`docs/experiments/corpus-measurements-2026-11-07.md:94-96`) has a log of about 4 gigabytes for +the first landing of each item. + +The rows kept already are what grows: with three versions an item, two thirds of the synthetic +lexical index were superseded versions. `[MEASURED §11]` What one superseded version keeps, by +arithmetic from the rows above for a note of four chunks all of which changed: four lexical +units, four occupancies and four atoms, 28.5 to 29.9 kilobytes of derived rows, and the note's +own bytes as a raw object, against 0.4 kilobytes in the log. At a hundred such landings a day +that is about 2.9 megabytes a day of derived rows, a gigabyte a year, which the instance pays +today whether or not anything reads a past. A transcript is the other large term: it is +retained whole at each growth, 0.79 MB each time for the fixture's session of 2,000 records. +What the snapshot brings is less a cost than the means to stop paying one: a horizon makes it +safe to drop. + +### 9.2 The rule, counted in events + +A chain can declare two windows, each in positions, and a retention pass runs at a recorded cut. + +- **A window for derived rows.** The derived rows of the versions closed at or under the head + less the window are dropped: lexical units and postings, plane occupancies, and the atoms + nothing retained holds. No horizon moves. The log and the raw objects stay, so every read of a + ledger at those cuts is still exact, and a derived row a cut asks for is pending and can be + derived again (§9.3). +- **A window for the history.** The chain's horizon moves to the later of the horizon in force + and the head less the window. A `horizon` row is appended first, so the positions under it are + unserved from that moment; then the derived rows still under it and the raw objects no + retained row names are dropped, and the log's rows closed at or under it are emptied. + +**What a window leaves of a row.** An emptied row keeps `chain`, `seq`, `kind`, `closed_at`, +`commitment` and `hash`, and loses every other field, its key included. No row of the log is +deleted. The rows closed at or under a horizon and the rows still alive there interleave, and a +row at the horizon's position is never closed under it, so with rows deleted there would be no +last row dropped whose hash could seed the rest, and the hashes of the rows kept under the +horizon could not be computed again. With the commitments kept, `verify` runs from the first +row as it does on a chain that was never pruned (§3.2), every certificate keeps verifying, as +after a purge (`verifies_purge`), and a row still alive under the horizon is checked like any +other, by its commitment and by the chain. For the reads an emptied row is a dropped one +(`genRead_prune_gens`): it has no key, so no seek by path finds it, and it needs none, since a +row closed at or under the horizon is the last event of its path at no cut from the horizon on; +its closing stamp keeps it out of the heads at those cuts. `[THEOREM: SNP-9 for the chain, +SNP-10 for the reads; DERIVED for the key]` By arithmetic, not measured: an emptied row is +about 100 bytes, two 32-byte hashes, the kind, three integers and its entry of the closing +index, against the 396 to 434 measured for a whole one. + +The window for the history is an exception to the rule that raw objects are kept +(`core/kernel/stores/rawstore.py:1-8`), which only the owner's purge makes today, so it is the +owner's to declare. Its order is the one the stores use for a cache: the horizon is declared +first, so a crash in the middle leaves rows that are no longer served, never a position that is +served and incomplete (the discipline of PLN-4, where a cache is stale only by excess). +`[DERIVED]` The attestation ledger and the version chains are not pruned: they are the audit +record, they are small, and they have no delete. That the ledger keeps every position is also +what §7.1 rests on: `att` is the one chain every landing reads, so a horizon on it would take +the landing chains down with it. The converse is why a pass attestation's reference to a +landing is filtered and not resolved (§3.5): resolved, a history window on one landing chain +would lower `att`, and through it every other landing chain. + +A window is counted in events because wall time orders nothing (Law C4): the last ten thousand +landings of a class, not the last ninety days. It is one position a chain, not a number of +versions an identity. Keeping the last `n` versions of each identity would leave no horizon: +which cuts are exact would differ from one identity to the next, with no position to record +them by. The control of §8 is proved for a store pruned at one horizon; that a store pruned per +identity is no better at telling what it lost is the step this note infers. `[INFERENCE, +falsifier SNF-9]` + +The default instance declares neither window and keeps everything; by the arithmetic above its +log is megabytes a year and its superseded derived rows about a gigabyte a year at a hundred +landings a day. An instance that must bound its disk declares the first window, which frees +those derived rows and moves no horizon. The second frees, beyond that, only the raw objects +and about three quarters of the bytes of the log's rows of the closed versions, and it is +declared only by the owner (D8). At the cuts a chain no longer serves it also withholds every +pass attestation, dream claim and interpreted row that read a landing of that chain (§7.1). + +### 9.3 Lazy landing, in time + +Under lazy embedding an item is complete without its vector, and the drain derives the vectors of +the current versions (`core/ingest/derive.py:85-118`). A version superseded before the drain +reached it never gets one. So at a past cut the plane can hold nothing for a version that was +the head, and the rule is the one two-phase ingestion already has: the item is pending, a +semantic clause ranks it by the lexical index or reports it, and no vector is invented (ING-21). +`[DERIVED from ING-19, ING-21]` + +The first window of §9.2 and lazy derivation are then one mechanism run in two directions. A +derived row is an entry of a cache of a function of a content digest and an identity (§5.2, +§5.3): present or absent, reported when absent, derivable again from the raw object while the +ledger holds it. The drain run over the versions a cut holds derives what a cut's readers ask +for, and nothing obliges an instance to derive a past nobody reads. + +### 9.4 The utility field + +The field is the fold of its update over the use log (UTL-4, `evolve_append`), so it is a derived +view in the sense of §5: its use log is a chain of the cut, its tick the position, and the field +as of a cut is the fold of the prefix, continued from a kept checkpoint over the uses since +(`foldAt_readBetween`). `[THEOREM: SNP-3 with UTL-4]` That answers the first open question of +dn-utility-field: the field's clock is a chain of the cut, `use`, and the field as of a cut is +then exact. Two more things follow. + +- **The use log has a natural horizon.** A site left alone returns within `ε` of its baseline after + `log(c/(lam ε))/lam` ticks (UTL-2, `idle_window`), so a horizon that far behind the head, with the + field's state at the horizon kept, is exact from the horizon on and loses nothing a reader of the + present could see. No chain but the chain of records reads the use log, so a cut under its horizon + lowers that chain, the chain of records with it, and no other (§7.1). `[DERIVED from UTL-2, SNP-3 + and SNP-10]` +- **The field could order what retention drops.** The order a pass drops in is by age: the + oldest closed versions first. When a window forces a choice among the derived rows of + superseded versions, the ones whose sites stand at the baseline were not used for anything + that produced value, and could go first instead. `[HYPOTHESIS: checked by comparing, on the corpus + instance, how often a pass ordered by the field drops a row a later cut asks for against a + pass ordered by age; falsifier SNF-9]` + +## 10. The laws + +Each law is stated so that it becomes a property test when its stage is built, and is proved +now. The Lean names are in `formal/Palace/Snapshot.lean`, the attacks and controls in +`formal/PalaceTest/Snapshot.lean`, by seed. `[THEOREM]` throughout. Each law also says what in +it is a theorem and what holds because the model was built that way, since the second kind +passes to the code only as an obligation of the stage that transcribes it. + +- **SNP-1 append invariance.** A read at a cut inside the store, a read between two such cuts and + every derived view are unchanged by any growth of the store (`readAt_grow`, `readAt_of_extends`, + `readBetween_grow`, `appendInvariant_view`), also under an erasure and a grant (`visible_grow`, + `snapshot_grow`, `shown_grow`), for the keyed forms (`stateAt_append`, `genRead_gens_append`) and + for the filtered read of SNP-8 (`kept_grown_iff`). By construction: a store is a family of lists, + so growth is append and nothing else. That the code's stores only append below a cut is what the + stage's test checks. Controls: the reader that ignores the cut + (`Witness.present_not_appendInvariant`); a read at a cut past the head (431, 487, 488). Attacks + 430, 432, 446. The test, at SN-1: over random sequences of catalog writes, `read_at(chain, c)` and + `state_at` of every path at `c`, taken after every further write, equal the ones taken when `c` + was the head. +- **SNP-2 monotonicity.** The read at an earlier cut is a prefix, chain by chain, of the read at a + later one, and a cut of a cut is the meet (`readAt_mono`, `mem_readAt_of_le`, `readAt_readAt`, + `head_readAt`, `visible_mono`), and the filtered read of SNP-8 grows with the cut (`Kept.mono`). + Controls: the read at one cut taken for a prefix of the read at any other (434); a cut of a cut + taken for the join (500). Attacks 433, 435, 515. The test, at SN-1: for `a ≤ b`, + `read_at(chain, a)` is a prefix of `read_at(chain, b)`. +- **SNP-3 composition.** The read at `a` followed by the read between `a` and `b` is the read at + `b`, and two adjacent reads-between compose (`readAt_append_readBetween`, `readBetween_append`); + a fold continued from a checkpoint over the delta is the fold of the prefix + (`foldAt_readBetween`, `stateAt_eq_foldl`); an event, or a pair of events, read at the later cut + was read at the earlier one or lies in the delta (`mem_readAt_iff`, `pair_readAt`); a key the + delta does not write has one state at both cuts (`stateAt_eq_of_not_written`). Controls: the + two cuts in any order (437); two reads-between composed in the other order (502); the delta + left out (503, 505); a key's state taken for unchanged whatever the delta writes (477). + Attacks 436, 438, 439, 447, 475, 476. The test, at SN-1: the catalog rebuilt from the state at + a checkpoint and the delta equals the catalog; at SN-8: the region of §7.4. +- **SNP-4 idempotence.** The read at the head cut is the store, and every reading at it is the + present's (`readAt_head`, `readAt_of_head_le`, `view_head`, `genRead_gens_length`, + `snapshot_head`, `shown_head`, `servedAt_length`, `servedNow_length`, `historyAt_length`, + `visible_head`). Control: the read at a cut that is not the head taken for the store (501). + Attack 440. The test, at every stage: a sentence under `as of "head"` returns what it returns + without. +- **SNP-5 a derived view depends only on the prefixes.** A reader is append invariant exactly + when it reads only the prefixes, exactly when it is a derived view (`prefixOnly_view`, + `view_congr`, `appendInvariant_iff_prefixOnly`, `appendInvariant_iff_exists_view`). For keyed + writes the generational store read at a cut is the state recomputed from the prefix and the + key's last write inside it, and at most one generation of a key is alive at a cut + (`genRead_gens`, `stateAt_eq_lastWrite`, `length_filter_selects_le_one`). Controls: the store + rewritten in place (`Witness.stateOf_forgets`, 444); generations without the closing stamp + (445). Attacks 441, 442, 443. The test, at SN-1: the three reads of the log agree at every + position, before and after rows are emptied, and no path has two rows alive. +- **SNP-6 grant restriction.** A narrower grant's snapshot is the restriction of a wider one's; + a snapshot reads only the chains the grant names and the cut on them; restricting to chains + commutes with the cut; the grant and the erasure applied together keep both (`snapshot_narrow`, + `snapshot_congr`, `snapshot_grow`, `restrict_restrict`, `restrict_readAt`, `shown_narrow`). The + cut read on a set of chains that read from no chain outside it is a function of that set + (`ResolvesIn.eq_on_of_closed`). By construction: the grant is an argument of the reader and + not of the cut, so that it is the asker's now is a choice of the model, not a theorem. + Controls: an event filter applied before the cut (`Witness.filter_before_cut`, 449); positions + that count hidden events (`Witness.position_channel`, 451); a named chain that reads an + unnamed one (`Witness.resolution_reads_unnamed`); a narrower grant under a smaller erasure + (510). Attacks 448, 450, 509. The test, at SN-4: of two grants one under the other, the rows + the narrower is shown at a cut, and the members of a sentence whose answer is a filter of + those rows, are the wider one's masked; a sentence that scores or ranks is not tested so + (§6.3); and landings of a class the grant does not name change neither the rows shown at a + recorded cut nor the cut shown. +- **SNP-7 erasure dominance.** No erased event is visible at any cut; a larger erasure shows a + sublist; the store with holes keeps every position; stores that differ only in erased events + read the same at every cut; a kept row is served only when none of its sources is erased + (`not_erased_of_mem_visible`, `not_erased_of_mem_shown`, `visible_sublist`, `head_redact`, + `redact_readAt`, `visible_eq_reduceOption`, `visible_congr`, `erased_invisible`, + `mem_serve_iff`, `serve_sublist`). A read by key on a chain whose holes keep their keys is the + key's last write at or under the cut, a hole when that write is erased, on all three reads + (`stateAt_holes`, `stateAt_holes_of_erased`, `not_erased_of_stateAt_holes`, + `genRead_gens_holes`, `lastWrite_holes`). A key retired after a cut is served at no earlier + cut, growth changes a served value only by removing it, and the looser seal serves what the + stricter one serves (`stateAt_of_servedAt`, `servedAt_append_of_retire`, + `servedAt_append_of_no_retire`, `servedAt_of_append`, `servedNow_of_servedAt`, + `servedNow_of_not_live`). The seal covers the key's versions: the history served ends at the + value served, a retire after the cut empties it, and after a retire it holds only versions + landed since, at every cut (`getLast?_historyAt`, `historyAt_append_of_retire`, + `historyAt_of_retire_inside`, `sinceRetire_append_retire`). By construction: these are laws of + a reader that reads `visible`, `holes` or `historyAt`. That every reader of every store in the + code does is the reach of SN-3, checked by its scan, and no theorem. Controls: the erasure + that deletes rows (`Witness.compact_moves`, 455); the hole that loses its key + (`Witness.keyless_hole`, 496, 497); the state served without the seal (458); the looser seal + taken for a monotone one (`Witness.servedNow_restores`, 474); the history without the seal + (513); kept rows served without their sources (460). Attacks 452, 453, 454, 456, 457, 459, + 473, 495, 511, 512. The test, at SN-3: after a purge no read at any cut and no scan of the + instance's files finds the purged words; after a purge of an old version of a live path, the + read of the path at a cut where that version was the head is a hole, by all three reads; after + a retire no cut before it serves the identity, and after a new note lands at the path no read + of its history, at the head or at any cut, returns a version from before the retire. +- **SNP-8 resolution.** Every frontier resolves to exactly one greatest consistent cut under + it, monotonically; a consistent cut stays consistent as the store grows; a cut consistent for + a recorded bound on the references is consistent for the true ones (`exists_resolves`, + `Resolves.unique`, `Resolves.mono`, `resolves_self`, `Consistent.of_grown`, + `Consistent.of_bound`). The consistent cuts are CLK-2's cuts among the frontier cuts + (`consistent_iff_isCut`), so their closure under meet and join is CLK-2, cited and not + claimed here (`Consistent.inf`, `Consistent.sup` and `consistentCuts`, derived from + `Clock.IsCut.frontier_inf` and `Clock.IsCut.frontier_sup`; `consistent_zero` for the bottom). + The references the resolver does not follow are kept by a filter of the read: a row is + withheld when it fails its own test, when a source of it lies outside the cut or when a + source of it is withheld. The filtered read holds the sources of its rows, is the greatest + such set inside the cut, is the prefix at a cut consistent for every reference, and never + withholds a row whose references are all resolved (`Kept.source`, `Kept.passes`, + `kept_of_closed`, `kept_iff_of_consistent`, `kept_of_resolved`, on `Withheld.anti` and + `Withheld.of_grown`). By construction: which references are resolved and which filtered is + the design's reading of the writers (§3.5), and that every reader of `att`, `runs` and the + `interp` chains at a cut goes through the filter is the stages' to transcribe. Controls: a + frontier taken for a cut (462); a consistent cut advanced by one position (464); resolution + taken to fall as the frontier rises (490); a pass attestation's reference resolved, which + lowers a landing chain that serves its position (`Witness.pass_drags`); the prefix read where + that reference is filtered, which is not closed (`Witness.pass_withheld`, 518); the filter + without its closure (517). Attacks 461, 463, 465, 514, 516. The test, at SN-2: the resolver + against enumeration on small stores, and no recorded cut with a resolved reference crossing + it; at SN-5 and SN-6: at every cut, no row served whose source, by any reference of §3.5, is + outside the cut or withheld, and at the head no row withheld that the present read returns. +- **SNP-9 certified cuts.** A certificate verifies on every extension of the store; under a + collision-free digest two stores that verify one certificate have the same prefix of every + digested chain at its cut and the same derived views of it; a certificate extends over the + delta; the meet and the join are certified from the two certificates; an erasure that keeps + commitments keeps every certificate, and a certificate attests no erasure; under a binding + commitment a certificate over commitments pins the events, so two stores that verify it read + the same store with holes under one erasure, and show the same under one grant and one + erasure (`verifies_certify`, `verifies_certify_of_extends`, `eq_of_chainDigest_eq`, + `Verifies.readAt_eq`, `Verifies.view_eq`, `certify_digest_readBetween`, `certify_inf`, + `certify_sup`, `commitments_purge`, `verifies_purge`, `verifies_purge_iff`, + `contents_purge_committed`, `Verifies.readAt_eq_of_committed`, `Verifies.contents_eq`, + `Verifies.shown_eq`). By hypothesis, not by theorem: the digest is collision free and the + commitment injective. Controls: a digest with collisions (`Witness.digest_collides`, 468); a + digest over contents, which an erasure changes (472); a seal written after the cut + (`Witness.seal_not_certified`); a renamed chain (`Witness.rename_breaks_certificate`); the + certificate of a cut past the head (489); the meet certified from the later digest (504). + Attacks 466, 467, 469, 470, 471. The test, at SN-2: a certificate verifies after any further + writes, on a copy of the files and after a purge, and fails when one row under the cut is + edited or a chain is given another id. +- **SNP-10 the horizon.** A generational store pruned at a horizon is exact at every cut from the + horizon on and never wrong under it; horizons compose to the later one; pruning commutes with a + later landing (`genRead_prune`, `genRead_prune_gens`, `stateAt_of_genRead_prune`, `prune_prune`, + `prune_landGen`). Among the positions the chains serve, every frontier resolves to exactly one + greatest consistent cut, which never passes the cut asked and rises with the frontier and with + served positions that grow (`exists_resolvesIn`, `ResolvesIn.unique`, `ResolvesIn.mono`, + `ResolvesIn.le_resolves`, `resolvesIn_univ`, `resolvesIn_self`). A chain that no other chain reads + is lowered alone, and so is every such chain at once (`Consistent.update_of_unread`, + `resolvesIn_update_of_unread`, `resolvesIn_of_unread`); a chain that reads the lowered chains, and + that nothing but itself reads, follows them and takes nothing with it (`resolvesIn_of_followed`). + Controls: the pruned store read under its horizon, which cannot tell a lost key from one never + written (`Witness.prune_forgets`, `Witness.prune_indistinct`, 480); a record on a chain that + content reads (`Witness.record_drags`); a chain of records taken to be read as recorded when a + chain it certifies is lowered (`Witness.record_follows`, 520); a chain that others read lowered + alone (499); served positions that shrink (`Witness.served_set_shrinks`, 507); a frontier lowered + to the served positions without the descent (483); the floor and the descent each run once, in + either order (493, 494); pruning at the earlier of two horizons (491); the cut read taken to reach + the floor, or the resolution of the frontier (506, 508). Attacks 478, 479, 481, 482, 484, 485, + 486, 492, 498, 519. The test, at SN-2: the served resolver against enumeration; at SN-4: the cut + read is under the cut asked on every chain, and at a recorded cut it differs from the record only + on the chains that could not serve and on the chain of records; at SN-7: every read at a cut from + the horizon on is the same before and after a retention pass. + +What the model leaves out, said plainly. A chain is a list and a store a family of lists: one writer +is assumed, and nothing is said of two. Events are opaque, and so is the stores' SQL. The set of +chain keys is fixed: a relabel is not in the model, which is why a chain has an id that a relabel +does not change (§3.1). The hash's collision freedom and the commitment's binding are hypotheses of +SNP-9 (`CollisionFree`, an injective `commit`), not theorems about SHA-256. The `unseal` and +`horizon` events are not in the model of the seal, and the owner's gate on them is the code's. There +is no single reader in the model that applies the cut's resolution, the grant, the erasure and the +seal together: `shown` composes the grant and the erasure over one read, the seal is stated on a +keyed chain, and the resolution on cuts; the sentence's reader applies the resolution first, then +`shown`, then the seal to each keyed read, and that order is the code's to transcribe. The row +filter of §3.5 is in the model as `Kept`, with the reads-from relation and each row's own test as +parameters; what the code's rows read is §3.5's reading of the writers and no theorem, and the bound +a pass attestation records is argued there, not proved. The filtered read is a derived view, not a +prefix. A repository history with merges is covered by CLK-2's down-sets and not by the chain model +(§3.1). The resolver, the descent and its alternation with the floor, is attacked, not proved. + +## 11. Measurements + +Every figure measured for this note is from a synthetic fixture: a temporary directory or +in-memory stores built by the probe, the test suite's throwaway palace for the purge, and +nothing of any instance. The other figures the note uses are the repository's own records of an +instance, cited where they stand and graded `[ESTABLISHED]`: the attestation ledger's bytes a +row, the job rate, the citation store's rows and bytes, the plane's bytes an occupancy and the +curated table's bytes an atom (`docs/experiments/corpus-measurements-2026-11-07.md:94-107`, +`docs/experiments/corpus-stage1-2026-11-07.md:416`, `core/reference_view.py:15-16`). Figures +given as arithmetic are marked so where they stand. + +The probes are short scripts and are not in the repository: this pull request changes no +Python, and the newest notes keep a harness under `eval/` with a record under +`docs/experiments/`. So these figures cannot be repeated from the tree as it stands. Each stage +of §12 commits the harness of what it builds with its record: SN-1 the log's size and reads, +SN-3 the purge probe as a test, SN-5 the causal probes. The table gives each fixture closely +enough to be built again. + +One machine (Apple M2 Pro, 12 cores, 32 GB, macOS 27.0) with other work running, the load +average between 2.4 and 5; Python 3.15.2, SQLite 3.54.1, LanceDB 0.33.0; the code at `e3e3ee47`. +The timings are medians with their ranges. Each probe was run at least twice, and a range across +the runs is given where they differed. `[MEASURED]` + +| probe | fixture | result | +|---|---|---| +| the landing log | the two tables of §3.2 with their three indexes, in one SQLite file; one chain, 100,000 paths of 37 characters with titles under twelve, ten landings a path in a shuffled order, one transaction, every row keyed, committed to and hashed and the path's previous row stamped; built twice, with every identity its path and with every identity a nine-character id | 1,000,000 rows in 434.3 MB where the identity is the path: 434 bytes a row (table 374, key index 47, closing index 13, identity index empty); 396.5 MB where it is an id: 396 bytes a row (table 315, key index 47, identity index 21, closing index 13); 35,000 to 42,000 rows a second written | +| its reads | the same files, 200 repetitions a point read, 5 a scan | one path at the middle cut 3 µs through the key index, and 1.4 to 1.5 µs for the keyed hash of its path; a path's seven versions at the middle cut 9 µs through the key index and 49 to 57 ms when the planner took the primary key; 1,000 positions 0.64 to 0.69 ms; every head 52 to 56 ms at a cut a tenth of the way in (65,103 rows), 147 to 166 ms at the middle cut (99,916 rows) and 240 to 275 ms at and near the head (100,000 rows); the chain's hash recomputed from the first row in 0.71 to 0.76 s; the stored hash at a position read in 3 µs | +| a hole in the log | the same files: the fifth of one path's ten rows emptied as §6.1 says, its key kept | the seek by key at the last cut before the path's next landing returned the emptied row, with no digest | +| a kept version in the lexical index | `LexicalStore` on a temporary file; 500 items of 4 chunks in 3 versions, each chunk 171 words drawn from a vocabulary of 20,000 with frequencies falling as the inverse of the rank | 6,000 units held, 2,000 of them current; 734,409 postings, 122 a unit; 25.1 MB, 4,179 bytes a unit; superseded share 0.67 | +| what a purge leaves | the test suite's throwaway palace (`tests/fixtures/ingress.py:73`), lazy, with its fake embedder: two notes landed and drained, one edited and drained, then deleted from the vault, then both its digests purged (`purge_raw`); a control note never purged, found at every step | gone: the raw objects, the plane's occupancies and supersession entries, the catalog rows. Left: the words in the vector table read at versions 2 to 9 and 3 to 7 of its 10; the lexical units, postings, title and version records; both version rows; one attestation a digest | +| after the purge | the same palace: the vector table compacted with no retention; every SQLite file checkpointed, then vacuumed; a new note landed at the path | the compaction left 1 dataset version and no purged word in the table's files; the deleted catalog and plane rows' path and digest were still in the files' bytes after the checkpoint and gone after the vacuum; the plane's supersession log held position 1 for the path again, and the version chain appended number 3 | +| the order of two jobs | in-memory stores; one session with a commit event; the ledger holds the commit before the integrator's first pass, or gains it after | 1 edge against 0, and still 0 after a second pass, the session being skipped as unchanged | +| the events of a prefix | a transcript of four records: a prompt, a reply with a `git commit` call, the call's result with the sha, a reply | the prefix that ends before the result gives the commit event an empty reference; the whole gives the sha; the two longer prefixes agree with the whole | +| re-deriving a session | a synthetic transcript of 2,000 records, 0.79 MB, 7 repetitions | 6.0 to 6.1 ms median (5.7 to 7.2) | +| what `as of` accepts | the unit tests' store fakes, with two readings in the reference store and with none; the real reference store on an empty temporary file; git read-only on the checkout | with readings held: `as of "HEAD"` and `as of "2026-11-01"` refused, a sha prefix accepted. With none held (`latest_commit()` is `None` on the empty store): `as of "HEAD"`, the date and an unknown name all answered, the universe's cut the string asked | +| `read` under `as of` | the same fakes, one reading at a commit of the checkout fourteen back and one at a sha of forty `d`s that git does not hold | at the commit git holds: that commit's blob and not the head's, under a note saying that `read` read the present, the hit carrying no commit; at the sha git does not hold: `HEAD`'s blob, the same note, the same hit | +| row numbering | a table keyed by text, five rows, in a temporary file | after the last row was deleted the next insert was numbered 5 again; a vacuum after a delete in the middle kept the numbers | + +Not measured: anything on an instance's own stores; the size of a recorded cut, of a chain table's +row and of a row of the log that a window emptied, which are arithmetic; how often a row of model +output is replaced; the lexical statistics computed from a mask at a corpus's size; the causal fiber +recomputed over a real instance's sessions, cold or warm; a vector search with superseded rows +joined to the heads at a cut; the reads of the chat log and the attestation ledger through their +chain tables; a retention pass. Each is the measurement of the stage that builds it. + +## 12. The build order + +Nothing is built by this note. What the merge licenses is decision D12. The stages, each a pull +request against main with its tests and its rollback, each transcribing its laws and +property-testing the transcription against the Lean statements; the laws a stage relies on enter +`docs/LAWS.md` and `formal/Spec/` with it, as design theorems do when code comes to rely on them. + +- **SN-1 the landing log.** What is built: + - The tables `landing_chains` and `landings` of §3.2 with their three indexes, in the + catalog's file, created by the catalog's own migration after it fills `doc_id` + (`core/stores/catalog.py:77-92`), and the genesis of §3.2 for each class the catalog holds. + - The log written inside `record`, `tombstone`, `relabel_provenance`, + `migrate_rekey_doc_id`, `remove` and `remove_digest`, in the transaction of the row each + writes, so that a `deferred()` batch (`catalog.py:125-138`) carries its log rows. `record` + gains a `version` argument (`None` where the place keeps no chain), passed at + `writer.py:419`, `:433` and `sync.py:201`. `att_head` is `NULL` at this stage. + `relabel_provenance` rewrites the label in `landing_chains` and no row of `landings`. + `remove` and `remove_digest` empty the log's rows of the path or of the digest as §6.1 + says, the key kept, so the purge's effect on the log is this stage's and not SN-3's. + - The reads, on `VaultCatalog`: `chains(class)`; `head(chain)`; `read_at(chain, c)`, the rows + with `seq ≤ c` in order; `state_at(class, path, c)`, the path's last event at or under the + cut over the class's chains, which is a `store`, a `retire` or `move`, a hole, or nothing; + `history_at(class, path, c)`, its `store` rows at or under the cut; `heads_at(class, c)`, + the `store` rows alive at the cut over the class's chains, a hole returned as a hole with + its position and no name; `read_between(chain, a, b)`; and `verify(chain)`, which recomputes + the hashes from the first row and the commitment of every row that still has its salt. The + statements of `state_at` and `history_at` name `landings_path`. Here `c` is a position of a + chain, or for a class one position a chain. + - Nothing reads them yet, and no reader's behaviour changes. + + Tests, in `tests/property/test_landing_log.py`: SNP-1 to SNP-5 as §10 states them, over + random sequences of catalog writes that include retires, renames, relabels and purges; the + catalog equals the fold of the log after every write, a purge included; a `record` that + changes nothing, and a store the UNCHANGED check skips, write no row; a transaction killed + between the two rows leaves neither; the genesis equals the catalog, tombstoned paths + included, and is followed by a horizon; after a relabel into a class that has rows, no row of + the log changed and every chain verifies; after a purge of an old version of a live path the + three reads return a hole at a cut where it was the head; `verify` fails on an edited row. + + The ledger: `docs/LAWS.md` gains a family XVI, the temporal snapshot, with rows SNP-1 to + SNP-5, each with its statement as §10 gives it, the reads above as its code, the tests above, + and the Lean declarations §10 lists for it. `formal/Spec/Snapshot.lean` restates those + declarations over `Palace/Snapshot/Defs.lean` with their proofs left out, and + `formal/comparator.json` gains their names, as the last family added did. + + Rollback: the tables are additive and unread, so dropping them restores the file; a build + that stops writing them and resumes later appends a `horizon`. +- **SN-2 cuts.** The chain tables, each with its running hash and its genesis followed by a horizon, + for `chat`, `att`, `staging` and `runs`; `att_head` filled from then on; on the chain-table row of + a pass attestation and of a run, the landing chains that held its inputs and the head of each + (§3.5); the extractor's version and the projection's position on `att` stamped on new citation + edges, the edges already held stamped with the genesis; the `cuts` table of §3.3, a record at a + trough that moved and on command, and an attestor method that builds and signs an attestation + without appending it; the four names, with every name that resolves to nothing refused; the + resolver of §3.5, the floor and the descent alternated; a command, `mind-palace cut` with + `record`, `list` and `verify`. Tests: SNP-8 and SNP-9 as stated; the served resolver against + enumeration; a record refused inside a job, and refused with jobs queued and no daemon; a cut read + below a record on one chain reading the chain of records at its last record under it. SNP-8 enters + the ledger as resolution, with its closure cited to CLK-2's row, and SNP-9 with it. Rollback: + additive tables and columns; the names fall back to today's. +- **SN-3 the erasure's reach and the seal.** A purge removes the lexical units, nulls the + version rows' digests, removes the relation edges and artifacts that name the digest, opens + the curated store, nulls the support and text of the dream claims and the digest and payload + of the staging rows, removes the claim ops on a removed artifact and the rejected requests + that hold the text, compacts both vector tables and writes its attestation, which names the + positions it emptied (§6.1); decision D9's form for the attestation ledger; the seal by + identity over the value and the history, and the owner's `unseal`. It lands before SN-4, since + SN-4 is the first stage that reads a superseded version. Tests: SNP-7 as stated, with the + purge probe of §11 turned into a test that must find nothing. Rollback: a purge has none by + its nature; the rest is additive. +- **SN-4 the notes at a cut.** The universe's nodes from `heads_at`, with kept heads for a chain + over the size §4.2 gives; `read` from the raw object the log names, and refused for a + repository path whose commit git lacks; the vectors and the lexical units joined to the heads; + the pending rule at a cut; the curated rows that landed through the catalog, and the count of + those that did not; the citation reading as projected at or under the cut; `trace` at a cut; + the cut read and its note (§7.1), which retires the note that says a verb read the present; + the commit on a `read` hit. Tests: `as of "head"` against no `as of` over the query battery + (`eval/query_battery.py`); a sentence at a recorded cut asked before and after unrelated + landings and after a re-projection; SNP-6 with two grants, as §10 states it; the cut read + under the cut asked, and equal to the record but for the chains that could not serve and the + chain of records. Rollback: one configuration switch under `[query]`, off being today's behaviour. +- **SN-5 the causal fiber at a cut.** The recomputation of §5.5 with its memo; edges named by + session, order and endpoint; the transcript integrator's checkpoint a cut on `chat` and `repo`; + `witness` at a cut, the ledger read by sequence number with the pass attestations filtered (§3.5). + Tests: the two job orders giving one result; the prefix that ends before a result; the stored rows + at the head equal to the recomputation; a pass attestation withheld at a cut that lacks a landing + it read, the attestations after it served, and none withheld at the head. Rollback: the stored + rows stay the head's cache. +- **SN-6 model output by generation.** A sequence number, a running hash and a history table + for the interpreted artifacts and the interpreted relation edges, a chain each; a sequence + number and a running hash for the claim ops and the authored supersessions, which need no + history table since no row of theirs is replaced; the authored relations recomputed at a cut; + `relate` at a cut; a kept row served only with its sources inside the cut and its attestation + kept there, a claim op only with the artifacts it names, a dream claim only with its run + (§3.5, §5.4). Tests: SNP-5 on random sequences of writes and replacements; `mem_serve_iff`'s + test; SNP-8's filter as §10 states it; an artifact replaced over the same titles served with + the sources each generation had. Rollback: additive columns and tables. +- **SN-7 retention.** The two windows a chain in the instance's configuration; the pass of + §9.2; the `horizon` row; the horizon in the answers. Tests: SNP-10 as stated; a pass killed at + each step leaving no served position incomplete; a derived row dropped under the first window + reported pending and derived again; a cut asked under a landing chain's new horizon read with + every other landing chain, `att` and `repo` as recorded, the chain of records at its last + record under the cut read, and the rows that read a landing of the lowered chain withheld; + after a pass, `verify` of the chain passing from its first row and a certificate taken before + the pass still verifying. Rollback: none for dropped rows by their nature; nothing runs + unless a window is declared. +- **SN-8 the delta.** `changed between` and `changed since` (§7.4); the integrator interface + below. Tests: the region's union law, and equal reads at both cuts for an identity outside it. + Rollback: the region is a new production of the grammar and the interface a new module, so + both are withdrawn by removing them; no store changes. + +**A generic integrator on the delta.** An integrator job is a registered, scoped job that reads +what changed and writes one batch of edges with their evidence. Its checkpoint is a cut `a`. A +run takes `b`, the greatest consistent cut under the head on the chains the job reads; reads +`read_between(a, b)` on them; writes its batch, every edge's sources inside `b`; and records `b` +as its checkpoint in the transaction of the batch. Three laws make that correct. The state the +job would compute from the whole prefix at `b` is its state at `a` continued over the delta +(`foldAt_readBetween`), so a run and a rebuild agree. The delta up to `b` is the same however +the stores grow while the job runs or after it (`readBetween_grow`), so a run repeated after a +crash reads what the interrupted one read, and anything more lies after `b` +(`readBetween_append`). And for a job that joins two chains, a pair read at `b` was read +at `a` or has a member in the delta (`pair_readAt`), so the job visits the old events of one +chain only against the new events of the other. The transcript integrator is the case at hand: +it joins `chat` and `repo`, a commit that reaches the ledger after its session was read is a +delta on `repo`, and the session's unresolved commit events are visited against it, which the +digest it keeps a session today does not do (§2.3, item 4). The integrators that +dn-decision-integrators designs, and the embed drain, are jobs of this shape; their designs stay +where they are. `[THEOREM: SNP-1, SNP-3; DERIVED for the job]` + +## 13. Decisions for the owner + +Each with the recommendation and what the alternative costs. Where a cost has a figure it is +given. D3, D4, D6, D11 and D12 are choices of behaviour: they have no cost in bytes or time to +give, and what each alternative costs is the answers it changes, which the entry states. + +1. **D1, where the catalog's past is kept.** Recommended: the landing log in the catalog's file, + written by the catalog (§3.2), at about 0.4 kilobytes a landing on the fixture. The + alternatives: version chains for every place, which is a second file, so the key and its + history are two transactions, one more commit a landing, and ING-7's order gains a stage, and + whose chains are per document, so a cut is a pair an item; or the plane's supersession log, + which an instance with no plane lacks, which records the drain's order under lazy embedding, + and which gives a position again after a purge. +2. **D2, the grain of a cut.** Recommended: one position a chain, the landing chains each of one + provenance class (§3.1): about a dozen integers. The alternatives: a position a document, + which today's spine has only for the one place that keeps version chains and which, extended + to every place, is ten million pairs a cut at the scale the corpus records plan for; or one + landing chain for every class, which saves a few integers a cut and tells a narrower reader, + by its positions, how many landings the classes it cannot read made. +3. **D3, what a retire does to the past.** Recommended: the stricter seal, by identity, over the + value and the versions, lifted only by the owner's `unseal` (§6.2). The alternative, the + looser seal, brings a deleted note's versions back at earlier cuts when another note is + written at its path, and lets a past answer grow; it needs no unseal when a vault is missing + at a sync, where the stricter one needs one row. Neither is free at the head: under both, + the history of a note written at a deleted note's path has to stop at the delete, which + today it does not (§2.3, item 8). +4. **D4, a store that cannot serve the cut asked.** Recommended: read at the greatest consistent + cut among the positions the stores serve, and name it (§7.1). With the recorded cuts on a + chain of their own (D13), and the rows that read a landing without being its record filtered + and not resolved (§3.5), that lowers only the chains that could not serve and the chain of + records; the rows that read what was lowered are withheld and counted in the answer's note. + The alternatives: + refuse the sentence, after which `as of` answers nothing that touches a store without a past + until SN-6, and nothing under a horizon ever; or keep today's behaviour, which answers from + after the cut and changes as the store grows. +5. **D5, the embedder's and the tokenizer's identity at a cut.** Recommended: the present's + (§5.2, §5.3). The alternative, the identity in force when the content landed, needs every + identity's vectors kept, a vector table an identity (1,536 bytes an atom at the present + dimension and precision), in a plane that refuses a second identity today. +6. **D6, the names `as of` takes.** Recommended: `head`, a recorded cut's id, a commit, a date + (§3.4). The alternatives: commits only, as today, which leaves no name for a moment between + two commits and none on an instance with no repository; or dates without the cut read in the + answer, which gives an answer that cannot be asked again. +7. **D7, between two cuts.** Recommended: the region `changed between` and `changed since` + (§7.4), one range read of the log. The alternatives: nothing, and every integrator and every + question about change is a hand-written read; or a general two-cut adjective, which is a + second universe a sentence and a pair sort, and which dn-graph-dynamics designs already as + GD-4. Neither alternative is sized here. +8. **D8, retention.** Recommended: no window on the default instance; where the disk is bounded, + a window for derived rows, which moves no horizon and frees what a superseded version mostly + costs, about 29 kilobytes of derived rows for a note of four chunks by §9.1's arithmetic; and + a window for the history only when the owner declares one, since it drops raw objects + (§9.2), and at the cuts under the new horizon withholds every pass attestation, dream claim + and interpreted row that read a landing of the chain. The alternatives: a horizon + everywhere, which over the first window frees only a closed version's raw bytes and about + 0.3 of its 0.4 kilobytes of log, by arithmetic, and loses the default instance's history for + it; that trade is worth making only where raw objects are large, as a transcript + retained whole at each growth is (0.79 MB a growth on the fixture). Or the last `n` versions + an identity, which leaves no horizon to name. +9. **D9, the attestation ledger under a purge.** It still names a purged digest (§6.1), against + the plane's rule that no content hash of purged text is kept. Recommended: from SN-3 on, an + attestation names a content digest by a salted commitment, the salt held in a side table of + the attestation store keyed by a keyed hash of the digest, written in the transaction of the + first attestation that names the digest. The landing order does not change: the attestation + still comes before the key, a re-run after a crash finds the salt by the digest and attests + nothing twice, and the landing still reads from its attestation. A purge deletes the side + row, after which no attestation can be tested against a guess of the content. It costs a + side row a distinct digest, of the order of a hundred bytes; a lookup an attestation; every + reader that matches an attestation's hashes against a digest going through the side table + (`core/attestation/attestor.py:59-69`, `core/ingest/landing.py:60-75`); and an outside + verifier needing the salt to check an attestation against bytes. The rows written before + stay, and a purge lists their ids as what it could not reach. The alternatives. Name the + landing log's commitment in the attestation: the log's row, its salt and its position are + written in the key's transaction, last, and its commitment covers `att_head`, so either the + attestation moves after the key, which reverses the reference of §3.5 and leaves a landed + item unattested after a crash between the two, or the salt and the position are fixed before + the attestation, which is a write before ING-7's first stage. Rewrite the ledger at a purge, + which breaks its construction as append-only and every id computed from a row. Or leave it, + and a digest of purged bytes stays. +10. **D10, model output.** Recommended: the interpreted artifacts and the interpreted relation + edges kept by generation (§5.4). The alternative, outside the snapshot, costs nothing and + means `relate` over interpreted edges and the dreams are never read at a past cut. The + relations a note declares are not part of this decision: they are recomputed at a cut + either way. +11. **D11, the read-only principal at a cut.** Recommended: the present's list, applied to the + edges inside the cut (§6.4). The alternative, the list taken at the cut's tree, shows at a + past cut a file that was tracked then and is not now, which the head withholds, and makes the + grant a function of the cut. +12. **D12, what the merge licenses.** Recommended: SN-1 and SN-2. SN-1 adds tables and changes + no reader. SN-2 adds tables, columns and names; the one behaviour it changes is that a name + which resolves to nothing is refused on an instance whose reference store is empty, where + today it is answered (§2.1). SN-3 to SN-8 change an erasure, the universe and what an + instance keeps, and each is licensed with its own pull request. The alternative, all eight + at once, saves the owner seven decisions and reviews the purge, the universe and retention + together. +13. **D13, where a recorded cut is kept.** Recommended: a chain of its own that no other chain + reads, its attestation in its own row (§3.3). That chain is read at its last record under + the cut read, and takes nothing with it. The alternative, a row of the attestation ledger, + is one table fewer and signs a record where every other attestation is signed; but every + landing reads that ledger, so a chain read below a position a record certified, as a + landing chain behind a history window is, can take every landing chain to its empty prefix + (`Witness.record_drags`). +14. **D14, what a purged row of the log keeps.** Recommended: the keyed hash of its path, with + its position (§6.1), 47 bytes a row of index on the fixture. The alternatives: keep the + path, which saves the hash and leaves a purged note's name readable in the log when every + version of it is purged; or keep no key, after which a read by path at a cut returns the + version before the purged one (`Witness.keyless_hole`). + +## Parked decisions + +| id | decision | default recorded | re-entry condition | +|---|---|---|---| +| SN-a | the cadence of recorded cuts | a trough that moved, the owner's command | a date that resolves to a cut farther from it than a declared tolerance | +| SN-b | the citation readings as rows valid over a range of commits | append-only rows a commit, stamped with their projection | the store's size on an instance | +| SN-c | the heads kept at some recorded cuts | none for a chain under 250,000 events; kept, from SN-4, for a chain over it (§4.2) | `heads_at` past a tenth of a second on a chain under the threshold, or under it by a wide margin on one over | +| SN-d | a second embedder identity's vectors kept beside the first | none: the present's identity | dn-two-phase-ingestion's open question 4 | +| SN-e | lexical statistics stored per class and per recorded cut | computed from the mask | a lexical query at a past cut over its budget | +| SN-f | `repo` as a graph of commits, and a chain a repository | the line of the branch the sensor reads, one repository | an instance whose history has merges or that reads several repositories | +| SN-g | which recorded cuts are kept under a horizon | the records stay; a landing chain keeps its commitments and hashes, so a record under its horizon still verifies there and reads nothing | a consumer that must read, and not only verify, a cut under a horizon | +| SN-h | generations with a diff for the causal fiber | recomputation with a memo | SNF-5 | +| SN-i | the curated rows written outside the catalog | outside the snapshot, counted in the answer's note (§5.6) | the script routed through the writer | +| SN-j | a date asked under a narrower grant | resolved over every record, the answer showing the record's id and its positions on the grant's chains only | a use that must hide when the instance was quiescent | +| SN-k | the genesis of a class seeded from the plane's supersession log | not seeded: the genesis is the catalog as it stands | a need for a path's order before the log existed, on an instance that has a plane | + +## Falsifiers + +- **SNF-1 (the log is not the catalog's past):** after some sequence of writes the fold of the + log differs from the catalog, or a row of one is found without its row of the other. Then the + log is not written in the key's transaction and SN-1 does not land. +- **SNF-2 (a position a document is needed):** a consumer that must name a cut holding one + document of a class at an older version and another at a newer one in an order the class's + chain did not have. Then chains are per document and decision D2 is reopened. +- **SNF-3 (a name resolves far from what was meant):** a date, or a commit, whose recorded cut + lies farther from it than the tolerance SN-a declares. Then the cadence changes; the names do + not. +- **SNF-4 (the cut read misleads):** readers take an answer at a lowered cut for the answer at + the cut asked, seen as `as of` sentences in the query log asked again without `as of` after an + answer with a lowered chain. Then such a sentence is refused (D4's first alternative). +- **SNF-5 (recomputing the causal fiber is too slow):** a sentence that walks `C` at a past cut + over a second on a real instance, the memo warm. Then generations with a diff (SN-h). +- **SNF-6 (the threshold for kept heads is wrong):** `heads_at` past a tenth of a second on a + chain under 250,000 events, or the kept heads costing more than the read they save on one + over. Then the threshold moves; on the fixture the read from the log alone passes a tenth of + a second between 100,000 and 500,000 events (§4.2). +- **SNF-7 (the mask is too slow for the lexical statistics):** a lexical query at a past cut over + its budget at the instance's size. Then SN-e; the rule that the statistics are the mask's does + not change. +- **SNF-8 (kept model output is never read):** no sentence under `as of` reads an archived + artifact or relation in a declared period. Then the archive stops and D10 takes its + alternative. +- **SNF-9 (retention drops what is asked for):** cuts asked for under a declared horizon, or a + pass ordered by the field that drops rows later asked for more often than a pass ordered by + age. Then the window grows, or the order stays age. +- **SNF-10 (the stricter seal is the wrong default):** unseals become routine, as an instance + whose vault goes missing at syncs would show. Then D3 takes the looser seal, with its cost. +- **SNF-11 (a transcription lies):** a built stage whose property test against a Lean statement + fails. A transcription defect; the stage does not land until it agrees. +- **SNF-12 (an erasure leaks):** after a purge, a read at any cut or a scan of the instance's + files finds the purged words. Then SN-3's reach is incomplete and no stage after it is on. +- **SNF-13 (append invariance fails on the code):** a sentence at a recorded cut that answers + differently after unrelated landings or a re-projection, the erasure, the seals and the grant + unchanged; or `as of "head"` that differs from no `as of`. Then some reader is not a function + of the prefixes, and SNP-5 says which kind of store to look for. +- **SNF-14 (the region is not what is asked):** questions about change that need the two + readings and cannot be put with the region. Then GD-4's form is built sooner, on the two + readings this note supplies. +- **SNF-15 (a lowering is not local):** at a recorded cut, a chain other than the chain of + records read below the record though it serves the record's position. Then some chain that + can fail to serve is read through a resolved reference by a chain that content reads, the + premise of §7.1 is false for it, and that reference is found and moved to the filter of §3.5 + or the chain is kept whole. +- **SNF-16 (a filtered row is served without its source):** at some cut, a pass attestation, a + dream claim, an interpreted row or a claim op served while a row it reads, by a reference of + §3.5 or one that list missed, is outside the cut or withheld. Then the list of §3.5 is + incomplete or a reader goes around the filter, and the stage that reads that store at a cut + does not land until it is closed. + +## Open questions + +Each with the default the stages build on until it is decided. + +- The chat log and the attestation ledger have no erasure today except a reset. Their chain + tables digest commitments so that one can leave a hole; who may erase a turn is not decided + here. Default: no erasure of a turn is built. +- A purge does not reach a backup or a migration's archive. A backup restored from before a + purge verifies every certificate and holds what was purged (§3.6), so a restore has to apply + the purges recorded since; that procedure, and whether a recorded cut is taken before a purge + so that the purge's own moment is certified, belong with the design of backups. Default: + neither is built, and the purge's attestation lists the positions it emptied so that either + can be. +- The `cuts` chain under a reset: the records name chains by id, and a reset makes new chains. + Default: the records are in the catalog's file and go with it. + +## Cross-references + +**Formal (this branch):** `formal/Palace/Snapshot/Defs.lean` (`Store`, `Cut`, `head`, `grow`, +`Extends`, `readAt`, `readBetween`, `view`, `present`, `AppendInvariant`, `PrefixOnly`, `foldAt`, +`stateOf`, `stateAt`, `lastWrite`, `Gen`, `closeAt`, `landGen`, `gens`, `selects`, `genRead`, +`prune`, `sealedAt`, `servedAt`, `servedNow`, `restrict`, `snapshot`, `redact`, `visible`, +`compact`, `serve`, `committed`, `purge`, `commitments`, `contents`, `Consistent`, `generator`, +`reached`, `Resolves`, `reachedIn`, `ResolvesIn`, `Withheld`, `Kept`, `chainDigest`, +`CollisionFree`, `Certificate`, `certify`, `Verifies`, and `sinceRetire`, `historyAt`, `holes`, +`shown`); `formal/Palace/Snapshot.lean` (the declarations §10 names, by law, and the eighteen +`Witness` controls); `formal/PalaceTest/Snapshot.lean` (seeds 430 to 520); the families cited: +`Palace/Clock.lean` (CLK-2: `IsCut`, `frontierCut`, `isCut_iff_not_crossed`, `IsCut.inter`, +`IsCut.union`, `IsCut.frontier_inf`, `IsCut.frontier_sup`), `Palace/Ingress.lean` (ING-7), +`Palace/Script.lean` (ING-17), `Palace/Derived.lean` (ING-19 to ING-21), `Palace/Plane.lean` +(PLN-4), `Palace/Utility.lean` (UTL-2, UTL-4), `Palace/Sentence.lean` (QSA-1 to QSA-4, QSA-10). + +**Code (read at `e3e3ee47`, unchanged):** `core/sentence/grammar.py`, `ast.py`, `universe.py`, +`execute.py` (`as of`, the universe, `read`); `core/query.py` (the modes, `note_graph`); +`core/temporal/spine.py` (`CertifiedCut`, `cut_at`); `core/stores/catalog.py`, `versions.py`, +`chatlog.py`, `chat_events.py`, `causal_edges.py`, `reference_edges.py`, `plane.py`, +`vectorstore.py`, `lexical.py`, `memberships.py`, `derived.py`, `edges.py`, `claim_ops.py`, +`authored_supersession.py`, `staging.py`, `observation_history.py`, `code_observations.py`, +`agent_observations.py`, `curated_store.py`, `runledger.py`, `verdicts.py`; +`core/kernel/stores/rawstore.py`, `core/kernel/recursion_ops.py`; `core/attestation/store.py`, +`record.py`, `attestor.py`; `core/ingest/writer.py`, `landing.py`, `table.py`, `purge.py`, +`derive.py`, `sync.py`, `curated.py`, `readers.py`, `ingress.py`, `stream.py`; +`core/relations.py`, `core/curator/curator.py`, `core/dreaming/dreamer.py`, +`core/complex/temporal.py`, `core/verdict/dispositions.py`; `core/chat_events.py`, +`core/integrator.py`; `ingress/sync_vault.palace`, `ingress/sync_corpus.palace`; +`scripts/purge_raw.py`, `scripts/curate_local.py`, `scripts/migrate_provenance_split.py`; +`ops/code_sensor.py`, `ops/self_sensor.py`, `ops/code_snapshot.py`, `ops/chat_sensor.py`, +`ops/heartbeat.py`, `ops/ledger.py`, `ops/effect_ledger.py`, `ops/lifecycle/launcher.py`, +`ops/lifecycle/runs.py`; `eval/harness/store.py`, `eval/predictions/ledger.py`. + +**Design:** global-event-clock §2.2 to §2.4 (the generators, Law C4, the certified frontier, +GC-N3's three certificates); +limits-of-the-algebra L7; dn-query-sentence-algebra §2.3, §2.7, §2.9; dn-ingress D1, D3, D5 +(ING-7, the one writer); dn-ingress-language (ING-13 to ING-17); dn-two-phase-ingestion D1, D2 +(ING-19 to ING-21); vector-membership-store A3.5, A3.7 (noninterference, the purge); +dn-utility-field §3.1, §4 (UTL-2, UTL-4) and its first open question; dn-graph-dynamics §6, §7.1 +(GD-4, the state at a cut); dn-decision-integrators (the integrators' layer); +dn-mathematical-foundations §2.4 (design theorems and the ledger); +`papers/2026-11-10-temporal-snapshot/paper.tex`. diff --git a/docs/tracks/query-language.md b/docs/tracks/query-language.md index 09ed944f..5ba8de4f 100644 --- a/docs/tracks/query-language.md +++ b/docs/tracks/query-language.md @@ -11,6 +11,7 @@ dod: - QL-2 the executor — clause evaluators over the existing stores, the mask/column/product/threshold operators, the product-automaton walker, the overlay for assume - QL-3 the surface — palace query, a /context skill, the resolution ledger, the query log as a sensor - QL-4 the falsifier battery run — composed sentences against flat search on owner-endorsed answers, a finding either way + - SN-0 the temporal snapshot's design proved: dn-temporal-snapshot with SNP-1 to SNP-10 machine-checked in formal/Palace/Snapshot.lean (append invariance, monotonicity, composition, idempotence at the head, derived views as functions of the prefixes, grant restriction, erasure dominance, the resolution of a frontier to a consistent cut, certified cuts, the horizon), attacks and controls green, the measurements on synthetic fixtures backlog_deskcheck: null links: - docs/design-notes/dn-query-sentence-algebra.md @@ -19,6 +20,8 @@ links: - docs/brainstorms/ingress.md - docs/design-notes/dn-two-phase-ingestion.md - docs/design-notes/dn-embedder-use.md + - docs/design-notes/dn-temporal-snapshot.md + - papers/2026-11-10-temporal-snapshot/paper.tex --- # Track — Query language (the sentence algebra, its compiler, and the surface) diff --git a/formal/Palace.lean b/formal/Palace.lean index f5703f66..a1a28363 100644 --- a/formal/Palace.lean +++ b/formal/Palace.lean @@ -65,6 +65,8 @@ public import Palace.Sever public import Palace.Sever.Defs public import Palace.SigmaStar public import Palace.SigmaStar.Defs +public import Palace.Snapshot +public import Palace.Snapshot.Defs public import Palace.Spectral public import Palace.Spectral.Defs public import Palace.Superconnection diff --git a/formal/Palace/Snapshot.lean b/formal/Palace/Snapshot.lean new file mode 100644 index 00000000..85ef1b2f --- /dev/null +++ b/formal/Palace/Snapshot.lean @@ -0,0 +1,1959 @@ +module + +public import Palace.Snapshot.Defs +public import Palace.Clock +public import Mathlib.Data.List.Induction +public import Mathlib.Data.List.ReduceOption +public import Mathlib.Order.Lattice +public import Mathlib.Order.Lattice.Nat +public import Mathlib.Order.Sublattice + +/-! +# The temporal snapshot: the laws of a read at a cut + +Design theorems of `docs/design-notes/dn-temporal-snapshot.md`, proved before any code reads a +store at a cut, on the model of `Palace/Snapshot/Defs.lean`: a store is a family of append chains, +a cut a prefix length for each. Cited from the note, not from the ledger. + +* SNP-1, append invariance: a read at a cut inside the store, a read between two such cuts and + every derived view of them are the same after any growth of the store (`readAt_grow`, + `readAt_of_extends`, `readBetween_grow`, `appendInvariant_view`). The control is the reader that + ignores the cut (`Witness.present_not_appendInvariant`). +* SNP-2, monotonicity: the read at an earlier cut is a prefix of the read at a later one, and a + cut of a cut is the meet (`readAt_mono`, `readAt_readAt`, `head_readAt`). +* SNP-3, composition: the read at `a` followed by the read between `a` and `b` is the read at + `b`, and two adjacent reads-between compose (`readAt_append_readBetween`, + `readBetween_append`); so a fold continued from a checkpoint over the events since is the fold + of the whole prefix (`foldAt_readBetween`, `stateAt_eq_foldl`): a job's checkpoint is a cut. + An event read at the later cut was read at the earlier one or lies in the delta, a pair of + events likewise, and a key the delta does not write has one state at both cuts + (`mem_readAt_iff`, `pair_readAt`, `stateAt_eq_of_not_written`). +* SNP-4, idempotence: the read at the head cut is the store, and every derived view at it is + the derivation of the present (`readAt_head`, `view_head`, `genRead_gens_length`). +* SNP-5, a derived view is a function of the prefixes: a reader is append invariant exactly when + it reads only the prefixes, exactly when it is a derived view + (`appendInvariant_iff_prefixOnly`, `appendInvariant_iff_exists_view`). For a store of keyed + writes the three ways of holding it agree: the generational store read at a cut is the state + recomputed from the prefix (`genRead_gens`), it is the last write inside the prefix + (`stateAt_eq_lastWrite`), and at most one generation of a key is alive at a cut + (`length_filter_selects_le_one`). The store rewritten in place determines no read at a past + cut (`Witness.stateOf_forgets`). +* SNP-6, grant restriction: a narrower grant's snapshot is the restriction of a wider one's, a + snapshot reads only the chains the grant names and the cut on them, and it is append + invariant (`snapshot_narrow`, `snapshot_congr`, `snapshot_grow`). Restricting to chains commutes + with the cut; filtering events before the cut does not, and a cut's positions count the events + a filter hides (`restrict_readAt`, `Witness.filter_before_cut`, `Witness.position_channel`). + The grant and the erasure applied to one read keep these laws (`shown_narrow`, `shown_grow`, + `not_erased_of_mem_shown`). The cut read on the chains a grant names is a function of those + chains when they read from no chain outside them (`ResolvesIn.eq_on_of_closed`); the control + is a named chain that reads an unnamed one (`Witness.resolution_reads_unnamed`). +* SNP-7, erasure dominance: no erased event is visible at any cut, a larger erasure shows a + sublist, the store with holes keeps every position, and two stores that differ only in erased + events give every derived view the same reading at every cut (`not_erased_of_mem_visible`, + `visible_sublist`, `redact_readAt`, `erased_invisible`); a kept derived row is served only when + none of its sources is erased (`mem_serve_iff`); a key retired after a cut is served at no + earlier cut, and growth of the chain changes a served value only by removing it + (`servedAt_append_of_retire`, `servedAt_append_of_no_retire`, `servedAt_of_append`); the looser + seal, under which a key is withheld only while it is not live, serves everything the stricter + one serves and is lifted by a later landing (`servedNow_of_servedAt`, + `Witness.servedNow_restores`). The seal covers the key's versions as it covers its value: the + history served at a cut ends at the value served there, and at every cut after a retire, the + head included, it holds only versions landed after that retire (`getLast?_historyAt`, + `historyAt_append_of_retire`, `historyAt_of_retire_inside`, `sinceRetire_append_retire`). The + control is the erasure that deletes rows (`Witness.compact_moves`). For a keyed chain whose + holes keep their keys, the read of a key at a cut is its last write at or under the cut, a + hole when that write is erased, and the three reads agree on it (`stateAt_holes`, + `stateAt_holes_of_erased`, `not_erased_of_stateAt_holes`, `genRead_gens_holes`, + `lastWrite_holes`); the control is the hole that loses its key, which returns a superseded + version or one from after the cut (`Witness.keyless_hole`). +* SNP-8, resolution: the consistent cuts are the clock's cuts, CLK-2, among the frontier cuts + (`consistent_iff_isCut`), so their closure under meet and join is CLK-2's, read through that + equivalence (`Consistent.inf`, `Consistent.sup`, `consistentCuts`). What this law adds is + resolution: every frontier resolves to exactly one greatest consistent cut under it, + monotonically (`exists_resolves`, `Resolves.unique`, `Resolves.mono`); a consistent cut stays + consistent as the store grows (`Consistent.of_grown`); and a cut consistent for a recorded + bound on the references is consistent for the true ones (`Consistent.of_bound`). A reference + the resolver does not follow is kept by a filter of the read: a row is withheld when a source + of it lies outside the cut or is withheld. The filtered read is closed under every reference, + it is the greatest such set of rows inside the cut, it is the prefix at a consistent cut, it + never withholds a row whose references are all resolved, and it is monotone and append + invariant (`Kept.source`, `kept_of_closed`, `kept_iff_of_consistent`, `kept_of_resolved`, + `Kept.mono`, `kept_grown_iff`). The controls: a pass attestation whose reference to a landing + is resolved, which takes another landing chain down, and the same reference filtered, where + the prefix is not closed and the filtered read is (`Witness.pass_drags`, + `Witness.pass_withheld`). +* SNP-9, certified cuts: the certificate of a cut verifies on every extension of the store, two + stores that verify one certificate under a collision-free digest have the same read at its cut + and so the same derived views, a certificate extends over the events since an earlier one, the + meet and the join of two certified cuts are certified from the two certificates alone, and an + erasure that keeps commitments keeps every certificate (`verifies_certify_of_extends`, + `Verifies.readAt_eq`, `Verifies.view_eq`, `certify_digest_readBetween`, `certify_inf`, + `certify_sup`, `verifies_purge`). A certificate over commitments attests no erasure + (`verifies_purge_iff`); under a binding commitment it pins the events, so two stores that + verify it read the same store with holes under one erasure + (`Verifies.readAt_eq_of_committed`, `Verifies.contents_eq`, `contents_purge_committed`, + `Verifies.shown_eq`). The controls: a digest with collisions (`Witness.digest_collides`), a + seal written after the cut (`Witness.seal_not_certified`), a renamed chain + (`Witness.rename_breaks_certificate`). +* SNP-10, the horizon: a generational store that drops the rows closed at or under a horizon + reads, at every cut from the horizon on, the state recomputed from the whole prefix; under the + horizon it is never wrong and reads what it lost as absent; horizons compose to the later one + (`genRead_prune`, `genRead_prune_gens`, `stateAt_of_genRead_prune`, `prune_prune`). Where the + chains serve only some positions, every frontier resolves to exactly one greatest consistent + cut among them, which rises with what is served and never passes the cut asked + (`exists_resolvesIn`, `ResolvesIn.unique`, `ResolvesIn.mono`, `ResolvesIn.le_resolves`, + `resolvesIn_univ`). A chain that no other chain reads is lowered alone, every other chain + read as asked (`Consistent.update_of_unread`, `resolvesIn_update_of_unread`, + `resolvesIn_of_unread`); a chain that reads a lowered chain, and that nothing else reads, + follows it and takes nothing with it, which is the case of a chain of records + (`resolvesIn_of_followed`, `Witness.record_follows`); and retention + commutes with growth (`prune_landGen`). The controls: the pruned store read under its horizon, + which cannot tell a lost key from one never written (`Witness.prune_forgets`, + `Witness.prune_indistinct`); a record on a chain that content reads, which drags every reader + down (`Witness.record_drags`); served sets that shrink, under which the cut read falls + (`Witness.served_set_shrinks`). +-/ + +@[expose] public section + +namespace Palace.Snapshot + +/-! ### SNP-1 to SNP-4 Reads -/ + +section Reads + +variable {K α β : Type*} + +theorem extends_grow (s t : Store K α) : Extends s (grow s t) := fun _ ↦ List.prefix_append _ _ + +/-- An extension of a store is the store grown: append is all that happened. -/ +theorem Extends.exists_grow {s s' : Store K α} (h : Extends s s') : ∃ t, s' = grow s t := + ⟨fun k ↦ (s' k).drop (s k).length, funext fun k ↦ (List.prefix_iff_eq_append.1 (h k)).symm⟩ + +theorem Extends.head_le {s s' : Store K α} (h : Extends s s') : head s ≤ head s' := + fun k ↦ (h k).length_le + +/-- SNP-1 Append invariance: the read at a cut inside the store does not change when the store +grows. -/ +theorem readAt_grow {s : Store K α} (t : Store K α) {c : Cut K} (h : c ≤ head s) : + readAt (grow s t) c = readAt s c := + funext fun k ↦ List.take_append_of_le_length (h k) + +/-- SNP-1 The same over every extension: a later state of an append-only store reads, at a cut +of an earlier state, what the earlier state read. -/ +theorem readAt_of_extends {s s' : Store K α} {c : Cut K} (h : Extends s s') (hc : c ≤ head s) : + readAt s' c = readAt s c := by + obtain ⟨t, rfl⟩ := h.exists_grow + exact readAt_grow t hc + +/-- SNP-1 The read between two cuts inside the store does not change when the store grows. -/ +theorem readBetween_grow {s : Store K α} (t : Store K α) (a : Cut K) {b : Cut K} + (h : b ≤ head s) : readBetween (grow s t) a b = readBetween s a b := + funext fun k ↦ congrArg (List.drop (a k)) (List.take_append_of_le_length (h k)) + +/-- SNP-1 Every derived view is append invariant. -/ +theorem appendInvariant_view (D : Store K α → β) : AppendInvariant (view D) := + fun _ t _ h ↦ congrArg D (readAt_grow t h) + +theorem readAt_extends (s : Store K α) (c : Cut K) : Extends (readAt s c) s := + fun k ↦ List.take_prefix (c k) (s k) + +/-- SNP-2 Monotonicity: the read at an earlier cut is a prefix, chain by chain, of the read at a +later one. -/ +theorem readAt_mono (s : Store K α) {c d : Cut K} (h : c ≤ d) : + Extends (readAt s c) (readAt s d) := + fun k ↦ List.take_prefix_take_left (h k) + +/-- SNP-2 An event read at a cut is read at every later cut. -/ +theorem mem_readAt_of_le {s : Store K α} {c d : Cut K} (h : c ≤ d) {k : K} {a : α} + (ha : a ∈ readAt s c k) : a ∈ readAt s d k := + (readAt_mono s h k).subset ha + +/-- SNP-2 A cut of a cut is the meet of the two. -/ +theorem readAt_readAt (s : Store K α) (c d : Cut K) : + readAt (readAt s c) d = readAt s (d ⊓ c) := + funext fun _ ↦ List.take_take + +theorem head_readAt (s : Store K α) (c : Cut K) : head (readAt s c) = c ⊓ head s := + funext fun _ ↦ List.length_take + +theorem head_readAt_of_le {s : Store K α} {c : Cut K} (h : c ≤ head s) : + head (readAt s c) = c := by + rw [head_readAt, inf_of_le_left h] + +/-- SNP-4 A cut at or past the head reads the store. -/ +theorem readAt_of_head_le {s : Store K α} {c : Cut K} (h : head s ≤ c) : readAt s c = s := + funext fun k ↦ List.take_of_length_le (h k) + +/-- SNP-4 Idempotence: the read at the head cut is the store. -/ +theorem readAt_head (s : Store K α) : readAt s (head s) = s := readAt_of_head_le le_rfl + +/-- SNP-4 Every derived view at the head cut is the derivation of the present: `as of` the +current cut is no `as of`. -/ +theorem view_head (D : Store K α → β) (s : Store K α) : view D s (head s) = D s := + congrArg D (readAt_head s) + +theorem drop_take_append_drop (l : List α) {a b : ℕ} (h : a ≤ b) : + (l.take b).drop a ++ l.drop b = l.drop a := by + conv_rhs => rw [← List.take_append_drop b l, List.drop_append] + congr 1 + rcases Nat.le_total b l.length with hb | hb + · rw [List.length_take, Nat.min_eq_left hb, Nat.sub_eq_zero_of_le h, List.drop_zero] + · rw [List.drop_of_length_le hb, List.drop_nil] + +/-- SNP-3 Composition: the read at `a` followed by the read between `a` and `b` is the read at +`b`. -/ +theorem readAt_append_readBetween (s : Store K α) {a b : Cut K} (h : a ≤ b) : + grow (readAt s a) (readBetween s a b) = readAt s b := by + funext k + have h1 : (s k).take (a k) = ((s k).take (b k)).take (a k) := by + rw [List.take_take, Nat.min_eq_left (h k)] + change (s k).take (a k) ++ ((s k).take (b k)).drop (a k) = (s k).take (b k) + rw [h1, List.take_append_drop] + +/-- SNP-3 Two adjacent reads-between compose. -/ +theorem readBetween_append (s : Store K α) {a b c : Cut K} (hab : a ≤ b) (hbc : b ≤ c) : + grow (readBetween s a b) (readBetween s b c) = readBetween s a c := by + funext k + have h1 : (s k).take (b k) = ((s k).take (c k)).take (b k) := by + rw [List.take_take, Nat.min_eq_left (hbc k)] + change ((s k).take (b k)).drop (a k) ++ ((s k).take (c k)).drop (b k) + = ((s k).take (c k)).drop (a k) + rw [h1] + exact drop_take_append_drop _ (hab k) + +/-- The read between the empty cut and a cut is the read at it. -/ +theorem readBetween_zero (s : Store K α) (b : Cut K) : + readBetween s (fun _ ↦ 0) b = readAt s b := rfl + +/-- The read between a cut and itself is empty. -/ +theorem readBetween_self (s : Store K α) (a : Cut K) : readBetween s a a = fun _ ↦ [] := by + funext k + refine List.drop_of_length_le ?_ + rw [List.length_take] + exact Nat.min_le_left _ _ + +/-- The read between a cut and the head is what the store appended since the cut. -/ +theorem readBetween_head (s : Store K α) (a : Cut K) : + readBetween s a (head s) = fun k ↦ (s k).drop (a k) := by + funext k + change ((s k).take (s k).length).drop (a k) = (s k).drop (a k) + rw [List.take_length] + +/-- SNP-3 The journal: a fold of the prefixes at a later cut is the fold at an earlier cut +continued over the events between the two. A job that keeps its state and the cut it stopped at +reads only the delta. -/ +theorem foldAt_readBetween (f : β → α → β) (init : K → β) (s : Store K α) {a b : Cut K} + (h : a ≤ b) (k : K) : + foldAt f init s b k = (readBetween s a b k).foldl f (foldAt f init s a k) := + calc foldAt f init s b k + = ((s k).take (a k) ++ ((s k).take (b k)).drop (a k)).foldl f (init k) := + congrArg (fun l ↦ l.foldl f (init k)) (congrFun (readAt_append_readBetween s h) k).symm + _ = _ := List.foldl_append + +/-- SNP-3 An event read at the later cut was read at the earlier cut or lies in the delta. -/ +theorem mem_readAt_iff {s : Store K α} {a b : Cut K} (h : a ≤ b) {k : K} {x : α} : + x ∈ readAt s b k ↔ x ∈ readAt s a k ∨ x ∈ readBetween s a b k := by + rw [← readAt_append_readBetween s h] + exact List.mem_append + +/-- SNP-3 The delta rule for a job that joins two chains: a pair of events read at the later +cut was read at the earlier cut, or one of the two lies in the delta. So a job that kept the +pairs of its checkpoint has only the pairs with a new member left to visit. -/ +theorem pair_readAt {s : Store K α} {a b : Cut K} (h : a ≤ b) {k k' : K} {x y : α} + (hx : x ∈ readAt s b k) (hy : y ∈ readAt s b k') : + (x ∈ readAt s a k ∧ y ∈ readAt s a k') ∨ x ∈ readBetween s a b k ∨ + y ∈ readBetween s a b k' := by + rcases (mem_readAt_iff h).1 hx with hx | hx + · rcases (mem_readAt_iff h).1 hy with hy | hy + · exact Or.inl ⟨hx, hy⟩ + · exact Or.inr (Or.inr hy) + · exact Or.inr (Or.inl hx) + +/-- SNP-5 A derived view reads only the prefixes. -/ +theorem prefixOnly_view (D : Store K α → β) : PrefixOnly (view D) := fun s c _ ↦ by + change D (readAt s c) = D (readAt (readAt s c) c) + rw [readAt_readAt, inf_idem] + +/-- SNP-5 Two stores with the same prefixes at a cut give every derived view the same +reading. -/ +theorem view_congr (D : Store K α → β) {s s' : Store K α} {c : Cut K} + (h : readAt s c = readAt s' c) : view D s c = view D s' c := congrArg D h + +/-- SNP-5 A reader is append invariant exactly when it reads only the prefixes. -/ +theorem appendInvariant_iff_prefixOnly (F : Store K α → Cut K → β) : + AppendInvariant F ↔ PrefixOnly F := by + constructor + · intro h s c hc + obtain ⟨t, ht⟩ := (readAt_extends s c).exists_grow + have hc' : c ≤ head (readAt s c) := le_of_eq (head_readAt_of_le hc).symm + calc F s c = F (grow (readAt s c) t) c := by rw [← ht] + _ = F (readAt s c) c := h _ t c hc' + · intro h s t c hc + rw [h (grow s t) c (hc.trans (extends_grow s t).head_le), readAt_grow t hc, ← h s c hc] + +/-- SNP-5 A reader is append invariant exactly when it is a derived view: on cuts inside the +store, a function of the prefixes alone. -/ +theorem appendInvariant_iff_exists_view (F : Store K α → Cut K → β) : + AppendInvariant F ↔ ∃ D : Store K α → β, ∀ s c, c ≤ head s → F s c = view D s c := by + rw [appendInvariant_iff_prefixOnly] + constructor + · intro h + refine ⟨fun t ↦ F t (head t), fun s c hc ↦ ?_⟩ + change F s c = F (readAt s c) (head (readAt s c)) + rw [head_readAt_of_le hc] + exact h s c hc + · rintro ⟨D, hD⟩ s c hc + have hc' : c ≤ head (readAt s c) := le_of_eq (head_readAt_of_le hc).symm + rw [hD s c hc, hD (readAt s c) c hc'] + exact prefixOnly_view D s c hc + +end Reads + +/-! ### SNP-5 A derived store, three ways -/ + +section Generations + +variable {κ β : Type*} [DecidableEq κ] + +theorem stateOf_append_singleton (l : List (κ × β)) (e : κ × β) : + stateOf (l ++ [e]) = Function.update (stateOf l) e.1 (some e.2) := by + simp only [stateOf, List.foldl_append, List.foldl_cons, List.foldl_nil] + +theorem stateAt_length (l : List (κ × β)) : stateAt l l.length = stateOf l := by + unfold stateAt + rw [List.take_length] + +theorem stateAt_of_length_le {l : List (κ × β)} {c : ℕ} (h : l.length ≤ c) : + stateAt l c = stateOf l := by + unfold stateAt + rw [List.take_of_length_le h] + +/-- SNP-1 The state at a cut inside the chain does not change when the chain grows. -/ +theorem stateAt_append {l : List (κ × β)} (t : List (κ × β)) {c : ℕ} (h : c ≤ l.length) : + stateAt (l ++ t) c = stateAt l c := by + unfold stateAt + rw [List.take_append_of_le_length h] + +/-- SNP-3 The journal of the keyed state: the state at a later cut is the state at an earlier +cut with the writes between the two applied in order. -/ +theorem stateAt_eq_foldl (l : List (κ × β)) {a b : ℕ} (h : a ≤ b) : + stateAt l b = ((l.take b).drop a).foldl + (fun (m : κ → Option β) (e : κ × β) ↦ Function.update m e.1 (some e.2)) (stateAt l a) := by + have h1 : l.take a = (l.take b).take a := by rw [List.take_take, Nat.min_eq_left h] + unfold stateAt stateOf + rw [h1, ← List.foldl_append, List.take_append_drop] + +theorem foldl_update_of_ne {t : List (κ × β)} {m : κ → Option β} {x : κ} + (ht : ∀ e ∈ t, e.1 ≠ x) : + (t.foldl (fun (m : κ → Option β) (e : κ × β) ↦ Function.update m e.1 (some e.2)) m) x + = m x := by + induction t generalizing m with + | nil => rfl + | cons e t ih => + rw [List.foldl_cons, ih fun e' he' ↦ ht e' (List.mem_cons_of_mem _ he')] + exact Function.update_of_ne (Ne.symm (ht e List.mem_cons_self)) _ _ + +/-- SNP-3 The delta bounds the change: a key the writes between two cuts do not name has the +same state at both. What changed between two cuts is found among the keys of the delta. -/ +theorem stateAt_eq_of_not_written (l : List (κ × β)) {a b : ℕ} (h : a ≤ b) {x : κ} + (hx : ∀ e ∈ (l.take b).drop a, e.1 ≠ x) : stateAt l b x = stateAt l a x := by + have h1 := congrFun (stateAt_eq_foldl l h) x + rw [h1] + exact foldl_update_of_ne hx + +theorem stateOf_eq_find? (l : List (κ × β)) (x : κ) : + stateOf l x = (l.reverse.find? fun e ↦ decide (e.1 = x)).map Prod.snd := by + induction l using List.reverseRecOn with + | nil => rfl + | append_singleton l e ih => + rw [stateOf_append_singleton, List.reverse_append, List.reverse_singleton, + List.singleton_append] + by_cases hx : e.1 = x + · simp [hx] + · simp [hx, Function.update_of_ne (Ne.symm hx), ih] + +/-- SNP-5 The state at a cut is the last write of the key inside the prefix: one seek on an +index of (key, position). -/ +theorem stateAt_eq_lastWrite (l : List (κ × β)) (c : ℕ) (x : κ) : + stateAt l c x = lastWrite l c x := + stateOf_eq_find? _ x + +theorem closeAt_key (x : κ) (p : ℕ) (r : Gen κ β) : (closeAt x p r).key = r.key := by + unfold closeAt + split_ifs <;> rfl + +theorem closeAt_val (x : κ) (p : ℕ) (r : Gen κ β) : (closeAt x p r).val = r.val := by + unfold closeAt + split_ifs <;> rfl + +theorem closeAt_of_ne {x : κ} {r : Gen κ β} (h : r.key ≠ x) (p : ℕ) : closeAt x p r = r := by + simp only [closeAt, h, false_and, ↓reduceIte] + +/-- Closing a row at a position past the cut changes nothing the cut selects. -/ +theorem selects_closeAt_of_lt (x y : κ) {c p : ℕ} (h : c < p) (r : Gen κ β) : + selects c x (closeAt y p r) = selects c x r := by + unfold closeAt + split_ifs with hr + · simp [selects, Gen.aliveAt, hr.2, h] + · rfl + +/-- Closing the rows of one key changes nothing a read of another key selects. -/ +theorem selects_closeAt_of_ne {x y : κ} (h : x ≠ y) (c p : ℕ) (r : Gen κ β) : + selects c x (closeAt y p r) = selects c x r := by + by_cases hr : r.key = y + · have hx : r.key ≠ x := fun h' ↦ h (h'.symm.trans hr) + simp [selects, closeAt_key, hx] + · rw [closeAt_of_ne hr] + +/-- A row of the key closed at a position inside the cut is not selected, when every earlier +closing stamp lies under that position. -/ +theorem selects_closeAt_self {y : κ} {n c : ℕ} (hc : n + 1 ≤ c) {r : Gen κ β} + (hr : ∀ d, r.died = some d → d ≤ n) : selects c y (closeAt y (n + 1) r) = false := by + unfold closeAt + split_ifs with h + · simp [selects, Gen.aliveAt, Nat.not_lt.2 hc] + · by_cases hk : r.key = y + · obtain ⟨d, hd⟩ := Option.ne_none_iff_exists'.1 fun h0 ↦ h ⟨hk, h0⟩ + have hcd : ¬c < d := by have := hr d hd; omega + simp [selects, Gen.aliveAt, hd, hcd] + · simp [selects, hk] + +theorem gens_nil : gens ([] : List (κ × β)) = [] := rfl + +/-- The generational store is appended to, and one closing stamp is written: the landing of a +write closes the key's open row and opens its own. -/ +theorem gens_append_singleton (l : List (κ × β)) (e : κ × β) : + gens (l ++ [e]) = landGen (gens l) (l.length + 1) e := by + simp [gens, gensRev] + +theorem died_le_of_mem_gens {l : List (κ × β)} {r : Gen κ β} (hr : r ∈ gens l) : + ∀ d, r.died = some d → d ≤ l.length := by + induction l using List.reverseRecOn generalizing r with + | nil => simp [gens_nil] at hr + | append_singleton l e ih => + rw [gens_append_singleton] at hr + intro d hd + rw [List.length_append, List.length_singleton] + rcases List.mem_append.1 hr with hr | hr + · obtain ⟨r', hr', rfl⟩ := List.mem_map.1 hr + unfold closeAt at hd + split_ifs at hd with h + · have h1 : l.length + 1 = d := Option.some.inj hd + omega + · exact (ih hr' d hd).trans (Nat.le_succ _) + · rw [List.mem_singleton.1 hr] at hd + exact absurd hd (by simp) + +theorem find?_landGen_of_stable {rs : List (Gen κ β)} {p : ℕ} {e : κ × β} + {q : Gen κ β → Bool} (hq : ∀ r, q (closeAt e.1 p r) = q r) + (hnew : q ⟨e.1, e.2, p, none⟩ = false) : + ((landGen rs p e).find? q).map Gen.val = (rs.find? q).map Gen.val := by + have hcomp : q ∘ closeAt e.1 p = q := funext hq + unfold landGen + rw [List.find?_append, List.find?_map, hcomp, List.find?_singleton, hnew] + simp [Function.comp_def, closeAt_val] + +theorem find?_landGen_of_new {rs : List (Gen κ β)} {p : ℕ} {e : κ × β} {q : Gen κ β → Bool} + (hq : ∀ r ∈ rs, q (closeAt e.1 p r) = false) (hnew : q ⟨e.1, e.2, p, none⟩ = true) : + (landGen rs p e).find? q = some ⟨e.1, e.2, p, none⟩ := by + have hnone : (rs.map (closeAt e.1 p)).find? q = none := by + rw [List.find?_eq_none] + intro r hr + obtain ⟨r', hr', rfl⟩ := List.mem_map.1 hr + simp [hq r' hr'] + simp only [landGen, List.find?_append, hnone, Option.none_or, List.find?_singleton, hnew, + ↓reduceIte] + +/-- SNP-5 Generations are recomputation: the generational store read at a cut is the state +recomputed from the chain's prefix, at every cut. -/ +theorem genRead_gens (l : List (κ × β)) (c : ℕ) (x : κ) : + genRead (gens l) c x = stateAt l c x := by + induction l using List.reverseRecOn with + | nil => simp [genRead, gens_nil, stateAt, stateOf] + | append_singleton l e ih => + rw [gens_append_singleton] + unfold genRead at ih ⊢ + rcases Nat.lt_or_ge c (l.length + 1) with hc | hc + · rw [find?_landGen_of_stable (rs := gens l) (p := l.length + 1) (e := e) (q := selects c x) + (fun r ↦ selects_closeAt_of_lt x e.1 hc r) + (by simp [selects, Gen.aliveAt, Nat.not_le.2 hc]), ih, + stateAt_append [e] (Nat.le_of_lt_succ hc)] + · have hlen : (l ++ [e]).length ≤ c := by simpa using hc + rw [stateAt_of_length_le hlen, stateOf_append_singleton] + by_cases hx : x = e.1 + · subst hx + rw [find?_landGen_of_new (rs := gens l) (p := l.length + 1) (e := e) + (q := selects c e.1) (fun r hr ↦ selects_closeAt_self hc (died_le_of_mem_gens hr)) + (by simp [selects, Gen.aliveAt, hc])] + simp only [Option.map_some, Function.update_self] + · rw [find?_landGen_of_stable (rs := gens l) (p := l.length + 1) (e := e) + (q := selects c x) (fun r ↦ selects_closeAt_of_ne hx c _ r) + (by simp [selects, Ne.symm hx]), ih, Function.update_of_ne hx, + stateAt_of_length_le (Nat.le_of_succ_le hc)] + +/-- SNP-4 At the head cut the generational store reads the store rewritten in place. -/ +theorem genRead_gens_length (l : List (κ × β)) (x : κ) : + genRead (gens l) l.length x = stateOf l x := by + rw [genRead_gens, stateAt_length] + +/-- SNP-1 The generational store read at a cut inside the chain does not change when the chain +grows, though the growth writes closing stamps into it. -/ +theorem genRead_gens_append {l : List (κ × β)} (t : List (κ × β)) {c : ℕ} (h : c ≤ l.length) + (x : κ) : genRead (gens (l ++ t)) c x = genRead (gens l) c x := by + rw [genRead_gens, genRead_gens, stateAt_append t h] + +theorem length_filter_landGen_of_stable {rs : List (Gen κ β)} {p : ℕ} {e : κ × β} + {q : Gen κ β → Bool} (hq : ∀ r, q (closeAt e.1 p r) = q r) + (hnew : q ⟨e.1, e.2, p, none⟩ = false) : + ((landGen rs p e).filter q).length = (rs.filter q).length := by + have hcomp : q ∘ closeAt e.1 p = q := funext hq + unfold landGen + rw [List.filter_append, List.filter_map, hcomp] + simp [hnew] + +theorem length_filter_landGen_of_new {rs : List (Gen κ β)} {p : ℕ} {e : κ × β} + {q : Gen κ β → Bool} (hq : ∀ r ∈ rs, q (closeAt e.1 p r) = false) + (hnew : q ⟨e.1, e.2, p, none⟩ = true) : ((landGen rs p e).filter q).length = 1 := by + have hnil : (rs.map (closeAt e.1 p)).filter q = [] := by + rw [List.filter_eq_nil_iff] + intro r hr + obtain ⟨r', hr', rfl⟩ := List.mem_map.1 hr + simp [hq r' hr'] + unfold landGen + rw [List.filter_append, hnil] + simp [hnew] + +/-- SNP-5 At most one generation of a key is alive at a cut: the snapshot of a keyed store is a +transversal of its chains. -/ +theorem length_filter_selects_le_one (l : List (κ × β)) (c : ℕ) (x : κ) : + ((gens l).filter (selects c x)).length ≤ 1 := by + induction l using List.reverseRecOn with + | nil => simp [gens_nil] + | append_singleton l e ih => + rw [gens_append_singleton] + rcases Nat.lt_or_ge c (l.length + 1) with hc | hc + · exact (length_filter_landGen_of_stable (rs := gens l) (p := l.length + 1) (e := e) + (q := selects c x) (fun r ↦ selects_closeAt_of_lt x e.1 hc r) + (by simp [selects, Gen.aliveAt, Nat.not_le.2 hc])).le.trans ih + · by_cases hx : x = e.1 + · subst hx + exact (length_filter_landGen_of_new (rs := gens l) (p := l.length + 1) (e := e) + (q := selects c e.1) (fun r hr ↦ selects_closeAt_self hc (died_le_of_mem_gens hr)) + (by simp [selects, Gen.aliveAt, hc])).le + · exact (length_filter_landGen_of_stable (rs := gens l) (p := l.length + 1) (e := e) + (q := selects c x) (fun r ↦ selects_closeAt_of_ne hx c _ r) + (by simp [selects, Ne.symm hx])).le.trans ih + +/-- A row a cut selects is kept by every horizon at or under the cut. -/ +theorem keeps_of_selects {h c : ℕ} (hc : h ≤ c) {x : κ} {r : Gen κ β} + (hr : selects c x r = true) : (r.died.all fun d ↦ decide (h < d)) = true := by + have h2 : (r.died.all fun d ↦ decide (c < d)) = true := by + simp only [selects, Gen.aliveAt, Bool.and_eq_true] at hr + exact hr.2.2 + cases hd : r.died with + | none => rfl + | some d => + rw [hd] at h2 + simp only [Option.all_some, decide_eq_true_eq] at h2 ⊢ + omega + +theorem find?_prune {h c : ℕ} (hc : h ≤ c) (rs : List (Gen κ β)) (x : κ) : + (prune h rs).find? (selects c x) = rs.find? (selects c x) := by + induction rs with + | nil => rfl + | cons r rs ih => + by_cases hk : (r.died.all fun d ↦ decide (h < d)) = true + · have e : prune h (r :: rs) = r :: prune h rs := by simp [prune, hk] + rw [e, List.find?_cons, List.find?_cons, ih] + · have hs : ¬selects c x r = true := fun hs ↦ hk (keeps_of_selects hc hs) + have e : prune h (r :: rs) = prune h rs := by simp [prune, hk] + rw [e, List.find?_cons_of_neg hs, ih] + +/-- SNP-10 Retention is exact from the horizon on: dropping the generations closed at or under +a horizon changes no read at a cut at or past it. -/ +theorem genRead_prune {h c : ℕ} (hc : h ≤ c) (rs : List (Gen κ β)) (x : κ) : + genRead (prune h rs) c x = genRead rs c x := by + unfold genRead + rw [find?_prune hc] + +/-- SNP-10 So the pruned generational store read at a cut from the horizon on is the state +recomputed from the whole prefix, though the prefix is no longer held. -/ +theorem genRead_prune_gens {h c : ℕ} (hc : h ≤ c) (l : List (κ × β)) (x : κ) : + genRead (prune h (gens l)) c x = stateAt l c x := by + rw [genRead_prune hc, genRead_gens] + +/-- SNP-10 Under the horizon the pruned store is never wrong: a value it returns at a cut is the +value the key held at the cut. What it has lost it reads as absent. -/ +theorem stateAt_of_genRead_prune {h c : ℕ} {l : List (κ × β)} {x : κ} {v : β} + (hv : genRead (prune h (gens l)) c x = some v) : stateAt l c x = some v := by + rw [← genRead_gens] + unfold genRead at hv ⊢ + obtain ⟨r, hr, rfl⟩ := Option.map_eq_some_iff.1 hv + have hsel : selects c x r = true := List.find?_some hr + have hmem : r ∈ gens l := List.mem_of_mem_filter (List.mem_of_find?_eq_some hr) + have hfil : r ∈ (gens l).filter (selects c x) := List.mem_filter.2 ⟨hmem, hsel⟩ + have hlen := length_filter_selects_le_one l c x + have heq : (gens l).filter (selects c x) = [r] := by + rcases hf : (gens l).filter (selects c x) with _ | ⟨a, _ | ⟨b, t⟩⟩ + · rw [hf] at hfil + exact absurd hfil List.not_mem_nil + · rw [hf] at hfil + rw [List.mem_singleton.1 hfil] + · rw [hf] at hlen + simp at hlen + rw [← List.head?_filter, heq] + rfl + +omit [DecidableEq κ] in +/-- SNP-10 Horizons compose: pruning at two horizons is pruning at the later one, so a horizon +only ever advances. -/ +theorem prune_prune (h h' : ℕ) (rs : List (Gen κ β)) : + prune h (prune h' rs) = prune (max h h') rs := by + unfold prune + rw [List.filter_filter] + refine List.filter_congr fun r _ ↦ ?_ + cases r.died with + | none => rfl + | some d => simp [max_lt_iff] + +/-- SNP-10 Retention commutes with growth: a store pruned at a horizon and then landed on, past +the horizon, is the landed store pruned at the horizon. -/ +theorem prune_landGen {h p : ℕ} (hp : h < p) (rs : List (Gen κ β)) (e : κ × β) : + prune h (landGen rs p e) = landGen (prune h rs) p e := by + have hq : (fun r : Gen κ β ↦ r.died.all fun d ↦ decide (h < d)) ∘ closeAt e.1 p + = fun r ↦ r.died.all fun d ↦ decide (h < d) := by + funext r + simp only [Function.comp_apply, closeAt] + split_ifs with hr + · simp [hr.2, hp] + · rfl + unfold landGen prune + rw [List.filter_append, List.filter_map, hq] + simp + +/-- SNP-4 At the head cut nothing is sealed: a chain of landings and retires serves what the +store rewritten in place holds live. -/ +theorem servedAt_length (l : List (κ × Option β)) (x : κ) : + servedAt l l.length x = (stateOf l x).join := by + simp [servedAt, sealedAt, stateAt_length] + +/-- SNP-7 What is served at a cut is what the key held at the cut: the seal only withholds. -/ +theorem stateAt_of_servedAt {l : List (κ × Option β)} {c : ℕ} {x : κ} {v : β} + (h : servedAt l c x = some v) : stateAt l c x = some (some v) := by + by_cases hs : sealedAt l c x = true + · simp [servedAt, hs] at h + · simp only [servedAt, hs] at h + exact Option.join_eq_some_iff.1 h + +theorem sealedAt_append {l : List (κ × Option β)} (t : List (κ × Option β)) {c : ℕ} + (hc : c ≤ l.length) (x : κ) : + sealedAt (l ++ t) c x = (sealedAt l c x || t.any fun e ↦ decide (e.1 = x) && e.2.isNone) := by + unfold sealedAt + rw [List.drop_append_of_le_length hc, List.any_append] + +/-- SNP-7 Erasure dominance for a retire: once the chain retires a key, no cut before the +retire serves the key. -/ +theorem servedAt_append_of_retire {l t : List (κ × Option β)} {c : ℕ} {x : κ} + (hc : c ≤ l.length) (h : (x, none) ∈ t) : servedAt (l ++ t) c x = none := by + have hs : sealedAt (l ++ t) c x = true := by + rw [sealedAt_append t hc, Bool.or_eq_true] + exact Or.inr (List.any_eq_true.2 ⟨(x, none), h, by simp⟩) + simp only [servedAt, hs, ↓reduceIte] + +/-- SNP-7 Append invariance under the seal: growth that does not retire the key changes nothing +served of it at a cut inside the chain. -/ +theorem servedAt_append_of_no_retire {l t : List (κ × Option β)} {c : ℕ} {x : κ} + (hc : c ≤ l.length) (h : (x, none) ∉ t) : servedAt (l ++ t) c x = servedAt l c x := by + have ht : (t.any fun e ↦ decide (e.1 = x) && e.2.isNone) = false := by + rw [Bool.eq_false_iff] + intro h' + obtain ⟨⟨e1, e2⟩, he, hq⟩ := List.any_eq_true.1 h' + simp only [Bool.and_eq_true, decide_eq_true_eq, Option.isNone_iff_eq_none] at hq + obtain ⟨rfl, rfl⟩ := hq + exact h he + unfold servedAt + rw [sealedAt_append t hc, ht, Bool.or_false, stateAt_append t hc] + +/-- SNP-7 Growth of the chain changes a served value only by removing it. -/ +theorem servedAt_of_append {l t : List (κ × Option β)} {c : ℕ} {x : κ} {v : β} + (hc : c ≤ l.length) (h : servedAt (l ++ t) c x = some v) : servedAt l c x = some v := by + by_cases ht : (x, none) ∈ t + · rw [servedAt_append_of_retire hc ht] at h + exact absurd h (by simp) + · rwa [servedAt_append_of_no_retire hc ht] at h + +theorem isSome_join_foldl {t : List (κ × Option β)} {m : κ → Option (Option β)} {x : κ} + (hm : ((m x).join).isSome = true) (ht : ∀ e ∈ t, e.1 = x → e.2.isSome = true) : + (((t.foldl (fun (m : κ → Option (Option β)) (e : κ × Option β) ↦ + Function.update m e.1 (some e.2)) m) x).join).isSome = true := by + induction t generalizing m with + | nil => exact hm + | cons e t ih => + refine ih ?_ fun e' he' ↦ ht e' (List.mem_cons_of_mem _ he') + change ((Function.update m e.1 (some e.2) x).join).isSome = true + by_cases hx : e.1 = x + · have he := ht e List.mem_cons_self hx + rw [← hx, Function.update_self] + simpa using he + · rw [Function.update_of_ne (Ne.symm hx)] + exact hm + +/-- SNP-7 Under the looser seal too, a key that is not live now is served at no cut. -/ +theorem servedNow_of_not_live {l : List (κ × Option β)} {x : κ} + (h : (stateOf l x).join = none) (c : ℕ) : servedNow l c x = none := by + simp [servedNow, h] + +/-- SNP-4 At the head cut the looser seal serves what the store rewritten in place holds +live. -/ +theorem servedNow_length (l : List (κ × Option β)) (x : κ) : + servedNow l l.length x = (stateOf l x).join := by + unfold servedNow + rw [stateAt_length] + cases (stateOf l x).join <;> rfl + +/-- SNP-7 The two seals are ordered: what the seal that a retire closes for good serves, the +seal that a later landing lifts serves too. Whichever is chosen, the other bounds it. -/ +theorem servedNow_of_servedAt {l : List (κ × Option β)} {c : ℕ} {x : κ} {v : β} + (h : servedAt l c x = some v) : servedNow l c x = some v := by + have hstate := stateAt_of_servedAt h + have hseal : ∀ e ∈ l.drop c, e.1 = x → e.2.isSome = true := by + intro e he hx + by_contra hnone + have hs : sealedAt l c x = true := + List.any_eq_true.2 ⟨e, he, by simpa [hx] using hnone⟩ + simp [servedAt, hs] at h + have hfold := stateAt_eq_foldl l (Nat.le_max_left c l.length) + rw [stateAt_of_length_le (Nat.le_max_right c l.length), + List.take_of_length_le (Nat.le_max_right c l.length)] at hfold + have hlive : ((stateOf l x).join).isSome = true := by + rw [hfold] + exact isSome_join_foldl (by rw [hstate]; rfl) hseal + have hnot : ((stateOf l x).join).isNone = false := by + cases hj : (stateOf l x).join with + | none => rw [hj] at hlive; exact absurd hlive (by simp) + | some w => rfl + simp only [servedNow, hnot, Bool.false_eq_true, ↓reduceIte, hstate, Option.join_some] + +theorem sinceRetire_append_singleton (l : List (κ × Option β)) (e : κ × Option β) (x : κ) : + sinceRetire (l ++ [e]) x + = if e.1 = x then (e.2.elim [] fun v ↦ sinceRetire l x ++ [v]) else sinceRetire l x := by + simp only [sinceRetire, List.foldl_append, List.foldl_cons, List.foldl_nil] + +theorem foldl_sinceRetire_of_retire (t : List (κ × Option β)) (x : κ) (acc : List β) : + ((x, none) :: t).foldl + (fun acc e ↦ if e.1 = x then (e.2.elim [] fun v ↦ acc ++ [v]) else acc) acc + = sinceRetire t x := by + simp [sinceRetire] + +/-- SNP-7 A retire closes the key's history: the versions landed before a retire of the key +are in no later history. -/ +theorem sinceRetire_append_retire (l t : List (κ × Option β)) (x : κ) : + sinceRetire (l ++ (x, none) :: t) x = sinceRetire t x := by + unfold sinceRetire + rw [List.foldl_append] + exact foldl_sinceRetire_of_retire t x _ + +/-- The last version of a key's present life is the value the key holds live. -/ +theorem getLast?_sinceRetire (l : List (κ × Option β)) (x : κ) : + (sinceRetire l x).getLast? = (stateOf l x).join := by + induction l using List.reverseRecOn with + | nil => rfl + | append_singleton l e ih => + rw [sinceRetire_append_singleton, stateOf_append_singleton] + by_cases hx : e.1 = x + · subst hx + rw [Function.update_self] + cases e.2 <;> simp + · rw [Function.update_of_ne (Ne.symm hx)] + simpa [hx] using ih + +/-- SNP-7 The history served at a cut ends at the value served there: the seal that withholds +a key's value withholds its versions with it. -/ +theorem getLast?_historyAt (l : List (κ × Option β)) (c : ℕ) (x : κ) : + (historyAt l c x).getLast? = servedAt l c x := by + unfold historyAt servedAt + split_ifs + · rfl + · exact getLast?_sinceRetire _ x + +/-- SNP-7 Once the chain retires a key, no cut before the retire serves any version of it. -/ +theorem historyAt_append_of_retire {l t : List (κ × Option β)} {c : ℕ} {x : κ} + (hc : c ≤ l.length) (h : (x, none) ∈ t) : historyAt (l ++ t) c x = [] := by + have hs : sealedAt (l ++ t) c x = true := by + rw [sealedAt_append t hc, Bool.or_eq_true] + exact Or.inr (List.any_eq_true.2 ⟨(x, none), h, by simp⟩) + simp only [historyAt, hs, ↓reduceIte] + +/-- SNP-7 At every cut after a retire of a key, the head included, the history served of the +key holds only versions landed after that retire: a new item under a retired identity does not +bring the retired item's versions with it. -/ +theorem historyAt_of_retire_inside (l t : List (κ × Option β)) (x : κ) {c : ℕ} + (hc : l.length + 1 ≤ c) : + historyAt (l ++ (x, none) :: t) c x + = if sealedAt (l ++ (x, none) :: t) c x then [] + else sinceRetire (t.take (c - (l.length + 1))) x := by + unfold historyAt + split_ifs + · rfl + · have h1 : (l ++ (x, none) :: t).take c + = l ++ (x, none) :: t.take (c - (l.length + 1)) := by + rw [List.take_append, List.take_of_length_le (by omega), + show c - l.length = (c - (l.length + 1)) + 1 by omega, List.take_succ_cons] + rw [h1, sinceRetire_append_retire] + +/-- SNP-4 At the head cut the history served is the key's present life. -/ +theorem historyAt_length (l : List (κ × Option β)) (x : κ) : + historyAt l l.length x = sinceRetire l x := by + simp [historyAt, sealedAt] + +omit [DecidableEq κ] in +theorem holes_append (E : κ × β → Bool) (l t : List (κ × β)) : + holes E (l ++ t) = holes E l ++ holes E t := + List.map_append + +/-- The store rewritten in place, with holes: each key's last write, erased or not. -/ +theorem stateOf_holes (E : κ × β → Bool) (l : List (κ × β)) (x : κ) : + stateOf (holes E l) x = (stateOf l x).map fun v ↦ if E (x, v) then none else some v := by + induction l using List.reverseRecOn with + | nil => rfl + | append_singleton l e ih => + rw [holes_append] + change stateOf (holes E l ++ [(e.1, if E e then none else some e.2)]) x = _ + rw [stateOf_append_singleton, stateOf_append_singleton] + by_cases hx : e.1 = x + · subst hx + simp + · rw [Function.update_of_ne (Ne.symm hx), Function.update_of_ne (Ne.symm hx)] + exact ih + +/-- SNP-7 The keyed read under an erasure: on a chain whose holes keep their keys, the read of +a key at a cut is its last write at or under the cut, as a hole when that write is erased. It is +never an earlier write of the key and never a later one. -/ +theorem stateAt_holes (E : κ × β → Bool) (l : List (κ × β)) (c : ℕ) (x : κ) : + stateAt (holes E l) c x = (stateAt l c x).map fun v ↦ if E (x, v) then none else some v := by + unfold stateAt + rw [holes, ← List.map_take] + exact stateOf_holes E _ x + +/-- SNP-7 A key whose head at the cut is erased reads as erased at that cut. -/ +theorem stateAt_holes_of_erased {E : κ × β → Bool} {l : List (κ × β)} {c : ℕ} {x : κ} {v : β} + (h : stateAt l c x = some v) (hE : E (x, v) = true) : + stateAt (holes E l) c x = some none := by + rw [stateAt_holes, h, Option.map_some, hE] + rfl + +/-- SNP-7 No keyed read at any cut returns an erased value. -/ +theorem not_erased_of_stateAt_holes {E : κ × β → Bool} {l : List (κ × β)} {c : ℕ} {x : κ} + {v : β} (h : stateAt (holes E l) c x = some (some v)) : + stateAt l c x = some v ∧ E (x, v) = false := by + rw [stateAt_holes] at h + cases hs : stateAt l c x with + | none => rw [hs] at h; exact absurd h (by simp) + | some w => + rw [hs, Option.map_some] at h + cases hE : E (x, w) + · rw [hE] at h + simp only [Bool.false_eq_true, ↓reduceIte, Option.some.injEq] at h + exact ⟨by rw [h], by rw [← h]; exact hE⟩ + · rw [hE] at h + simp at h + +/-- SNP-7 The three reads agree on a chain with holes: the generational store of the chain with +holes, read at a cut, is the keyed read under the erasure. -/ +theorem genRead_gens_holes (E : κ × β → Bool) (l : List (κ × β)) (c : ℕ) (x : κ) : + genRead (gens (holes E l)) c x + = (stateAt l c x).map fun v ↦ if E (x, v) then none else some v := by + rw [genRead_gens, stateAt_holes] + +/-- SNP-7 And so is the seek by key: the last row of the key at or under the cut, hole or +not. -/ +theorem lastWrite_holes (E : κ × β → Bool) (l : List (κ × β)) (c : ℕ) (x : κ) : + lastWrite (holes E l) c x + = (stateAt l c x).map fun v ↦ if E (x, v) then none else some v := by + rw [← stateAt_eq_lastWrite, stateAt_holes] + +end Generations + +/-! ### SNP-6 The grant -/ + +section Grant + +variable {K α : Type*} + +/-- SNP-6 A snapshot under a grant is append invariant. -/ +theorem snapshot_grow (G : K → Prop) [DecidablePred G] (p : α → Bool) {s : Store K α} + (t : Store K α) {c : Cut K} (h : c ≤ head s) : + snapshot G p (grow s t) c = snapshot G p s c := by + unfold snapshot + rw [readAt_grow t h] + +/-- Restricting twice is restricting to the chains both grants name and the events both +let through. -/ +theorem restrict_restrict (G G' : K → Prop) [DecidablePred G] [DecidablePred G'] + (p p' : α → Bool) (t : Store K α) : + restrict G p (restrict G' p' t) = restrict (fun k ↦ G k ∧ G' k) (fun a ↦ p a && p' a) t := by + funext k + by_cases h : G k <;> by_cases h' : G' k <;> simp [restrict, h, h', List.filter_filter] + +/-- SNP-6 Grant restriction: a narrower grant's snapshot is the restriction of a wider one's, +at every cut. What a wider grant was shown at a cut bounds what a narrower one is shown there. -/ +theorem snapshot_narrow {G G' : K → Prop} [DecidablePred G] [DecidablePred G'] + {p p' : α → Bool} (hG : ∀ k, G k → G' k) (hp : ∀ a, p a = true → p' a = true) + (s : Store K α) (c : Cut K) : + snapshot G p s c = restrict G p (snapshot G' p' s c) := by + funext k + by_cases h : G k + · have h' := hG k h + simp only [snapshot, restrict, h, h', ↓reduceIte, List.filter_filter] + refine List.filter_congr fun a _ ↦ ?_ + cases hpa : p a + · rfl + · simp [hp a hpa] + · simp [snapshot, restrict, h] + +/-- SNP-6 Noninterference: a snapshot under a grant reads only the chains the grant names, and +of the cut only its positions on them. Two stores that agree on those chains, at two cuts that +agree on them, are one snapshot. -/ +theorem snapshot_congr (G : K → Prop) [DecidablePred G] (p : α → Bool) {s s' : Store K α} + {c c' : Cut K} (hs : ∀ k, G k → s k = s' k) (hc : ∀ k, G k → c k = c' k) : + snapshot G p s c = snapshot G p s' c' := by + funext k + by_cases h : G k + · simp [snapshot, restrict, readAt, h, hs k h, hc k h] + · simp [snapshot, restrict, h] + +/-- SNP-4 At the head cut a snapshot is the grant's restriction of the store. -/ +theorem snapshot_head (G : K → Prop) [DecidablePred G] (p : α → Bool) (s : Store K α) : + snapshot G p s (head s) = restrict G p s := by + unfold snapshot + rw [readAt_head] + +/-- SNP-6 Restricting to chains commutes with the cut: a grant that names whole chains may be +applied before the read or after it. -/ +theorem restrict_readAt (G : K → Prop) [DecidablePred G] (s : Store K α) (c : Cut K) : + restrict G (fun _ ↦ true) (readAt s c) = readAt (restrict G (fun _ ↦ true) s) c := by + funext k + by_cases h : G k <;> simp [restrict, readAt, h] + +/-- SNP-1 for the composite reader: what an asker is shown at a cut inside the store is the +same after any growth. -/ +theorem shown_grow (G : K → Prop) [DecidablePred G] (p E : α → Bool) {s : Store K α} + (t : Store K α) {c : Cut K} (h : c ≤ head s) : + shown G p E (grow s t) c = shown G p E s c := + snapshot_grow G _ t h + +/-- SNP-7 for the composite reader: no erased event is shown at any cut, under any grant. -/ +theorem not_erased_of_mem_shown {G : K → Prop} [DecidablePred G] {p E : α → Bool} + {s : Store K α} {c : Cut K} {k : K} {a : α} (h : a ∈ shown G p E s c k) : E a = false := by + unfold shown snapshot restrict at h + split_ifs at h + · exact (by simpa using (List.mem_filter.1 h).2 : p a = true ∧ E a = false).2 + · simp at h + +/-- SNP-6 for the composite reader: under a narrower grant and a larger erasure, what is shown +is the restriction of what the wider grant is shown under the smaller erasure. -/ +theorem shown_narrow {G G' : K → Prop} [DecidablePred G] [DecidablePred G'] + {p p' E E' : α → Bool} (hG : ∀ k, G k → G' k) (hp : ∀ a, p a = true → p' a = true) + (hE : ∀ a, E' a = true → E a = true) (s : Store K α) (c : Cut K) : + shown G p E s c = restrict G (fun a ↦ p a && !E a) (shown G' p' E' s c) := + snapshot_narrow hG (fun a ha ↦ by + rw [Bool.and_eq_true] at ha ⊢ + refine ⟨hp a ha.1, ?_⟩ + cases h : E' a + · rfl + · have := hE a h + simp [this] at ha) s c + +/-- SNP-4 for the composite reader: at the head cut it is the grant's restriction of the store +without the erased events. -/ +theorem shown_head (G : K → Prop) [DecidablePred G] (p E : α → Bool) (s : Store K α) : + shown G p E s (head s) = restrict G (fun a ↦ p a && !E a) s := + snapshot_head G _ s + +end Grant + +/-! ### SNP-7 The erasure -/ + +section Erasure + +variable {K α β C : Type*} + +/-- SNP-7 The store with holes keeps every position. -/ +theorem head_redact (E : α → Bool) (s : Store K α) : head (redact E s) = head s := + funext fun _ ↦ List.length_map _ + +/-- SNP-7 Erasing with holes commutes with the cut: the positions of the events that stay are +the positions they had. -/ +theorem redact_readAt (E : α → Bool) (s : Store K α) (c : Cut K) : + readAt (redact E s) c = redact E (readAt s c) := + funext fun _ ↦ List.map_take.symm + +theorem reduceOption_map_hole (E : α → Bool) (l : List α) : + (l.map fun a ↦ if E a then none else some a).reduceOption = l.filter fun a ↦ !E a := by + induction l with + | nil => rfl + | cons a l ih => + cases h : E a + · simp [h, List.reduceOption_cons_of_some, ih] + · simp [h, List.reduceOption_cons_of_none, ih] + +/-- SNP-7 What is visible at a cut is the store with holes read at the cut, the holes dropped. -/ +theorem visible_eq_reduceOption (E : α → Bool) (s : Store K α) (c : Cut K) (k : K) : + visible E s c k = (readAt (redact E s) c k).reduceOption := by + rw [redact_readAt] + exact (reduceOption_map_hole E _).symm + +/-- SNP-7 Erasure dominance: no erased event is visible at any cut. -/ +theorem not_erased_of_mem_visible {E : α → Bool} {s : Store K α} {c : Cut K} {k : K} {a : α} + (h : a ∈ visible E s c k) : E a = false := by + simpa using (List.mem_filter.1 h).2 + +/-- SNP-7 A larger erasure shows a sublist of what a smaller one shows, at every cut. -/ +theorem visible_sublist {E E' : α → Bool} (h : ∀ a, E a = true → E' a = true) + (s : Store K α) (c : Cut K) (k : K) : (visible E' s c k).Sublist (visible E s c k) := by + refine List.monotone_filter_right _ fun a ha ↦ ?_ + cases hE : E a + · rfl + · simp [h a hE] at ha + +/-- SNP-2 under an erasure: what is visible at an earlier cut is a prefix of what is visible +at a later one. -/ +theorem visible_mono (E : α → Bool) (s : Store K α) {c d : Cut K} (h : c ≤ d) (k : K) : + visible E s c k <+: visible E s d k := + (List.take_prefix_take_left (h k)).filter _ + +/-- SNP-4 under an erasure: at the head cut what is visible is the store without the erased +events. -/ +theorem visible_head (E : α → Bool) (s : Store K α) : visible E s (head s) = compact E s := + funext fun _ ↦ congrArg (List.filter fun a ↦ !E a) List.take_length + +/-- SNP-1 under an erasure: growth of the store changes nothing visible at a cut inside it. -/ +theorem visible_grow (E : α → Bool) {s : Store K α} (t : Store K α) {c : Cut K} + (h : c ≤ head s) : visible E (grow s t) c = visible E s c := + funext fun k ↦ congrArg (List.filter fun a ↦ !E a) (List.take_append_of_le_length (h k)) + +/-- SNP-7 Two stores that differ only in erased events show the same at every cut. -/ +theorem visible_congr {E : α → Bool} {s s' : Store K α} (h : redact E s = redact E s') + (c : Cut K) : visible E s c = visible E s' c := by + funext k + rw [visible_eq_reduceOption, visible_eq_reduceOption, h] + +/-- SNP-7 So erased content is an argument of no read: every derivation of what is visible at +a cut is the same on two stores that differ only in erased events. -/ +theorem erased_invisible (D : Store K α → β) {E : α → Bool} {s s' : Store K α} + (h : redact E s = redact E s') (c : Cut K) : D (visible E s c) = D (visible E s' c) := + congrArg D (visible_congr h c) + +/-- SNP-7 A kept derived row is served exactly when none of its sources is erased. -/ +theorem mem_serve_iff {E : α → Bool} {rows : List (List α × β)} {r : List α × β} : + r ∈ serve E rows ↔ r ∈ rows ∧ ∀ a ∈ r.1, E a = false := by + simp [serve, List.mem_filter] + +/-- SNP-7 A larger erasure serves a sublist of the kept rows. -/ +theorem serve_sublist {E E' : α → Bool} (h : ∀ a, E a = true → E' a = true) + (rows : List (List α × β)) : (serve E' rows).Sublist (serve E rows) := by + refine List.monotone_filter_right _ fun r hr ↦ ?_ + rw [List.all_eq_true] at hr ⊢ + intro a ha + have h1 := hr a ha + cases hE : E a + · rfl + · simp [h a hE] at h1 + +/-- SNP-9 An erasure on a committed store keeps every commitment in its place. -/ +theorem commitments_purge (E : α → Bool) (t : Store K (C × Option α)) : + commitments (purge E t) = commitments t := by + funext k + simp [commitments, purge, Function.comp_def] + +/-- SNP-9 What a reader reads of a committed store after an erasure is the store with holes. -/ +theorem contents_purge_committed (commit : α → C) (E : α → Bool) (s : Store K α) : + contents (purge E (committed commit s)) = redact E s := by + funext k + simp only [contents, purge, committed, redact, List.map_map] + refine List.map_congr_left fun a _ ↦ ?_ + cases h : E a <;> simp [h] + +end Erasure + +/-! ### SNP-8 Consistent cuts -/ + +section Consistency + +variable {K : Type*} {R : K → ℕ → K → ℕ → Prop} + +/-- The empty cut is consistent. -/ +theorem consistent_zero : Consistent R fun _ ↦ 0 := fun _ _ _ _ _ h ↦ absurd h (Nat.not_lt_zero _) + +/-- SNP-8 The consistent cuts are the clock's cuts (CLK-2) among the frontier cuts: a cut is +consistent exactly when the events under its frontier are a down-set of the order the append +chains and the reads-from references generate. -/ +theorem consistent_iff_isCut (R : K → ℕ → K → ℕ → Prop) (c : Cut K) : + Consistent R c ↔ Clock.IsCut (generator R) (Clock.frontierCut Prod.fst Prod.snd c) := by + rw [Clock.isCut_iff_not_crossed] + constructor + · rintro h ⟨a, b, hab, hb, ha⟩ + have hb' : b.2 < c b.1 := hb + rcases hab with ⟨h1, h2⟩ | hR + · refine ha ?_ + change a.2 < c a.1 + rw [h1] + exact lt_trans h2 hb' + · exact ha (h _ _ _ _ hR hb') + · intro h k i k' j hR hi + by_contra hj + exact h ⟨(k', j), (k, i), Or.inr hR, hi, hj⟩ + +/-- Closure under the meet is CLK-2's: the frontier cut of a pointwise minimum is the +intersection of the two cuts (`Clock.IsCut.frontier_inf`), read here through +`consistent_iff_isCut`. -/ +theorem Consistent.inf {c d : Cut K} (hc : Consistent R c) (hd : Consistent R d) : + Consistent R (c ⊓ d) := + (consistent_iff_isCut R _).2 + (Clock.IsCut.frontier_inf Prod.fst Prod.snd ((consistent_iff_isCut R c).1 hc) + ((consistent_iff_isCut R d).1 hd)) + +/-- And under the join, CLK-2's again (`Clock.IsCut.frontier_sup`). -/ +theorem Consistent.sup {c d : Cut K} (hc : Consistent R c) (hd : Consistent R d) : + Consistent R (c ⊔ d) := + (consistent_iff_isCut R _).2 + (Clock.IsCut.frontier_sup Prod.fst Prod.snd ((consistent_iff_isCut R c).1 hc) + ((consistent_iff_isCut R d).1 hd)) + +/-- The consistent cuts as a sublattice of the cuts, so a distributive lattice: CLK-2's +closure, packaged. -/ +def consistentCuts (R : K → ℕ → K → ℕ → Prop) : Sublattice (Cut K) where + carrier := {c | Consistent R c} + supClosed' := fun _ hc _ hd ↦ Consistent.sup hc hd + infClosed' := fun _ hc _ hd ↦ Consistent.inf hc hd + +/-- A frontier resolves to at most one cut. -/ +theorem Resolves.unique {f c c' : Cut K} (h : Resolves R f c) (h' : Resolves R f c') : c = c' := + le_antisymm (h'.2.2 c h.1 h.2.1) (h.2.2 c' h'.1 h'.2.1) + +/-- SNP-8 Resolution is monotone: a later frontier resolves to a later cut. -/ +theorem Resolves.mono {f f' c c' : Cut K} (hf : f ≤ f') (h : Resolves R f c) + (h' : Resolves R f' c') : c ≤ c' := + h'.2.2 c h.1 (h.2.1.trans hf) + +/-- A consistent frontier resolves to itself. -/ +theorem resolves_self {f : Cut K} (h : Consistent R f) : Resolves R f f := + ⟨h, le_rfl, fun _ _ hd ↦ hd⟩ + +/-- SNP-8 Every frontier resolves: among the consistent cuts under it there is a greatest. -/ +theorem exists_resolves (R : K → ℕ → K → ℕ → Prop) (f : Cut K) : ∃ c, Resolves R f c := by + have hne : ∀ k, (reached R f k).Nonempty := fun k ↦ + ⟨0, fun _ ↦ 0, consistent_zero, fun _ ↦ Nat.zero_le _, rfl⟩ + have hbdd : ∀ k, BddAbove (reached R f k) := fun k ↦ + ⟨f k, by rintro n ⟨d, -, hd, rfl⟩; exact hd k⟩ + refine ⟨fun k ↦ sSup (reached R f k), ?_, ?_, ?_⟩ + · intro k i k' j hR hi + obtain ⟨d, hd, hdf, hdk⟩ := Nat.sSup_mem (hne k) (hbdd k) + have hj : j < d k' := hd k i k' j hR (by rw [hdk]; exact hi) + exact lt_of_lt_of_le hj (le_csSup (hbdd k') ⟨d, hd, hdf, rfl⟩) + · intro k + exact csSup_le (hne k) (by rintro n ⟨d, -, hd, rfl⟩; exact hd k) + · intro d hd hdf k + exact le_csSup (hbdd k) ⟨d, hd, hdf, rfl⟩ + +/-- SNP-8 Consistency is append invariant: when the references a store gains by growing all +start at events at or past its old head, a cut inside the old head that was consistent stays +consistent. -/ +theorem Consistent.of_grown {R' : K → ℕ → K → ℕ → Prop} {h c : Cut K} + (hR : ∀ k i k' j, R' k i k' j → R k i k' j ∨ h k ≤ i) (hc : c ≤ h) + (hcons : Consistent R c) : Consistent R' c := fun k i k' j hr hi ↦ + (hR k i k' j hr).elim (fun h0 ↦ hcons k i k' j h0 hi) + fun hle ↦ absurd (lt_of_lt_of_le hi (hc k)) (not_lt.2 hle) + +/-- SNP-10 Every frontier resolves among the positions the chains serve, when every chain serves +its empty prefix: among the consistent cuts under the frontier with every position served there +is a greatest. This is the cut a read is taken at when a store cannot serve the cut asked. -/ +theorem exists_resolvesIn (R : K → ℕ → K → ℕ → Prop) {S : K → Set ℕ} (h0 : ∀ k, 0 ∈ S k) + (f : Cut K) : ∃ c, ResolvesIn R S f c := by + have hne : ∀ k, (reachedIn R S f k).Nonempty := fun k ↦ + ⟨0, fun _ ↦ 0, consistent_zero, fun k' ↦ h0 k', fun _ ↦ Nat.zero_le _, rfl⟩ + have hbdd : ∀ k, BddAbove (reachedIn R S f k) := fun k ↦ + ⟨f k, by rintro n ⟨d, -, -, hd, rfl⟩; exact hd k⟩ + refine ⟨fun k ↦ sSup (reachedIn R S f k), ?_, ?_, ?_, ?_⟩ + · intro k i k' j hR hi + obtain ⟨d, hd, hS, hdf, hdk⟩ := Nat.sSup_mem (hne k) (hbdd k) + have hj : j < d k' := hd k i k' j hR (by rw [hdk]; exact hi) + exact lt_of_lt_of_le hj (le_csSup (hbdd k') ⟨d, hd, hS, hdf, rfl⟩) + · intro k + obtain ⟨d, -, hS, -, hdk⟩ := Nat.sSup_mem (hne k) (hbdd k) + change sSup (reachedIn R S f k) ∈ S k + rw [← hdk] + exact hS k + · intro k + exact csSup_le (hne k) (by rintro n ⟨d, -, -, hd, rfl⟩; exact hd k) + · intro d hd hS hdf k + exact le_csSup (hbdd k) ⟨d, hd, hS, hdf, rfl⟩ + +/-- A frontier resolves among the served positions to at most one cut. -/ +theorem ResolvesIn.unique {S : K → Set ℕ} {f c c' : Cut K} (h : ResolvesIn R S f c) + (h' : ResolvesIn R S f c') : c = c' := + le_antisymm (h'.2.2.2 c h.1 h.2.1 h.2.2.1) (h.2.2.2 c' h'.1 h'.2.1 h'.2.2.1) + +/-- SNP-10 The cut read rises with what is served and with the frontier: a store that gains a +past, or a later cut asked, never lowers the cut read. -/ +theorem ResolvesIn.mono {S S' : K → Set ℕ} {f f' c c' : Cut K} (hS : ∀ k, S k ⊆ S' k) + (hf : f ≤ f') (h : ResolvesIn R S f c) (h' : ResolvesIn R S' f' c') : c ≤ c' := + h'.2.2.2 c h.1 (fun k ↦ hS k (h.2.1 k)) (h.2.2.1.trans hf) + +/-- When every position is served the cut read is the resolution of the frontier. -/ +theorem resolvesIn_univ {f c : Cut K} : + ResolvesIn R (fun _ ↦ Set.univ) f c ↔ Resolves R f c := by + constructor + · rintro ⟨h1, -, h3, h4⟩ + exact ⟨h1, h3, fun d hd hdf ↦ h4 d hd (fun _ ↦ Set.mem_univ _) hdf⟩ + · rintro ⟨h1, h2, h3⟩ + exact ⟨h1, fun _ ↦ Set.mem_univ _, h2, fun d hd _ hdf ↦ h3 d hd hdf⟩ + +/-- SNP-10 The cut read is never past the cut asked: it lies under the resolution of the +frontier, so a read under `as of` holds no event from after the cut it names. -/ +theorem ResolvesIn.le_resolves {S : K → Set ℕ} {f c c' : Cut K} (h : ResolvesIn R S f c) + (h' : Resolves R f c') : c ≤ c' := + h'.2.2 c h.1 h.2.2.1 + +/-- A consistent frontier every position of which is served is read as asked. -/ +theorem resolvesIn_self {S : K → Set ℕ} {f : Cut K} (h : Consistent R f) + (hS : ∀ k, f k ∈ S k) : ResolvesIn R S f f := + ⟨h, hS, le_rfl, fun _ _ _ hd ↦ hd⟩ + +/-- SNP-8 A recorded bound is sound: when every true source of an event lies at or under a +recorded one on its chain, a cut consistent for the recorded references is consistent for the +true ones. So a resolver may work from the head a row recorded at its writing. -/ +theorem Consistent.of_bound {R' : K → ℕ → K → ℕ → Prop} + (hb : ∀ k i k' j, R k i k' j → ∃ j', j ≤ j' ∧ R' k i k' j') {c : Cut K} + (h : Consistent R' c) : Consistent R c := fun k i k' j hr hi ↦ by + obtain ⟨j', hj, hr'⟩ := hb k i k' j hr + exact lt_of_le_of_lt hj (h k i k' j' hr' hi) + +/-- SNP-10 A chain that no other chain reads can be lowered alone: a consistent cut stays +consistent when its position on such a chain is lowered, the chain's own references pointing +backward. -/ +theorem Consistent.update_of_unread [DecidableEq K] {c : Cut K} {x : K} {p : ℕ} + (hc : Consistent R c) (hp : p ≤ c x) (hx : ∀ k i j, R k i x j → k = x ∧ j ≤ i) : + Consistent R (Function.update c x p) := fun k i k' j hr hi ↦ by + have hik : i < c k := by + by_cases hk : k = x + · subst hk + rw [Function.update_self] at hi + exact lt_of_lt_of_le hi hp + · rwa [Function.update_of_ne hk] at hi + by_cases hk' : k' = x + · subst hk' + obtain ⟨rfl, hji⟩ := hx k i j hr + rw [Function.update_self] at hi ⊢ + exact lt_of_le_of_lt hji hi + · rw [Function.update_of_ne hk'] + exact hc k i k' j hr hik + +/-- SNP-10 The local lowering: when the cut asked is consistent and every chain but one serves +its position, and no other chain reads that one, the cut read is the cut asked with that chain +at the greatest position it serves at or under the one asked. Every other chain is read as +asked. The control is a chain that others read (`Witness.record_drags`). -/ +theorem resolvesIn_update_of_unread [DecidableEq K] {S : K → Set ℕ} {f : Cut K} {x : K} {p : ℕ} + (hf : Consistent R f) (hS : ∀ k, k ≠ x → f k ∈ S k) + (hx : ∀ k i j, R k i x j → k = x ∧ j ≤ i) (hp : p ∈ S x) (hpf : p ≤ f x) + (hmax : ∀ q ∈ S x, q ≤ f x → q ≤ p) : ResolvesIn R S f (Function.update f x p) := by + refine ⟨hf.update_of_unread hpf hx, fun k ↦ ?_, fun k ↦ ?_, fun d _ hdS hdf k ↦ ?_⟩ + · by_cases hk : k = x + · subst hk + rwa [Function.update_self] + · rw [Function.update_of_ne hk] + exact hS k hk + · by_cases hk : k = x + · subst hk + rwa [Function.update_self] + · rw [Function.update_of_ne hk] + · by_cases hk : k = x + · subst hk + rw [Function.update_self] + exact hmax _ (hdS k) (hdf k) + · rw [Function.update_of_ne hk] + exact hdf k + +/-- SNP-10 The same for every chain that no other chain reads, at once: from a consistent cut +asked, when the chains others read serve their positions, the cut read is the cut asked with +each unread chain at the greatest position it serves at or under the one asked. -/ +theorem resolvesIn_of_unread {S : K → Set ℕ} {f p : Cut K} (U : K → Prop) [DecidablePred U] + (hf : Consistent R f) (hS : ∀ k, ¬U k → f k ∈ S k) + (hU : ∀ k i x j, U x → R k i x j → k = x ∧ j ≤ i) + (hp : ∀ x, U x → p x ∈ S x ∧ p x ≤ f x ∧ ∀ q ∈ S x, q ≤ f x → q ≤ p x) : + ResolvesIn R S f fun k ↦ if U k then p k else f k := by + have hle : ∀ k, (if U k then p k else f k) ≤ f k := fun k ↦ by + by_cases hk : U k + · simp only [hk, ↓reduceIte] + exact (hp k hk).2.1 + · simp only [hk, ↓reduceIte] + exact le_rfl + refine ⟨fun k i k' j hr hi ↦ ?_, fun k ↦ ?_, hle, fun d _ hdS hdf k ↦ ?_⟩ + · have hj := hf k i k' j hr (lt_of_lt_of_le hi (hle k)) + by_cases hk' : U k' + · obtain ⟨rfl, hji⟩ := hU k i k' j hk' hr + exact lt_of_le_of_lt hji hi + · simp only [hk', ↓reduceIte] + exact hj + · by_cases hk : U k + · simp only [hk, ↓reduceIte] + exact (hp k hk).1 + · simp only [hk, ↓reduceIte] + exact hS k hk + · by_cases hk : U k + · simp only [hk, ↓reduceIte] + exact (hp k hk).2.2 _ (hdS k) (hdf k) + · simp only [hk, ↓reduceIte] + exact hdf k + +/-- SNP-10 The lowering with followers. `U` are chains that cannot serve the position asked and +`V` chains that read them; nothing else reads a chain of `U`, and nothing but itself reads a +chain of `V`. From a consistent cut asked, the cut read has each chain of `U` at the greatest +position it serves at or under the one asked, each chain of `V` at the greatest position it +serves whose events read the chains of `U` inside those positions, and every other chain as +asked. A chain of records, which reads every chain it certifies and is read by none, is a chain +of `V`: it is lowered with what it certifies, to its last record that the cut read holds, and +takes nothing with it. The control is `Witness.record_follows`. -/ +theorem resolvesIn_of_followed {S : K → Set ℕ} {f p q : Cut K} (U V : K → Prop) + [DecidablePred U] [DecidablePred V] (hf : Consistent R f) (hUV : ∀ k, V k → ¬U k) + (hS : ∀ k, ¬U k → ¬V k → f k ∈ S k) + (hU : ∀ k i x j, U x → R k i x j → (k = x ∧ j ≤ i) ∨ V k) + (hV : ∀ k i x j, V x → R k i x j → k = x ∧ j ≤ i) + (hp : ∀ x, U x → p x ∈ S x ∧ p x ≤ f x ∧ ∀ n ∈ S x, n ≤ f x → n ≤ p x) + (hq : ∀ x, V x → q x ∈ S x ∧ q x ≤ f x ∧ (∀ i y j, U y → R x i y j → i < q x → j < p y) ∧ + ∀ n ∈ S x, n ≤ f x → (∀ i y j, U y → R x i y j → i < n → j < p y) → n ≤ q x) : + ResolvesIn R S f fun k ↦ if U k then p k else if V k then q k else f k := by + have hle : ∀ k, (if U k then p k else if V k then q k else f k) ≤ f k := fun k ↦ by + by_cases hk : U k + · simp only [hk, ↓reduceIte] + exact (hp k hk).2.1 + · by_cases hv : V k + · simp only [hk, hv, ↓reduceIte] + exact (hq k hv).2.1 + · simp only [hk, hv, ↓reduceIte] + exact le_rfl + refine ⟨fun k i k' j hr hi ↦ ?_, fun k ↦ ?_, hle, fun d hd hdS hdf k ↦ ?_⟩ + · by_cases hk' : U k' + · rcases hU k i k' j hk' hr with ⟨rfl, hji⟩ | hv + · exact lt_of_le_of_lt hji hi + · have hk : ¬U k := hUV k hv + simp only [hk, hv, ↓reduceIte] at hi + simp only [hk', ↓reduceIte] + exact (hq k hv).2.2.1 i k' j hk' hr hi + · by_cases hv' : V k' + · obtain ⟨rfl, hji⟩ := hV k i k' j hv' hr + exact lt_of_le_of_lt hji hi + · simp only [hk', hv', ↓reduceIte] + exact hf k i k' j hr (lt_of_lt_of_le hi (hle k)) + · by_cases hk : U k + · simp only [hk, ↓reduceIte] + exact (hp k hk).1 + · by_cases hv : V k + · simp only [hk, hv, ↓reduceIte] + exact (hq k hv).1 + · simp only [hk, hv, ↓reduceIte] + exact hS k hk hv + · by_cases hk : U k + · simp only [hk, ↓reduceIte] + exact (hp k hk).2.2 _ (hdS k) (hdf k) + · by_cases hv : V k + · simp only [hk, hv, ↓reduceIte] + exact (hq k hv).2.2.2 _ (hdS k) (hdf k) fun i y j hy hr hi ↦ + lt_of_lt_of_le (hd k i y j hr hi) ((hp y hy).2.2 _ (hdS y) (hdf y)) + · simp only [hk, hv, ↓reduceIte] + exact hdf k + +theorem ResolvesIn.le_on_of_closed {R' : K → ℕ → K → ℕ → Prop} {S S' : K → Set ℕ} + {f f' c c' : Cut K} (G : K → Prop) + (hclosed : ∀ k i k' j, G k → R' k i k' j → G k') + (hR : ∀ k i k' j, G k → R' k i k' j → R k i k' j) (hS : ∀ k, G k → S k ⊆ S' k) + (h0 : ∀ k, 0 ∈ S' k) (hf : ∀ k, G k → f k ≤ f' k) (h : ResolvesIn R S f c) + (h' : ResolvesIn R' S' f' c') : ∀ k, G k → c k ≤ c' k := by + classical + have hcons : Consistent R' fun k ↦ if G k then c k else 0 := by + intro k i k' j hr hi + by_cases hk : G k + · have hk' := hclosed k i k' j hk hr + simp only [hk, ↓reduceIte] at hi + simp only [hk', ↓reduceIte] + exact h.1 k i k' j (hR k i k' j hk hr) hi + · simp [hk] at hi + have hserved : ∀ k, (if G k then c k else 0) ∈ S' k := by + intro k + by_cases hk : G k + · simp only [hk, ↓reduceIte] + exact hS k hk (h.2.1 k) + · simp only [hk, ↓reduceIte] + exact h0 k + have hle : (fun k ↦ if G k then c k else 0) ≤ f' := by + intro k + by_cases hk : G k + · simp only [hk, ↓reduceIte] + exact (h.2.2.1 k).trans (hf k hk) + · simp only [hk, ↓reduceIte] + exact Nat.zero_le _ + intro k hk + simpa [hk] using h'.2.2.2 _ hcons hserved hle k + +/-- SNP-6 The cut read on the chains a grant names is a function of those chains when they +read from no chain outside them: two stores of references, served positions and frontiers that +agree on such a set of chains resolve to cuts that agree on it. The control is a named chain +that reads an unnamed one (`Witness.resolution_reads_unnamed`). -/ +theorem ResolvesIn.eq_on_of_closed {R' : K → ℕ → K → ℕ → Prop} {S S' : K → Set ℕ} + {f f' c c' : Cut K} (G : K → Prop) + (hclosed : ∀ k i k' j, G k → R k i k' j → G k') + (hR : ∀ k i k' j, G k → (R k i k' j ↔ R' k i k' j)) (hS : ∀ k, G k → S k = S' k) + (h0 : ∀ k, 0 ∈ S k) (h0' : ∀ k, 0 ∈ S' k) (hf : ∀ k, G k → f k = f' k) + (h : ResolvesIn R S f c) (h' : ResolvesIn R' S' f' c') : ∀ k, G k → c k = c' k := + fun k hk ↦ le_antisymm + (h.le_on_of_closed G (fun a i b j ha hr ↦ hclosed a i b j ha ((hR a i b j ha).2 hr)) + (fun a i b j ha hr ↦ (hR a i b j ha).2 hr) (fun a ha ↦ (hS a ha).subset) h0' + (fun a ha ↦ (hf a ha).le) h' k hk) + (h'.le_on_of_closed G hclosed (fun a i b j ha hr ↦ (hR a i b j ha).1 hr) + (fun a ha ↦ (hS a ha).superset) h0 (fun a ha ↦ (hf a ha).ge) h k hk) + +/-! The filtered read: the references a resolver does not follow. -/ + +section Filter + +variable {ok : K → ℕ → Prop} {c : Cut K} + +/-- SNP-8 The filtered read is closed: every source of a kept row is kept, so it lies inside the +cut and is itself not withheld. The read holds no fact whose sources lie after the cut, whatever +the cut. -/ +theorem Kept.source {k k' : K} {i j : ℕ} (h : Kept R ok c k i) (hr : R k i k' j) : + Kept R ok c k' j := + ⟨lt_of_not_ge fun hle ↦ h.2 (.outside hr hle), fun hw ↦ h.2 (.through hr hw)⟩ + +/-- A kept row passes its own test. -/ +theorem Kept.passes {k : K} {i : ℕ} (h : Kept R ok c k i) : ok k i := + not_not.1 fun hn ↦ h.2 (.own hn) + +/-- SNP-8 The filtered read withholds no more than it must: every set of rows inside the cut +that pass their own test and that holds the sources of its rows is kept. So the filtered read is +the greatest such set. -/ +theorem kept_of_closed (T : K → ℕ → Prop) (hT : ∀ k i, T k i → i < c k ∧ ok k i) + (hclosed : ∀ k i k' j, T k i → R k i k' j → T k' j) {k : K} {i : ℕ} (h : T k i) : + Kept R ok c k i := by + refine ⟨(hT k i h).1, fun hw ↦ ?_⟩ + induction hw with + | own hn => exact hn (hT _ _ h).2 + | outside hr hle => exact absurd (hT _ _ (hclosed _ _ _ _ h hr)).1 (not_lt.2 hle) + | through hr _ ih => exact ih (hclosed _ _ _ _ h hr) + +/-- SNP-8 At a consistent cut, with every row passing its own test, the filter withholds +nothing: the filtered read is the prefix. So it is the prefix at the head. -/ +theorem kept_iff_of_consistent (hc : Consistent R c) (hok : ∀ k i, ok k i) {k : K} {i : ℕ} : + Kept R ok c k i ↔ i < c k := + ⟨fun h ↦ h.1, fun h ↦ kept_of_closed (fun k i ↦ i < c k) (fun k i hi ↦ ⟨hi, hok k i⟩) + (fun k i k' j hi hr ↦ hc k i k' j hr hi) h⟩ + +/-- SNP-8 The rows whose references are all resolved are never withheld. `P` is a set of rows +that pass their own test, whose every reference is one the resolver follows (`R'`) and leads +into `P`: the landings, the attestations of landings and of commits, the commits. At a cut +consistent for `R'` every row of `P` inside the cut is kept under the whole relation `R`. -/ +theorem kept_of_resolved {R' : K → ℕ → K → ℕ → Prop} (P : K → ℕ → Prop) + (hP : ∀ k i k' j, P k i → R k i k' j → R' k i k' j ∧ P k' j) (hok : ∀ k i, P k i → ok k i) + (hc : Consistent R' c) {k : K} {i : ℕ} (h : P k i) (hi : i < c k) : Kept R ok c k i := + kept_of_closed (fun k i ↦ P k i ∧ i < c k) (fun k i hk ↦ ⟨hk.2, hok k i hk.1⟩) + (fun k i k' j hk hr ↦ ⟨(hP k i k' j hk.1 hr).2, hc k i k' j (hP k i k' j hk.1 hr).1 hk.2⟩) + ⟨h, hi⟩ + +/-- A row withheld at a later cut is withheld at an earlier one. -/ +theorem Withheld.anti {c d : Cut K} (hcd : c ≤ d) {k : K} {i : ℕ} (h : Withheld R ok d k i) : + Withheld R ok c k i := by + induction h with + | own hn => exact .own hn + | outside hr hle => exact .outside hr ((hcd _).trans hle) + | through hr _ ih => exact .through hr ih + +/-- SNP-2 The filtered read is monotone in the cut, for a test that does not depend on the cut: +a row kept at a cut is kept at every later one. -/ +theorem Kept.mono {c d : Cut K} (hcd : c ≤ d) {k : K} {i : ℕ} (h : Kept R ok c k i) : + Kept R ok d k i := + ⟨lt_of_lt_of_le h.1 (hcd k), fun hw ↦ h.2 (hw.anti hcd)⟩ + +/-- A row inside the old head that is withheld for the references of a grown store was withheld +for the old ones, when the rows inside the old head kept their references. -/ +theorem Withheld.of_grown {R' : K → ℕ → K → ℕ → Prop} {h : Cut K} + (hR : ∀ k i k' j, i < h k → R' k i k' j → R k i k' j) (hc : c ≤ h) {k : K} {i : ℕ} + (hw : Withheld R' ok c k i) (hi : i < h k) : Withheld R ok c k i := by + induction hw with + | own hn => exact .own hn + | outside hr hle => exact .outside (hR _ _ _ _ hi hr) hle + | @through k k' i j hr _ ih => + by_cases hj : j < h k' + · exact .through (hR _ _ _ _ hi hr) (ih hj) + · exact .outside (hR _ _ _ _ hi hr) ((hc k').trans (not_lt.1 hj)) + +/-- SNP-1 The filtered read is append invariant: when the rows inside the old head keep the +references they had, the rows kept at a cut inside the old head are the same after the store +grows. -/ +theorem kept_grown_iff {R' : K → ℕ → K → ℕ → Prop} {h : Cut K} + (hR : ∀ k i k' j, i < h k → (R' k i k' j ↔ R k i k' j)) (hc : c ≤ h) {k : K} {i : ℕ} : + Kept R' ok c k i ↔ Kept R ok c k i := + ⟨fun hk ↦ ⟨hk.1, fun hw ↦ hk.2 (hw.of_grown (fun a b a' b' hb hr ↦ (hR a b a' b' hb).2 hr) hc + (lt_of_lt_of_le hk.1 (hc k)))⟩, + fun hk ↦ ⟨hk.1, fun hw ↦ hk.2 (hw.of_grown (fun a b a' b' hb hr ↦ (hR a b a' b' hb).1 hr) hc + (lt_of_lt_of_le hk.1 (hc k)))⟩⟩ + +end Filter + +end Consistency + +/-! ### SNP-9 Certified cuts -/ + +section Certified + +variable {K α C H : Type*} {step : H → α → H} {h₀ : H} + +theorem verifies_certify {s : Store K α} {c : Cut K} (h : c ≤ head s) : + Verifies step h₀ (certify step h₀ s c) s := + ⟨h, fun _ ↦ rfl⟩ + +/-- SNP-9 A certificate is append invariant: the certificate of a cut of a store verifies on +every extension of the store. -/ +theorem verifies_certify_of_extends {s s' : Store K α} {c : Cut K} (h : Extends s s') + (hc : c ≤ head s) : Verifies step h₀ (certify step h₀ s c) s' := + ⟨hc.trans h.head_le, + fun k ↦ congrArg (chainDigest step h₀) (congrFun (readAt_of_extends h hc) k)⟩ + +theorem chainDigest_append_singleton (step : H → α → H) (h₀ : H) (l : List α) (a : α) : + chainDigest step h₀ (l ++ [a]) = step (chainDigest step h₀ l) a := by + simp only [chainDigest, List.foldl_append, List.foldl_cons, List.foldl_nil] + +/-- Under a collision-free step, two chains of one length with one digest are one chain. -/ +theorem eq_of_chainDigest_eq (hstep : CollisionFree step) {l l' : List α} + (hlen : l.length = l'.length) + (h : chainDigest step h₀ l = chainDigest step h₀ l') : l = l' := by + induction l using List.reverseRecOn generalizing l' with + | nil => exact (List.length_eq_zero_iff.1 hlen.symm).symm + | append_singleton l a ih => + rcases List.eq_nil_or_concat l' with rfl | ⟨m, b, rfl⟩ + · simp at hlen + · rw [List.concat_eq_append] at hlen h + rw [chainDigest_append_singleton, chainDigest_append_singleton] at h + obtain ⟨h1, rfl⟩ := hstep _ _ _ _ h + rw [List.concat_eq_append, ih (by simpa using hlen) h1] + +/-- SNP-9 A certificate pins the read: under a collision-free digest, two stores that verify +one certificate have the same read at its cut. -/ +theorem Verifies.readAt_eq (hstep : CollisionFree step) {z : Certificate K H} + {s s' : Store K α} (h : Verifies step h₀ z s) (h' : Verifies step h₀ z s') : + readAt s z.cut = readAt s' z.cut := by + funext k + refine eq_of_chainDigest_eq hstep ?_ ((h.2 k).trans (h'.2 k).symm) + have hk : z.cut k ≤ (s k).length := h.1 k + have hk' : z.cut k ≤ (s' k).length := h'.1 k + change ((s k).take (z.cut k)).length = ((s' k).take (z.cut k)).length + rw [List.length_take, List.length_take, Nat.min_eq_left hk, Nat.min_eq_left hk'] + +/-- SNP-9 So a snapshot is reproducible and checkable: every derived view at a certified cut +is the same on every store that verifies the certificate. -/ +theorem Verifies.view_eq {β : Type*} (hstep : CollisionFree step) (D : Store K α → β) + {z : Certificate K H} {s s' : Store K α} (h : Verifies step h₀ z s) + (h' : Verifies step h₀ z s') : view D s z.cut = view D s' z.cut := + congrArg D (h.readAt_eq hstep h') + +/-- SNP-9 A certificate extends: the digest at a later cut is the digest at an earlier cut +continued over the events between the two, so certifying costs the delta. -/ +theorem certify_digest_readBetween (s : Store K α) {a b : Cut K} (h : a ≤ b) (k : K) : + (certify step h₀ s b).digest k + = chainDigest step ((certify step h₀ s a).digest k) (readBetween s a b k) := + foldAt_readBetween step (fun _ ↦ h₀) s h k + +/-- SNP-9 The meet of two certified cuts is certified from the two certificates alone: on each +chain, the digest of the one that is earlier there. -/ +theorem certify_inf (s : Store K α) (c d : Cut K) (k : K) : + (certify step h₀ s (c ⊓ d)).digest k + = if c k ≤ d k then (certify step h₀ s c).digest k else (certify step h₀ s d).digest k := by + by_cases h : c k ≤ d k + · simp only [h, ↓reduceIte] + change chainDigest step h₀ ((s k).take (c k ⊓ d k)) = chainDigest step h₀ ((s k).take (c k)) + rw [inf_of_le_left h] + · simp only [h, ↓reduceIte] + change chainDigest step h₀ ((s k).take (c k ⊓ d k)) = chainDigest step h₀ ((s k).take (d k)) + rw [inf_of_le_right (not_le.1 h).le] + +/-- SNP-9 And the join: on each chain, the digest of the one that is later there. -/ +theorem certify_sup (s : Store K α) (c d : Cut K) (k : K) : + (certify step h₀ s (c ⊔ d)).digest k + = if c k ≤ d k then (certify step h₀ s d).digest k else (certify step h₀ s c).digest k := by + by_cases h : c k ≤ d k + · simp only [h, ↓reduceIte] + change chainDigest step h₀ ((s k).take (c k ⊔ d k)) = chainDigest step h₀ ((s k).take (d k)) + rw [sup_of_le_right h] + · simp only [h, ↓reduceIte] + change chainDigest step h₀ ((s k).take (c k ⊔ d k)) = chainDigest step h₀ ((s k).take (c k)) + rw [sup_of_le_left (not_le.1 h).le] + +/-- SNP-9 Erasure keeps the certificate: a certificate over the commitments of a committed +store verifies after any erasure of contents. -/ +theorem verifies_purge {step : H → C → H} {z : Certificate K H} {t : Store K (C × Option α)} + (E : α → Bool) (h : Verifies step h₀ z (commitments t)) : + Verifies step h₀ z (commitments (purge E t)) := by + rwa [commitments_purge] + +/-- SNP-9 And only the commitments: a store verifies a certificate after an erasure exactly +when it did before, so a certificate attests no erasure. A copy taken before a purge verifies +every certificate the purged store verifies. -/ +theorem verifies_purge_iff {step : H → C → H} {z : Certificate K H} + {t : Store K (C × Option α)} (E : α → Bool) : + Verifies step h₀ z (commitments (purge E t)) ↔ Verifies step h₀ z (commitments t) := by + rw [commitments_purge] + +/-- SNP-9 Under a binding commitment a certificate over commitments pins the events: two +committed stores that verify one certificate, each after an erasure of its own, were made from +the same events at its cut. -/ +theorem Verifies.readAt_eq_of_committed {step : H → C → H} (hstep : CollisionFree step) + {commit : α → C} (hcommit : Function.Injective commit) {z : Certificate K H} + {s s' : Store K α} (E E' : α → Bool) + (h : Verifies step h₀ z (commitments (purge E (committed commit s)))) + (h' : Verifies step h₀ z (commitments (purge E' (committed commit s')))) : + readAt s z.cut = readAt s' z.cut := by + rw [commitments_purge] at h h' + funext k + have hk := congrFun (h.readAt_eq hstep h') k + simp only [readAt, commitments, committed, List.map_map] at hk + have hfun : (Prod.fst ∘ fun a : α ↦ (commit a, some a)) = commit := rfl + rw [hfun, ← List.map_take, ← List.map_take] at hk + exact List.map_injective_iff.2 hcommit hk + +/-- SNP-9 So what is read at a certified cut is pinned up to the erasure: two committed stores +that verify one certificate read, at its cut and under one erasure, the same store with holes. -/ +theorem Verifies.contents_eq {step : H → C → H} (hstep : CollisionFree step) + {commit : α → C} (hcommit : Function.Injective commit) (E : α → Bool) + {z : Certificate K H} {s s' : Store K α} + (h : Verifies step h₀ z (commitments (purge E (committed commit s)))) + (h' : Verifies step h₀ z (commitments (purge E (committed commit s')))) : + readAt (contents (purge E (committed commit s))) z.cut + = readAt (contents (purge E (committed commit s'))) z.cut := by + rw [contents_purge_committed, contents_purge_committed, redact_readAt, redact_readAt, + Verifies.readAt_eq_of_committed hstep hcommit E E h h'] + +/-- SNP-9 for the composite reader: two stores that verify one certificate show the same at +its cut under one grant and one erasure. The grant and the erasure are not in the certificate. -/ +theorem Verifies.shown_eq (hstep : CollisionFree step) (G : K → Prop) [DecidablePred G] + (p E : α → Bool) {z : Certificate K H} {s s' : Store K α} (h : Verifies step h₀ z s) + (h' : Verifies step h₀ z s') : shown G p E s z.cut = shown G p E s' z.cut := by + unfold shown snapshot + rw [h.readAt_eq hstep h'] + +end Certified + +namespace Witness + +/-- The control for SNP-1: the reader that ignores the cut, which is what a verb reads of a +store rewritten in place, is not append invariant. -/ +theorem present_not_appendInvariant : + ¬AppendInvariant (present fun s : Store Unit ℕ ↦ (s ()).length) := by + intro h + have h1 := h (fun _ ↦ []) (fun _ ↦ [0]) (fun _ ↦ 0) (fun _ ↦ le_rfl) + simp [present, grow] at h1 + +/-- The control for SNP-5: the store rewritten in place determines no read at a past cut. Two +chains leave one head state and had different states at the first cut. -/ +theorem stateOf_forgets : + ¬∃ G : (Unit → Option ℕ) → ℕ → Unit → Option ℕ, + ∀ (l : List (Unit × ℕ)) (c : ℕ), stateAt l c = G (stateOf l) c := by + rintro ⟨G, hG⟩ + have h1 := congrFun (hG [((), 0), ((), 1)] 1) () + have h2 := congrFun (hG [((), 1)] 1) () + have e : stateOf [((), 0), ((), 1)] = stateOf [((), 1)] := by + funext u + simp [stateOf] + rw [e, ← h2] at h1 + simp [stateAt, stateOf] at h1 + +/-- The control for SNP-6: an event filter applied before the cut reads another thing than the +snapshot, since it moves the positions. -/ +theorem filter_before_cut : + ∃ (s : Store Unit Bool) (c : Cut Unit), + readAt (restrict (fun _ ↦ True) id s) c ≠ snapshot (fun _ ↦ True) id s c := by + refine ⟨fun _ ↦ [false, true], fun _ ↦ 1, fun h ↦ ?_⟩ + have h1 := congrFun h () + simp [readAt, restrict, snapshot] at h1 + +/-- The control for SNP-6: a cut's positions count the events an event filter hides. Two stores +that agree on every admitted event have different snapshots at one cut, so within a chain a +position tells how many hidden events came before: what must be hidden in number is hidden by +chain. -/ +theorem position_channel : + ∃ (s s' : Store Unit Bool) (c : Cut Unit), (∀ k, (s k).filter id = (s' k).filter id) ∧ + snapshot (fun _ ↦ True) id s c ≠ snapshot (fun _ ↦ True) id s' c := by + refine ⟨fun _ ↦ [false, true], fun _ ↦ [true], fun _ ↦ 1, fun _ ↦ rfl, fun h ↦ ?_⟩ + have h1 := congrFun h () + simp [readAt, restrict, snapshot] at h1 + +/-- The control for SNP-7: an erasure that deletes rows moves the later ones up, so a read at a +cut then holds an event from after the cut. -/ +theorem compact_moves : + ∃ (E : ℕ → Bool) (s : Store Unit ℕ) (c : Cut Unit) (a : ℕ), + a ∈ readAt (compact E s) c () ∧ a ∉ readAt s c () := by + refine ⟨fun n ↦ n == 0, fun _ ↦ [0, 1], fun _ ↦ 1, 1, ?_, ?_⟩ <;> simp [readAt, compact] + +/-- The control for SNP-7's stricter seal: the looser seal is lifted by a later landing, so +under it growth of the chain brings a retired key's past back to a cut inside the chain. -/ +theorem servedNow_restores : + ∃ (l t : List (Unit × Option ℕ)) (c : ℕ), c ≤ l.length ∧ + servedNow l c () = none ∧ servedNow (l ++ t) c () = some 0 := by + refine ⟨[((), some 0), ((), none)], [((), some 1)], 1, by decide, ?_, ?_⟩ <;> + simp [servedNow, stateAt, stateOf] + +/-- The control for SNP-10: under the horizon the pruned store reads a key as absent where it +held a value. So the horizon is recorded, and a cut under it is not served. -/ +theorem prune_forgets : + ∃ (l : List (Unit × ℕ)) (h c : ℕ), c < h ∧ + genRead (prune h (gens l)) c () = none ∧ stateAt l c () = some 0 := by + refine ⟨[((), 0), ((), 1)], 2, 1, by decide, ?_, ?_⟩ + · decide + · decide + +/-- The control for SNP-9: a digest that is not collision free pins nothing. Under addition two +chains of one length and one digest differ. -/ +theorem digest_collides : + ∃ l l' : List ℕ, l.length = l'.length ∧ + chainDigest (· + ·) 0 l = chainDigest (· + ·) 0 l' ∧ l ≠ l' := + ⟨[1, 2], [2, 1], rfl, rfl, by decide⟩ + +/-- The control for SNP-10, in its stronger form: nothing in the rows that remain tells a lost +key from a key that was never there. Two chains have the same pruned store, and at one cut under +the horizon a key held a value in the first and had never been written in the second. -/ +theorem prune_indistinct : + ∃ (l l' : List (ℕ × ℕ)) (h c : ℕ), c < h ∧ + (prune h (gens l)).map (fun r ↦ (r.key, r.val, r.born, r.died)) + = (prune h (gens l')).map (fun r ↦ (r.key, r.val, r.born, r.died)) ∧ + stateAt l c 1 = some 0 ∧ stateAt l' c 1 = none := + ⟨[(0, 0), (1, 0), (0, 1), (1, 1)], [(0, 0), (0, 2), (0, 1), (1, 1)], 4, 2, by decide, + by decide, by decide, by decide⟩ + +/-- The control for SNP-7's keyed read: a hole that loses its key. Path `()` lands versions 1, +2 and 3 and version 2 is erased. With the key kept, the read at cut 2 is a hole. A seek over the +rows of the prefix that still carry the key returns version 1, which was superseded at the cut; +a seek over the chain with the holes deleted returns version 3, which landed after it. -/ +theorem keyless_hole : + ∃ (l : List (Unit × ℕ)) (E : Unit × ℕ → Bool) (c : ℕ), + stateAt (holes E l) c () = some none ∧ + stateOf ((l.take c).filter fun e ↦ !E e) () = some 1 ∧ + lastWrite (l.filter fun e ↦ !E e) c () = some 3 := + ⟨[((), 1), ((), 2), ((), 3)], fun e ↦ e.2 == 2, 2, by decide, by decide, by decide⟩ + +/-- The control for SNP-9: a certificate attests no seal. A chain and its growth by a retire +verify the certificate of one cut, under every digest, and serve different things at it. -/ +theorem seal_not_certified : + ∃ (l t : List (Unit × Option ℕ)) (c : ℕ), + (∀ (step : ℕ → Unit × Option ℕ → ℕ) (h₀ : ℕ), + Verifies step h₀ (certify step h₀ (fun _ : Unit ↦ l) fun _ ↦ c) fun _ ↦ l ++ t) ∧ + servedAt l c () = some 5 ∧ servedAt (l ++ t) c () = none := by + refine ⟨[((), some 5)], [((), none)], 1, fun step h₀ ↦ ?_, by decide, by decide⟩ + exact verifies_certify_of_extends (extends_grow (fun _ ↦ [((), some 5)]) fun _ ↦ [((), none)]) + fun _ ↦ le_rfl + +/-- The control for SNP-9's fixed chain keys: a renamed chain is not an extension. The +certificate of a cut does not verify on the store with its two chains exchanged, under any +digest, so a chain is keyed by an id that a relabel does not change. -/ +theorem rename_breaks_certificate : + ∃ (s s' : Store Bool ℕ) (c : Cut Bool), c ≤ head s ∧ (∀ k, s' k = s (!k)) ∧ + ∀ (step : ℕ → ℕ → ℕ) (h₀ : ℕ), ¬Verifies step h₀ (certify step h₀ s c) s' := by + refine ⟨fun k ↦ if k then [7] else [], fun k ↦ if k then [] else [7], + fun k ↦ if k then 1 else 0, fun k ↦ ?_, fun k ↦ ?_, ?_⟩ + · cases k <;> simp [head] + · cases k <;> rfl + · rintro step h₀ ⟨h, -⟩ + have := h true + simp [certify, head] at this + +/-- The control for SNP-10's local lowering: a record on a chain that content reads. Chain 0 is +a landing log, chain 1 the attestations, chain 2 a chain `X`. The first attestation is a recorded +cut that certifies the first event of `X`; the landing reads its own attestation, the second. +The frontier asked is consistent, and the landing log and the attestations serve every position. +`X` serves its empty prefix and the positions from 2 on. Then every cut the frontier resolves to +among the served positions reads the landing log and the attestations at their empty prefixes: +one chain read low drags down every chain that reads the chain the record sits on. -/ +theorem record_drags : + ∃ (R : ℕ → ℕ → ℕ → ℕ → Prop) (S : ℕ → Set ℕ) (f : Cut ℕ), + Consistent R f ∧ (∀ k, k ≠ 2 → S k = Set.univ) ∧ + ∀ c, ResolvesIn R S f c → c 0 = 0 ∧ c 1 = 0 := by + refine ⟨fun k i k' j ↦ (k = 1 ∧ i = 0 ∧ k' = 2 ∧ j = 0) ∨ (k = 0 ∧ i = 0 ∧ k' = 1 ∧ j = 1), + fun k ↦ if k = 2 then {p | p = 0 ∨ 2 ≤ p} else Set.univ, + fun k ↦ if k = 0 then 1 else if k = 1 then 2 else 1, ?_, fun k hk ↦ by simp [hk], ?_⟩ + · rintro k i k' j (⟨rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl, rfl⟩) _ <;> decide + · rintro c ⟨hc, hS, hcf, -⟩ + have hX : c 2 = 0 := by + have h2 : c 2 = 0 ∨ 2 ≤ c 2 := by simpa using hS 2 + have h1 : c 2 ≤ 1 := by simpa using hcf 2 + omega + have hatt : c 1 = 0 := by + by_contra h + have := hc 1 0 2 0 (Or.inl ⟨rfl, rfl, rfl, rfl⟩) (Nat.pos_of_ne_zero h) + omega + have hland : c 0 = 0 := by + by_contra h + have := hc 0 0 1 1 (Or.inr ⟨rfl, rfl, rfl, rfl⟩) (Nat.pos_of_ne_zero h) + omega + exact ⟨hland, hatt⟩ + +/-- The control for SNP-10's lowering with followers: a chain of records is lowered with what +it certifies. Chain 0 is a landing log, chain 1 the attestations, chain 2 a chain `X` that +serves its empty prefix and the positions from 2 on, chain 3 the records. The landing reads its +attestation, and the one record reads the first event of every other chain. Asked at the head, +the cut read keeps the landing log and the attestations as asked and reads `X` and the records +at their empty prefixes: the records' chain is not read as recorded, and it takes no chain with +it. -/ +theorem record_follows : + ∃ (R : ℕ → ℕ → ℕ → ℕ → Prop) (S : ℕ → Set ℕ) (f : Cut ℕ), + Consistent R f ∧ (∀ k, k ≠ 2 → S k = Set.univ) ∧ (∀ k, f k = 1) ∧ + ∀ c, ResolvesIn R S f c → c 0 = 1 ∧ c 1 = 1 ∧ c 2 = 0 ∧ c 3 = 0 := by + refine ⟨fun k i k' j ↦ (k = 0 ∧ i = 0 ∧ k' = 1 ∧ j = 0) ∨ (k = 3 ∧ i = 0 ∧ k' ≠ 3 ∧ j = 0), + fun k ↦ if k = 2 then {p | p = 0 ∨ 2 ≤ p} else Set.univ, fun _ ↦ 1, ?_, + fun k hk ↦ by simp [hk], fun _ ↦ rfl, ?_⟩ + · rintro k i k' j (⟨rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, -, rfl⟩) _ <;> exact Nat.one_pos + · rintro c ⟨hc, hS, hcf, hmax⟩ + have hX : c 2 = 0 := by + have h2 : c 2 = 0 ∨ 2 ≤ c 2 := by simpa using hS 2 + have h1 : c 2 ≤ 1 := hcf 2 + omega + have h3 : c 3 = 0 := by + by_contra h + have := hc 3 0 2 0 (Or.inr ⟨rfl, rfl, by decide, rfl⟩) (Nat.pos_of_ne_zero h) + omega + have hd : Consistent (fun k i k' j ↦ (k = 0 ∧ i = 0 ∧ k' = 1 ∧ j = 0) ∨ + (k = 3 ∧ i = 0 ∧ k' ≠ 3 ∧ j = 0)) (fun k ↦ if k = 2 ∨ k = 3 then 0 else 1) := by + rintro k i k' j (⟨rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, -, rfl⟩) hi + · decide + · simp at hi + have hle := hmax _ hd (fun k ↦ by by_cases hk : k = 2 <;> simp [hk]) (fun k ↦ by + change (if k = 2 ∨ k = 3 then 0 else 1) ≤ 1 + by_cases hk : k = 2 ∨ k = 3 <;> simp [hk]) + have a0 : 1 ≤ c 0 := by simpa using hle 0 + have a1 : 1 ≤ c 1 := by simpa using hle 1 + have b0 : c 0 ≤ 1 := hcf 0 + have b1 : c 1 ≤ 1 := hcf 1 + exact ⟨by omega, by omega, hX, h3⟩ + +/-- The control for SNP-8's filtered read: a pass attestation whose reference to a landing is +resolved. Chain 0 is a landing log behind a history window: it serves its empty prefix and the +positions from 2 on. Chain 1 is the attestations: the attestation of the landing on chain 0, a +pass attestation that reads that landing, and the attestation of the landing on chain 2. Chain 2 +is a landing log of another class that serves every position. The cut asked is the head and is +consistent. With the pass attestation's reference followed by the resolver, the second landing +log is read at its empty prefix, though it serves the position asked: the cascade of +`record_drags`, through a pass and not a record. -/ +theorem pass_drags : + ∃ (R : ℕ → ℕ → ℕ → ℕ → Prop) (S : ℕ → Set ℕ) (f : Cut ℕ), + Consistent R f ∧ (∀ k, k ≠ 0 → S k = Set.univ) ∧ f 2 = 1 ∧ + ∀ c, ResolvesIn R S f c → c 2 = 0 := by + refine ⟨fun k i k' j ↦ (k = 0 ∧ i = 0 ∧ k' = 1 ∧ j = 0) ∨ (k = 1 ∧ i = 1 ∧ k' = 0 ∧ j = 0) ∨ + (k = 2 ∧ i = 0 ∧ k' = 1 ∧ j = 2), + fun k ↦ if k = 0 then {p | p = 0 ∨ 2 ≤ p} else Set.univ, + fun k ↦ if k = 0 then 1 else if k = 1 then 3 else 1, ?_, fun k hk ↦ by simp [hk], rfl, ?_⟩ + · rintro k i k' j (⟨rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl, rfl⟩) _ <;> + decide + · rintro c ⟨hc, hS, hcf, -⟩ + have h0 : c 0 = 0 := by + have a : c 0 = 0 ∨ 2 ≤ c 0 := by simpa using hS 0 + have b : c 0 ≤ 1 := by simpa using hcf 0 + omega + have h1 : c 1 ≤ 1 := by + by_contra h + have := hc 1 1 0 0 (Or.inr (Or.inl ⟨rfl, rfl, rfl, rfl⟩)) (by omega) + omega + by_contra h + have := hc 2 0 1 2 (Or.inr (Or.inr ⟨rfl, rfl, rfl, rfl⟩)) (Nat.pos_of_ne_zero h) + omega + +/-- The same store with the pass attestation's reference filtered and not resolved. The +resolver follows the landings' references alone, and the cut read is the cut asked with the +first landing log at its empty prefix. That cut is not consistent for the whole relation, so the +prefix read at it holds a pass whose landing is outside. The filtered read withholds that pass +and keeps the attestation after it and the second landing. -/ +theorem pass_withheld : + ∃ (R R' : ℕ → ℕ → ℕ → ℕ → Prop) (S : ℕ → Set ℕ) (f g : Cut ℕ), + (∀ k i k' j, R' k i k' j → R k i k' j) ∧ ResolvesIn R' S f g ∧ g 2 = f 2 ∧ + ¬Consistent R g ∧ ¬Kept R (fun _ _ ↦ True) g 1 1 ∧ Kept R (fun _ _ ↦ True) g 1 2 ∧ + Kept R (fun _ _ ↦ True) g 2 0 := by + let R' : ℕ → ℕ → ℕ → ℕ → Prop := fun k i k' j ↦ + (k = 0 ∧ i = 0 ∧ k' = 1 ∧ j = 0) ∨ (k = 2 ∧ i = 0 ∧ k' = 1 ∧ j = 2) + let R : ℕ → ℕ → ℕ → ℕ → Prop := fun k i k' j ↦ R' k i k' j ∨ (k = 1 ∧ i = 1 ∧ k' = 0 ∧ j = 0) + let S : ℕ → Set ℕ := fun k ↦ if k = 0 then {p | p = 0 ∨ 2 ≤ p} else Set.univ + let f : Cut ℕ := fun k ↦ if k = 0 then 1 else if k = 1 then 3 else 1 + let g : Cut ℕ := fun k ↦ if k = 0 then 0 else f k + have hf : Consistent R' f := by + rintro k i k' j (⟨rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl, rfl⟩) _ <;> decide + have hg : ResolvesIn R' S f g := + resolvesIn_of_unread (R := R') (S := S) (f := f) (p := fun _ ↦ 0) (fun k ↦ k = 0) hf + (fun k hk ↦ by simp [S, hk]) (fun k i x j hx hr ↦ by + subst hx + rcases hr with ⟨-, -, h, -⟩ | ⟨-, -, h, -⟩ <;> simp at h) + (fun x hx ↦ by + subst hx + refine ⟨by simp [S], by simp [f], fun n hn hnf ↦ ?_⟩ + have a : n = 0 ∨ 2 ≤ n := by simpa [S] using hn + have b : n ≤ 1 := by simpa [f] using hnf + change n ≤ 0 + omega) + have hP : ∀ k i, Kept R (fun _ _ ↦ True) g k i ↔ i < g k ∧ ¬(k = 1 ∧ i = 1) := by + intro k i + constructor + · intro hk + refine ⟨hk.1, ?_⟩ + rintro ⟨rfl, rfl⟩ + have := (hk.source (Or.inr ⟨rfl, rfl, rfl, rfl⟩ : R 1 1 0 0)).1 + simp [g] at this + · intro hk + refine kept_of_closed (fun k i ↦ i < g k ∧ ¬(k = 1 ∧ i = 1)) (fun k i h ↦ ⟨h.1, trivial⟩) + ?_ hk + rintro k i k' j ⟨hi, hne⟩ ((⟨rfl, rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl, rfl⟩) | + ⟨rfl, rfl, rfl, rfl⟩) + · simp [g] at hi + · exact ⟨by decide, by decide⟩ + · exact absurd ⟨rfl, rfl⟩ hne + refine ⟨R, R', S, f, g, fun _ _ _ _ h ↦ Or.inl h, hg, rfl, fun h ↦ ?_, fun h ↦ ?_, ?_, ?_⟩ + · have := h 1 1 0 0 (Or.inr ⟨rfl, rfl, rfl, rfl⟩) (by decide) + simp [g] at this + · exact ((hP 1 1).1 h).2 ⟨rfl, rfl⟩ + · exact (hP 1 2).2 ⟨by decide, by decide⟩ + · exact (hP 2 0).2 ⟨by decide, by decide⟩ + +/-- The control for SNP-6's closed set of chains: the cut read on a chain a grant names depends +on what a chain it reads serves. One relation and one frontier, served positions that agree on +the named chain, and two different cuts read on it. -/ +theorem resolution_reads_unnamed : + ∃ (R : Bool → ℕ → Bool → ℕ → Prop) (S S' : Bool → Set ℕ) (f c c' : Cut Bool), + S true = S' true ∧ ResolvesIn R S f c ∧ ResolvesIn R S' f c' ∧ c true ≠ c' true := by + refine ⟨fun k i k' j ↦ k = true ∧ i = 0 ∧ k' = false ∧ j = 0, fun _ ↦ Set.univ, + fun k ↦ if k then Set.univ else {0}, fun _ ↦ 1, fun _ ↦ 1, fun _ ↦ 0, by simp, ?_, ?_, + by simp⟩ + · refine resolvesIn_self (fun k i k' j h _ ↦ ?_) fun _ ↦ Set.mem_univ _ + obtain ⟨-, -, -, rfl⟩ := h + exact Nat.one_pos + · refine ⟨consistent_zero, fun k ↦ ?_, fun _ ↦ Nat.zero_le _, fun d hd hS _ k ↦ ?_⟩ + · cases k <;> simp + · have h0 : d false = 0 := by simpa using hS false + have h1 : d true = 0 := by + by_contra h + have := hd true 0 false 0 ⟨rfl, rfl, rfl, rfl⟩ (Nat.pos_of_ne_zero h) + omega + cases k + · exact h0.le + · exact h1.le + +/-- The control for SNP-10's monotonicity: it needs the served sets to grow. A store that keeps +no past serves its empty prefix and its head, and loses its old head when it grows. Asked at 5 +while the head is 5 the cut read is 5; asked again at 5 after the head moved to 7 it is 0. -/ +theorem served_set_shrinks : + ∃ (S S' : Unit → Set ℕ) (f : Cut Unit), + ResolvesIn (fun _ _ _ _ ↦ False) S f f ∧ + ResolvesIn (fun _ _ _ _ ↦ False) S' f fun _ ↦ 0 := by + refine ⟨fun _ ↦ {0, 5}, fun _ ↦ {0, 7}, fun _ ↦ 5, ?_, ?_⟩ + · exact resolvesIn_self (fun _ _ _ _ h ↦ h.elim) fun _ ↦ by simp + · refine ⟨consistent_zero, fun _ ↦ by simp, fun _ ↦ Nat.zero_le _, fun d _ hS hdf u ↦ ?_⟩ + have h1 : d u = 0 ∨ d u = 7 := by simpa using hS u + have h2 : d u ≤ 5 := hdf u + change d u ≤ 0 + omega + +end Witness + +end Palace.Snapshot diff --git a/formal/Palace/Snapshot/Defs.lean b/formal/Palace/Snapshot/Defs.lean new file mode 100644 index 00000000..34247ef7 --- /dev/null +++ b/formal/Palace/Snapshot/Defs.lean @@ -0,0 +1,366 @@ +module + +public import Mathlib.Data.List.Basic +public import Mathlib.Logic.Function.Basic +public import Mathlib.Order.Basic +public import Mathlib.Order.SetNotation + +/-! +# The temporal snapshot: the model + +dn-temporal-snapshot, on the clock's cuts (`Palace/Clock/Defs.lean`, CLK-2). A **store** is a +family of append chains: for every chain key the events appended to it, in order. The palace's +ledgers are such families (a document's versions, a session's turns, a class's landing log, the +attestations), and a chain only grows at its end. A **cut** is a prefix length for every chain, +the vector of per-chain positions of dn-global-event-clock §2.4. The **read at a cut** is the +prefix of every chain, the **read between two cuts** the events after the first and up to the +second, and a **derived view** at a cut is a derivation applied to the prefixes. + +What is derived can be held three ways, and the model has each: recomputed from the prefix +(`stateAt`, the fold of a chain of keyed writes), journaled (the same fold continued from a +checkpoint over the events between two cuts, `foldAt`), or kept by generation (`gens`: one row +per write, valid from the cut that contains it up to the cut that contains the key's next write, +read by `genRead`). The store rewritten in place is `stateOf`, the fold of the whole chain, which +has no past. Retention drops the generations closed at or under a horizon (`prune`), after which +the store serves the cuts from the horizon on. + +Two things are parameters of a read and no function of the cut, because they are the present's: +the asker's **grant** (`snapshot`: the chains it names and the events it may see named) and the +**erasure** (`visible`: the erased events masked; `redact`: the store with a hole at each, every +position kept; `holes`: the same for a keyed chain, the hole keeping its key; `shown`: the grant +and the erasure applied to one read; `servedAt`: a key retired after the cut is served at no +earlier cut, with `servedNow` the looser seal that a later landing lifts, and `historyAt` the +versions the stricter seal serves). The control for the erasure is `compact`, an erasure that +deletes rows and lets the later ones move up. + +Events may read from events of other chains (`R k i k' j`: the `i`-th event of chain `k` reads +from the `j`-th of chain `k'`); a cut is **consistent** when every source of an event inside it is +inside it, and a frontier **resolves** to the greatest consistent cut under it, or, where a store +serves only some positions (those from its horizon on, and the empty prefix), to the greatest +consistent cut under it among the served positions (`ResolvesIn`). A reference the resolver +does not follow is kept by a filter of the read instead: a row is withheld when a source of it +lies outside the cut or is withheld (`Withheld`, `Kept`). A cut is +**certified** by the digest of each chain's prefix under a chain digest (`chainDigest`, a fold), +and a later store **verifies** the certificate when its own prefixes have those digests. A store +that keeps a commitment beside each event (`committed`) can lose an event's content to an erasure +(`purge`) and keep every certificate. +-/ + +@[expose] public section + +namespace Palace.Snapshot + +/-- A store: a family of append chains, the events of each chain in the order they were +appended. -/ +abbrev Store (K α : Type*) := K → List α + +/-- A cut: a prefix length for every chain (dn-global-event-clock §2.4, the vector of per-chain +positions). -/ +abbrev Cut (K : Type*) := K → ℕ + +/-! ### Reads -/ + +section Reads + +variable {K α β : Type*} + +/-- The head cut: every chain whole. -/ +def head (s : Store K α) : Cut K := fun k ↦ (s k).length + +/-- The store grown by appending `t`, chain by chain. -/ +def grow (s t : Store K α) : Store K α := fun k ↦ s k ++ t k + +/-- `s'` extends `s`: every chain of `s` is a prefix of its chain in `s'`, which is all an +append-only store can do. -/ +def Extends (s s' : Store K α) : Prop := ∀ k, s k <+: s' k + +/-- The read at a cut: the prefix of every chain. -/ +def readAt (s : Store K α) (c : Cut K) : Store K α := fun k ↦ (s k).take (c k) + +/-- The read between two cuts: the events after `a` and up to `b`, chain by chain. -/ +def readBetween (s : Store K α) (a b : Cut K) : Store K α := + fun k ↦ ((s k).take (b k)).drop (a k) + +/-- A derived view at a cut: the derivation applied to the prefixes. -/ +def view (D : Store K α → β) (s : Store K α) (c : Cut K) : β := D (readAt s c) + +/-- The reader that ignores the cut: the derivation applied to the whole store, which is what a +verb reads of a store that keeps no past. -/ +def present (D : Store K α → β) : Store K α → Cut K → β := fun s _ ↦ D s + +/-- A reader of a store at a cut is append invariant when no growth of the store changes what it +reads at a cut inside the store. -/ +def AppendInvariant (F : Store K α → Cut K → β) : Prop := + ∀ s t c, c ≤ head s → F (grow s t) c = F s c + +/-- A reader reads only the prefixes when what it reads at a cut inside the store is what it +reads of the prefixes alone. -/ +def PrefixOnly (F : Store K α → Cut K → β) : Prop := + ∀ s c, c ≤ head s → F s c = F (readAt s c) c + +/-- A journaled view: every chain's prefix folded by a step function from the chain's start +value. A job that keeps such a state and a checkpoint continues the fold over the events between +its checkpoint and a later cut. -/ +def foldAt (f : β → α → β) (init : K → β) (s : Store K α) (c : Cut K) : K → β := + fun k ↦ ((s k).take (c k)).foldl f (init k) + +end Reads + +/-! ### A derived store, three ways -/ + +section Generations + +variable {κ β : Type*} + +/-- The store rewritten in place: after a chain of keyed writes, each key's last value. It is +the fold of the whole chain, so it has no past. -/ +def stateOf [DecidableEq κ] (l : List (κ × β)) : κ → Option β := + l.foldl (fun m e ↦ Function.update m e.1 (some e.2)) fun _ ↦ none + +/-- The state at a cut, recomputed from the chain's prefix. -/ +def stateAt [DecidableEq κ] (l : List (κ × β)) (c : ℕ) : κ → Option β := stateOf (l.take c) + +/-- The state at a cut read off the chain by one seek: the last write of the key inside the +prefix. -/ +def lastWrite [DecidableEq κ] (l : List (κ × β)) (c : ℕ) (x : κ) : Option β := + ((l.take c).reverse.find? fun e ↦ decide (e.1 = x)).map Prod.snd + +/-- A generation: one write of a key, valid from the cut `born` up to, and not at, the cut +`died`. -/ +structure Gen (κ β : Type*) where + /-- The key written. -/ + key : κ + /-- The value written. -/ + val : β + /-- The first cut that contains the write. -/ + born : ℕ + /-- The first cut that contains the key's next write; `none` while the row is the key's + head. -/ + died : Option ℕ + +/-- A generation is alive at a cut from its birth up to, and not at, its death. -/ +def Gen.aliveAt (r : Gen κ β) (c : ℕ) : Bool := + decide (r.born ≤ c) && r.died.all fun d ↦ decide (c < d) + +/-- Close a row at position `p` when it is the open row of the key `x`; any other row is left +as it is. The closing stamp is the one field ever written after a row is appended, and it is a +function of the rows: the position of the key's next write. -/ +def closeAt [DecidableEq κ] (x : κ) (p : ℕ) (r : Gen κ β) : Gen κ β := + if r.key = x ∧ r.died = none then { r with died := some p } else r + +/-- One landing in the generational store, at position `p`: the key's open row is closed at `p` +and the write's own row opens there. -/ +def landGen [DecidableEq κ] (rs : List (Gen κ β)) (p : ℕ) (e : κ × β) : List (Gen κ β) := + rs.map (closeAt e.1 p) ++ [⟨e.1, e.2, p, none⟩] + +/-- The generational store of a chain given newest first: the write over `n` older ones lands at +position `n + 1`, the first cut that contains it. -/ +def gensRev [DecidableEq κ] : List (κ × β) → List (Gen κ β) + | [] => [] + | e :: older => landGen (gensRev older) (older.length + 1) e + +/-- The generational store after a chain of keyed writes. -/ +def gens [DecidableEq κ] (l : List (κ × β)) : List (Gen κ β) := gensRev l.reverse + +/-- What a read of the generational store selects: the rows of the key alive at the cut. -/ +def selects [DecidableEq κ] (c : ℕ) (x : κ) (r : Gen κ β) : Bool := + decide (r.key = x) && r.aliveAt c + +/-- The read of the generational store at a cut: the value of the key's row alive there. -/ +def genRead [DecidableEq κ] (rs : List (Gen κ β)) (c : ℕ) (x : κ) : Option β := + (rs.find? (selects c x)).map Gen.val + +/-- Retention by a horizon: the generations kept are those whose closing stamp, if any, lies past +the horizon. A row closed at or under the horizon is alive at no cut from the horizon on. -/ +def prune (h : ℕ) (rs : List (Gen κ β)) : List (Gen κ β) := + rs.filter fun r ↦ r.died.all fun d ↦ decide (h < d) + +/-- A key is sealed at a cut when the chain retires it after the cut: a retire, the write of +`none`, among the events the cut does not contain. -/ +def sealedAt [DecidableEq κ] (l : List (κ × Option β)) (c : ℕ) (x : κ) : Bool := + (l.drop c).any fun e ↦ decide (e.1 = x) && e.2.isNone + +/-- What a chain of landings and retires serves of a key at a cut: nothing when the key is +sealed there, else the value the key held at the cut, if it was live. The seal is read off the +whole chain, the present, and no prefix of it. -/ +def servedAt [DecidableEq κ] (l : List (κ × Option β)) (c : ℕ) (x : κ) : Option β := + if sealedAt l c x then none else (stateAt l c x).join + +/-- The looser seal: a key is withheld at every cut exactly while it is not live at the head, so +a key landed again after its retire is served again at the cuts before the retire. -/ +def servedNow [DecidableEq κ] (l : List (κ × Option β)) (c : ℕ) (x : κ) : Option β := + if ((stateOf l x).join).isNone then none else (stateAt l c x).join + +/-- The landings of a key that no retire of it follows, oldest first: the versions of the key's +present life. -/ +def sinceRetire [DecidableEq κ] (l : List (κ × Option β)) (x : κ) : List β := + l.foldl (fun acc e ↦ if e.1 = x then (e.2.elim [] fun v ↦ acc ++ [v]) else acc) [] + +/-- The history a chain of landings and retires serves of a key at a cut, under the stricter +seal: nothing when the key is sealed there, else its landings inside the cut that no retire +follows. A version landed before a retire of its key is in no history, at any cut. -/ +def historyAt [DecidableEq κ] (l : List (κ × Option β)) (c : ℕ) (x : κ) : List β := + if sealedAt l c x then [] else sinceRetire (l.take c) x + +/-- A keyed chain with a hole at each erased write: the hole keeps the write's key and its +position and loses its value, so it still shadows the key's earlier writes. The alternative, a +hole that loses its key too, is the control (`Witness.keyless_hole`). -/ +def holes (E : κ × β → Bool) (l : List (κ × β)) : List (κ × Option β) := + l.map fun e ↦ (e.1, if E e then none else some e.2) + +end Generations + +/-! ### The grant and the erasure, the present's -/ + +section Present + +variable {K α β C : Type*} + +/-- A family of chains restricted to the chains `G` names and, within them, to the events `p` +admits. -/ +def restrict (G : K → Prop) [DecidablePred G] (p : α → Bool) (t : Store K α) : Store K α := + fun k ↦ if G k then (t k).filter p else [] + +/-- What a grant reads of a store at a cut: the chains it names, each read at the cut and kept to +the events it may see named. The grant is no function of the cut: it is the asker's now. -/ +def snapshot (G : K → Prop) [DecidablePred G] (p : α → Bool) (s : Store K α) (c : Cut K) : + Store K α := + restrict G p (readAt s c) + +/-- What an asker is shown of a store at a cut: the grant's snapshot with the erased events +masked. The cut, the grant and the erasure in one reader, the last two the present's. -/ +def shown (G : K → Prop) [DecidablePred G] (p E : α → Bool) (s : Store K α) (c : Cut K) : + Store K α := + snapshot G (fun a ↦ p a && !E a) s c + +/-- The store with every erased event replaced by a hole: the erasure keeps every position. -/ +def redact (E : α → Bool) (s : Store K α) : Store K (Option α) := + fun k ↦ (s k).map fun a ↦ if E a then none else some a + +/-- What is visible at a cut once `E` is erased: the prefixes without the erased events. The +erasure is no function of the cut either. -/ +def visible (E : α → Bool) (s : Store K α) (c : Cut K) : Store K α := + fun k ↦ ((s k).take (c k)).filter fun a ↦ !E a + +/-- The control: an erasure that deletes the rows, so that the later ones move up. -/ +def compact (E : α → Bool) (s : Store K α) : Store K α := + fun k ↦ (s k).filter fun a ↦ !E a + +/-- The kept derived rows that may be served once `E` is erased: those none of whose sources is +erased. A row is its sources and its value. -/ +def serve (E : α → Bool) (rows : List (List α × β)) : List (List α × β) := + rows.filter fun r ↦ r.1.all fun a ↦ !E a + +/-- A store that keeps a commitment beside each event: the pair of the event's commitment and +its content. -/ +def committed (commit : α → C) (s : Store K α) : Store K (C × Option α) := + fun k ↦ (s k).map fun a ↦ (commit a, some a) + +/-- The erasure on a committed store: the content of every erased event goes, its commitment +and its position stay. -/ +def purge (E : α → Bool) (t : Store K (C × Option α)) : Store K (C × Option α) := + fun k ↦ (t k).map fun x ↦ (x.1, x.2.filter fun a ↦ !E a) + +/-- The commitments of a committed store, chain by chain: what a certificate digests. -/ +def commitments (t : Store K (C × Option α)) : Store K C := fun k ↦ (t k).map Prod.fst + +/-- The contents of a committed store, chain by chain, a hole where an event was erased: what a +reader reads. -/ +def contents (t : Store K (C × Option α)) : Store K (Option α) := fun k ↦ (t k).map Prod.snd + +end Present + +/-! ### Consistent cuts -/ + +section Consistency + +variable {K : Type*} + +/-- A cut is consistent for the reads-from relation `R` (`R k i k' j`: the `i`-th event of chain +`k` reads from the `j`-th event of chain `k'`) when every source of an event inside the cut is +inside it: no fact whose sources lie after the cut. -/ +def Consistent (R : K → ℕ → K → ℕ → Prop) (c : Cut K) : Prop := + ∀ k i k' j, R k i k' j → i < c k → j < c k' + +/-- The generator edges of the clock on events as (chain, index) pairs: an earlier event of a +chain is before a later one (g1), and a source is before its reader (g2). -/ +def generator (R : K → ℕ → K → ℕ → Prop) (a b : K × ℕ) : Prop := + (a.1 = b.1 ∧ a.2 < b.2) ∨ R b.1 b.2 a.1 a.2 + +/-- The positions of chain `k` that some consistent cut under the frontier `f` reaches. -/ +def reached (R : K → ℕ → K → ℕ → Prop) (f : Cut K) (k : K) : Set ℕ := + {n | ∃ d, Consistent R d ∧ d ≤ f ∧ d k = n} + +/-- The cut `c` resolves the frontier `f`: it is the greatest consistent cut under `f`. A name +(a commit, a certificate, a wall time looked up in the bookmarks) selects a frontier; the read is +at the cut that resolves it. -/ +def Resolves (R : K → ℕ → K → ℕ → Prop) (f c : Cut K) : Prop := + Consistent R c ∧ c ≤ f ∧ ∀ d, Consistent R d → d ≤ f → d ≤ c + +/-- The positions of chain `k` that some consistent cut under the frontier `f`, every position +of which its chain serves, reaches. -/ +def reachedIn (R : K → ℕ → K → ℕ → Prop) (S : K → Set ℕ) (f : Cut K) (k : K) : Set ℕ := + {n | ∃ d, Consistent R d ∧ (∀ k', d k' ∈ S k') ∧ d ≤ f ∧ d k = n} + +/-- The cut `c` resolves the frontier `f` among the positions the chains serve: `S k` is the set +of positions at which the store of chain `k` can be read exactly (every position from its horizon +on, and the empty prefix), and `c` is the greatest consistent cut under `f` every position of +which is served. It is the cut a read is taken at when the cut asked cannot be served whole. -/ +def ResolvesIn (R : K → ℕ → K → ℕ → Prop) (S : K → Set ℕ) (f c : Cut K) : Prop := + Consistent R c ∧ (∀ k, c k ∈ S k) ∧ c ≤ f ∧ + ∀ d, Consistent R d → (∀ k, d k ∈ S k) → d ≤ f → d ≤ c + +/-- A row is withheld at a cut when it fails its own test `ok` (it is erased, or it is about a +version the cut does not hold), when one of its sources lies outside the cut, or when one of its +sources is withheld. The last clause is what makes the filter a closure and not a test of the +row alone. -/ +inductive Withheld (R : K → ℕ → K → ℕ → Prop) (ok : K → ℕ → Prop) (c : Cut K) : K → ℕ → Prop + /-- The row fails its own test. -/ + | own {k : K} {i : ℕ} : ¬ok k i → Withheld R ok c k i + /-- A source of the row lies outside the cut. -/ + | outside {k k' : K} {i j : ℕ} : R k i k' j → c k' ≤ j → Withheld R ok c k i + /-- A source of the row is withheld. -/ + | through {k k' : K} {i j : ℕ} : R k i k' j → Withheld R ok c k' j → Withheld R ok c k i + +/-- The filtered read at a cut: the rows inside the cut that are not withheld. Where a +reference is not resolved, because resolving it would lower a chain that others read, the read +at a cut is this filter of the prefix and not the prefix. -/ +def Kept (R : K → ℕ → K → ℕ → Prop) (ok : K → ℕ → Prop) (c : Cut K) (k : K) (i : ℕ) : Prop := + i < c k ∧ ¬Withheld R ok c k i + +end Consistency + +/-! ### Certified cuts -/ + +section Certified + +variable {K α H : Type*} + +/-- The digest of a chain's prefix: the fold of a step function from a seed, the shape of a hash +chain. -/ +def chainDigest (step : H → α → H) (h₀ : H) (l : List α) : H := l.foldl step h₀ + +/-- A step function is collision free when it is injective in the pair of the digest so far and +the event: the property a cryptographic hash is used for. -/ +def CollisionFree (step : H → α → H) : Prop := + ∀ h a h' a', step h a = step h' a' → h = h' ∧ a = a' + +/-- A certificate of a cut: the cut and the digest of every chain's prefix at it. -/ +structure Certificate (K H : Type*) where + /-- The cut certified. -/ + cut : Cut K + /-- The digest of each chain's prefix at the cut. -/ + digest : K → H + +/-- The certificate of a cut of a store. -/ +def certify (step : H → α → H) (h₀ : H) (s : Store K α) (c : Cut K) : Certificate K H := + ⟨c, fun k ↦ chainDigest step h₀ ((s k).take (c k))⟩ + +/-- A store verifies a certificate when the cut lies inside it and its own prefixes at the cut +have the certified digests. -/ +def Verifies (step : H → α → H) (h₀ : H) (z : Certificate K H) (s : Store K α) : Prop := + z.cut ≤ head s ∧ ∀ k, chainDigest step h₀ ((s k).take (z.cut k)) = z.digest k + +end Certified + +end Palace.Snapshot diff --git a/formal/PalaceTest.lean b/formal/PalaceTest.lean index 8e066937..b16be187 100644 --- a/formal/PalaceTest.lean +++ b/formal/PalaceTest.lean @@ -30,6 +30,7 @@ public import PalaceTest.Scope public import PalaceTest.Script public import PalaceTest.Sentence public import PalaceTest.SigmaStar +public import PalaceTest.Snapshot public import PalaceTest.Spectral public import PalaceTest.Superconnection public import PalaceTest.Utility diff --git a/formal/PalaceTest/Snapshot.lean b/formal/PalaceTest/Snapshot.lean new file mode 100644 index 00000000..256bab1a --- /dev/null +++ b/formal/PalaceTest/Snapshot.lean @@ -0,0 +1,715 @@ +module + +public import Palace.Snapshot +public import PalaceTest.Attack +public meta import Palace.Snapshot +public meta import PalaceTest.Attack + +/-! +# Attacks on `Palace.Snapshot` + +The Plausible attacks and negative controls for the laws of `Palace/Snapshot.lean`, on the +model's own definitions: stores of two chains over an alphabet of three events, each chain a +list; cuts from two naturals; keyed chains as lists of (key, value) over three keys; chains of +landings and retires from codes in `Fin 9`; grants from two bits and event filters and erasures +from three; reads-from relations as lists of edges between events of the two chains at positions +under four; a digest that reads a chain as a numeral in base four, which is collision free, and +one that adds, which is not. Beside the model the attacks carry one thing the library does not: +an executable resolver, the descent that lowers a frontier until no event inside it has a source +outside, tested against the definition of the greatest consistent cut by enumeration; and, for +the horizon, the positions a chain serves from ten bits, with the greatest consistent cut among +them found by enumeration. The controls are the readings a build must not take: a read at a cut +past the head, the store rewritten in place, generations without their closing stamp, a key's +state taken for unchanged whatever the delta writes, an event filter before the cut, an erasure +that deletes rows, a state served without the seal, the looser seal taken for a monotone one, +kept rows served without their sources, a frontier taken for a cut, an additive digest, a digest +over contents, the pruned store read under its horizon, a frontier lowered to the served +positions without the descent, the floor and the descent each run once in either order, a hole +that loses its key, a chain that others read lowered alone, and each law of growth, order and +composition with its hypothesis dropped or its sides exchanged. The served resolver is +executable here too: the floor and the descent alternated until nothing moves, tested against +the enumeration. So is the row filter: the rows no chain of sources leads outside the cut, +tested against every set of rows of the two chains that lies inside the cut and holds its own +sources; its controls are the filter without its closure, the prefix taken for the filtered +read, and a chain that follows a lowered chain read as asked. They run when this module builds +(`lake test`). +-/ + +@[expose] public section + +namespace Palace.Snapshot.Attack + +/-- A store of two chains. -/ +def st {γ : Type} (a b : List γ) : Store (Fin 2) γ := fun k ↦ if k = 0 then a else b + +/-- A cut of two chains. -/ +def cu (m n : ℕ) : Cut (Fin 2) := fun k ↦ if k = 0 then m else n + +/-- Two stores of two chains agree. -/ +def same {γ : Type} [BEq γ] (s t : Store (Fin 2) γ) : Bool := + (List.finRange 2).all fun k ↦ s k == t k + +/-- A grant from two bits: the chains it names. -/ +def gr (g : Fin 4) (k : Fin 2) : Bool := g.val.testBit k.val + +/-- An event filter, or an erasure, from three bits. -/ +def pf (c : Fin 8) (a : Fin 3) : Bool := c.val.testBit a.val + +/-- A landing or a retire from a code: the key from the residue, `none` (a retire) or a value +from the quotient. -/ +def ev (n : Fin 9) : Fin 3 × Option (Fin 2) := + (⟨n.val % 3, Nat.mod_lt _ (by decide)⟩, + match n.val / 3 with + | 0 => none + | 1 => some 0 + | _ => some 1) + +/-- Generations without the closing stamp: every write a row that never dies. -/ +def openRows (l : List (Fin 3 × Fin 3)) : List (Gen (Fin 3) (Fin 3)) := + l.zipIdx.map fun x ↦ ⟨x.1.1, x.1.2, x.2 + 1, none⟩ + +/-- A reads-from edge: the reader's chain and position, then the source's. -/ +abbrev Edge := (Fin 2 × Fin 4) × (Fin 2 × Fin 4) + +/-- Consistency, decided on a list of edges. -/ +def cons (es : List Edge) (c : Cut (Fin 2)) : Bool := + es.all fun e ↦ !decide (e.1.2.val < c e.1.1) || decide (e.2.2.val < c e.2.1) + +/-- A cut of two chains read off a pair: the descent holds values, not closures. -/ +def at2 (c : ℕ × ℕ) (k : Fin 2) : ℕ := if k = 0 then c.1 else c.2 + +/-- One pass of the descent on one chain: its position lowered to the first event inside it +whose source lies outside the cut. -/ +def lowerAt (es : List Edge) (c : ℕ × ℕ) (k : Fin 2) : ℕ := + es.foldl (fun n e ↦ + if e.1.1 = k ∧ e.1.2.val < n ∧ ¬e.2.2.val < at2 c e.2.1 then e.1.2.val else n) (at2 c k) + +/-- One pass of the descent on both chains. -/ +def lower (es : List Edge) (c : ℕ × ℕ) : ℕ × ℕ := (lowerAt es c 0, lowerAt es c 1) + +/-- The executable resolver: the descent run from the frontier `(x, y)` until it can lower +nothing more, which is at most as many passes as the frontier has positions. -/ +def resolve (es : List Edge) (x y : ℕ) : Cut (Fin 2) := + cu ((lower es)^[x + y] (x, y)).1 ((lower es)^[x + y] (x, y)).2 + +/-- The rows of a generational store as tuples, to compare two of them. -/ +def rowsOf (rs : List (Gen (Fin 3) (Fin 3))) : List (Fin 3 × Fin 3 × ℕ × Option ℕ) := + rs.map fun r ↦ (r.key, r.val, r.born, r.died) + +/-- The positions a chain serves, from ten bits: its empty prefix always, and of the positions +one to five those whose bit is set. -/ +def sv (m : Fin 1024) (k : Fin 2) (p : ℕ) : Bool := + p == 0 || (decide (p ≤ 5) && m.val.testBit (5 * k.val + p - 1)) + +/-- The greatest consistent cut under the frontier `(x, y)` among the served positions, by +enumeration: the pointwise maximum of every consistent cut of the grid under the frontier whose +two positions are served. -/ +def bestIn (es : List Edge) (p : Fin 2 → ℕ → Bool) (x y : ℕ) : ℕ × ℕ := + (List.range 6).foldl (fun (acc : ℕ × ℕ) (u : ℕ) ↦ + (List.range 6).foldl (fun (acc : ℕ × ℕ) (v : ℕ) ↦ + if cons es (cu u v) && p 0 u && p 1 v && decide (u ≤ x) && decide (v ≤ y) + then (max acc.1 u, max acc.2 v) else acc) acc) (0, 0) + +/-- The greatest served position of a chain at or under a position: the frontier lowered to +what is served, before any descent. -/ +def floorSv (p : Fin 2 → ℕ → Bool) (k : Fin 2) (x : ℕ) : ℕ := + (List.range (x + 1)).foldl (fun (n : ℕ) (q : ℕ) ↦ if p k q then q else n) 0 + +/-- One round of the served resolver: each chain lowered to the greatest position it serves at +or under its own, then one pass of the descent. -/ +def roundIn (es : List Edge) (p : Fin 2 → ℕ → Bool) (c : ℕ × ℕ) : ℕ × ℕ := + lower es (floorSv p 0 c.1, floorSv p 1 c.2) + +/-- The executable served resolver: the floor and the descent alternated from the frontier +`(x, y)` until nothing moves. A round that moves anything lowers a position, so that is at most +as many rounds as the frontier has positions. -/ +def resolveIn (es : List Edge) (p : Fin 2 → ℕ → Bool) (x y : ℕ) : ℕ × ℕ := + (roundIn es p)^[x + y] (x, y) + +/-- The edges whose source lies in chain 0: with them alone, no event reads chain 1. -/ +def into0 (es : List Edge) : List Edge := es.filter fun e ↦ e.2.1 = 0 + +/-- Chain 0 serves every position and chain 1 the positions of the mask. -/ +def sv1 (m : Fin 1024) (k : Fin 2) (q : ℕ) : Bool := k == 0 || sv m 1 q + +/-- The edges of a store whose chain 1 is read by itself and by chain 0, and whose chain 0 is +read by itself alone, each chain's own references pointing backward: chain 0 follows chain 1. -/ +def foll (es : List Edge) : List Edge := + es.filter fun e ↦ (e.1.1 = 0 || e.2.1 = 1) && (e.1.1 != e.2.1 || decide (e.2.2 ≤ e.1.2)) + +/-- The eight events of two chains of four positions. -/ +def evs : List (Fin 2 × Fin 4) := (List.finRange 2).flatMap fun k ↦ (List.finRange 4).map (k, ·) + +/-- One pass of the row filter: the rows with a source outside the cut or a source already +withheld. -/ +def withholdStep (es : List Edge) (c : ℕ × ℕ) (w : List (Fin 2 × Fin 4)) : + List (Fin 2 × Fin 4) := + evs.filter fun x ↦ es.any fun e ↦ + e.1 == x && (!decide (e.2.2.val < at2 c e.2.1) || w.contains e.2) + +/-- The executable row filter: the rows inside the cut that no chain of sources leads outside +it, the pass run as many times as there are rows. -/ +def keptRows (es : List Edge) (c : ℕ × ℕ) : List (Fin 2 × Fin 4) := + evs.filter fun x ↦ + decide (x.2.val < at2 c x.1) && !((withholdStep es c)^[8] []).contains x + +/-- A set of rows from eight bits. -/ +def rowSet (m : Fin 256) : List (Fin 2 × Fin 4) := + evs.filter fun x ↦ m.val.testBit (4 * x.1.val + x.2.val) + +/-- A set of rows lies inside the cut and holds the sources of its rows. -/ +def closedIn (es : List Edge) (c : ℕ × ℕ) (t : List (Fin 2 × Fin 4)) : Bool := + t.all (fun x ↦ decide (x.2.val < at2 c x.1)) + && es.all fun e ↦ !t.contains e.1 || t.contains e.2 + +/-- The rows whose own sources lie inside the cut: the filter without its closure. -/ +def oneStep (es : List Edge) (c : ℕ × ℕ) : List (Fin 2 × Fin 4) := + evs.filter fun x ↦ decide (x.2.val < at2 c x.1) + && es.all fun e ↦ !(e.1 == x) || decide (e.2.2.val < at2 c e.2.1) + +/-- An erasure of keyed writes by their value. -/ +def ek (e : Fin 8) (w : Fin 3 × Fin 3) : Bool := pf e w.2 + +/-- What is shown under the narrower of two grants and the larger of two erasures is the +restriction of what the wider grant is shown under the smaller erasure. -/ +def shownNarrow (a b : List (Fin 3)) (m : ℕ) (g g' : Fin 4) (c c' e e' : Fin 8) : Bool := + same (shown (fun k ↦ (gr g k && gr g' k) = true) (fun x ↦ pf c x && pf c' x) + (fun x ↦ pf e x || pf e' x) (st a b) (cu m m)) + (restrict (fun k ↦ (gr g k && gr g' k) = true) + (fun x ↦ (pf c x && pf c' x) && !(pf e x || pf e' x)) + (shown (fun k ↦ gr g' k = true) (pf c') (pf e') (st a b) (cu m m))) + +/-- A collision-free step: the chain read as a numeral in base four, digits one to three. -/ +def step4 (h : ℕ) (a : Fin 3) : ℕ := 4 * h + a.val + 1 + +/-- The additive step, which forgets the order. -/ +def stepAdd (h : ℕ) (a : Fin 3) : ℕ := h + a.val + 1 + +/-- A commitment of an event, and the step that digests commitments. -/ +def commit3 (a : Fin 3) : ℕ := a.val + 1 + +/-- The step over commitments. -/ +def stepC (h c : ℕ) : ℕ := 4 * h + c + +/-- A step over contents, a hole digested as zero. -/ +def stepO (h : ℕ) (o : Option (Fin 3)) : ℕ := + 4 * h + match o with + | none => 0 + | some a => a.val + 1 + +/-- Whether a store of two chains verifies a certificate, decided. -/ +def verifies (z : Certificate (Fin 2) ℕ) (s : Store (Fin 2) (Fin 3)) : Bool := + (List.finRange 2).all fun k ↦ + decide (z.cut k ≤ (s k).length) && chainDigest step4 0 ((s k).take (z.cut k)) == z.digest k + +/- SNP-1: a read at a cut inside the store is the same after any growth. -/ +#eval survives (∀ (a b a' b' : List (Fin 3)) (m n : ℕ), + same (readAt (grow (st a b) (st a' b')) (cu m n ⊓ head (st a b))) + (readAt (st a b) (cu m n ⊓ head (st a b))) = true) 430 + +/- Control: a read at a cut past the head changes when the store grows. -/ +#eval refuted (∀ (a b a' b' : List (Fin 3)) (m n : ℕ), + same (readAt (grow (st a b) (st a' b')) (cu m n)) (readAt (st a b) (cu m n)) = true) 431 + +/- SNP-1: a read between two cuts, the later inside the store, is the same after any growth. -/ +#eval survives (∀ (a b t : List (Fin 3)) (i m n : ℕ), + same (readBetween (grow (st a b) (st t t)) (cu i i) (cu m n ⊓ head (st a b))) + (readBetween (st a b) (cu i i) (cu m n ⊓ head (st a b))) = true) 432 + +/- SNP-2: the read at the meet of two cuts is a prefix of the read at either. -/ +#eval survives (∀ (a b : List (Fin 3)) (m n i j : ℕ), + (List.finRange 2).all (fun k ↦ + (readAt (st a b) (cu m n ⊓ cu i j) k).isPrefixOf (readAt (st a b) (cu i j) k)) = true) 433 + +/- Control: the read at one cut is not a prefix of the read at any other. -/ +#eval refuted (∀ (a b : List (Fin 3)) (m n i j : ℕ), + (List.finRange 2).all (fun k ↦ + (readAt (st a b) (cu m n) k).isPrefixOf (readAt (st a b) (cu i j) k)) = true) 434 + +/- SNP-2: a cut of a cut is the meet. -/ +#eval survives (∀ (a b : List (Fin 3)) (m n i j : ℕ), + same (readAt (readAt (st a b) (cu m n)) (cu i j)) (readAt (st a b) (cu i j ⊓ cu m n)) + = true) 435 + +/- SNP-3: the read at `a` followed by the read between `a` and `b` is the read at `b`. -/ +#eval survives (∀ (a b : List (Fin 3)) (i j m n : ℕ), + same (grow (readAt (st a b) (cu i j)) (readBetween (st a b) (cu i j) (cu (i + m) (j + n)))) + (readAt (st a b) (cu (i + m) (j + n))) = true) 436 + +/- Control: with the two cuts in any order it is not. -/ +#eval refuted (∀ (a b : List (Fin 3)) (i j m n : ℕ), + same (grow (readAt (st a b) (cu i j)) (readBetween (st a b) (cu i j) (cu m n))) + (readAt (st a b) (cu m n)) = true) 437 + +/- SNP-3: two adjacent reads-between compose. -/ +#eval survives (∀ (a b : List (Fin 3)) (i j m n : ℕ), + same (grow (readBetween (st a b) (cu i j) (cu (i + m) (j + n))) + (readBetween (st a b) (cu (i + m) (j + n)) (cu (i + m + n) (j + n + m)))) + (readBetween (st a b) (cu i j) (cu (i + m + n) (j + n + m))) = true) 438 + +/- SNP-3: a fold continued from a checkpoint over the delta is the fold of the prefix. -/ +#eval survives (∀ (a b : List (Fin 3)) (i j m n : ℕ), + (List.finRange 2).all (fun k ↦ + foldAt step4 (fun _ ↦ 0) (st a b) (cu (i + m) (j + n)) k + == (readBetween (st a b) (cu i j) (cu (i + m) (j + n)) k).foldl step4 + (foldAt step4 (fun _ ↦ 0) (st a b) (cu i j) k)) = true) 439 + +/- SNP-4: the read at the head cut, and at any cut past it, is the store. -/ +#eval survives (∀ (a b : List (Fin 3)) (m n : ℕ), + (same (readAt (st a b) (head (st a b))) (st a b) + && same (readAt (st a b) (head (st a b) + cu m n)) (st a b)) = true) 440 + +/- SNP-5: the generational store read at a cut is the state recomputed from the prefix. -/ +#eval survives (∀ (l : List (Fin 3 × Fin 3)) (c : ℕ) (x : Fin 3), + (genRead (gens l) c x == stateAt l c x) = true) 441 + +/- SNP-5: and the last write of the key inside the prefix. -/ +#eval survives (∀ (l : List (Fin 3 × Fin 3)) (c : ℕ) (x : Fin 3), + (lastWrite l c x == stateAt l c x) = true) 442 + +/- SNP-5: at most one generation of a key is alive at a cut. -/ +#eval survives (∀ (l : List (Fin 3 × Fin 3)) (c : ℕ) (x : Fin 3), + decide (((gens l).filter (selects c x)).length ≤ 1) = true) 443 + +/- Control: the store rewritten in place is not the state at a cut. -/ +#eval refuted (∀ (l : List (Fin 3 × Fin 3)) (c : ℕ) (x : Fin 3), + (stateOf l x == stateAt l c x) = true) 444 + +/- Control: generations without the closing stamp read the key's oldest write. -/ +#eval refuted (∀ (l : List (Fin 3 × Fin 3)) (c : ℕ) (x : Fin 3), + (genRead (openRows l) c x == stateAt l c x) = true) 445 + +/- SNP-1: the generational store read at a cut inside the chain is the same after growth. -/ +#eval survives (∀ (l t : List (Fin 3 × Fin 3)) (c : ℕ) (x : Fin 3), + (genRead (gens (l ++ t)) (min c l.length) x == genRead (gens l) (min c l.length) x) + = true) 446 + +/- SNP-3: the state at a later cut is the state at an earlier cut with the writes between. -/ +#eval survives (∀ (l : List (Fin 3 × Fin 3)) (a d : ℕ), + (List.finRange 3).all (fun x ↦ + stateAt l (a + d) x == ((l.take (a + d)).drop a).foldl + (fun (m : Fin 3 → Option (Fin 3)) (e : Fin 3 × Fin 3) ↦ Function.update m e.1 (some e.2)) + (stateAt l a) x) = true) 447 + +/- SNP-3: an event read at the later cut was read at the earlier cut or lies in the delta. -/ +#eval survives (∀ (a b : List (Fin 3)) (i j m n : ℕ), + (List.finRange 2).all (fun k ↦ + (readAt (st a b) (cu (i + m) (j + n)) k).all fun x ↦ + (readAt (st a b) (cu i j) k).contains x + || (readBetween (st a b) (cu i j) (cu (i + m) (j + n)) k).contains x) = true) 475 + +/- SNP-3: a key the writes between two cuts do not name has the same state at both. -/ +#eval survives (∀ (l : List (Fin 3 × Fin 3)) (a d : ℕ) (x : Fin 3), + (((l.take (a + d)).drop a).any (fun e ↦ e.1 == x) + || stateAt l (a + d) x == stateAt l a x) = true) 476 + +/- Control: a key's state at two cuts is not the same whatever the delta writes. -/ +#eval refuted (∀ (l : List (Fin 3 × Fin 3)) (a d : ℕ) (x : Fin 3), + (stateAt l (a + d) x == stateAt l a x) = true) 477 + +/- SNP-6: a narrower grant's snapshot is the restriction of a wider one's. -/ +#eval survives (∀ (a b : List (Fin 3)) (m : ℕ) (g g' : Fin 4) (c c' : Fin 8), + same (snapshot (fun k ↦ (gr g k && gr g' k) = true) (fun x ↦ pf c x && pf c' x) (st a b) + (cu m m)) + (restrict (fun k ↦ (gr g k && gr g' k) = true) (fun x ↦ pf c x && pf c' x) + (snapshot (fun k ↦ gr g' k = true) (pf c') (st a b) (cu m m))) = true) 448 + +/- Control: an event filter applied before the cut is not the snapshot. -/ +#eval refuted (∀ (a b : List (Fin 3)) (m n : ℕ) (g : Fin 4) (c : Fin 8), + same (readAt (restrict (fun k ↦ gr g k = true) (pf c) (st a b)) (cu m n)) + (snapshot (fun k ↦ gr g k = true) (pf c) (st a b) (cu m n)) = true) 449 + +/- SNP-6: a snapshot reads only the chains the grant names, and the cut on them. -/ +#eval survives (∀ (a b b' : List (Fin 3)) (m n n' : ℕ) (c : Fin 8), + same (snapshot (fun k ↦ k = 0) (pf c) (st a b) (cu m n)) + (snapshot (fun k ↦ k = 0) (pf c) (st a b') (cu m n')) = true) 450 + +/- Control: a hidden event before the cut changes the snapshot, though every admitted event +is the same: positions count what an event filter hides. -/ +#eval refuted (∀ (a b : List (Fin 3)) (m n : ℕ), + same (snapshot (fun _ ↦ True) (fun x ↦ x != 0) (st a b) (cu m n)) + (snapshot (fun _ ↦ True) (fun x ↦ x != 0) (st (0 :: a) b) (cu m n)) = true) 451 + +/- SNP-7: no erased event is visible at any cut. -/ +#eval survives (∀ (a b : List (Fin 3)) (m n : ℕ) (e : Fin 8), + (List.finRange 2).all (fun k ↦ + (visible (pf e) (st a b) (cu m n) k).all fun x ↦ !pf e x) = true) 452 + +/- SNP-7: the store with holes keeps every position, and reading it commutes with the cut. -/ +#eval survives (∀ (a b : List (Fin 3)) (m n : ℕ) (e : Fin 8), + (same (readAt (redact (pf e) (st a b)) (cu m n)) (redact (pf e) (readAt (st a b) (cu m n))) + && (List.finRange 2).all fun k ↦ + head (redact (pf e) (st a b)) k == head (st a b) k) = true) 453 + +/- SNP-7: what is visible is the store with holes read at the cut, the holes dropped. -/ +#eval survives (∀ (a b : List (Fin 3)) (m n : ℕ) (e : Fin 8), + (List.finRange 2).all (fun k ↦ visible (pf e) (st a b) (cu m n) k + == (readAt (redact (pf e) (st a b)) (cu m n) k).reduceOption) = true) 454 + +/- Control: after an erasure that deletes rows, a read at a cut holds events from after it. -/ +#eval refuted (∀ (a b : List (Fin 3)) (m n : ℕ) (e : Fin 8), + (List.finRange 2).all (fun k ↦ (readAt (compact (pf e) (st a b)) (cu m n) k).all fun x ↦ + (readAt (st a b) (cu m n) k).contains x) = true) 455 + +/- SNP-7: once the chain retires a key, no cut before the retire serves it. -/ +#eval survives (∀ (l t : List (Fin 9)) (c : ℕ) (x : Fin 3), + (servedAt (l.map ev ++ (x, none) :: t.map ev) (min c l.length) x == none) = true) 456 + +/- SNP-7: growth of the chain changes a served value only by removing it. -/ +#eval survives (∀ (l t : List (Fin 9)) (c : ℕ) (x : Fin 3), + ((servedAt (l.map ev ++ t.map ev) (min c l.length) x).isNone + || servedAt (l.map ev ++ t.map ev) (min c l.length) x + == servedAt (l.map ev) (min c l.length) x) = true) 457 + +/- Control: the state at the cut, without the seal, serves a key retired since. -/ +#eval refuted (∀ (l t : List (Fin 9)) (c : ℕ) (x : Fin 3), + ((stateAt (l.map ev ++ t.map ev) (min c l.length) x).join + == servedAt (l.map ev ++ t.map ev) (min c l.length) x) = true) 458 + +/- SNP-7: the looser seal serves everything the stricter one serves. -/ +#eval survives (∀ (l : List (Fin 9)) (c : ℕ) (x : Fin 3), + ((servedAt (l.map ev) c x).isNone || servedAt (l.map ev) c x == servedNow (l.map ev) c x) + = true) 473 + +/- Control: under the looser seal growth does not only remove: a landing after a retire +brings the key's past back. -/ +#eval refuted (∀ (l t : List (Fin 9)) (c : ℕ) (x : Fin 3), + ((servedNow (l.map ev ++ t.map ev) (min c l.length) x).isNone + || servedNow (l.map ev ++ t.map ev) (min c l.length) x + == servedNow (l.map ev) (min c l.length) x) = true) 474 + +/- SNP-7: a served kept row has no erased source. -/ +#eval survives (∀ (rows : List (List (Fin 3) × Fin 2)) (e : Fin 8), + (serve (pf e) rows).all (fun r ↦ r.1.all fun a ↦ !pf e a) = true) 459 + +/- Control: the kept rows served as they are hold erased sources. -/ +#eval refuted (∀ (rows : List (List (Fin 3) × Fin 2)) (e : Fin 8), + rows.all (fun r ↦ r.1.all fun a ↦ !pf e a) = true) 460 + +/- SNP-8: the resolver's cut is consistent, lies under the frontier, and is above every +consistent cut under the frontier (all thirty-six of the grid). -/ +#eval survives (∀ (es : List Edge) (x y : Fin 6), + (cons es (resolve es x.val y.val) + && decide (resolve es x.val y.val ≤ cu x.val y.val) + && (List.range 6).all fun u ↦ (List.range 6).all fun v ↦ + !(cons es (cu u v) && decide (cu u v ≤ cu x.val y.val)) + || decide (cu u v ≤ resolve es x.val y.val)) = true) 461 + +/- Control: the frontier itself is not always consistent. -/ +#eval refuted (∀ (es : List Edge) (x y : Fin 6), cons es (cu x.val y.val) = true) 462 + +/- SNP-8: the meet and the join of two consistent cuts are consistent. -/ +#eval survives (∀ (es : List Edge) (x y u v : Fin 6), + (cons es (resolve es x.val y.val ⊓ resolve es u.val v.val) + && cons es (resolve es x.val y.val ⊔ resolve es u.val v.val)) = true) 463 + +/- Control: a consistent cut advanced by one position on a chain is not always consistent. -/ +#eval refuted (∀ (es : List Edge) (x y : Fin 6), + cons es (resolve es x.val y.val + cu 1 0) = true) 464 + +/- SNP-8: resolution is monotone in the frontier. -/ +#eval survives (∀ (es : List Edge) (x y u v : Fin 6), + decide (resolve es (min x.val u.val) (min y.val v.val) ≤ resolve es x.val y.val) + = true) 465 + +/- SNP-9: the certificate of a cut of a store verifies on the store grown. -/ +#eval survives (∀ (a b a' b' : List (Fin 3)) (m n : ℕ), + verifies (certify step4 0 (st a b) (cu m n ⊓ head (st a b))) (grow (st a b) (st a' b')) + = true) 466 + +/- SNP-9: under the collision-free step a chain and its reverse have one digest only when +they are one chain. -/ +#eval survives (∀ (l : List (Fin 3)), + (l.reverse == l || chainDigest step4 0 l.reverse != chainDigest step4 0 l) = true) 467 + +/- Control: under the additive step a chain and its reverse always have one digest. -/ +#eval refuted (∀ (l : List (Fin 3)), + (l.reverse == l || chainDigest stepAdd 0 l.reverse != chainDigest stepAdd 0 l) = true) 468 + +/- SNP-9: the digest at a later cut is the digest at an earlier cut continued over the +delta. -/ +#eval survives (∀ (a b : List (Fin 3)) (i j m n : ℕ), + (List.finRange 2).all (fun k ↦ + (certify step4 0 (st a b) (cu (i + m) (j + n))).digest k + == chainDigest step4 ((certify step4 0 (st a b) (cu i j)).digest k) + (readBetween (st a b) (cu i j) (cu (i + m) (j + n)) k)) = true) 469 + +/- SNP-9: the meet and the join of two certified cuts are certified from the certificates. -/ +#eval survives (∀ (a b : List (Fin 3)) (i j m n : ℕ), + (List.finRange 2).all (fun k ↦ + ((certify step4 0 (st a b) (cu i j ⊓ cu m n)).digest k + == if cu i j k ≤ cu m n k then (certify step4 0 (st a b) (cu i j)).digest k + else (certify step4 0 (st a b) (cu m n)).digest k) + && (certify step4 0 (st a b) (cu i j ⊔ cu m n)).digest k + == if cu i j k ≤ cu m n k then (certify step4 0 (st a b) (cu m n)).digest k + else (certify step4 0 (st a b) (cu i j)).digest k) = true) 470 + +/- SNP-9: an erasure on a committed store keeps the certificate over its commitments, and +what a reader reads is the store with holes. -/ +#eval survives (∀ (a b : List (Fin 3)) (m n : ℕ) (e : Fin 8), + ((List.finRange 2).all (fun k ↦ + (certify stepC 0 (commitments (purge (pf e) (committed commit3 (st a b)))) (cu m n)).digest k + == (certify stepC 0 (commitments (committed commit3 (st a b))) (cu m n)).digest k) + && same (contents (purge (pf e) (committed commit3 (st a b)))) (redact (pf e) (st a b))) + = true) 471 + +/- Control: a digest over the contents does not survive an erasure. -/ +#eval refuted (∀ (a b : List (Fin 3)) (m n : ℕ) (e : Fin 8), + (List.finRange 2).all (fun k ↦ + chainDigest stepO 0 ((contents (purge (pf e) (committed commit3 (st a b))) k).take (cu m n k)) + == chainDigest stepO 0 ((contents (committed commit3 (st a b)) k).take (cu m n k))) + = true) 472 + +/- SNP-10: the generational store pruned at a horizon reads, at every cut from the horizon on, +the state recomputed from the whole prefix. -/ +#eval survives (∀ (l : List (Fin 3 × Fin 3)) (h d : ℕ) (x : Fin 3), + (genRead (prune h (gens l)) (h + d) x == stateAt l (h + d) x) = true) 478 + +/- SNP-10: at any cut the pruned store returns nothing or the value the key held there. -/ +#eval survives (∀ (l : List (Fin 3 × Fin 3)) (h c : ℕ) (x : Fin 3), + ((genRead (prune h (gens l)) c x).isNone + || genRead (prune h (gens l)) c x == stateAt l c x) = true) 479 + +/- Control: the pruned store read at a cut under its horizon is not the state at the cut. -/ +#eval refuted (∀ (l : List (Fin 3 × Fin 3)) (h c : ℕ) (x : Fin 3), + (genRead (prune h (gens l)) c x == stateAt l c x) = true) 480 + +/- SNP-10: pruning at two horizons is pruning at the later one. -/ +#eval survives (∀ (l : List (Fin 3 × Fin 3)) (h h' : ℕ), + (rowsOf (prune h (prune h' (gens l))) == rowsOf (prune (max h h') (gens l))) = true) 481 + +/- SNP-10: among the served positions the greatest consistent cut under a frontier exists: the +pointwise maximum of every consistent served cut under the frontier (all thirty-six of the grid) +is consistent and served. -/ +#eval survives (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + (cons es (at2 (bestIn es (sv m) x.val y.val)) + && sv m 0 (bestIn es (sv m) x.val y.val).1 + && sv m 1 (bestIn es (sv m) x.val y.val).2) = true) 482 + +/- Control: the frontier lowered to the served positions, without the descent, is not always +consistent. -/ +#eval refuted (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + cons es (cu (floorSv (sv m) 0 x.val) (floorSv (sv m) 1 y.val)) = true) 483 + +/- SNP-10: the cut read lies under the resolution of the frontier, and under the frontier +lowered to the served positions. -/ +#eval survives (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + (decide (at2 (bestIn es (sv m) x.val y.val) ≤ resolve es x.val y.val) + && decide ((bestIn es (sv m) x.val y.val).1 ≤ floorSv (sv m) 0 x.val) + && decide ((bestIn es (sv m) x.val y.val).2 ≤ floorSv (sv m) 1 y.val)) = true) 484 + +/- SNP-10: the cut read rises with what is served. -/ +#eval survives (∀ (es : List Edge) (m m' : Fin 1024) (x y : Fin 6), + decide (at2 (bestIn es (fun k p ↦ sv m k p && sv m' k p) x.val y.val) + ≤ at2 (bestIn es (sv m) x.val y.val)) = true) 485 + +/- SNP-10: when every position is served the cut read is the resolution of the frontier. -/ +#eval survives (∀ (es : List Edge) (x y : Fin 6), + (List.finRange 2).all (fun k ↦ + at2 (bestIn es (fun _ _ ↦ true) x.val y.val) k == resolve es x.val y.val k) = true) 486 + +/- SNP-10: the served resolver, the floor and the descent alternated until nothing moves, +returns the greatest consistent served cut under the frontier. -/ +#eval survives (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + (resolveIn es (sv m) x.val y.val == bestIn es (sv m) x.val y.val) = true) 492 + +/- Control: the floor once and then the descent alone does not: the descent leaves the served +positions. -/ +#eval refuted (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + (List.finRange 2).all (fun k ↦ + resolve es (floorSv (sv m) 0 x.val) (floorSv (sv m) 1 y.val) k + == at2 (bestIn es (sv m) x.val y.val) k) = true) 493 + +/- Control: nor the descent and then the floor once: the floor breaks consistency again. -/ +#eval refuted (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + ((floorSv (sv m) 0 (resolve es x.val y.val 0), floorSv (sv m) 1 (resolve es x.val y.val 1)) + == bestIn es (sv m) x.val y.val) = true) 494 + +/- SNP-7: on a keyed chain whose holes keep their keys, the read of a key at a cut is its last +write at or under the cut, a hole when that write is erased, and the three reads agree. -/ +#eval survives (∀ (l : List (Fin 3 × Fin 3)) (e : Fin 8) (c : ℕ) (x : Fin 3), + (stateAt (holes (ek e) l) c x + == (stateAt l c x).map (fun v ↦ if pf e v then none else some v) + && genRead (gens (holes (ek e) l)) c x == stateAt (holes (ek e) l) c x + && lastWrite (holes (ek e) l) c x == stateAt (holes (ek e) l) c x) = true) 495 + +/- Control: a seek over the rows of the prefix that kept their key returns a superseded +version where the head is a hole. -/ +#eval refuted (∀ (l : List (Fin 3 × Fin 3)) (e : Fin 8) (c : ℕ) (x : Fin 3), + ((stateOf ((l.take c).filter fun w ↦ !ek e w) x).map some + == stateAt (holes (ek e) l) c x) = true) 496 + +/- Control: a seek over the chain with its holes deleted returns a version from after the +cut. -/ +#eval refuted (∀ (l : List (Fin 3 × Fin 3)) (e : Fin 8) (c : ℕ) (x : Fin 3), + ((lastWrite (l.filter fun w ↦ !ek e w) c x).map some + == stateAt (holes (ek e) l) c x) = true) 497 + +/- SNP-10: a chain that no event reads is lowered alone. From a consistent frontier, with +chain 0 serving every position, the cut read is the frontier with chain 1 at the greatest +position it serves. -/ +#eval survives (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + (bestIn (into0 es) (sv1 m) (resolve (into0 es) x.val y.val 0) (resolve (into0 es) x.val y.val 1) + == (resolve (into0 es) x.val y.val 0, + floorSv (sv1 m) 1 (resolve (into0 es) x.val y.val 1))) = true) 498 + +/- Control: when events may read chain 1, lowering it alone is not the cut read. -/ +#eval refuted (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + (bestIn es (sv1 m) (resolve es x.val y.val 0) (resolve es x.val y.val 1) + == (resolve es x.val y.val 0, floorSv (sv1 m) 1 (resolve es x.val y.val 1))) = true) 499 + +/- SNP-6, SNP-7: under a narrower grant and a larger erasure, what is shown is the restriction +of what the wider grant is shown under the smaller erasure. -/ +#eval survives (∀ (a b : List (Fin 3)) (m : ℕ) (g g' : Fin 4) (c c' e e' : Fin 8), + shownNarrow a b m g g' c c' e e' = true) 509 + +/- SNP-7: and it holds no erased event. -/ +#eval survives (∀ (a b : List (Fin 3)) (m n : ℕ) (g : Fin 4) (c e : Fin 8), + (List.finRange 2).all (fun k ↦ + (shown (fun k ↦ gr g k = true) (pf c) (pf e) (st a b) (cu m n) k).all fun x ↦ !pf e x) + = true) 511 + +/- Control: under a smaller erasure the narrower grant is shown more than that restriction. -/ +#eval refuted (∀ (a b : List (Fin 3)) (m : ℕ) (g g' : Fin 4) (c c' e e' : Fin 8), + same (shown (fun k ↦ (gr g k && gr g' k) = true) (fun x ↦ pf c x && pf c' x) (pf e) (st a b) + (cu m m)) + (restrict (fun k ↦ (gr g k && gr g' k) = true) (fun x ↦ (pf c x && pf c' x) && !pf e x) + (shown (fun k ↦ gr g' k = true) (pf c') (fun x ↦ pf e x || pf e' x) (st a b) (cu m m))) + = true) 510 + +/- SNP-7: the history served of a key at a cut ends at the value served there, and after a +retire of the key it holds no version landed before the retire. -/ +#eval survives (∀ (l t : List (Fin 9)) (c : ℕ) (x : Fin 3), + ((historyAt (l.map ev) c x).getLast? == servedAt (l.map ev) c x + && historyAt (l.map ev ++ (x, none) :: t.map ev) (l.length + 1 + c) x + == if sealedAt (l.map ev ++ (x, none) :: t.map ev) (l.length + 1 + c) x then [] + else sinceRetire ((t.map ev).take c) x) = true) 512 + +/- Control: the versions of a key inside the cut, without the seal, hold versions landed +before a retire. -/ +#eval refuted (∀ (l : List (Fin 9)) (c : ℕ) (x : Fin 3), + (((l.map ev).take c).filterMap (fun e ↦ if e.1 = x then e.2 else none) + == historyAt (l.map ev) c x) = true) 513 + +/- Control for 432: a read between two cuts, the later past the head, changes with growth. -/ +#eval refuted (∀ (a b t : List (Fin 3)) (i m n : ℕ), + same (readBetween (grow (st a b) (st t t)) (cu i i) (cu m n)) + (readBetween (st a b) (cu i i) (cu m n)) = true) 487 + +/- Control for 446: the generational store read at a cut past the old head changes with +growth. -/ +#eval refuted (∀ (l t : List (Fin 3 × Fin 3)) (c : ℕ) (x : Fin 3), + (genRead (gens (l ++ t)) c x == genRead (gens l) c x) = true) 488 + +/- Control for 466: the certificate of a cut past the head does not verify on the store +grown. -/ +#eval refuted (∀ (a b a' b' : List (Fin 3)) (m n : ℕ), + verifies (certify step4 0 (st a b) (cu m n)) (grow (st a b) (st a' b')) = true) 489 + +/- Control for 465: resolution does not fall as the frontier rises. -/ +#eval refuted (∀ (es : List Edge) (x y u v : Fin 6), + decide (resolve es x.val y.val ≤ resolve es (min x.val u.val) (min y.val v.val)) + = true) 490 + +/- Control for 481: pruning at two horizons is not pruning at the earlier one. -/ +#eval refuted (∀ (l : List (Fin 3 × Fin 3)) (h h' : ℕ), + (rowsOf (prune h (prune h' (gens l))) == rowsOf (prune (min h h') (gens l))) = true) 491 + +/- Control for 435: a cut of a cut is not the join. -/ +#eval refuted (∀ (a b : List (Fin 3)) (m n i j : ℕ), + same (readAt (readAt (st a b) (cu m n)) (cu i j)) (readAt (st a b) (cu i j ⊔ cu m n)) + = true) 500 + +/- Control for 440: the read at a cut that is not the head is not the store. -/ +#eval refuted (∀ (a b : List (Fin 3)) (m n : ℕ), + same (readAt (st a b) (cu m n)) (st a b) = true) 501 + +/- Control for 438: two adjacent reads-between do not compose in the other order. -/ +#eval refuted (∀ (a b : List (Fin 3)) (i j m n : ℕ), + same (grow (readBetween (st a b) (cu (i + m) (j + n)) (cu (i + m + n) (j + n + m))) + (readBetween (st a b) (cu i j) (cu (i + m) (j + n)))) + (readBetween (st a b) (cu i j) (cu (i + m + n) (j + n + m))) = true) 502 + +/- Control for 439 and 469: the fold at a later cut is not the fold at the earlier one: the +delta counts. -/ +#eval refuted (∀ (a b : List (Fin 3)) (i j m n : ℕ), + (List.finRange 2).all (fun k ↦ + (certify step4 0 (st a b) (cu (i + m) (j + n))).digest k + == (certify step4 0 (st a b) (cu i j)).digest k) = true) 503 + +/- Control for 470: the meet of two certified cuts does not take, chain by chain, the later +digest. -/ +#eval refuted (∀ (a b : List (Fin 3)) (i j m n : ℕ), + (List.finRange 2).all (fun k ↦ + (certify step4 0 (st a b) (cu i j ⊓ cu m n)).digest k + == if cu i j k ≤ cu m n k then (certify step4 0 (st a b) (cu m n)).digest k + else (certify step4 0 (st a b) (cu i j)).digest k) = true) 504 + +/- Control for 447 and 475: an event read at the later cut was not always read at the +earlier. -/ +#eval refuted (∀ (a b : List (Fin 3)) (i j m n : ℕ), + (List.finRange 2).all (fun k ↦ + decide ((readAt (st a b) (cu (i + m) (j + n)) k).length + ≤ (readAt (st a b) (cu i j) k).length)) = true) 505 + +/- Control for 484: the cut read does not always reach the frontier lowered to the served +positions. -/ +#eval refuted (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + (decide (floorSv (sv m) 0 x.val ≤ (bestIn es (sv m) x.val y.val).1) + && decide (floorSv (sv m) 1 y.val ≤ (bestIn es (sv m) x.val y.val).2)) = true) 506 + +/- Control for 485: the cut read does not rise when less is served. -/ +#eval refuted (∀ (es : List Edge) (m m' : Fin 1024) (x y : Fin 6), + decide (at2 (bestIn es (sv m) x.val y.val) + ≤ at2 (bestIn es (fun k p ↦ sv m k p && sv m' k p) x.val y.val)) = true) 507 + +/- Control for 486: when not every position is served the cut read is not the resolution of +the frontier. -/ +#eval refuted (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + (List.finRange 2).all (fun k ↦ + at2 (bestIn es (sv m) x.val y.val) k == resolve es x.val y.val k) = true) 508 + +/- SNP-8: the filtered read is closed, and it is the greatest closed set of rows inside the +cut: every such set lies in it. -/ +#eval survives (∀ (es : List Edge) (x y : Fin 6) (m : Fin 256), + (closedIn es (x.val, y.val) (keptRows es (x.val, y.val)) + && (!closedIn es (x.val, y.val) (rowSet m) + || (rowSet m).all fun r ↦ (keptRows es (x.val, y.val)).contains r)) = true) 514 + +/- SNP-2: a row kept at a cut is kept at every later cut. -/ +#eval survives (∀ (es : List Edge) (x y u v : Fin 6), + ((keptRows es (min x.val u.val, min y.val v.val)).all fun r ↦ + (keptRows es (x.val, y.val)).contains r) = true) 515 + +/- SNP-8: at a consistent cut the filter withholds nothing. -/ +#eval survives (∀ (es : List Edge) (x y : Fin 6), + (keptRows es (resolve es x.val y.val 0, resolve es x.val y.val 1) + == evs.filter fun r ↦ decide (r.2.val < resolve es x.val y.val r.1)) = true) 516 + +/- Control: the rows whose own sources lie inside the cut are not closed: a row is withheld +through a source that is withheld. -/ +#eval refuted (∀ (es : List Edge) (x y : Fin 6), + closedIn es (x.val, y.val) (oneStep es (x.val, y.val)) = true) 517 + +/- Control: at a cut that is not consistent the prefix is not the filtered read. -/ +#eval refuted (∀ (es : List Edge) (x y : Fin 6), + (keptRows es (x.val, y.val) == evs.filter fun r ↦ decide (r.2.val < at2 (x.val, y.val) r.1)) + = true) 518 + +/- SNP-10: a chain that reads a lowered chain follows it. Chain 1 is read by itself and by +chain 0, chain 0 by itself alone. From a consistent frontier the cut read has chain 1 at the +greatest position it serves and chain 0 at the first of its events that reads chain 1 past +that position. -/ +#eval survives (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + (bestIn (foll es) (sv1 m) (resolve (foll es) x.val y.val 0) (resolve (foll es) x.val y.val 1) + == (lowerAt (foll es) (resolve (foll es) x.val y.val 0, + floorSv (sv1 m) 1 (resolve (foll es) x.val y.val 1)) 0, + floorSv (sv1 m) 1 (resolve (foll es) x.val y.val 1))) = true) 519 + +/- Control: the chain that follows is not read as asked. -/ +#eval refuted (∀ (es : List Edge) (m : Fin 1024) (x y : Fin 6), + (bestIn (foll es) (sv1 m) (resolve (foll es) x.val y.val 0) (resolve (foll es) x.val y.val 1) + == (resolve (foll es) x.val y.val 0, + floorSv (sv1 m) 1 (resolve (foll es) x.val y.val 1))) = true) 520 + +end Palace.Snapshot.Attack diff --git a/formal/README.md b/formal/README.md index 7db85666..620cf516 100644 --- a/formal/README.md +++ b/formal/README.md @@ -27,7 +27,7 @@ Each family comes in three parts: `Spec/` is proved in `Palace` with exactly the same statement, from the standard axioms, and everything the statements reach passes Lean's kernel and five independent checkers. A proof file therefore cannot change what the ledger's laws state: only `Spec/` and the model can. The design -theorems (Sever, Frustration, Leak, Transport, Superconnection, Lineage, Dynamics, Scale, and the parts of Magnetic and +theorems (Sever, Frustration, Leak, Transport, Superconnection, Lineage, Dynamics, Scale, Snapshot, and the parts of Magnetic and NegativeType no row cites) have no `Spec/` statements yet: the kernel replays their proofs, but their statements live in the proof files, which can change them, until code relies on them and a row cites them. Whether a statement says what its row says stays a reader's judgment, and the reading is now confined to those two places; @@ -297,6 +297,80 @@ Roundoff and FloatModel, so it has no statements of its own): `eval/utility_field.py` transcribes the model on synthetic graphs and its tests are the Python falsifiers, so the six laws are the ledger's family XV (`Spec/Utility.lean`, 20 statements); the controls and the gap stay design theorems. +- `Snapshot`: a read of the stores at a cut (`docs/design-notes/dn-temporal-snapshot.md`), proved + before any code reads a store at a cut, on a model of a store as a family of append chains (a + document's versions, a session's turns, a class's landing log), a cut as a prefix length for + each chain (the frontier of the event clock's §2.4), the read at a cut and between two cuts, a + derived view as a derivation of the prefixes, a store of keyed writes held three ways (rewritten + in place, recomputed from the prefix, kept by generation with a closing stamp), the grant and + the erasure as parameters of a read that are the present's, the reads-from references between + chains, and the certificate of a cut as the digest of each chain's prefix. SNP-1 append + invariance: a read at a cut inside the store, a read between two such cuts and every derived + view are unchanged by any growth of the store; SNP-2 the read at an earlier cut is a prefix of + the read at a later one, and a cut of a cut is the meet; SNP-3 the read at `a` followed by the + read between `a` and `b` is the read at `b` and adjacent reads-between compose, so a fold + continued from a checkpoint over the events since is the fold of the prefix (a job's checkpoint + is a cut), an event or a pair of events read at the later cut was read at the earlier one or + lies in the delta, and a key the delta does not write has one state at both cuts; SNP-4 the + read at the head cut is the store, so `as of` the current cut is no + `as of`; SNP-5 a reader is append invariant exactly when it reads only the prefixes, exactly + when it is a derived view, and for keyed writes the generational store read at a cut is the + state recomputed from the prefix and the last write inside it, with at most one generation of a + key alive at a cut, while the store rewritten in place determines no read at a past cut; SNP-6 + a narrower grant's snapshot is the restriction of a wider one's, a snapshot reads only the + chains the grant names and the cut on them, and restricting to chains commutes with the cut + where filtering events does not (a cut's positions count the events a filter hides); SNP-7 no + erased event is visible at any cut, a larger erasure shows a sublist, the store with holes + keeps every position, two stores that differ only in erased events give every derivation the + same reading at every cut, a kept derived row is served only when none of its sources is + erased, and a key retired after a cut is served at no earlier cut, growth changing a served + value only by removing it, where the looser seal that withholds a key only while it is not + live serves everything the stricter one serves and is lifted by a later landing; the seal + covers a key's versions as it covers its value, so after a retire the history served holds + only versions landed since, at every cut; and on a keyed chain whose holes keep their keys + the read of a key at a cut is its last write at or under the cut, a hole when that write is + erased; SNP-8 resolution: the consistent cuts (every source of an event inside is inside) are + CLK-2's cuts among the frontier cuts, so their closure under meet and join is CLK-2's, derived + here from `Clock.IsCut.frontier_inf` and `frontier_sup`; every frontier resolves to exactly + one greatest consistent cut under it, monotonically, a consistent cut stays consistent as the + store grows, and a cut consistent for a recorded bound on the references is consistent for + the true ones; a reference the resolver does not follow is kept by a filter of the read, a + row withheld when a source of it lies outside the cut or is withheld, and the filtered read + holds the sources of its rows, is the greatest such set inside the cut, is the prefix at a + consistent cut, never withholds a row whose references are all resolved, and is monotone and + append invariant; SNP-9 the certificate of a cut verifies on every extension of the store, two + stores that verify one certificate under a collision-free digest have the same prefix of + every digested chain at its cut and so the same derived views of it, a certificate extends + over the events since an earlier one, the meet and the join of two certified cuts are + certified from the two certificates alone, an erasure that keeps a commitment beside each + event keeps every certificate, a certificate attests no erasure, and under a binding + commitment it pins the events, so two stores that verify it read the same store with holes + under one erasure; SNP-10 the horizon: a generational store that drops the rows closed at or + under a horizon reads, at every cut from the horizon on, the state recomputed from the whole + prefix, under the horizon it is never wrong and reads what it lost as absent, horizons compose + to the later one and commute with a later landing, and where the chains serve only some + positions (those from a horizon on, and the empty prefix) every frontier resolves to exactly + one greatest consistent cut among them, which never passes the cut asked and rises with the + frontier and with served positions that grow; a chain that no other chain reads is lowered + alone, every other chain read as asked, and a chain that reads the lowered chains and that + nothing but itself reads, as a chain of records does, follows them and takes nothing with + it. The grant and the erasure applied to one read + (`shown`) keep the laws of each. The eighteen controls as theorems, in `Witness`: the reader + that ignores the cut (`present_not_appendInvariant`), the store rewritten in place + (`stateOf_forgets`), an event filter applied before the cut (`filter_before_cut`), positions + that count hidden events (`position_channel`), the erasure that deletes rows + (`compact_moves`), the looser seal lifted by a later landing (`servedNow_restores`), the + pruned store read under its horizon and unable to tell a lost key from one never written + (`prune_forgets`, `prune_indistinct`), a digest with collisions (`digest_collides`), a hole + that loses its key (`keyless_hole`), a seal written after a certified cut + (`seal_not_certified`), a renamed chain (`rename_breaks_certificate`), a record on a chain + that content reads (`record_drags`), a chain of records lowered with a chain it certifies + (`record_follows`), a pass attestation whose reference to a landing is resolved, and the + same reference filtered, where the prefix is not closed and the filtered read is + (`pass_drags`, `pass_withheld`), a named chain that reads an unnamed one + (`resolution_reads_unnamed`), and served positions that shrink (`served_set_shrinks`). Design + theorems (Palace and PalaceTest, no Spec rows): `as of` reads the citation graph at a commit + and every other store as it is now. - `Bridges`: theorems that join two families, so that what one proves serves the other: BRG-1 the Laplacian as `∂₁ ∂₁ᵀ`, BRG-2 Euler and Poincaré on the flag complex, BRG-3 Thomson's principle on edge flows, BRG-4 the clock's cuts and scope's closed strata as lower sets, BRG-5 @@ -313,8 +387,8 @@ Roundoff and FloatModel, so it has no statements of its own): exported, every module contributes, and only the unsafe compiler helpers are left out, and `check.sh` holds its count to the audit's, since a checker accepts an empty export. - `PalaceTest/`: the attacks, one module per ledger family's `Palace` module (of the design - theorems, Magnetic, NegativeType, Superconnection, Dynamics and Scale have them), as Mathlib keeps - its tests in `MathlibTest`. `lake test` builds them, which runs every attack and negative control. + theorems, Magnetic, NegativeType, Superconnection, Dynamics, Scale and Snapshot have them), as + Mathlib keeps its tests in `MathlibTest`. `lake test` builds them, which runs every attack and negative control. `PalaceTest/Attack.lean` holds `survives` and `refuted`, which run Plausible with a fixed seed and count the instances that passed their guards. - `Audit.lean`: lists the axioms behind every `Palace` declaration and fails on anything beyond @@ -827,6 +901,58 @@ at a gain above the rate the ceiling is fixed, on the first instance; at exponen not constant, on the first instance; and the greedy walk's empirical measure is not within `1/8` of the structural stationary distribution, on the first instance. +The snapshot is attacked on the model's own definitions (seeds 430 to 520): stores of two +chains over three events, cuts from two naturals, keyed chains over three keys, chains of +landings and retires from codes, grants from two bits and event filters and erasures from three, +reads-from relations as lists of edges between the two chains at positions under four, a +digest that reads a chain as a numeral in base four, which is collision free, and the positions +a chain serves from ten bits. Forty-nine attacks survived, every one all 500 instances: the read +at a cut and between two cuts under growth; the prefix order and the meet; the two compositions +and the journal; the head cut; the generational store against the recomputed state and the last +write, one generation alive at most, the same under growth, and the keyed journal; an event of +the later cut in the earlier one or in the delta, and the key the delta does not write; the +narrower grant, the chains a snapshot reads, and the grant and the erasure together; the erasure +(nothing erased visible or shown, positions kept, the holes dropped), the keyed read on a chain +whose holes keep their keys, the retire that seals every earlier cut, growth that only removes, +the two seals in their order, the history served under the seal, and the kept rows with their +sources; the resolver, the meet and the join of consistent cuts, and the monotone resolution; +the certificate under growth, the digest of a reversed chain, the certificate over the delta, at +the meet and the join, and across an erasure on a committed store; the pruned generational +store at and past its horizon, never wrong under it, and two horizons as the later one; and, +among the served positions, the greatest consistent cut under a frontier found by enumeration, +consistent and served, under the resolution of the frontier, rising with what is served, equal +to the resolution when every position is served, equal to the frontier with an unread chain +lowered alone, and with a chain that reads it lowered after it; and the row filter, closed, the +greatest closed set of rows inside the cut by enumeration of every set of rows, growing with +the cut, and withholding nothing at a consistent cut. Two resolvers are attacked that the +library does not define: the descent that +lowers a frontier until no event inside it has a source outside, checked against the greatest +consistent cut by enumerating the thirty-six cuts of the grid (461), and its alternation with +the floor to the served positions, checked against the greatest consistent served cut (492). + +The forty-two controls, each refuted, with the instances it took. A read at a cut past the +head changes with growth, for the prefix, the read between two cuts and the generational store +(11, 11, 7). The read at one cut is a prefix of the read at any other (6); a cut of a cut is +the join (5); the read at a cut that is not the head is the store (8). The composition with +the cuts in any order (6), in the other order (16), and with the delta left out (7, 6). The +store rewritten in place as the state at a cut (5); generations without the closing stamp +(18); a key's state the same at two cuts whatever the delta writes (17). An event filter +applied before the cut (26); a hidden event more before the cut (7); a narrower grant under a +smaller erasure (45). An erasure that deletes rows (29); a seek over the rows that kept their +key, and over the chain with its holes deleted (35, 17); the state served without the seal +(53); the looser seal as one under which growth only removes (48); the history without the +seal (33); the kept rows served without their sources (11). The frontier taken for a +consistent cut (11); a consistent cut advanced by one position (12); resolution falling as the +frontier rises (6). The additive digest (11); a digest over the contents (14); the certificate +of a cut past the head (6); the meet certified from the later digest (5). The pruned store read +under its horizon (30); pruning at the earlier of two horizons (24); a frontier lowered to the +served positions without the descent (24); the floor and the descent each run once, in either +order (17, 26); a chain that others read lowered alone (17); the cut read reaching the floor +(23), rising when less is served (10), and equal to the resolution when not every position is +served (5). The rows whose own sources lie inside the cut taken for a closed set (61); the +prefix taken for the filtered read (15); a chain that follows a lowered chain read as asked +(38). + ## Build The toolchain is pinned in `lean-toolchain` (elan resolves it); Mathlib is pinned in diff --git a/papers/2026-11-10-temporal-snapshot/paper.tex b/papers/2026-11-10-temporal-snapshot/paper.tex new file mode 100644 index 00000000..53aa204a --- /dev/null +++ b/papers/2026-11-10-temporal-snapshot/paper.tex @@ -0,0 +1,548 @@ +\documentclass[11pt]{article} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{microtype} +\usepackage[margin=1in]{geometry} +\usepackage{amsmath,amssymb,amsthm,mathtools} +\usepackage{algorithm} +\usepackage{algpseudocode} +\usepackage{booktabs} +\usepackage[numbers,sort&compress]{natbib} +\usepackage[hidelinks]{hyperref} +\usepackage[capitalise,noabbrev]{cleveref} +\setlength{\emergencystretch}{3em} + +\theoremstyle{plain} +\newtheorem{theorem}{Theorem}[section] +\newtheorem{proposition}[theorem]{Proposition} +\theoremstyle{definition} +\newtheorem{definition}[theorem]{Definition} + +\newcommand{\lean}[1]{\path{#1}} +\newcommand{\N}{\mathbb{N}} +\newcommand{\at}[2]{#1|_{#2}} +\newcommand{\btw}[3]{#1|_{(#2,\,#3]}} +\newcommand{\hd}[1]{\lvert #1 \rvert} +\newcommand{\pre}{\preceq} + +\title{A Knowledge Store as of a Cut:\\ +Append Chains, Consistent Cuts, and What Erasure and Scope Do to a Snapshot} +\author{Alberto Serrano-Calva} +\date{November 10, 2026} + +\begin{document} +\maketitle + +\begin{abstract} +A query on a knowledge store can ask for the store as of a past moment. In the store studied here +that reading exists for one relation, a citation graph indexed by commit, and for the files of +its repository; every other store is read as it is now. We design the rest. A store is modelled as a family of append chains, a cut as a +prefix length for each, and the read at a cut as the prefixes. Ten laws are machine-checked in +Lean~4 over Mathlib. A read at a cut is unchanged by growth of the store, and a reader has that +property exactly when it is a function of the prefixes. Reads at cuts are ordered and compose with +reads between cuts, so a job's checkpoint is a cut. A derived store kept by generation reads what +recomputation reads, with at most one generation of a key alive at a cut. A narrower grant's +snapshot is the restriction of a wider one's, and positions on a shared chain count what a filter +hides. Nothing erased is visible at any cut when an erasure leaves holes; a hole must keep its +key, or a read by key returns a superseded version; and a seal keeps a retired identity, with +its versions, out of earlier cuts. Every frontier resolves to one greatest consistent cut. The +digest of each prefix certifies a cut, survives an erasure that keeps commitments, and attests +no erasure. A store that drops old generations is exact from its horizon on, never wrong under +it, and unable to tell what it lost. The last law gives the rule for an incomplete history: a +read is taken at the greatest consistent cut among the positions the stores still serve, which +never lies after the cut asked; a chain that nothing reads is lowered alone, and a chain that +others read takes them down with it. Reading the code against the usual picture of ledgers and +derived stores locates the one missing ledger, the past of the map from paths to content, and a +log of about 400 bytes a landing on a synthetic fixture supplies it. Measurements on synthetic +fixtures give the cost of its reads and show what an erasure leaves behind today. +\end{abstract} + +\section{Introduction} + +The system is a personal knowledge store \cite{serranocalva2026palace}: notes, dialogue, papers and +code land through one writer into a dozen stores (content-addressed raw objects, a catalog from +paths to content, version chains, a chat log, attestations, a vector plane, a lexical index, edge +stores), and a sentence of a query algebra reads them. A sentence may carry +\texttt{as of ""}. Today it moves one relation. The citation graph, which is +stored by commit, is read at the commit named, and a file of the repository is read as that +commit's blob; every other read is of the present, and the answer says so. + +Finishing the adjective is not a matter of adding a timestamp filter. The stores have no common +clock: each has its own append order, and wall time is by rule never an ordering key. Some stores +keep their past and some are rewritten in place. Content can be erased, and an erased item must +not return through a snapshot. The asker's grant is today's, not the cut's. And a history is never +complete: it starts somewhere, and retention may move the start. Each of these changes what +``the store as of a cut'' has to mean, and each can be stated and proved before any code reads a +store at a cut. The contributions: +\begin{enumerate} +\item A model (\Cref{sec:model}) of a multi-store as a family of append chains with cuts, reads at + and between cuts, derived views, a grant, an erasure and certificates. +\item Ten laws (\Cref{sec:laws}), SNP-1 to SNP-10, machine-checked as 175 theorems, with eighteen + failure modes as theorems too, among them the reader that ignores the cut, the store rewritten + in place, a filter applied before the cut, an erasure that deletes rows, a hole that loses its + key, a digest with collisions, a pruned store read under its horizon, and a record of a cut + placed on a chain that content reads. +\item A rule for incomplete histories (\Cref{thm:horizon}): among the positions the stores still + serve there is one greatest consistent cut under the cut asked, a read taken there holds no + event from after the cut it names, and it differs from the cut asked only on the chains that + could not serve when no other chain reads them. +\item A design (\Cref{sec:design}) read off the code: the one ledger that is missing, how each + derived store is a function of a cut, what an erasure must reach, and what an answer says, + with measurements on synthetic fixtures (\Cref{sec:eval}). +\end{enumerate} + +\section{Background and related work} + +\paragraph{Consistent cuts.} +Lamport's happened-before relation \cite{lamport1978time} orders events without a global clock; a +global state is a consistent cut, a set of events closed under that order +\cite{chandy1985snapshots}. Vector timestamps characterize the order, and the consistent cuts +form a lattice \cite{mattern1989virtual}; the down-sets of any partial order form a distributive +lattice \cite{birkhoff1937rings,davey2002lattices}. The store's own clock design already takes a +cut to be a down-set of a derived event order with a per-store frontier, and its ledger of laws +already has their closure under meet and join. Here there is one writer, so no marker protocol +is needed; what is needed is the greatest consistent cut under a named frontier, also when a +store cannot serve a position. + +\paragraph{Temporal and multiversion data.} +Temporal databases keep rows valid over a period, and system-versioned tables answer a query as +of a system time \cite{snodgrass1999temporal,kulkarni2012sql2011}; multiversion concurrency +control keeps versions so that a reader sees a state as of its start +\cite{reed1978naming,bernstein1983mvcc}. Our generations are system-versioned rows whose period +is counted in positions of an append chain, never in wall time (\Cref{thm:forms}). Incremental +view maintenance \cite{gupta1995views} takes the changes to a view's inputs; the delta between +two cuts is that input here. + +\paragraph{Hash chains and commitments.} +A hash chain makes an append history tamper-evident +\cite{merkle1987signature,haber1991timestamp}. A chain over contents cannot survive an erasure of +content, and a plain hash of erased content is a test for it. A salted commitment +\cite{halevi1996commitment} whose salt is destroyed avoids both (\Cref{thm:cert}). + +\paragraph{Noninterference.} +A grant restricts what a reader may learn \cite{goguen1982security}. A position on a chain is +itself data: it counts every event before it, hidden or not (\Cref{thm:grant}). + +\section{The model}\label{sec:model} + +\begin{definition}[Stores, cuts, reads] +A \emph{store} is a family of append chains $s : K \to \mathrm{List}\,\alpha$: for each chain key +the events appended to it, in order. Its \emph{head} is $\hd{s}(k) = \mathrm{length}(s\,k)$. +$s'$ \emph{extends} $s$, written $s \pre s'$, when every chain of $s$ is a prefix of its chain in +$s'$; $s \mathbin{+\!\!+} t$ appends chain by chain. A \emph{cut} is $c : K \to \N$, ordered +pointwise. The \emph{read at} $c$ is $\at{s}{c}(k) = \mathrm{take}\,(c\,k)\,(s\,k)$, and the +\emph{read between} $a$ and $b$ is $\btw{s}{a}{b}(k) = \mathrm{drop}\,(a\,k)\,(\at{s}{b}\,k)$. A +\emph{derived view} at a cut is $D(\at{s}{c})$ for a derivation $D$. A reader $F(s, c)$ is +\emph{append invariant} when $F(s \mathbin{+\!\!+} t, c) = F(s, c)$ for all $t$ and all +$c \le \hd{s}$. +\end{definition} + +\begin{definition}[A keyed chain, three ways] +For a chain $l$ of writes $(x, v)$, $\mathrm{state}(l)$ maps each key to its last value: the store +rewritten in place. $\mathrm{state}_c(l) = \mathrm{state}(\at{l}{c})$ is the state recomputed at a +cut. The \emph{generational} store $\mathrm{gens}(l)$ has a row per write: the $i$-th write +$(x, v)$ gives $(x, v, \mathrm{born} = i, \mathrm{died})$ with $\mathrm{died}$ the position of +the next write of $x$, absent while the row is the head; a row is \emph{alive} at $c$ when +$\mathrm{born} \le c < \mathrm{died}$, and $\mathrm{read}(\mathrm{gens}(l), c, x)$ is the value of +the row of $x$ alive at $c$. Retention at a horizon $h$, $\mathrm{prune}_h$, drops the rows with +$\mathrm{died} \le h$. +\end{definition} + +\begin{definition}[Grant, erasure, seal] +For a set of chains $G$ and an event predicate $p$, the \emph{snapshot} is +$\mathrm{snap}_{G,p}(s, c) = \mathrm{restrict}_{G,p}(\at{s}{c})$: the chains in $G$, each read at +the cut and filtered by $p$. For an erasure predicate $E$, $\mathrm{redact}_E(s)$ replaces each +erased event by a hole, $\mathrm{visible}_E(s, c)$ is $\at{s}{c}$ without the erased events, and +$\mathrm{compact}_E(s)$ deletes them. For a keyed chain, $\mathrm{holes}_E(l)$ replaces the value +of each erased write by a hole and keeps its key. In a chain of landings $(x, \mathrm{some}\,v)$ +and retires $(x, \mathrm{none})$, the \emph{stricter seal} serves at $c$ the value $x$ held at +$c$ unless a retire of $x$ lies after $c$, and as its \emph{history} the landings of $x$ inside +$c$ that no retire follows; the \emph{looser seal} serves the value unless $x$ is not live at the +head. +\end{definition} + +\begin{definition}[Consistency, resolution, certificates] +Let $R\,k\,i\,k'\,j$ say that the $i$-th event of chain $k$ reads from the $j$-th of $k'$. A cut +$c$ is \emph{consistent} when $R\,k\,i\,k'\,j$ and $i < c\,k$ imply $j < c\,k'$. It \emph{resolves} +a frontier $f$ when it is the greatest consistent cut under $f$. Given for each chain a set $S_k$ +of \emph{served} positions, it resolves $f$ \emph{among} them when it is the greatest consistent +cut under $f$ with $c\,k \in S_k$ for all $k$. For a step $\sigma : H \to \alpha \to H$ and a seed +$h_0$, the \emph{digest} of a chain is its left fold; the \emph{certificate} of a cut is the cut +with the digest of every prefix, and a store \emph{verifies} it when the cut lies inside the +store and its own prefixes have those digests. +\end{definition} + +\section{The laws}\label{sec:laws} + +Each statement names the declarations of \lean{formal/Palace/Snapshot.lean} that check it. + +\begin{theorem}[SNP-1 and SNP-5: append invariance]\label{thm:append} +For $c \le \hd{s}$ and any $t$, $\at{(s \mathbin{+\!\!+} t)}{c} = \at{s}{c}$ and +$\btw{(s \mathbin{+\!\!+} t)}{a}{c} = \btw{s}{a}{c}$. A reader $F$ is append invariant if and only +if there is a derivation $D$ with $F(s, c) = D(\at{s}{c})$ for all $c \le \hd{s}$. The reader +$F(s, c) = D(s)$, which ignores the cut, is not append invariant. +\end{theorem} +\begin{proof}[Sketch] +Taking a prefix of an appended list within the first list's length ignores the second +(\lean{readAt_grow}, \lean{readBetween_grow}). For the equivalence, $s$ is $\at{s}{c}$ grown by +its own suffix, so an append invariant $F$ satisfies $F(s, c) = F(\at{s}{c}, c)$, and +$D(t) = F(t, \hd{t})$ works; the converse is the first part (\lean{appendInvariant_iff_exists_view}). +The control is \lean{Witness.present_not_appendInvariant}. +\end{proof} + +\begin{theorem}[SNP-2 to SNP-4: order, composition, the head]\label{thm:compose} +If $c \le d$ then $\at{s}{c} \pre \at{s}{d}$, and $\at{(\at{s}{c})}{d} = \at{s}{c \sqcap d}$. For +$a \le b \le c$, $\at{s}{a} \mathbin{+\!\!+} \btw{s}{a}{b} = \at{s}{b}$ and +$\btw{s}{a}{b} \mathbin{+\!\!+} \btw{s}{b}{c} = \btw{s}{a}{c}$. A fold of the prefix at $b$ is the +fold at $a$ continued over $\btw{s}{a}{b}$. An event read at $b$ was read at $a$ or lies in +$\btw{s}{a}{b}$, and a key the delta does not write has the same state at both cuts. Finally +$\at{s}{\hd{s}} = s$, so every view at the head is the derivation of the present. +\end{theorem} +\begin{proof}[Sketch] +List identities for \texttt{take} and \texttt{drop} (\lean{readAt_mono}, \lean{readAt_readAt}, +\lean{readAt_append_readBetween}, \lean{readBetween_append}, \lean{foldAt_readBetween}, +\lean{mem_readAt_iff}, \lean{stateAt_eq_of_not_written}, \lean{readAt_head}, \lean{view_head}). +\end{proof} +The composition is what lets a job keep a checkpoint: its state at $b$ is its state at $a$ +continued over the delta, so a run and a rebuild agree. For a job that joins two chains, a pair +read at $b$ was read at $a$ or has a member in the delta (\lean{pair_readAt}). + +\begin{theorem}[SNP-5: three ways of holding a derived store]\label{thm:forms} +For every chain $l$ of keyed writes, cut $c$ and key $x$, +$\mathrm{read}(\mathrm{gens}(l), c, x) = \mathrm{state}_c(l)(x)$, and both are the last write of +$x$ inside $\at{l}{c}$. At most one row of $x$ is alive at $c$. Growth of the chain, which writes +closing stamps into $\mathrm{gens}$, changes no read at a cut inside it. There is no function $G$ +with $\mathrm{state}_c(l) = G(\mathrm{state}(l), c)$ for all $l$ and $c$. +\end{theorem} +\begin{proof}[Sketch] +Induction on the chain from its end: a landing closes the key's open row at its own position and +opens a row there, which leaves every read at an earlier cut and of another key as it was +(\lean{genRead_gens}, \lean{stateAt_eq_lastWrite}, \lean{length_filter_selects_le_one}, +\lean{genRead_gens_append}). For the last part two chains with one final state differ at the +first cut (\lean{Witness.stateOf_forgets}). +\end{proof} + +\begin{theorem}[SNP-6: the grant]\label{thm:grant} +If $G \subseteq G'$ and $p$ implies $p'$, then +$\mathrm{snap}_{G,p}(s, c) = \mathrm{restrict}_{G,p}(\mathrm{snap}_{G',p'}(s, c))$. A snapshot +depends only on the chains of $G$ and on the cut's positions on them, and it is append invariant. +Restricting to whole chains commutes with the cut. Filtering events does not: there are stores +that agree on every admitted event and differ in their snapshots at one cut. The cut read +(\Cref{thm:horizon}) on a set of chains that read from no chain outside it is a function of that +set alone. +\end{theorem} +\begin{proof}[Sketch] +Filters compose and are applied after the prefix (\lean{snapshot_narrow}, \lean{snapshot_congr}, +\lean{snapshot_grow}, \lean{restrict_readAt}). For the control, $[\mathrm{hidden}, a]$ and $[a]$ +read at position one give nothing and $a$ (\lean{Witness.filter_before_cut}, +\lean{Witness.position_channel}). For the last part, a resolved cut restricted to a closed set +and zero elsewhere is consistent and served (\lean{ResolvesIn.eq_on_of_closed}; the control is +\lean{Witness.resolution_reads_unnamed}). +\end{proof} +So what must be hidden in number is hidden by chain: where clearances separate rows, a chain per +class. The law is about the rows a grant is shown. It passes to an answer that filters those +rows, and not to a score, whose collection statistics are the reader's own. + +\begin{theorem}[SNP-7: erasure]\label{thm:erase} +No erased event is in $\mathrm{visible}_E(s, c)$; a larger erasure shows a sublist; reading the +store with holes commutes with the cut and keeps the head; and if +$\mathrm{redact}_E(s) = \mathrm{redact}_E(s')$ then $D(\mathrm{visible}_E(s, c)) = +D(\mathrm{visible}_E(s', c))$ for every $D$ and $c$. After $\mathrm{compact}_E$ a read at a cut +can hold an event from after it. On $\mathrm{holes}_E(l)$ the state of a key at a cut is its +last write at or under the cut, a hole when that write is erased, and the generational read and +the seek by key agree with it; if a hole loses its key, a seek returns a superseded version, or +one from after the cut. Under the stricter seal, once a chain retires a key no cut before the +retire serves it, and for any growth $t$ a value served by $l \mathbin{+\!\!+} t$ at a cut inside +$l$ was served by $l$; the history served ends at the value served, and at every cut after a +retire it holds only landings after that retire. The looser seal serves everything the stricter +one serves, and a landing after a retire brings the key's past back under it. +\end{theorem} +\begin{proof}[Sketch] +Filtering and mapping commute with \texttt{take} (\lean{not_erased_of_mem_visible}, +\lean{redact_readAt}, \lean{erased_invisible}, \lean{stateAt_holes}). The seal is a predicate +on the suffix past the cut, which only grows (\lean{servedAt_of_append}, +\lean{historyAt_of_retire_inside}, \lean{servedNow_of_servedAt}). The controls are +\lean{Witness.compact_moves}, \lean{Witness.keyless_hole} and \lean{Witness.servedNow_restores}. +\end{proof} + +\begin{theorem}[SNP-8: resolution]\label{thm:lattice} +A cut is consistent exactly when the events under its frontier are a down-set of the order +generated by the chains and by $R$. Every frontier is resolved by exactly one cut, monotonically +in the frontier. If growth only adds references that start at or past the old head, a consistent +cut inside the old head stays consistent. If every source of an event lies at or under a +recorded one on its chain, a cut consistent for the recorded references is consistent for $R$. +Withholding from a cut every row with a source outside it or withheld leaves a set that holds +the sources of its rows, the greatest such, and the whole prefix when the cut is consistent. +\end{theorem} +\begin{proof}[Sketch] +The down-set form is the clock's cut criterion, no generator edge crossing +(\lean{consistent_iff_isCut}). Closure under pointwise meet and join then is the clock's law for +frontiers, already in the store's ledger, and is derived from it, not claimed here +(\lean{Consistent.inf}, \lean{Consistent.sup}). For resolution take on each chain the supremum +of the positions reached by consistent cuts under $f$: it is attained, and a source of an event +under it is under the witness's position on the source's chain (\lean{exists_resolves}, +\lean{Resolves.unique}, \lean{Resolves.mono}, \lean{Consistent.of_grown}, +\lean{Consistent.of_bound}, \lean{Kept.source}, \lean{kept_of_closed}). +\end{proof} + +\begin{theorem}[SNP-9: certificates]\label{thm:cert} +The certificate of a cut of $s$ verifies on every $s' \succeq s$. If the step is collision free, +two stores that verify one certificate have the same read at its cut, hence the same derived +views. The digest at $b$ is the digest at $a$ continued over $\btw{s}{a}{b}$, and the digests at +$c \sqcap d$ and $c \sqcup d$ are, chain by chain, those of $c$ or of $d$. If the chain digests +commitments kept beside the events, a store verifies a certificate after an erasure of contents +exactly when it did before, and the contents then read as the store with holes; if moreover the +commitment is injective, two such stores that verify one certificate were made from the same +events at its cut. +\end{theorem} +\begin{proof}[Sketch] +Append invariance of the prefix; induction from the end for injectivity of the fold +(\lean{verifies_certify_of_extends}, \lean{Verifies.readAt_eq}, \lean{Verifies.view_eq}, +\lean{certify_digest_readBetween}, \lean{certify_inf}, \lean{certify_sup}, +\lean{verifies_purge_iff}, \lean{contents_purge_committed}); the last part is +\lean{Verifies.readAt_eq_of_committed}. Under addition two chains of one length collide +(\lean{Witness.digest_collides}). +\end{proof} +A certificate thus pins what it digests and nothing else. It attests no erasure, so a copy taken +before an erasure verifies it and still holds what was erased; no seal, since a retire written +after the cut changes what is served at it (\lean{Witness.seal_not_certified}); and no grant. +Its chains are named, and a renamed chain no longer verifies +(\lean{Witness.rename_breaks_certificate}). + +\begin{theorem}[SNP-10: the horizon]\label{thm:horizon} +For $h \le c$, $\mathrm{read}(\mathrm{prune}_h(\mathrm{gens}(l)), c, x) = \mathrm{state}_c(l)(x)$. +For any $c$, a value the pruned store returns at $c$ is $\mathrm{state}_c(l)(x)$; but there are +$l$ and $c < h$ at which it returns nothing where a value stood. +Two chains can have one pruned store and differ, at a cut under $h$, in whether a key had been +written. $\mathrm{prune}_h \circ \mathrm{prune}_{h'} = \mathrm{prune}_{\max(h, h')}$. If every +$S_k$ contains $0$, every frontier $f$ is resolved among the served positions by exactly one cut; +that cut lies under the resolution of $f$, equals it when every position is served, and rises +with $f$ and with served sets that grow. If $f$ is consistent, the chains in a set $U$ are read +only by themselves and by chains of a set $V$ that only themselves read, and every other chain +serves its position, then the cut is $f$ with each chain of $U$ at the greatest position it +serves at or under $f$, and each chain of $V$ at the greatest it serves whose events read $U$ +inside those positions. Without the hypothesis on $U$ that fails: one chain read low can take +every other chain to its empty prefix. +\end{theorem} +\begin{proof}[Sketch] +A row alive at $c \ge h$ has no closing stamp at or under $h$, so pruning removes no row a read +at $c$ selects; under $h$ a selected row is still the unique row alive in the full store +(\lean{genRead_prune_gens}, \lean{stateAt_of_genRead_prune}, \lean{prune_prune}); the two +controls are \lean{Witness.prune_forgets} and \lean{Witness.prune_indistinct}. Resolution among +served +positions is the argument of \Cref{thm:lattice} with the supremum taken over served consistent +cuts: the supremum on a chain is attained by one of them, so it is served +(\lean{exists_resolvesIn}, \lean{ResolvesIn.unique}, \lean{ResolvesIn.mono}, +\lean{ResolvesIn.le_resolves}, \lean{resolvesIn_univ}). Lowering an unread chain breaks no +reference, and no served consistent cut under $f$ is higher (\lean{resolvesIn_of_unread}, +\lean{resolvesIn_of_followed}). The controls are \lean{Witness.record_drags}, +\lean{Witness.record_follows} and, for sets that shrink, \lean{Witness.served_set_shrinks}. +\end{proof} + +\section{The design}\label{sec:design} + +\paragraph{The missing ledger.} +The usual picture has ledgers that only append and derived stores that are rewritten and can be +recomputed. Read against the code it fails at one place that matters. The catalog, the map from a +path to the content it holds and the idempotence key of every landing, is rewritten in place: an +upsert, a tombstone flag, a delete. Version chains exist for one of four places; elsewhere the +attestation ledger names a digest and no path, once per action and digest; so for most items the +sequence of contents a path held is recorded nowhere. The vector plane and the lexical index, which +the picture calls rewritten, keep every version's rows and move a flag. They are generations +without a clock. A clock on their rows would be wrong, since a path that returns to earlier bytes +makes the same rows current again, so a version's rows are valid on a set of intervals. The fix +is one ledger: a \emph{landing log} in the catalog's own file, hash chains that each hold one +provenance class, a row per catalog write (chain, position, kind, a keyed hash of the path, path, +identity, digest, a salt, a commitment, the chain hash, the position of the path's next event), +written by the catalog's own methods in the transaction of the row they write. A chain has an id +and its class is a label, so relabelling a class moves no row and breaks no certificate. The +catalog is then the fold of the log (\Cref{thm:forms}), and every version-keyed store has a +past: the log names the version at a cut. + +\paragraph{Cuts, names, certificates.} +A cut is one position per chain, about a dozen integers: the landing chains, the chat log, the +attestations, the repository's commit, the generations of model output. It is not a position per +document, which is millions of pairs on a large instance. A cut is recorded, with the digest of every +hashed prefix, when the writer's queue and its handoff are empty, and attested. The records form +a chain of their own that no other chain reads: every landing reads the attestation ledger, so +a record placed there can, by \Cref{thm:horizon}, take a landing chain to its empty prefix with +any chain read below a position it certified. The adjective takes \texttt{head}, a record's id, a commit +(the first record that holds it, with the repository lowered to the commit and resolved), or a +date, which selects the last record whose wall bookmark is not later. Wall time is a lookup key +there and orders nothing. The resolver follows three references, each through a recorded bound +that is sound because there is one writer (\Cref{thm:lattice}): a landing's to the attestation +ledger, an attestation's to its commit, a record's to its frontier. A pass's attestation and a +row of model output read landings too; resolved, they would lower the ledger, and that can take +another landing chain down (\lean{Witness.pass_drags}), so the filter of \Cref{thm:lattice} withholds them +from the read instead. + +\begin{algorithm}[t] +\caption{The cut a read under \texttt{as of} is taken at. $S_k$: the positions chain $k$ serves. +$\beta_k(i)$: for the $i$-th event of chain $k$, the heads of the chains it reads, as recorded at +its writing; they rise with $i$.}\label{alg:resolve} +\begin{algorithmic}[1] +\Require a frontier $f$ from the name +\Ensure the greatest consistent cut under $f$ every position of which is served +\State $c \gets f$ +\Repeat + \For{each chain $k$} + \State $c_k \gets \max\{p \in S_k : p \le c_k\}$ \Comment{$0 \in S_k$} + \If{some event of $k$ under $c_k$ has $\beta_k(i)(k') > c_{k'}$ for some $k'$} + \State $c_k \gets$ the least such $i$ \Comment{a binary search} + \EndIf + \EndFor +\Until{nothing moved} +\State \Return $c$ +\end{algorithmic} +\end{algorithm} + +\paragraph{Derived stores.} +By \Cref{thm:append} a derived store can be read at a cut exactly when it is a function of the +prefixes, and by \Cref{thm:forms} the ways of holding it agree, so the choice is cost. Vectors +are a function of a chunk's text and the embedder's identity and are content addressed; the +plane keeps superseded versions, so the vectors at a cut are those of the versions the log names, +at no new bytes. The lexical index is the same, and its collection statistics +\cite{robertson2009bm25} at a cut are those of the units alive at the cut: a cut, like a +clearance, is a mask whose statistics must be its own. The causal edges from session transcripts +to commits and files are recomputed from the transcript as retained at the cut, which is cheap +and also removes a dependence on job order that the stored rows have today. The relations a note +declares in its own text are recomputed too. A commit's citation edges are stamped with the +projection that wrote them, since a later extractor adds edges under an old commit and the +reading would otherwise grow under a cut that did not move. Model output cannot be recomputed +and is kept by generation, the replaced row archived with its interval; a kept row is served +only while every content it was derived from is alive at the cut and not erased. One storage form is +ruled out as the carrier of a snapshot: the vector table's own versioned manifests. An erased +text stays readable through an earlier manifest until a compaction that removes every earlier +manifest (\Cref{sec:eval}), so a manifest version cannot be both the position of a snapshot and +within reach of an erasure. The cut is a predicate on rows taken from the log. + +\paragraph{Erasure and scope.} +Both are parameters of a read, not functions of the cut. A purge empties the log's row and keeps +its position, its commitment, its hash and the keyed hash of its path, so that a read by path +finds the hole (\Cref{thm:erase,thm:cert}); the salt goes with the content, so the commitment +cannot be tested against a guess. A retire seals the identity's earlier cuts under the stricter +seal, lifted only by an owner's act. A new note written at a deleted note's path inherits its +identity by default; the looser seal would bring the deleted versions back at earlier cuts, and +without the seal on the history they would stand under the new note at every later one. The grant is the asker's now, an event filter is applied after the read, +and an answer names the cut only on the chains the grant names (\Cref{thm:grant}). + +\paragraph{What an answer says.} +A store may be unable to serve the cut asked: it keeps no past yet, or the cut is under its +horizon. The read is then taken at the cut \Cref{alg:resolve} returns, which by +\Cref{thm:horizon} exists, is unique, never lies after the cut asked and rises as stores gain a +past. A chain that can fail to serve a recorded cut is read, by resolved references, only by +the chain of records, so only those chains and the records' are lowered, and the rows that read +them are withheld. The answer is exact for that cut and names it, chain by chain, with +the reason wherever it differs from the cut asked. Reading such a store at the present instead, which is what the +executor does today, is the reader \Cref{thm:append} refutes. At the head the read is the +present (\Cref{thm:compose}), so \texttt{as of "head"} is the sentence without the adjective. + +\paragraph{The horizon and retention.} +A chain's horizon is set by the genesis of its log, by retention, or by a reset. Retention is +counted in positions and has two levels. The derived rows of old versions can be dropped without +moving a horizon: they are cache entries of a function of content, a cut that asks for one finds +it pending, and it is derived again from the raw object. Moving the horizon drops raw objects +and empties the log's rows closed under it, which only the store's owner declares. That pass +appends a horizon row first, so a crash leaves rows that are unserved, never a position that is +served and incomplete, and it keeps every commitment, so the chain verifies from its first row. A window counted per identity (the last $n$ +versions of each) would leave no horizon to record. + +\section{Evaluation}\label{sec:eval} + +\paragraph{What is proved.} +\Cref{thm:append,thm:compose,thm:forms,thm:grant,thm:erase,thm:lattice,thm:cert,thm:horizon} are +machine-checked in \lean{formal/Palace/Snapshot.lean} over \lean{formal/Palace/Snapshot/Defs.lean} +on Lean~4 \cite{moura2021lean4}, v4.36.0-rc2, and the Mathlib \cite{mathlib2020} it pins: 175 +theorems, eighteen of them the controls, no +\lean{sorry}, and the axioms of all 5{,}213 library declarations audited (\lean{propext}, +\lean{Classical.choice}, \lean{Quot.sound} only). The library's export, 56{,}188 declarations +from \lean{Init} up, is replayed by Lean's kernel and five independent checkers. These are +design theorems: no code relies on them yet, so they are not among the 328 statements the +library restates separately and judges against its ledger of laws. + +\paragraph{The attacks.} +The definitions compute, so they are attacked as they are with property-based testing +(\lean{formal/PalaceTest/Snapshot.lean}, seeds 430 to 520, 500 draws each): stores of two chains +over three events, keyed chains over three keys, chains of landings and retires, grants and +erasures from bit masks, reads-from relations as edge lists, a base-four digest, served positions +from ten bits. Forty-nine attacks survive every draw. \Cref{alg:resolve}, which the library +does not define, is run as an equivalent alternation, every chain floored and then one pass of +the descent, and agrees on every draw with the pointwise maximum of every consistent served cut +under the frontier. Forty-two controls are refuted within 61 draws: among them a read at a cut past the head, generations +without the closing stamp, an event filter before the cut, an erasure that deletes rows, a seek +over rows that lost their key, an additive digest, the pruned store read under its horizon, a chain that others read lowered alone, and the floor and the +descent each run once, in either order. + +\paragraph{What is measured.} +All on synthetic fixtures built by each probe, on one machine (Apple M2 Pro, SQLite 3.54.1, +LanceDB 0.33.0), with other work running; no instance was read. The probes are not in the +repository; the design note describes each fixture, and each build stage commits its harness. \Cref{tab:measure} gives the figures. + +\begin{table}[t] +\centering +\small +\begin{tabular}{@{}p{0.34\linewidth}p{0.60\linewidth}@{}} +\toprule +probe & result \\ +\midrule +landing log, $10^6$ events over $10^5$ paths, keyed and hashed, one transaction & + 396 to 434 bytes a row with its three indexes; 35{,}000 to 42{,}000 rows a second \\ +one path at the middle cut; its seven versions & 3 $\mu$s and 9 $\mu$s through the key index; + 49 to 57 ms when the planner takes the primary key; after a version's row is emptied the + seek returns the hole \\ +the delta of 1{,}000 positions & 0.64 to 0.69 ms \\ +every head at a cut & 147 to 166 ms at the middle; 240 to 275 ms at the head \\ +the chain's hash from the first row; the stored hash at a position & 0.7 to 0.8 s; 3 $\mu$s \\ +lexical index, 500 items, 4 chunks, 3 versions & + 4{,}179 bytes a unit at 122 postings; 0.67 of the units superseded \\ +a purge of both versions of a note, on the test suite's throwaway store & + the words remain in the lexical postings, and in the vector table read at 8 and at 5 of its 10 + versions until a compaction that leaves 1; the version rows and attestations keep the + digests; the plane's per-path log gives position 1 again \\ +the same transcripts and commits, two job orders & 1 causal edge against 0 \\ +re-deriving a session of 2{,}000 records & 6 ms \\ +\bottomrule +\end{tabular} +\caption{Measurements on synthetic fixtures. Ranges are across two runs.}\label{tab:measure} +\end{table} + +The log's cost is small against what the stores already keep: the vector plane and the lexical +index drop no superseded version today, so most bytes of a past are paid already. Reading every +head from the log alone passes a tenth of a second at about a quarter of a million events in a +chain, past which heads are kept at recorded cuts. The purge row orders the build: the stores +that would be read at a cut are the ones an erasure does not reach, so the erasure's reach lands +before the first stage that reads a superseded version. + +\section{Limitations} + +The model has one writer: a chain is a list, and nothing is said of two writers. Collision +freedom and a binding commitment are hypotheses of \Cref{thm:cert}, not theorems about a hash +function. \Cref{alg:resolve} is attacked, not proved; the library proves the cut it must return +exists and is unique. The laws of the grant and the erasure are laws of a reader that reads +through them; that every reader in the code does is an obligation of the build, and no single +reader in the model applies the resolution, the grant, the erasure and the seal together. A +repository history with merges is a partial order, which the clock's down-set laws cover and +the chain model does not. Every measurement is on a synthetic fixture and cannot yet be repeated from the +repository: the cost of the lexical statistics from a mask at a corpus's size, of a vector +search joined to the heads at a cut, and of a retention pass are not measured. The attestation +ledger still names an erased digest; the note proposes a salted commitment in its place and +leaves the choice to the store's owner. + +\section{Future work} + +The build is eight stages, each with its tests and its rollback: the landing log; +recorded cuts, names and the resolver; the erasure's reach and the seal; the notes, vectors and +lexical index at a cut; the causal edges at a cut; model output by generation; retention; and +the delta between two cuts. Each stage property-tests its transcription against the Lean +statements, and its laws then enter the ledger. + +\section{Conclusion} + +A snapshot of a store with many stores is a prefix of each chain at a consistent cut, read +through the present's grant and the present's erasure. Stated that way its properties are +theorems, and the same statements located what the code lacked, a ledger of the catalog's past, +and what it must not do: answer a question about the past from the present. + +\bibliographystyle{plainnat} +\bibliography{refs} +\end{document} diff --git a/papers/2026-11-10-temporal-snapshot/refs.bib b/papers/2026-11-10-temporal-snapshot/refs.bib new file mode 100644 index 00000000..9b37ace8 --- /dev/null +++ b/papers/2026-11-10-temporal-snapshot/refs.bib @@ -0,0 +1,163 @@ +@article{lamport1978time, + author = {Lamport, Leslie}, + title = {Time, Clocks, and the Ordering of Events in a Distributed System}, + journal = {Communications of the ACM}, + volume = {21}, + number = {7}, + pages = {558--565}, + year = {1978} +} + +@article{chandy1985snapshots, + author = {Chandy, K. Mani and Lamport, Leslie}, + title = {Distributed Snapshots: Determining Global States of Distributed Systems}, + journal = {ACM Transactions on Computer Systems}, + volume = {3}, + number = {1}, + pages = {63--75}, + year = {1985} +} + +@incollection{mattern1989virtual, + author = {Mattern, Friedemann}, + title = {Virtual Time and Global States of Distributed Systems}, + booktitle = {Parallel and Distributed Algorithms}, + publisher = {North-Holland}, + year = {1989} +} + +@article{birkhoff1937rings, + author = {Birkhoff, Garrett}, + title = {Rings of Sets}, + journal = {Duke Mathematical Journal}, + volume = {3}, + number = {3}, + pages = {443--454}, + year = {1937} +} + +@book{davey2002lattices, + author = {Davey, B. A. and Priestley, H. A.}, + title = {Introduction to Lattices and Order}, + edition = {Second}, + publisher = {Cambridge University Press}, + year = {2002} +} + +@phdthesis{reed1978naming, + author = {Reed, David P.}, + title = {Naming and Synchronization in a Decentralized Computer System}, + school = {Massachusetts Institute of Technology}, + year = {1978} +} + +@article{bernstein1983mvcc, + author = {Bernstein, Philip A. and Goodman, Nathan}, + title = {Multiversion Concurrency Control: Theory and Algorithms}, + journal = {ACM Transactions on Database Systems}, + volume = {8}, + number = {4}, + pages = {465--483}, + year = {1983} +} + +@book{snodgrass1999temporal, + author = {Snodgrass, Richard T.}, + title = {Developing Time-Oriented Database Applications in {SQL}}, + publisher = {Morgan Kaufmann}, + year = {1999} +} + +@article{kulkarni2012sql2011, + author = {Kulkarni, Krishna and Michels, Jan-Eike}, + title = {Temporal Features in {SQL}:2011}, + journal = {ACM SIGMOD Record}, + volume = {41}, + number = {3}, + pages = {34--43}, + year = {2012} +} + +@inproceedings{merkle1987signature, + author = {Merkle, Ralph C.}, + title = {A Digital Signature Based on a Conventional Encryption Function}, + booktitle = {Advances in Cryptology -- CRYPTO '87}, + series = {Lecture Notes in Computer Science}, + volume = {293}, + pages = {369--378}, + publisher = {Springer}, + year = {1988} +} + +@article{haber1991timestamp, + author = {Haber, Stuart and Stornetta, W. Scott}, + title = {How to Time-Stamp a Digital Document}, + journal = {Journal of Cryptology}, + volume = {3}, + number = {2}, + pages = {99--111}, + year = {1991} +} + +@inproceedings{halevi1996commitment, + author = {Halevi, Shai and Micali, Silvio}, + title = {Practical and Provably-Secure Commitment Schemes from Collision-Free Hashing}, + booktitle = {Advances in Cryptology -- CRYPTO '96}, + series = {Lecture Notes in Computer Science}, + volume = {1109}, + pages = {201--215}, + publisher = {Springer}, + year = {1996} +} + +@article{gupta1995views, + author = {Gupta, Ashish and Mumick, Inderpal Singh}, + title = {Maintenance of Materialized Views: Problems, Techniques, and Applications}, + journal = {IEEE Data Engineering Bulletin}, + volume = {18}, + number = {2}, + pages = {3--18}, + year = {1995} +} + +@inproceedings{goguen1982security, + author = {Goguen, Joseph A. and Meseguer, Jos{\'e}}, + title = {Security Policies and Security Models}, + booktitle = {Proceedings of the 1982 IEEE Symposium on Security and Privacy}, + pages = {11--20}, + year = {1982} +} + +@article{robertson2009bm25, + author = {Robertson, Stephen and Zaragoza, Hugo}, + title = {The Probabilistic Relevance Framework: {BM25} and Beyond}, + journal = {Foundations and Trends in Information Retrieval}, + year = {2009}, + doi = {10.1561/1500000019} +} + +@inproceedings{moura2021lean4, + author = {de Moura, Leonardo and Ullrich, Sebastian}, + title = {The {L}ean 4 theorem prover and programming language}, + booktitle = {Automated Deduction -- CADE 28}, + series = {Lecture Notes in Computer Science}, + volume = {12699}, + pages = {625--635}, + publisher = {Springer}, + year = {2021} +} + +@inproceedings{mathlib2020, + author = {{The mathlib Community}}, + title = {The {L}ean mathematical library}, + booktitle = {Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs}, + pages = {367--381}, + year = {2020} +} + +@misc{serranocalva2026palace, + author = {Serrano-Calva, Alberto}, + title = {mind-palace}, + howpublished = {\url{https://github.com/ascalva/mind-palace}}, + year = {2026} +}