interplane.Get Omega
Read in your language

mailhand

mailhand: agents look after a person's email in seeded Omega. Maildir + MIME parsing, JSONL CLI and MCP, rule triage, policy-gated sending, hash-chained audit. Free (Apache-2.0).

Brought by drakestapleton

branch main Branches Tags History

mailhand / proofs / README.md

116 lines · 5435 bytes Raw Blame History Rendered
1# Mailhand proofs
2
3`Mailhand.lean` is a plain Lean 4 file (core library only: no Mathlib, no
4unfinished proofs, no `axiom` declarations, no `native_decide`). It proves facts
5about two small **models**. It does not prove anything about the compiled Omega
6program itself: the models are hand-written from the algorithm description in
7the task brief, and `src/mime.om` did not exist yet when they were written, so the
8match between model and code has to be checked by reading the code against the
9model below.
10
11## How to check
12
13From the repository root, with a Lean 4 toolchain (4.35.0 was used for the recorded check):
14
15
16 lean proofs/Mailhand.lean; echo exit=$?
17
18Expected: `exit=0` and these axiom lines (only Lean's standard axioms):
19
20 'Mailhand.B64.decode_length' depends on axioms: [propext, Classical.choice, Quot.sound]
21 'Mailhand.B64.decode_bound' depends on axioms: [propext, Classical.choice, Quot.sound]
22 'Mailhand.Chain.chain_unique' depends on axioms: [propext, Classical.choice, Quot.sound]
23 'Mailhand.Chain.single_change_detected' depends on axioms: [propext, Classical.choice, Quot.sound]
24 'Mailhand.Chain.truncation_verifies' depends on axioms: [propext]
25 'Mailhand.B64.lenient_breaks_bound' depends on axioms: [propext]
26 'Mailhand.Chain.needs_injective' does not depend on any axioms
27 'Mailhand.Chain.needs_fixed_length' does not depend on any axioms
28
29Toolchain: Lean 4.35.0 (`~/.elan/bin/lean --version`).
30
31## Part 1: base64 decoder
32
33### Model (`Mailhand.B64.decode`)
34
35The input is a list of bytes. The model **produces the decoded bytes**, not just
36a count:
37
38- SP, TAB, CR, LF are skipped.
39- Each alphabet byte (`A-Z a-z 0-9 + /`) adds one 6-bit value to the current
40 group of 4. When a group is full, 3 bytes are written out.
41- `=` is padding. It is allowed only when the current group holds 2 or 3 values.
42 After it, only `=` and whitespace may follow. The number of `=` is not
43 checked: `QQ=` and `QQ==` are both accepted.
44- Any other byte is a refusal (`none`).
45- At the end of the input, a group of 0 values gives no extra bytes, 1 value
46 is a refusal, 2 values give 1 byte, and 3 values give 2 bytes.
47- Leftover low bits in a final group are not checked (not part of the brief).
48
49### Proved
50
51- `decode_length`: if `decode i = some o`, then
52 `o.length = 3*(q/4) + [0,0,1,2][q%4]`, where `q` is the number of alphabet
53 bytes in `i`.
54- `decode_bound`: if `decode i = some o`, then `o.length ≤ 3 * i.length / 4`
55 (whole-number division).
56- Sanity checks evaluated by the kernel: `TWFu`→`Man`, `TWE=`→`Ma`,
57 `TQ==`→`M`, input with whitespace in it→`Man`, empty→empty. These are
58 refused: `Q`, `Q===`, `QQ=Q`, `TW-u`.
59- Negative control `lenient_breaks_bound`: a decoder that writes one byte for a
60 final 1-value group instead of refusing breaks the bound. This shows the bound
61 depends on that refusal and is not true for every decoder.
62
63### Not proved
64
65- That `src/mime.om` implements this model.
66- That the output bytes are the correct base64 decoding beyond the listed
67 examples. Only the length law is proved for every input.
68- Anything about refusals, for example that every valid encoding is accepted.
69
70## Part 2: hash-chain audit log
71
72### Model (`Mailhand.Chain`)
73
74A log is a list of records `(body, stored)`. Verification starts with
75`prev = genesis`. For each record it requires `stored = H(prev ++ body)` and then
76sets `prev := stored`. The head is the last `stored` value, or `genesis` if the
77log is empty.
78
79`H` stands for SHA-256. Each theorem that needs facts about `H` takes them as
80**hypotheses**. They are not added as axioms:
81
821. `H` is injective (no two inputs give the same output). This is an
83 idealisation of collision resistance. Real SHA-256 does have collisions; they
84 are only believed infeasible to find. So these results hold only as far as
85 that belief holds.
862. All outputs of `H` have the same length (SHA-256: 32 bytes). Without this,
87 `prev ++ body` could be split at a different point. `needs_fixed_length`
88 gives a concrete injective `H` with varying output length where two
89 different logs share a head.
90
91### Proved
92
93- `chain_unique`: given hypotheses 1 and 2, if two logs of the same length both
94 verify from the same genesis and give the same head, then the logs are equal.
95- `single_change_detected` (corollary): if a log verifies with head `h` and
96 record `j` is replaced by any different record (for example one byte of its
97 body or of its stored hash changed), then the changed log either fails
98 verification or has a head other than `h`.
99- Negative control `needs_injective`: with a constant `H`, two different logs
100 share a head.
101
102### Truncation is NOT detected by verification alone
103
104`truncation_verifies` proves that dropping the last record of a log that
105verifies gives a log that still verifies (`prefix_verifies` is the general
106statement for any prefix). Removing trailing records is therefore detected only
107by comparing the head with a head value kept somewhere else (outside the log).
108Nothing in this file proves the truncated head differs from the original head.
109That needs the kept head and a comparison step, neither of which is modelled.
110
111### Not proved
112
113- That the Omega audit writer or verifier implements this model, or what the
114 genesis value is.
115- Anything about real SHA-256 beyond the two hypotheses above.
116- Anything about logs of different lengths, apart from the truncation statement.