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

9c8323f send gate, SMTP submission, test sink; send scenario (143 steps); stats op documented Drake Stapleton committed 2026-11-11
..
Mailhand.lean14871
README.md5435

README.md

Mailhand proofs

Mailhand.lean is a plain Lean 4 file (core library only: no Mathlib, no unfinished proofs, no axiom declarations, no native_decide). It proves facts about two small models. It does not prove anything about the compiled Omega program itself: the models are hand-written from the algorithm description in the task brief, and src/mime.om did not exist yet when they were written, so the match between model and code has to be checked by reading the code against the model below.

How to check

From the repository root, with a Lean 4 toolchain (4.35.0 was used for the recorded check):

lean proofs/Mailhand.lean; echo exit=$?

Expected: exit=0 and these axiom lines (only Lean's standard axioms):

'Mailhand.B64.decode_length' depends on axioms: [propext, Classical.choice, Quot.sound]
'Mailhand.B64.decode_bound' depends on axioms: [propext, Classical.choice, Quot.sound]
'Mailhand.Chain.chain_unique' depends on axioms: [propext, Classical.choice, Quot.sound]
'Mailhand.Chain.single_change_detected' depends on axioms: [propext, Classical.choice, Quot.sound]
'Mailhand.Chain.truncation_verifies' depends on axioms: [propext]
'Mailhand.B64.lenient_breaks_bound' depends on axioms: [propext]
'Mailhand.Chain.needs_injective' does not depend on any axioms
'Mailhand.Chain.needs_fixed_length' does not depend on any axioms

Toolchain: Lean 4.35.0 (~/.elan/bin/lean --version).

Part 1: base64 decoder

Model (Mailhand.B64.decode)

The input is a list of bytes. The model produces the decoded bytes, not just a count:

  • SP, TAB, CR, LF are skipped.
  • Each alphabet byte (A-Z a-z 0-9 + /) adds one 6-bit value to the current group of 4. When a group is full, 3 bytes are written out.
  • = is padding. It is allowed only when the current group holds 2 or 3 values. After it, only = and whitespace may follow. The number of = is not checked: QQ= and QQ== are both accepted.
  • Any other byte is a refusal (none).
  • At the end of the input, a group of 0 values gives no extra bytes, 1 value is a refusal, 2 values give 1 byte, and 3 values give 2 bytes.
  • Leftover low bits in a final group are not checked (not part of the brief).

Proved

  • decode_length: if decode i = some o, then o.length = 3*(q/4) + [0,0,1,2][q%4], where q is the number of alphabet bytes in i.
  • decode_bound: if decode i = some o, then o.length ≤ 3 * i.length / 4 (whole-number division).
  • Sanity checks evaluated by the kernel: TWFu→Man, TWE=→Ma, TQ==→M, input with whitespace in it→Man, empty→empty. These are refused: Q, Q===, QQ=Q, TW-u.
  • Negative control lenient_breaks_bound: a decoder that writes one byte for a final 1-value group instead of refusing breaks the bound. This shows the bound depends on that refusal and is not true for every decoder.

Not proved

  • That src/mime.om implements this model.
  • That the output bytes are the correct base64 decoding beyond the listed examples. Only the length law is proved for every input.
  • Anything about refusals, for example that every valid encoding is accepted.

Part 2: hash-chain audit log

Model (Mailhand.Chain)

A log is a list of records (body, stored). Verification starts with prev = genesis. For each record it requires stored = H(prev ++ body) and then sets prev := stored. The head is the last stored value, or genesis if the log is empty.

H stands for SHA-256. Each theorem that needs facts about H takes them as hypotheses. They are not added as axioms:

  1. H is injective (no two inputs give the same output). This is an idealisation of collision resistance. Real SHA-256 does have collisions; they are only believed infeasible to find. So these results hold only as far as that belief holds.
  2. All outputs of H have the same length (SHA-256: 32 bytes). Without this, prev ++ body could be split at a different point. needs_fixed_length gives a concrete injective H with varying output length where two different logs share a head.

Proved

  • chain_unique: given hypotheses 1 and 2, if two logs of the same length both verify from the same genesis and give the same head, then the logs are equal.
  • single_change_detected (corollary): if a log verifies with head h and record j is replaced by any different record (for example one byte of its body or of its stored hash changed), then the changed log either fails verification or has a head other than h.
  • Negative control needs_injective: with a constant H, two different logs share a head.

Truncation is NOT detected by verification alone

truncation_verifies proves that dropping the last record of a log that verifies gives a log that still verifies (prefix_verifies is the general statement for any prefix). Removing trailing records is therefore detected only by comparing the head with a head value kept somewhere else (outside the log). Nothing in this file proves the truncated head differs from the original head. That needs the kept head and a comparison step, neither of which is modelled.

Not proved

  • That the Omega audit writer or verifier implements this model, or what the genesis value is.
  • Anything about real SHA-256 beyond the two hypotheses above.
  • Anything about logs of different lengths, apart from the truncation statement.