Documentation

CslibFrontier.Computability.Distributed.BenOr.Basic

Quorum-phase model and deterministic safety for Ben-Or's binary consensus #

Fischer, Lynch, and Paterson (Cslib.FLP.Consensus.ge_one_not_exists) proved that no deterministic asynchronous consensus protocol can tolerate even a single crash fault on two or more processes. Ben-Or ([BO83], §3, Protocol A, printed p. 28) introduced a two-stage binary consensus protocol for 2 * t < Fintype.card P using quorums of size n - t (n = Fintype.card P) and a Stage-2 coin flip when no concrete proposal arrives.

This module formalizes quorum-phase deterministic safety after [BO83], §3, Protocol A (printed p. 28; compare Theorem 1(ii)–(iii) on printed p. 29): it defines the two-stage phase transition over per-recipient n - t quorums (PhaseSchedule.Valid), connects quorum-phase runs to phased dynamic mid-stage crashes (CrashSchedule.Valid, crashRun), proves that deterministic safety (Stage-1 proposal uniqueness, 1-phase unanimous validity without coin use, single-phase estimate lock-in, cross-phase uniform agreement, and input integrity) holds unconditionally for every coin sequence, and exhibits an explicit non-terminating execution on Fin 3, t = 1 for every static deterministic coin fallback.

