Cairn.Optimistic.Claims
lean/Cairn/Optimistic/Claims.lean
Optimistic values: the claims
Cairn.Optimistic's claims (cairn^1100–cairn^1114, docs/optimistic.md), stated over a
harness machine whose state is the server model's World at keys Nat and boolean values
(liked or not), with same equality. Its moves are every way the person, the server and the
network act (Cairn.Optimistic.Server): the person flips a key (^1100); the server handles or
refuses a packet (^1101, ^1102); the network delivers or loses one, before or after the server
handled it (^1103, ^1104); the backoff timer fires (^1105); a view is fetched (^1106). A move's
key i picks the i-th packet in the network (nothing if there is none). Any sequence of these
is any interleaving of sets and replies, so an invariant of the machine holds after every one.
The invariants:
| Id | Claim | Theorem |
|---|---|---|
| ^1107 | a set shows in its own step | Table.shown_set |
| ^1108 | at most one write in flight per key | World.Ok.oneWrite |
| ^1109 | never more writes than sets, per key | World.Ok.writes_le_sets, Table.writes_le_sets |
| ^1110 | a refusal rolls back in its step | Table.refused_rollback |
| ^1111 | once settled, a key shows what the server holds, for any order of replies | World.Ok.converges |
| ^1112 | inputs for different keys commute | Table.feed_comm |
| ^1113 | a settled count is the view's others plus the server's own, never below zero | World.Ok.count, count_ge |
| ^1114 | a view never moves a key written this session | Table.seen_written |
^1107, ^1110, ^1112 and ^1114 hold of every table; the harness states them of the table in every
reachable state. The theorems are general (any key type with a lawful order, any value type,
any same that is an equivalence); the harness instantiates them. Not imported by Cairn (the
host links that); CairnAll imports it, so the ledger reads it.
Imports Cairn.Claims.Core, Cairn.Claims.Elab, Cairn.Optimistic.Server
Claims 15
The person flips key k (likes or unlikes it).
SeesKey k shows the new value in that step, whatever is in flight.
Formal statementpress.post s k s' := s'.table.shown k = !s.table.shown k
- proved
- 1 theorem (sound press), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean). - not seen
- No capture ran.
lean/Cairn/Optimistic/Claims.lean:88 · press · ledger: active
6 generated declarations
apply (s : W) (k : Nat) : W
What ^1100 does on press.
info : ClaimInfo
The human half of claim ^1100.
preserves (P : W → Prop) (press : ∀ (s : W) (k : Nat), P s → P (press.apply s k)) : Claims.press.Preserves P
To show every handler of ^1100 keeps a property, show it in the move's own terms.
sound (s : W) (k : Nat) : post s k (apply s k)
press : Claims.Move W
^1100 Set a value (move)
Does: The person flips key k (likes or unlikes it).
Sees: Key k shows the new value in that step, whatever is in flight.
post (s : W) (k : Nat) (s' : W) : Prop
What must follow ^1100 Set a value on press: Key k shows the new value in that step, whatever is in flight.
The server handles the i-th packet in the network: applies a write (its answer becomes acked) or answers a read with what it holds.
SeesNothing changes on screen: the table hears nothing until an answer arrives.
Formal statementpress.post s i s' := s'.table = s.table
- proved
- 1 theorem (sound press), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean). - not seen
- No capture ran.
lean/Cairn/Optimistic/Claims.lean:96 · serve · ledger: active
6 generated declarations
apply (s : W) (i : Nat) : W
What ^1101 does on press.
sound (s : W) (i : Nat) : post s i (apply s i)
preserves (P : W → Prop) (press : ∀ (s : W) (i : Nat), P s → P (press.apply s i)) : serve.Preserves P
To show every handler of ^1101 keeps a property, show it in the move's own terms.
serve : Claims.Move W
^1101 The server handles a request (move)
Does: The server handles the i-th packet in the network: applies a write (its answer becomes acked) or answers a read with what it holds.
Sees: Nothing changes on screen: the table hears nothing until an answer arrives.
info : ClaimInfo
The human half of claim ^1101.
post (s : W) (i : Nat) (s' : W) : Prop
What must follow ^1101 The server handles a request on press: Nothing changes on screen: the table hears nothing until an answer arrives.
The server refuses the i-th packet in the network, and changes nothing.
SeesNeither the screen nor the server changes; the refusal is on its way.
Formal statementpress.post s i s' := s'.table = s.table ∧ s'.srv = s.srv
- proved
- 1 theorem (sound press), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean). - not seen
- No capture ran.
lean/Cairn/Optimistic/Claims.lean:104 · refuse · ledger: active
6 generated declarations
post (s : W) (i : Nat) (s' : W) : Prop
What must follow ^1102 The server refuses a request on press: Neither the screen nor the server changes; the refusal is on its way.
apply (s : W) (i : Nat) : W
What ^1102 does on press.
preserves (P : W → Prop) (press : ∀ (s : W) (i : Nat), P s → P (press.apply s i)) : refuse.Preserves P
To show every handler of ^1102 keeps a property, show it in the move's own terms.
info : ClaimInfo
The human half of claim ^1102.
refuse : Claims.Move W
^1102 The server refuses a request (move)
Does: The server refuses the i-th packet in the network, and changes nothing.
Sees: Neither the screen nor the server changes; the refusal is on its way.
sound (s : W) (i : Nat) : post s i (apply s i)
The network delivers the i-th packet, an answer or a view, to the table.
SeesThe table settles, rolls back, retries or takes the view; the server is unchanged.
Formal statementpress.post s i s' := s'.srv = s.srv
- proved
- 1 theorem (sound press), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean). - not seen
- No capture ran.
lean/Cairn/Optimistic/Claims.lean:115 · deliver · ledger: active
6 generated declarations
apply (s : W) (i : Nat) : W
What ^1103 does on press.
deliver : Claims.Move W
^1103 An answer arrives (move)
Does: The network delivers the i-th packet, an answer or a view, to the table.
Sees: The table settles, rolls back, retries or takes the view; the server is unchanged.
post (s : W) (i : Nat) (s' : W) : Prop
What must follow ^1103 An answer arrives on press: The table settles, rolls back, retries or takes the view; the server is unchanged.
preserves (P : W → Prop) (press : ∀ (s : W) (i : Nat), P s → P (press.apply s i)) : deliver.Preserves P
To show every handler of ^1103 keeps a property, show it in the move's own terms.
info : ClaimInfo
The human half of claim ^1103.
sound (s : W) (i : Nat) : post s i (apply s i)
The network loses the i-th packet, before or after the server handled it; the table hears lost (a write) or readFailed (a read).
SeesA lost write puts its key in doubt and sends a read; the server is unchanged.
Formal statementpress.post s i s' := s'.srv = s.srv
- proved
- 1 theorem (sound press), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean). - not seen
- No capture ran.
lean/Cairn/Optimistic/Claims.lean:123 · lose · ledger: active
6 generated declarations
preserves (P : W → Prop) (press : ∀ (s : W) (i : Nat), P s → P (press.apply s i)) : lose.Preserves P
To show every handler of ^1104 keeps a property, show it in the move's own terms.
info : ClaimInfo
The human half of claim ^1104.
sound (s : W) (i : Nat) : post s i (apply s i)
lose : Claims.Move W
^1104 A request or answer is lost (move)
Does: The network loses the i-th packet, before or after the server handled it; the table hears lost (a write) or readFailed (a read).
Sees: A lost write puts its key in doubt and sends a read; the server is unchanged.
apply (s : W) (i : Nat) : W
What ^1104 does on press.
post (s : W) (i : Nat) (s' : W) : Prop
What must follow ^1104 A request or answer is lost on press: A lost write puts its key in doubt and sends a read; the server is unchanged.
Key k's backoff timer fires.
SeesA key waiting after a failed read sends the next read; the server is unchanged.
Formal statementpress.post s k s' := s'.srv = s.srv
- proved
- 1 theorem (sound press), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean). - not seen
- No capture ran.
lean/Cairn/Optimistic/Claims.lean:131 · retry · ledger: active
6 generated declarations
sound (s : W) (k : Nat) : post s k (apply s k)
retry : Claims.Move W
^1105 A retry comes due (move)
Does: Key k's backoff timer fires.
Sees: A key waiting after a failed read sends the next read; the server is unchanged.
info : ClaimInfo
The human half of claim ^1105.
post (s : W) (k : Nat) (s' : W) : Prop
What must follow ^1105 A retry comes due on press: A key waiting after a failed read sends the next read; the server is unchanged.
apply (s : W) (k : Nat) : W
What ^1105 does on press.
preserves (P : W → Prop) (press : ∀ (s : W) (k : Nat), P s → P (press.apply s k)) : retry.Preserves P
To show every handler of ^1105 keeps a property, show it in the move's own terms.
The app fetches a view of key k: what the server holds now, delivered whenever (^1103).
SeesNothing changes until the view arrives.
Formal statementpress.post s k s' := s'.table = s.table
- proved
- 1 theorem (sound press), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean). - not seen
- No capture ran.
lean/Cairn/Optimistic/Claims.lean:139 · look · ledger: active
6 generated declarations
post (s : W) (k : Nat) (s' : W) : Prop
What must follow ^1106 A view is fetched on press: Nothing changes until the view arrives.
info : ClaimInfo
The human half of claim ^1106.
sound (s : W) (k : Nat) : post s k (apply s k)
preserves (P : W → Prop) (press : ∀ (s : W) (k : Nat), P s → P (press.apply s k)) : look.Preserves P
To show every handler of ^1106 keeps a property, show it in the move's own terms.
apply (s : W) (k : Nat) : W
What ^1106 does on press.
look : Claims.Move W
Whatever is in flight or in doubt, setting a key to f of what it shows makes it show exactly that in the same step: what is shown is want, and a set changes want at once.
Formal statementholds s := ∀ (k : Nat) (f : Bool → Bool), (s.table.feed (Input.set k f)).fst.shown k = f (s.table.shown k)
- proved
- 5 theorems (init, step, receive, reachable, reachableAll), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean).
lean/Cairn/Optimistic/Claims.lean:181 · setShows · ledger: active
8 generated declarations
info : ClaimInfo
The human half of claim ^1107.
receive (s✝ : Claims.StateOf machine) (m✝ : Msg) : holds s✝ → holds (machine.receive s✝ m✝).fst
Every message from the world preserves ^1107.
init : holds machine.init
^1107 holds in the initial state.
step (s✝ : Claims.StateOf machine) (a✝ : Action) : holds s✝ → holds (machine.update s✝ a✝).fst
Every update, so every move, preserves ^1107.
holds (s : Claims.StateOf machine) : Prop
^1107 A set shows in its own step: Whatever is in flight or in doubt, setting a key to f of what it shows makes it show exactly that in the same step: what is shown is want, and a set changes want at once.
reachableAll (s✝ : Claims.StateOf machine) : machine.ReachableAll s✝ → holds s✝
^1107 holds in every state reachable by actions and messages from the world.
setShows : Claims.Invariant machine
^1107 A set shows in its own step (invariant)
Whatever is in flight or in doubt, setting a key to f of what it shows makes it show exactly that in the same step: what is shown is want, and a set changes want at once.
reachable (s✝ : Claims.StateOf machine) : machine.Reachable s✝ → holds s✝
^1107 holds in every reachable state.
For every key, at most one write is in the network, before or after the server handled it: a set while one is in flight only changes what is shown.
Formal statementholds s := Good s ∧ ∀ (k : Nat), List.countP Pkt.isWrite (World.at s.net k) ≤ 1- proved
- 5 theorems (init, step, receive, reachable, reachableAll), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean).
lean/Cairn/Optimistic/Claims.lean:187 · oneWrite · ledger: active
8 generated declarations
init : holds machine.init
^1108 holds in the initial state.
oneWrite : Claims.Invariant machine
^1108 At most one write in flight per key (invariant)
For every key, at most one write is in the network, before or after the server handled it: a set while one is in flight only changes what is shown.
reachable (s✝ : Claims.StateOf machine) : machine.Reachable s✝ → holds s✝
^1108 holds in every reachable state.
info : ClaimInfo
The human half of claim ^1108.
reachableAll (s✝ : Claims.StateOf machine) : machine.ReachableAll s✝ → holds s✝
^1108 holds in every state reachable by actions and messages from the world.
holds (s : Claims.StateOf machine) : Prop
^1108 At most one write in flight per key: For every key, at most one write is in the network, before or after the server handled it: a set while one is in flight only changes what is shown.
step (s✝ : Claims.StateOf machine) (a✝ : Action) : holds s✝ → holds (machine.update s✝ a✝).fst
Every update, so every move, preserves ^1108.
receive (s✝ : Claims.StateOf machine) (m✝ : Msg) : holds s✝ → holds (machine.receive s✝ m✝).fst
Every message from the world preserves ^1108.
For every key, the writes the table has sent never outnumber the person's sets of it, whatever answers came back in whatever order: a lost write is read back, never sent again blind.
Formal statementholds s := Good s ∧ ∀ (k : Nat), List.count k s.writes ≤ List.count k s.sets- proved
- 5 theorems (init, step, receive, reachable, reachableAll), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean).
lean/Cairn/Optimistic/Claims.lean:193 · writesWithinSets · ledger: active
8 generated declarations
holds (s : Claims.StateOf machine) : Prop
^1109 Never more writes than sets: For every key, the writes the table has sent never outnumber the person's sets of it, whatever answers came back in whatever order: a lost write is read back, never sent again blind.
info : ClaimInfo
The human half of claim ^1109.
Cairn.Optimistic.Claims.writesWithinSets.reachableAll
provedlean/Cairn/Optimistic/Claims.lean:193reachableAll (s✝ : Claims.StateOf machine) : machine.ReachableAll s✝ → holds s✝
^1109 holds in every state reachable by actions and messages from the world.
step (s✝ : Claims.StateOf machine) (a✝ : Action) : holds s✝ → holds (machine.update s✝ a✝).fst
Every update, so every move, preserves ^1109.
receive (s✝ : Claims.StateOf machine) (m✝ : Msg) : holds s✝ → holds (machine.receive s✝ m✝).fst
Every message from the world preserves ^1109.
writesWithinSets : Claims.Invariant machine
^1109 Never more writes than sets (invariant)
For every key, the writes the table has sent never outnumber the person's sets of it, whatever answers came back in whatever order: a lost write is read back, never sent again blind.
init : holds machine.init
^1109 holds in the initial state.
Cairn.Optimistic.Claims.writesWithinSets.reachable
provedlean/Cairn/Optimistic/Claims.lean:193reachable (s✝ : Claims.StateOf machine) : machine.Reachable s✝ → holds s✝
^1109 holds in every reachable state.
When a key's write in flight is refused, the key shows the server's last confirmed value in that step, that value is unchanged, and nothing is outstanding for the key.
Formal statementholds s := ∀ (k n : Nat) (why : String) (w : Bool), (s.table.get k).phase = Phase.writing w → n = (s.table.get k).seq → (s.table.feed (Input.refused { key := k, seq := n } why)).fst.shown k = s.table.server k ∧ (s.table.feed (Input.refused { key := k, seq := n } why)).fst.server k = s.table.server k ∧ (s.table.feed (Input.refused { key := k, seq := n } why)).fst.settled k = true
- proved
- 5 theorems (init, step, receive, reachable, reachableAll), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean).
lean/Cairn/Optimistic/Claims.lean:199 · refusalRollsBack · ledger: active
8 generated declarations
info : ClaimInfo
The human half of claim ^1110.
holds (s : Claims.StateOf machine) : Prop
^1110 A refusal rolls back in its step: When a key's write in flight is refused, the key shows the server's last confirmed value in that step, that value is unchanged, and nothing is outstanding for the key.
step (s✝ : Claims.StateOf machine) (a✝ : Action) : holds s✝ → holds (machine.update s✝ a✝).fst
Every update, so every move, preserves ^1110.
receive (s✝ : Claims.StateOf machine) (m✝ : Msg) : holds s✝ → holds (machine.receive s✝ m✝).fst
Every message from the world preserves ^1110.
init : holds machine.init
^1110 holds in the initial state.
Cairn.Optimistic.Claims.refusalRollsBack.reachableAll
provedlean/Cairn/Optimistic/Claims.lean:199reachableAll (s✝ : Claims.StateOf machine) : machine.ReachableAll s✝ → holds s✝
^1110 holds in every state reachable by actions and messages from the world.
refusalRollsBack : Claims.Invariant machine
^1110 A refusal rolls back in its step (invariant)
When a key's write in flight is refused, the key shows the server's last confirmed value in that step, that value is unchanged, and nothing is outstanding for the key.
Cairn.Optimistic.Claims.refusalRollsBack.reachable
provedlean/Cairn/Optimistic/Claims.lean:199reachable (s✝ : Claims.StateOf machine) : machine.Reachable s✝ → holds s✝
^1110 holds in every reachable state.
Against a server that is a register per key with idempotent writes, for any sequence of sets and any interleaving of replies (each acknowledged, refused, or lost before or after the server applied it, delivered in any order, with views fetched at any time), every key with nothing in flight and nothing in doubt shows what the server holds. So once every reply is in, every key does.
Formal statementholds s := Good s ∧ ∀ (k : Nat), s.table.settled k = true → s.table.shown k = World.reg s k
- proved
- 5 theorems (init, step, receive, reachable, reachableAll), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean).
lean/Cairn/Optimistic/Claims.lean:209 · converges · ledger: active
8 generated declarations
step (s✝ : Claims.StateOf machine) (a✝ : Action) : holds s✝ → holds (machine.update s✝ a✝).fst
Every update, so every move, preserves ^1111.
receive (s✝ : Claims.StateOf machine) (m✝ : Msg) : holds s✝ → holds (machine.receive s✝ m✝).fst
Every message from the world preserves ^1111.
init : holds machine.init
^1111 holds in the initial state.
reachable (s✝ : Claims.StateOf machine) : machine.Reachable s✝ → holds s✝
^1111 holds in every reachable state.
info : ClaimInfo
The human half of claim ^1111.
reachableAll (s✝ : Claims.StateOf machine) : machine.ReachableAll s✝ → holds s✝
^1111 holds in every state reachable by actions and messages from the world.
converges : Claims.Invariant machine
^1111 Settled keys show what the server holds (invariant)
Against a server that is a register per key with idempotent writes, for any sequence of sets and any interleaving of replies (each acknowledged, refused, or lost before or after the server applied it, delivered in any order, with views fetched at any time), every key with nothing in flight and nothing in doubt shows what the server holds. So once every reply is in, every key does.
holds (s : Claims.StateOf machine) : Prop
^1111 Settled keys show what the server holds: Against a server that is a register per key with idempotent writes, for any sequence of sets and any interleaving of replies (each acknowledged, refused, or lost before or after the server applied it, delivered in any order, with views fetched at any time), every key with nothing in flight and nothing in doubt shows what the server holds. So once every reply is in, every key does.
Two inputs about different keys, in either order, leave the table the same at every key, and each gives the outputs it gives alone, so the two orders' outputs are the same two lists swapped.
Formal statementholds s := ∀ (i j : Input Nat Bool), i.key ≠ j.key → (∀ (k : Nat), ((s.table.feed i).fst.feed j).fst.get k = ((s.table.feed j).fst.feed i).fst.get k) ∧ ((s.table.feed i).fst.feed j).snd = (s.table.feed j).snd ∧ ((s.table.feed j).fst.feed i).snd = (s.table.feed i).snd
- proved
- 5 theorems (init, step, receive, reachable, reachableAll), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean).
lean/Cairn/Optimistic/Claims.lean:215 · commute · ledger: active
8 generated declarations
commute : Claims.Invariant machine
^1112 Replies for different keys commute (invariant)
Two inputs about different keys, in either order, leave the table the same at every key, and each gives the outputs it gives alone, so the two orders' outputs are the same two lists swapped.
info : ClaimInfo
The human half of claim ^1112.
init : holds machine.init
^1112 holds in the initial state.
reachable (s✝ : Claims.StateOf machine) : machine.Reachable s✝ → holds s✝
^1112 holds in every reachable state.
holds (s : Claims.StateOf machine) : Prop
^1112 Replies for different keys commute: Two inputs about different keys, in either order, leave the table the same at every key, and each gives the outputs it gives alone, so the two orders' outputs are the same two lists swapped.
step (s✝ : Claims.StateOf machine) (a✝ : Action) : holds s✝ → holds (machine.update s✝ a✝).fst
Every update, so every move, preserves ^1112.
reachableAll (s✝ : Claims.StateOf machine) : machine.ReachableAll s✝ → holds s✝
^1112 holds in every state reachable by actions and messages from the world.
receive (s✝ : Claims.StateOf machine) (m✝ : Msg) : holds s✝ → holds (machine.receive s✝ m✝).fst
Every message from the world preserves ^1112.
For a view whose count is other people's o plus the person's own [v], a settled key shows o + [what the server holds]: exactly the server's count when no one else acted since the view. The count shown, c − [v] + [shown], is never below zero, and never below the person's own [shown].
Formal statementholds s := Good s ∧ ∀ (k o : Nat) (v : Bool), s.table.settled k = true → count (o + ind v) v (s.table.shown k) = o + ind (World.reg s k) ∧ ind (s.table.shown k) ≤ count (o + ind v) v (s.table.shown k)
- proved
- 5 theorems (init, step, receive, reachable, reachableAll), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean).
lean/Cairn/Optimistic/Claims.lean:224 · counts · ledger: active
8 generated declarations
info : ClaimInfo
The human half of claim ^1113.
receive (s✝ : Claims.StateOf machine) (m✝ : Msg) : holds s✝ → holds (machine.receive s✝ m✝).fst
Every message from the world preserves ^1113.
init : holds machine.init
^1113 holds in the initial state.
reachable (s✝ : Claims.StateOf machine) : machine.Reachable s✝ → holds s✝
^1113 holds in every reachable state.
step (s✝ : Claims.StateOf machine) (a✝ : Action) : holds s✝ → holds (machine.update s✝ a✝).fst
Every update, so every move, preserves ^1113.
counts : Claims.Invariant machine
^1113 A settled count is the server's (invariant)
For a view whose count is other people's o plus the person's own [v], a settled key shows o + [what the server holds]: exactly the server's count when no one else acted since the view. The count shown, c − [v] + [shown], is never below zero, and never below the person's own [shown].
holds (s : Claims.StateOf machine) : Prop
^1113 A settled count is the server's: For a view whose count is other people's o plus the person's own [v], a settled key shows o + [what the server holds]: exactly the server's count when no one else acted since the view. The count shown, c − [v] + [shown], is never below zero, and never below the person's own [shown].
reachableAll (s✝ : Claims.StateOf machine) : machine.ReachableAll s✝ → holds s✝
^1113 holds in every state reachable by actions and messages from the world.
A value in a view the app fetched, which may be stale (fetched before a write, or from a server that hasn't indexed it yet), never changes what a key written this session shows, or its confirmed value.
Formal statementholds s := ∀ (k : Nat) (v : Bool), s.table.written k = true → (s.table.feed (Input.seen k v)).fst.shown k = s.table.shown k ∧ (s.table.feed (Input.seen k v)).fst.server k = s.table.server k
- proved
- 5 theorems (init, step, receive, reachable, reachableAll), standard axioms only.
- not fuzzed
- No
build/fuzz/Cairn.json: runcairn fuzz. - not tested
- Cairn has no conformance generator yet (
tools/conformance/lean/Conformance/Apps/Cairn.lean).
lean/Cairn/Optimistic/Claims.lean:233 · viewKeepsWritten · ledger: active
8 generated declarations
step (s✝ : Claims.StateOf machine) (a✝ : Action) : holds s✝ → holds (machine.update s✝ a✝).fst
Every update, so every move, preserves ^1114.
Cairn.Optimistic.Claims.viewKeepsWritten.reachable
provedlean/Cairn/Optimistic/Claims.lean:233reachable (s✝ : Claims.StateOf machine) : machine.Reachable s✝ → holds s✝
^1114 holds in every reachable state.
Cairn.Optimistic.Claims.viewKeepsWritten.reachableAll
provedlean/Cairn/Optimistic/Claims.lean:233reachableAll (s✝ : Claims.StateOf machine) : machine.ReachableAll s✝ → holds s✝
^1114 holds in every state reachable by actions and messages from the world.
info : ClaimInfo
The human half of claim ^1114.
holds (s : Claims.StateOf machine) : Prop
^1114 A view never moves a written key: A value in a view the app fetched, which may be stale (fetched before a write, or from a server that hasn't indexed it yet), never changes what a key written this session shows, or its confirmed value.
init : holds machine.init
^1114 holds in the initial state.
viewKeepsWritten : Claims.Invariant machine
^1114 A view never moves a written key (invariant)
A value in a view the app fetched, which may be stale (fetched before a write, or from a server that hasn't indexed it yet), never changes what a key written this session shows, or its confirmed value.
receive (s✝ : Claims.StateOf machine) (m✝ : Msg) : holds s✝ → holds (machine.receive s✝ m✝).fst
Every message from the world preserves ^1114.
Definitions 6
W : Type
The harness's world: keys are numbers, values booleans.
pick (s : W) (i : Nat) : Option (Nat × Pkt Bool)
The packet the i-th place in the network holds, if any.
onPkt (s : W) (i : Nat) (f : W → Nat → Pkt Bool → W) : W
Act on the i-th packet, if there is one.
machine : Claims.Machine W
Good (s : W) : Prop
The server model's invariant, with same the harness's equality.
claimInfos : List ClaimInfo
Theorems 10
onPkt_ok {s : W} (h : World.Ok s) (i : Nat)
{f : W → Nat → Pkt Bool → W} (hf : ∀ (k : Nat) (p : Pkt Bool), World.Ok (f s k p)) :
World.Ok (onPkt s i f)
onPkt_eq {s : W} (i : Nat) {f : W → Nat → Pkt Bool → W}
{P : W → Prop} (hf : ∀ (k : Nat) (p : Pkt Bool), P (f s k p)) (hs : P s) : P (onPkt s i f)
serve_table (s : W) (k : Nat) (p : Pkt Bool) : (World.serve s k p).table = s.table
refuse_table (s : W) (k : Nat) (p : Pkt Bool) : (World.refuse s k p).table = s.table ∧ (World.refuse s k p).srv = s.srv
deliver_srv (s : W) (k : Nat) (p : Pkt Bool) : (World.deliver s k p).srv = s.srv
lose_srv (s : W) (k : Nat) (p : Pkt Bool) : (World.lose s k p).srv = s.srv
init_good : Good machine.init
onPkt_good {s : W} (h : Good s) (i : Nat)
{f : W → Nat → Pkt Bool → W} (hf : ∀ (k : Nat) (p : Pkt Bool), World.Ok (f s k p))
(hs : ∀ (k : Nat) (p : Pkt Bool), (f s k p).table.same = s.table.same) :
Good (onPkt s i f)
update_good (s : W) (a : Action) : Good s → Good (machine.update s a).fst
Every move keeps Good.
converges {s : W} (h : Good s) (k : Nat)
(hk : s.table.settled k = true) : s.table.shown k = World.reg s k