interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / chain / README.md
| 1 | # chain: the INTERPLANE ledger, a record anyone can check |
| 2 | |
| 3 | A hash chain for what agents and people did: hand-offs, verdicts, merges, messages. Each record |
| 4 | commits to its payload and to the record before it, so the ledger's last digest fixes its whole |
| 5 | history. Checking it needs no trust in this program, its author or any model vendor: the format is |
| 6 | one text line per record and the only arithmetic is SHA-256, which `sha256sum` already does. |
| 7 | |
| 8 | Status: IMPLEMENTED and EXERCISED on the Spark host (gate below). No ledger is published yet. |
| 9 | |
| 10 | ## Format |
| 11 | |
| 12 | One line per record, seven tab-separated fields, ended by a line feed: |
| 13 | |
| 14 | ``` |
| 15 | seq utc kind actor subject payload prev |
| 16 | ``` |
| 17 | |
| 18 | | Field | Rule | |
| 19 | |---|---| |
| 20 | | `seq` | counts from 1, no gaps, no leading zero | |
| 21 | | `utc` | `YYYY-MM-DDTHH:MM:SSZ`, a real date and time, never earlier than the record before | |
| 22 | | `kind` | `A-Z`, `0-9`, `_`; 1 to 24 bytes | |
| 23 | | `actor`, `subject` | printable ASCII; 1 to 64 and 1 to 128 bytes | |
| 24 | | `payload` | SHA-256 of the payload bytes, 64 lowercase hex digits | |
| 25 | | `prev` | SHA-256 of the previous record's line (without its line feed); `GENESIS` in record 1 | |
| 26 | |
| 27 | The head of a ledger is the SHA-256 of its last line. |
| 28 | |
| 29 | ## Use |
| 30 | |
| 31 | ```sh |
| 32 | OMV=$HOME/work/flux/omega-mv # sha2.om sha256 5cf0f981…fdb33, omc 3ad9f10f…93194 |
| 33 | { printf 'om2\n'; cat $OMV/om/tls/sha2.om chain/chain.om; } | $OMV/seed/out/omc > chain-bin |
| 34 | ./chain-bin add LEDGER KIND ACTOR SUBJECT < payload # prints: OK <seq> <head> |
| 35 | ./chain-bin verify LEDGER # prints: OK <count> <head>, or BAD line N code |
| 36 | ./chain-bin check LEDGER SEQ < payload # exit 0 only if this is the payload record SEQ committed to |
| 37 | ./chain-bin feed LEDGER FILE KIND ACTOR [PAGE] # one record per new complete line of FILE; then PAGE |
| 38 | ./chain-bin page LEDGER OUT # the head as a page with the check by hand |
| 39 | ``` |
| 40 | |
| 41 | `add` takes an exclusive lock, verifies the whole ledger and refuses to append to one that does not |
| 42 | verify. `verify` enforces every rule in the table above, not only the chain. Commands are matched as |
| 43 | whole words (`add`, `verify`, `check`, `feed`, `page`). Exit 0 done; 1 usage or a bad argument; 2 the ledger |
| 44 | does not verify; 3 read or write failed; 4 `check`: no such record, or the payload is not the one |
| 45 | committed; 5 `feed`: the file has fewer complete lines than were already recorded from it. BAD |
| 46 | codes: 1 not seven fields, or a byte that is not a tab or printable ASCII; 2 seq; 3 utc; 4 payload |
| 47 | digest; 5 prev; 6 line longer than 1,023 bytes; 7 last line has no line feed; 8 kind, actor or |
| 48 | subject breaks its rule. |
| 49 | |
| 50 | `page` verifies the ledger and writes one HTML file: the record count, the time of the last |
| 51 | record, the head, and the commands from "Checking it without this program" with the public |
| 52 | address of the ledger. It writes nothing for a ledger that does not verify. The file has no script |
| 53 | and no inline style; it links `/assets/tokens.css` and `/assets/proof.css` (`chain/proof.css`). |
| 54 | It is written as `OUT.tmp` and renamed. `feed` with a fifth argument writes the same page after |
| 55 | its last record, so one service keeps ledger and page together. A page name, or its `.tmp`, that is |
| 56 | the ledger or (in `feed`) the fed file is refused with exit 1 before anything is written. A stale |
| 57 | `OUT.tmp` is removed first (the name, never what a link points to), the new one is created |
| 58 | exclusively, and it is removed again when writing or renaming fails. |
| 59 | |
| 60 | `feed` is how a running log becomes a chain. It records line N of FILE with the subject |
| 61 | `<file name> line N` and the SHA-256 of the line's bytes, without its line feed, as the payload. |
| 62 | It resumes after the highest N already recorded for that KIND and file name, so running it again |
| 63 | adds only new lines; a last line with no line feed yet is left for the next run. Only the digest |
| 64 | enters the ledger, so a private log can be chained in public: whoever holds a line can prove it was |
| 65 | recorded (`printf %s "$(sed -n 'Np' FILE)" | chain check LEDGER SEQ`, with the line number for N, |
| 66 | so the line needs no quoting), and nobody can read it from the ledger. |
| 67 | The file name is at most 100 bytes of printable ASCII. Two files with one base name share a resume |
| 68 | point under one KIND, so give each its own KIND. A record another writer adds with the same kind and |
| 69 | a subject of the same form moves the resume point; one ledger per trusted set of writers. FILE may |
| 70 | not be the ledger itself, by any name: that feed would never end, so it is refused (exit 1). |
| 71 | `add` syncs its record to disk before it answers. `feed` syncs once, after its last record, so a |
| 72 | first run over a long file costs one sync, not one per line; the gate counts the syncs with |
| 73 | `strace` and fails without it. |
| 74 | |
| 75 | ## Checking it without this program |
| 76 | |
| 77 | ```sh |
| 78 | # every record's prev is the digest of the line above it |
| 79 | awk 'NR>1' ledger.tsv | cut -f7 > claimed |
| 80 | sed '$d' ledger.tsv | while IFS= read -r line; do printf %s "$line" | sha256sum | cut -d' ' -f1; done > computed |
| 81 | cmp claimed computed && echo chain intact |
| 82 | # a payload is the one a record committed to |
| 83 | sha256sum < payload # equals field 6 of that record |
| 84 | ``` |
| 85 | |
| 86 | ## What it proves, and what it does not |
| 87 | |
| 88 | - Proved (`Ledger.lean`, Lean 4, no axioms, `lean chain/Ledger.lean`): two valid ledgers with the |
| 89 | same head are the same ledger, provided SHA-256 never gives one digest for two different lines. |
| 90 | So an edit, removal, insertion or reordering anywhere changes the head. |
| 91 | - Assumed, not proved: that nobody can find such a SHA-256 collision. |
| 92 | - Not proved by the chain alone: when a record was written, and who wrote the payload. A ledger |
| 93 | kept only on one machine can be rebuilt from scratch by whoever holds it. Time and authorship |
| 94 | come from outside: publish each new head where the publisher cannot take it back (for example a |
| 95 | signed commit copied to machines other people run), and the record existed no later than that. |
| 96 | A model vendor does not sign what its model says, so "this model wrote this text" needs a |
| 97 | witness of the vendor connection; that is a later unit, not claimed here. |
| 98 | |
| 99 | ## Service (after merge) |
| 100 | |
| 101 | `infra/spark/interplane-chain.service` chains the hive's message board, `~/handoffs/BOARD.md`, |
| 102 | one record per line, into `~/forge-data/proof/board.tsv`, and rewrites the page |
| 103 | `~/forge-data/proof/index.html` after each run. It runs when the folder changes (inotify through |
| 104 | `aien-onchange`, at most once a minute), not on a clock. Only digests enter the ledger. |
| 105 | |
| 106 | ```sh |
| 107 | mkdir -p ~/.local/share/interplane-chain ~/forge-data/proof |
| 108 | { printf 'om2\n'; cat $OMV/om/tls/sha2.om chain/chain.om; } | $OMV/seed/out/omc > ~/.local/share/interplane-chain/chain |
| 109 | chmod 755 ~/.local/share/interplane-chain/chain |
| 110 | cp chain/proof.css ~/forge-data/proof/ |
| 111 | cp infra/spark/interplane-chain.service ~/.config/systemd/user/ |
| 112 | systemctl --user daemon-reload && systemctl --user enable --now interplane-chain.service |
| 113 | ``` |
| 114 | |
| 115 | Undo: `systemctl --user disable --now interplane-chain.service`. The ledger file stays; it is |
| 116 | append-only by intent. On a copy of the board of 2026-11-09 (3,294 lines) the first feed took |
| 117 | 0.04 s and wrote 3,294 records that `verify` accepts; a second run added none. |
| 118 | |
| 119 | ## Gate |
| 120 | |
| 121 | ```sh |
| 122 | sh chain/tests/run.sh # prints RESULT pass=<count> fail=0 when every case holds |
| 123 | ``` |
| 124 | |
| 125 | The oracle is `sha256sum`, never the program under test: every `prev`, every payload digest |
| 126 | (text, empty, 5 MiB of random bytes) and the head are recomputed with it. Seven kinds of damage are |
| 127 | each refused with the expected line and code (an edited record, a removed one, two swapped, a |
| 128 | forged one with a stale prev, a cut-off last line, record 1 not on GENESIS, a non-hex digest); a |
| 129 | damaged ledger cannot be appended to; twenty writers at once leave one valid chain. Nineteen |
| 130 | hand-made ledgers, relinked with `sha256sum`, each break one field rule (seq with a leading zero, |
| 131 | an earlier time, an impossible date or time such as 2100-02-29, April 31, month 00, day 00, hour 24, |
| 132 | minute or second 60, a bad kind, an over-long actor or subject, a DEL, carriage return or non-ASCII |
| 133 | byte) and are refused with the expected code; two leap days (2024, 2400) and the longest allowed |
| 134 | fields are accepted. `add` on a ledger whose last record is later than the clock is refused and |
| 135 | writes nothing. A command that only starts like `add` or `verify`, or has a byte after `add`, |
| 136 | `verify` or `check`, is refused and writes nothing. `feed` is checked against `sha256sum` line by |
| 137 | line (an empty line, a line with a tab, a 200,000-byte line of arbitrary bytes), for leaving an |
| 138 | unfinished line, for adding nothing when run again, for resuming only on its own kind and exact file |
| 139 | name, for exit 5 with nothing written when the file lost lines, for refusing the ledger itself as |
| 140 | the file (by its name and through a link), and for its argument rules. `page` is checked on a |
| 141 | ledger of 1,234 records: its head and count against `sha256sum` and `wc`, and then the commands |
| 142 | are taken out of the page itself, entity-decoded and run: the head command gives the page's head, |
| 143 | the link check prints `chain intact`, and on a copy with one edited record it does not; the |
| 144 | "prove one message" command, run on a board line holding a quote, an apostrophe, parentheses and a |
| 145 | dollar sign, gives that line's SHA-256; the page ends with `</html>` and its line feed. (A page |
| 146 | that would pass the 16,383-byte page buffer is refused with exit 3, never cut short; today's page |
| 147 | is under 3,000 bytes, so the gate does not reach that case.) A damaged |
| 148 | ledger gets exit 2 and no page; an empty one says so. A page named as the ledger, as the ledger's |
| 149 | name plus `.tmp`, or (in `feed`) as the fed file is refused and leaves both unchanged; a stale |
| 150 | `OUT.tmp` link is not written through; a failed rename leaves no `OUT.tmp`. |
| 151 | Negative controls: a mutant that skips the prev check accepts the edited ledger; a mutant that |
| 152 | forgets what was recorded records lines twice; a mutant without the lost-lines rule exits 0; a |
| 153 | mutant without the verify rule writes a page for a damaged ledger; a mutant without the name guard |
| 154 | replaces its own ledger with the page. The |
| 155 | gate refuses any compiler or `sha2.om` other than the pins (exit 2). |
| 156 | |
| 157 | ## Not done |
| 158 | |
| 159 | - The ledger and its page are not served from interplane.io yet: the files exist under |
| 160 | `~/forge-data/proof/`, the forged routes (`/proof`, `/proof/board.tsv`, `/assets/proof.css`) do not. |
| 161 | - No outside time anchor yet: publishing each head where it cannot be taken back is a later unit. |
| 162 | - A ledger line is at most 1,023 bytes. |