Model scope (#7120): PhaseSchedule and CrashSchedule group execution by synchronous phase boundaries over n - t Stage-1/Stage-2 sender sets, rather than modeling the primitive message-buffer and arbitrary cross-round step-interleaving scheduler of [BO83], §2 (printed pp. 27–28). Companion module CslibFrontier.Computability.Distributed.BenOr.Liveness proves a pre-coin phase-scheduler termination step (probRun) toward Theorem 1(i) of [BO83] (and for a separate common-coin variant), while termination against full §2 asynchronous schedulers remains open in #7120.

Quorum-phase abstraction and non-halting write-once decisions #

In [BO83], §3, Protocol A (printed p. 28), messages carry their round number r and stage tag ((1, r, x_P) in step 1; (2, r, v, D) or (2, r, ?) in step 2), and each process waits for n - t messages of the matching (stage, r) tag before advancing. Here a single phase is modeled by a per-recipient quorum pair PhaseSchedule P (q1, q2 : P → Finset P) satisfying PhaseSchedule.Valid t (n - t ≤ (q1 p).card and n - t ≤ (q2 p).card).

Each process maintains ProcState (est : Bool, write-once decided : Option Bool, matching §2 printed p. 27) and continues executing subsequent phases after deciding (step 4 of Protocol A, printed p. 28) so slower processes still collect n - t messages. CrashSchedule and crashRun_eq_run verify that phased mid-stage crashes—where processes in crashed1 r ⊆ crashed2 r stop sending and freeze their local states—coincide on all surviving processes with run on a valid PhaseSchedule, giving uniform agreement even across processes that crash immediately after deciding (crashRun_agreement).

In each phase r on state st : P → ProcState with n = Fintype.card P (matching steps 1–3 of Protocol A, [BO83], §3, printed p. 28, with 0-indexed r : ℕ):

  1. Stage 1 (stage1Proposal, Protocol A steps 1–2): process j collects reports from q1 j. If strictly more than n / 2 (majorityThreshold n = n / 2 + 1) senders in q1 j reported b, j proposes some b ((2, r, b, D)); otherwise j proposes none ((2, r, ?)).
  2. Stage 2 (stage2Update, Protocol A step 3): process p collects Stage-2 proposals from q2 p.
    • Adopt (step 3(a)): if at least 1 sender in q2 p proposed some b, set next estimate est := b; otherwise (step 3(c): all proposals in q2 p are none) set est := coins r p.
    • Decide (step 3(b)): if decided = none and strictly more than t (t + 1) senders in q2 p proposed some b, set decided := some b.

Main definitions #

Main results #

References #

Process states and asynchronous phase schedules #

Local state of a process at a phase boundary in Ben-Or's binary consensus protocol.

  • est : Bool

    Current binary estimate carried into the next phase.

  • decided : Option Bool

    Write-once decision register (some b once decided, none otherwise).

theorem Cslib.Distributed.BenOr.ProcState.ext {x y : ProcState} (est : x.est = y.est) (decided : x.decided = y.decided) :
x = y
def Cslib.Distributed.BenOr.initState {P : Type u_1} (inp : P → Bool) (p : P) :

Initial process states for input assignment inp : P → Bool.

@[simp]
theorem Cslib.Distributed.BenOr.initState_est {P : Type u_1} (inp : P → Bool) (p : P) :
(initState inp p).est = inp p

Initial estimate of process p equals its input inp p.

@[simp]
theorem Cslib.Distributed.BenOr.initState_decided {P : Type u_1} (inp : P → Bool) (p : P) :

Initial decision register of process p is none.

Per-recipient quorum schedule for one two-stage phase of Ben-Or's protocol. In Stage 1, process p receives reports from q1 p; in Stage 2, p receives proposals from q2 p. Allowing distinct sender sets per recipient captures recipient-varying quorum delivery within a phase boundary.

  • q1 : P → Finset P

    Senders whose Stage-1 (report) messages arrive at process p before p advances.

  • q2 : P → Finset P

    Senders whose Stage-2 (propose) messages arrive at process p before p advances.

theorem Cslib.Distributed.BenOr.PhaseSchedule.ext {P : Type u_1} {x y : PhaseSchedule P} (q1 : x.q1 = y.q1) (q2 : x.q2 = y.q2) :
x = y

A phase schedule is valid for fault bound t if every process receives Stage-1 and Stage-2 messages from at least |P| - t distinct senders.

theorem Cslib.Distributed.BenOr.PhaseSchedule.Valid.mono {P : Type u_1} [Fintype P] {sched : PhaseSchedule P} {t t' : ℕ} (h : sched.Valid t) (ht : t ≤ t') :
sched.Valid t'

A schedule valid for fault threshold t is valid for any larger threshold t' ≥ t.

Static quorum schedule in which every process hears from all non-faulty processes univ \ F.

Whenever at most t processes are faulty, honestQuorum F is a valid n - t schedule.

Threshold arithmetic #

Strict majority threshold ⌊n / 2⌋ + 1.

Stage 1 (report) and proposal uniqueness #

def Cslib.Distributed.BenOr.reportCount {P : Type u_1} (st : P → ProcState) (S : Finset P) (b : Bool) :

Number of senders in S whose current estimate equals b.

Stage-1 proposal computed from received reports in S: propose some b if at least majorityThreshold |P| senders in S reported b, and none otherwise.

@[simp]

Symmetric characterization of when stage1Proposal emits some b.

Symmetric characterization of when stage1Proposal emits none.

theorem Cslib.Distributed.BenOr.stage1Proposal_unique {P : Type u_1} [Fintype P] (st : P → ProcState) (S₁ S₂ : Finset P) {b₁ b₂ : Bool} (h₁ : stage1Proposal st S₁ = some b₁) (h₂ : stage1Proposal st S₂ = some b₂) :
b₁ = b₂

Stage-1 proposal uniqueness: across the entire network, no two Stage-1 quorums S₁ and S₂ can produce conflicting some proposals from the same state st, because two strict majorities cannot be disjoint in P.

Stage 2 (propose) and phase execution #

def Cslib.Distributed.BenOr.proposalCount {P : Type u_1} (prop : P → Option Bool) (S : Finset P) (b : Bool) :

Number of senders in S whose Stage-2 proposal equals some b.

def Cslib.Distributed.BenOr.stage2Update {P : Type u_1} (t : ℕ) (prop : P → Option Bool) (S : Finset P) (coin : Bool) (cur : ProcState) :

Stage-2 local state transition for a process in state cur receiving Stage-2 proposals from senders S with coin bit coin under fault threshold t.

def Cslib.Distributed.BenOr.phaseStep {P : Type u_1} [Fintype P] (t : ℕ) (sched : PhaseSchedule P) (coins : P → Bool) (st : P → ProcState) (p : P) :

Execute one two-stage phase of Ben-Or's protocol on global state st under quorum-phase schedule sched and coin assignment coins.

def Cslib.Distributed.BenOr.run {P : Type u_1} [Fintype P] (t : ℕ) (sched : ℕ → PhaseSchedule P) (coins : ℕ → P → Bool) (inp : P → Bool) :
ℕ → P → ProcState

Execute r phases of Ben-Or's protocol from initial inputs inp under schedule sequence sched and coin sequence coins.

def Cslib.Distributed.BenOr.adaptiveRun {P : Type u_1} [Fintype P] (t : ℕ) (strat : ℕ → (P → ProcState) → PhaseSchedule P) (coins : ℕ → P → Bool) (inp : P → Bool) :
ℕ → P → ProcState

Execute r phases against an adaptive state-based scheduler strat that inspects the global state at the start of each phase before choosing that phase's quorums.

theorem Cslib.Distributed.BenOr.adaptiveRun_eq_run {P : Type u_1} [Fintype P] (t : ℕ) (strat : ℕ → (P → ProcState) → PhaseSchedule P) (coins : ℕ → P → Bool) (inp : P → Bool) (r : ℕ) :
adaptiveRun t strat coins inp r = run t (fun (k : ℕ) => strat k (adaptiveRun t strat coins inp k)) coins inp r

An adaptive scheduler produces the same trace as the fixed schedule sequence of quorums it chooses along the run.

Every process currently carries the same binary estimate.

Every process has decided, and all decided values coincide.

Lucky coin, unanimous progress, lock-in, and deterministic safety #

theorem Cslib.Distributed.BenOr.phaseStep_lucky_coin {P : Type u_1} [Fintype P] (t : ℕ) (sched : PhaseSchedule P) (st : P → ProcState) :
∃ (b : Bool), ∀ (p : P), (phaseStep t sched (fun (x : P) => b) st p).est = b

Lucky-coin alignment: for any state st and schedule sched (even without quorum size bounds), there exists a bit b : Bool such that if every process's coin in this phase equals b, every process ends the phase with estimate b.

theorem Cslib.Distributed.BenOr.phaseStep_of_est_eq {P : Type u_1} [Fintype P] {t : ℕ} {sched : PhaseSchedule P} (ht : 2 * t < Fintype.card P) (hv : sched.Valid t) (coins : P → Bool) {st : P → ProcState} {b : Bool} (hest : ∀ (p : P), (st p).est = b) (p : P) :
(phaseStep t sched coins st p).est = b ∧ ((st p).decided = none → (phaseStep t sched coins st p).decided = some b)

From any state where all processes hold estimate b, one valid phase preserves estimate b on every process and sets every undecided process's decision register to some b, independent of coins.

theorem Cslib.Distributed.BenOr.IsUnanimous.phaseStep {P : Type u_1} [Fintype P] {t : ℕ} {sched : PhaseSchedule P} {st : P → ProcState} (hu : IsUnanimous st) (ht : 2 * t < Fintype.card P) (hv : sched.Valid t) (coins : P → Bool) :
IsUnanimous (BenOr.phaseStep t sched coins st)

IsUnanimous is preserved across any valid phase under arbitrary coins.

theorem Cslib.Distributed.BenOr.phaseStep_lock_in {P : Type u_1} [Fintype P] {t : ℕ} {sched : PhaseSchedule P} (ht : 2 * t < Fintype.card P) (hv : sched.Valid t) {coins : P → Bool} {st : P → ProcState} {p : P} {b : Bool} (hnone : (st p).decided = none) (hdec : (phaseStep t sched coins st p).decided = some b) (q : P) :
(phaseStep t sched coins st q).est = b

Single-phase lock-in: if process p newly decides b in Stage 2 of a valid phase (when 2 * t < |P|), then every process q adopts next estimate b in that phase, regardless of coins.

theorem Cslib.Distributed.BenOr.run_decided_stable {P : Type u_1} [Fintype P] {t : ℕ} {sched : ℕ → PhaseSchedule P} {coins : ℕ → P → Bool} {inp : P → Bool} {r₁ r₂ : ℕ} (hr : r₁ ≤ r₂) {p : P} {b : Bool} (hd : (run t sched coins inp r₁ p).decided = some b) :
(run t sched coins inp r₂ p).decided = some b

Write-once monotonicity of decided across any number of phases.

Lock invariant: whenever any process has decided b, every process carries estimate b. Preserved across all valid phases once 2 * t < |P|.

EstimateLocked holds vacuously in the initial state before any process has decided.

theorem Cslib.Distributed.BenOr.EstimateLocked.phaseStep {P : Type u_1} [Fintype P] {t : ℕ} {sched : PhaseSchedule P} {st : P → ProcState} (hinv : EstimateLocked st) (ht : 2 * t < Fintype.card P) (hv : sched.Valid t) (coins : P → Bool) :
EstimateLocked (BenOr.phaseStep t sched coins st)

EstimateLocked is preserved across any valid phase when 2 * t < |P|.

theorem Cslib.Distributed.BenOr.phaseStep_allDecided_of_est_eq {P : Type u_1} [Fintype P] {t : ℕ} {sched : PhaseSchedule P} (ht : 2 * t < Fintype.card P) (hv : sched.Valid t) (coins : P → Bool) {st : P → ProcState} (hlock : EstimateLocked st) {b : Bool} (hest : ∀ (p : P), (st p).est = b) (p : P) :
(phaseStep t sched coins st p).decided = some b

When EstimateLocked st holds and all processes share estimate b, one valid phase leaves every process with decided = some b.

theorem Cslib.Distributed.BenOr.run_validity {P : Type u_1} [Fintype P] {t : ℕ} {sched : ℕ → PhaseSchedule P} (ht : 2 * t < Fintype.card P) (hv₀ : (sched 0).Valid t) (coins : ℕ → P → Bool) {inp : P → Bool} {b : Bool} (hinp : ∀ (p : P), inp p = b) (p : P) :
(run t sched coins inp 1 p).decided = some b

Quorum-phase unanimous validity (quorum-phase counterpart of Theorem 1(ii), [BO83], §3, printed p. 29): if all processes start with input b, every process decides b after phase 0 (r = 1), without depending on any coin value.

theorem Cslib.Distributed.BenOr.run_decide_next_phase {P : Type u_1} [Fintype P] {t : ℕ} {sched : ℕ → PhaseSchedule P} (ht : 2 * t < Fintype.card P) {r : ℕ} (hv : ∀ k ≤ r, (sched k).Valid t) {coins : ℕ → P → Bool} {inp : P → Bool} {p : P} {b : Bool} (hd : (run t sched coins inp r p).decided = some b) (q : P) :
(run t sched coins inp (r + 1) q).decided = some b

Quorum-phase next-phase global decision (quorum-phase counterpart of Theorem 1(iii), [BO83], §3, printed p. 29): once any process p has decided b by phase r, every process q has decided b by phase r + 1.

theorem Cslib.Distributed.BenOr.run_agreement {P : Type u_1} [Fintype P] {t : ℕ} {sched : ℕ → PhaseSchedule P} (ht : 2 * t < Fintype.card P) {r₁ r₂ : ℕ} (hv : ∀ k < max r₁ r₂, (sched k).Valid t) {coins : ℕ → P → Bool} {inp : P → Bool} {p₁ p₂ : P} {b₁ b₂ : Bool} (hd₁ : (run t sched coins inp r₁ p₁).decided = some b₁) (hd₂ : (run t sched coins inp r₂ p₂).decided = some b₂) :
b₁ = b₂

Cross-phase agreement: in any valid execution with 2 * t < |P| and arbitrary coins, no two processes ever decide different values, whether in the same phase or in different phases.

theorem Cslib.Distributed.BenOr.run_exists_inp_eq_of_decided {P : Type u_1} [Fintype P] {t : ℕ} {sched : ℕ → PhaseSchedule P} (ht : 2 * t < Fintype.card P) {r : ℕ} (hv : ∀ k < r, (sched k).Valid t) {coins : ℕ → P → Bool} {inp : P → Bool} {p : P} {b : Bool} (hd : (run t sched coins inp r p).decided = some b) :
∃ (q : P), inp q = b

Input integrity (strong binary validity): whenever any process decides b in any phase, at least one process started with initial input b.

Dynamic mid-stage crash simulation and uniform agreement #

Phased schedule with cumulative mid-stage crashes: crashed1 r is the set of processes that have crashed before completing Stage 1 of phase r, and crashed2 r is the set of processes that have crashed before completing Stage 2 of phase r. Crashed processes stop sending in subsequent stages and freeze their local state.

  • crashed1 : ℕ → Finset P

    Cumulative processes crashed prior to completing Stage 1 of phase r.

  • crashed2 : ℕ → Finset P

    Cumulative processes crashed prior to completing Stage 2 of phase r.

  • q1 : ℕ → P → Finset P

    Stage-1 sender quorums for processes completing Stage 1 of phase r.

  • q2 : ℕ → P → Finset P

    Stage-2 sender quorums for processes completing Stage 2 of phase r.

Validity of a dynamic crash schedule for fault bound t: crashes grow monotonically with at most t crashes in any phase, surviving processes receive at least |P| - t messages per stage, Stage-1 quorums in phase r + 1 exclude processes already crashed in phase r, and Stage-2 quorums exclude processes crashed before completing Stage 1.

  • crashed1_subset (r : ℕ) : cs.crashed1 r ⊆ cs.crashed2 r

    Processes crashed before Stage 1 remain crashed through Stage 2.

  • crashed2_subset (r : ℕ) : cs.crashed2 r ⊆ cs.crashed1 (r + 1)

    Processes crashed in phase r remain crashed in phase r + 1.

  • card_crashed2 (r : ℕ) : (cs.crashed2 r).card ≤ t

    At most t processes crash in total by Stage 2 of any phase.

  • card_q1 (r : ℕ) (p : P) : p ∉ cs.crashed1 r → Fintype.card P - t ≤ (cs.q1 r p).card

    Surviving Stage-1 recipients collect at least |P| - t reports.

  • card_q2 (r : ℕ) (p : P) : p ∉ cs.crashed2 r → Fintype.card P - t ≤ (cs.q2 r p).card

    Surviving Stage-2 recipients collect at least |P| - t proposals.

  • disjoint_q1 (r : ℕ) (p : P) : p ∉ cs.crashed1 (r + 1) → Disjoint (cs.q1 (r + 1) p) (cs.crashed2 r)

    Stage-1 quorums in phase r + 1 exclude senders that crashed in phase r.

  • disjoint_q2 (r : ℕ) (p : P) : p ∉ cs.crashed2 r → Disjoint (cs.q2 r p) (cs.crashed1 r)

    Stage-2 quorums exclude senders that crashed before completing Stage 1.

def Cslib.Distributed.BenOr.crashStep {P : Type u_1} [Fintype P] [DecidableEq P] (t : ℕ) (crashed1 crashed2 : Finset P) (q1 q2 : P → Finset P) (coins : P → Bool) (st : P → ProcState) (p : P) :

One phase of Ben-Or's protocol with mid-stage crashes: processes in crashed1 emit no Stage-2 proposal, and processes in crashed2 freeze their local state (including any prior decision).

def Cslib.Distributed.BenOr.crashRun {P : Type u_1} [Fintype P] [DecidableEq P] (t : ℕ) (cs : CrashSchedule P) (coins : ℕ → P → Bool) (inp : P → Bool) :
ℕ → P → ProcState

Execute r phases under a dynamic mid-stage crash schedule cs.

Total PhaseSchedule sequence extending cs by assigning the surviving set univ \ crashed2 r as a dummy quorum for already-crashed processes (whose states no surviving recipient ever reads).

Extending a valid dynamic crash schedule via toSchedule yields a valid PhaseSchedule in every phase.

theorem Cslib.Distributed.BenOr.crashRun_eq_run {P : Type u_1} [Fintype P] [DecidableEq P] {t : ℕ} {cs : CrashSchedule P} (hv : cs.Valid t) (coins : ℕ → P → Bool) (inp : P → Bool) :
(∀ (p : P), crashRun t cs coins inp 0 p = run t cs.toSchedule coins inp 0 p) ∧ ∀ (r : ℕ), ∀ p ∉ cs.crashed2 r, crashRun t cs coins inp (r + 1) p = run t cs.toSchedule coins inp (r + 1) p

Dynamic crash simulation: at phase 0 on all processes, and after phase r + 1 on every process p ∉ cs.crashed2 r, crashRun coincides identically with run on cs.toSchedule.

theorem Cslib.Distributed.BenOr.crashRun_agreement {P : Type u_1} [Fintype P] [DecidableEq P] {t : ℕ} {cs : CrashSchedule P} (ht : 2 * t < Fintype.card P) (hv : cs.Valid t) {coins : ℕ → P → Bool} {inp : P → Bool} {r₁ r₂ : ℕ} {p₁ p₂ : P} {b₁ b₂ : Bool} (hd₁ : (crashRun t cs coins inp r₁ p₁).decided = some b₁) (hd₂ : (crashRun t cs coins inp r₂ p₂).decided = some b₂) :
b₁ = b₂

Uniform agreement under dynamic crashes: even if a process decides in some phase and immediately crashes afterward, its decision agrees with the decision of every other process across all phases.

Non-termination under deterministic static coin fallbacks (Fin 3, t = 1) #

theorem Cslib.Distributed.BenOr.exists_nonterminating_of_fixed_coin (fallback : Fin 3 → Bool) :
∃ (inp : Fin 3 → Bool) (sched : PhaseSchedule (Fin 3)), sched.Valid 1 ∧ ∀ (r : ℕ) (p : Fin 3), (run 1 (fun (x : ℕ) => sched) (fun (x : ℕ) => fallback) inp r p).decided = none

Necessity of fresh randomization (Fin 3, t = 1): for every static deterministic coin fallback fallback : Fin 3 → Bool, there exist an input assignment inp and a valid crash-free quorum-phase schedule sched (sched.Valid 1) such that no process ever decides in any phase r : ℕ.