unchanged · A short history

Machines change. Work, unchanged.

Open-source software, built on models, proofs and verifiers.

01Method

From assembly to natural language. Same three steps.

Each generation raised the level at which programs are written. None changed what it takes to know a program is correct.

  1. 01

    Understand

    Say what must hold in every reachable state, before the code exists.

  2. 02

    Write

    Machine code, assembly, high-level languages, natural language. Each generation automated more of this step, and it is the only one that changed. In TLA+, UNCHANGED asserts that a step leaves the listed variables as they were. The name is taken from it.

  3. 03

    Verify

    Check what was written against what was stated. The author of the code, human or agent, is not its judge.

VARIABLES language, understand, write, verify \* Stated first: all three are still required.Inv == understand /\ write /\ verify
Next == \E l \in Languages :  /\ language' = l   \* "machine code"  /\ UNCHANGED <<understand, write, verify>>
$ java -jar tla2tools.jar Engineering.tlaModel checking completed. No error has been found.17 states generated, 4 distinct states found,0 states left on queue.

02Specification

A compiler translates.
An agent infers.

  1. 01

    Source code has semantics.

    The language defines what a program means, so a compiler can preserve it. What was written is what runs.

  2. 02

    Natural language does not.

    One sentence admits many programs. The agent picks one, and nothing in the sentence says whether it picked yours.

  3. 03

    So the specification is written down.

    Each question gets one answer, in a form a tool can check. A person approves it. After that the code may be rewritten freely; the specification may not.

add.cpromptCommit.tlacompiledthree open questionsone answer each
int add(int a, int b) {    return a + b;} ; cc -O1 -S add.c   (arm64)_add:    add   w0, w1, w0    ret
> A committed transaction is never lost. # committed: acknowledged, or on stable storage?# lost: after a crash, power loss, a torn page?# never: in every interleaving, or the ones tested?
Commit(t) ==  /\ t \in synced \ acked  /\ acked' = acked \cup {t}  /\ UNCHANGED <<wal, synced>> \* An acknowledged transaction is on stable storage.Inv == acked \subseteq synced

03Evidence

Three kinds of evidence.
None is enough alone.

  1. 01

    Model

    Establishes that the design keeps the invariant in every reachable state, within the bounds checked. Blind to the code: nothing here says the implementation follows the model.

  2. 02

    Proof

    Establishes that the code meets its contract on every input. Blind to whether the contract is the one you meant. This one says sorted, not a permutation of the input, so an empty vector verifies.

  3. 03

    Verifier

    Establishes that the real code did the right thing on the runs it made. Blind to every run it did not make. Here one test catches what the proof accepted.

Commit.tla · TLCsort.rs · Verussort_test.rs64 states, no error1 verified, 0 errors1 failed
$ java -jar tla2tools.jar -deadlock Commit.tlaModel checking completed. No error has been found.134 states generated, 64 distinct states found,0 states left on queue. \* Txns = {t1, t2, t3}
// spec: the result is sortedpub fn sort(v: Vec<u64>) -> (r: Vec<u64>)    ensures forall|i: int, j: int|        0 <= i < j < r.len() ==> r[i] <= r[j],{    Vec::new()}
$ rustc --test sort_test.rs && ./sort_testtest keeps_every_element ... FAILED assertion `left == right` failed  left: 0 right: 3 test result: FAILED. 0 passed; 1 failed

04Verifiers

A verifier for every way to be wrong.

A replicated log, a parser and a cipher fail differently. A map of the field: which verifier sees which failure, and what each is blind to.

Distributed systemsJepsenMaelstromTLA+QuintP

Catches split brain, lost acknowledged writes, stale reads under partition.

Blind to faults the nemesis never schedules.

Histories & isolationElleKnossosPorcupineLincheck

Catches linearizability violations and isolation anomalies: G0, G1c, G2, lost updates.

Blind to operations no client ever issued.

Deterministic simulationSeeded DSTturmoilmadsimAntithesis

Catches rare orderings of time, network and disk, replayed exactly from a seed.

Blind to anything outside the simulated world.

Storage & crashesCrash-state enumerationALICECrashMonkeytorn writes

Catches data lost, or resurrected, after a crash at any point.

Blind to devices that break the disk model.

ConcurrencyloomShuttleCoyoteGenMCThreadSanitizer

Catches races, deadlocks and weak-memory reorderings.

Blind to protocols too large to enumerate.

Inputs & parsersProperty testsproptestHypothesislibFuzzerAFL++

Catches crashes and broken contracts: round-trips, idempotence, equivalence to a reference.

Blind to deep states, and bugs the reference shares.

Memory & undefined behaviourMiriASanMSanUBSanKaniCBMC

Catches out-of-bounds access, use-after-free, undefined behaviour.

Blind to object bounds the tool was never told.

Queries & numericsSQLancerTLPNoRECmetamorphic testingHerbie

Catches optimizer logic bugs and floating-point error: wrong answers that never crash.

Blind to relations the metamorphic rule does not state.

Cryptography & protocolsTamarinProVerifWycheproofdudect

Catches protocol attacks, known-bad edge cases, timing leaks.

Blind to the gap between the protocol model and the code.

The verifiers themselvesMutation testingplanted defectsmust-fail model configs

Catches a suite that passes because it cannot fail.

Blind to defect classes nobody thought to plant.

05Software

Software, built this way.

Four systems, each built from a specification, with models for the design and verifiers on the code. Varaq, a B+tree database, comes first.

  1. 001

    Varaq

    ورق

    A fast embedded B+tree in Rust, with ACID transactions: the pages in use stay in memory, and a page that is not costs one 4 KiB read.

    Version 0.1.0Announcement →See Varaq →

The tools will keep changing.
The method stays unchanged.

Models for the design, proofs for the code, verifiers for the running system, each covering what the others miss.

⌂ 换网址