Documentation

CslibFrontier.Computability.Distributed.ByzantineQuorum.PBFT

Practical Byzantine Fault Tolerance: Normal-Case and View-Change Multi-Slot SMR Step #

This module formalizes an ideal-authentication, checkpoint-free intermediate step toward the Practical Byzantine Fault Tolerance (PBFT) state-machine replication protocol of Castro and Liskov (§§4.2, 4.4, 4.5, pp. 3–7; extended journal version [CL02]), and not the full cryptographic, garbage-collected protocol of those papers, as part of #7506 (#3261).

Model scope and explicit abstractions #

Over a finite replica universe P, static Byzantine fault set F : Finset P (F.card ≤ f), view numbers v : ℕ with primary schedule primary : ℕ → P, sequence slots s : ℕ, and request values V (Option V carries some val for client requests and none for PBFT's null no-op request of §4.4, p. 6):

Main definitions #

Main results #

References #

Quorum size, certificates, and authenticated PBFT messages #

Byzantine quorum certificate size |P| - f (which equals 2 * f + 1 when |P| = 3 * f + 1 and satisfies dissemination intersection for every 3 * f < |P|).

A (view, slot, val) protocol entry stored in a replica's accepted or committed log, where val : Option V represents either a client request some r or PBFT's null no-op none.

  • view : ℕ

    View number in which val was proposed or committed.

  • slot : ℕ

    Sequence number (slot) in the replicated log.

  • val : Option V

    Client request (some r) or null no-op (none).

theorem Cslib.Distributed.ByzantineQuorum.SlotEntry.ext {V : Type u_1} {x y : SlotEntry V} (view : x.view = y.view) (slot : x.slot = y.slot) (val : x.val = y.val) :
x = y
structure Cslib.Distributed.ByzantineQuorum.PreparedCert (P : Type u_1) (V : Type u_2) :
Type (max u_1 u_2)

A PBFT prepared certificate (P_m in [CL99], §§4.2, 4.4, pp. 4, 6) witnessing that primary view pre-prepared (view, slot, val) and the backup replicas in prepares sent matching Prepare messages.

  • view : ℕ

    View in which (slot, val) prepared.

  • slot : ℕ

    Sequence slot prepared in view.

  • val : Option V

    Prepared slot value (some r or none for null).

  • prepares : Finset P

    Backup replicas (≠ primary view) contributing matching Prepare messages.

theorem Cslib.Distributed.ByzantineQuorum.PreparedCert.ext {P : Type u_1} {V : Type u_2} {x y : PreparedCert P V} (view : x.view = y.view) (slot : x.slot = y.slot) (val : x.val = y.val) (prepares : x.prepares = y.prepares) :
x = y
def Cslib.Distributed.ByzantineQuorum.instDecidableEqPreparedCert.decEq {P✝ : Type u_1} {V✝ : Type u_2} [DecidableEq P✝] [DecidableEq V✝] (x✝ x✝¹ : PreparedCert P✝ V✝) :
Decidable (x✝ = x✝¹)
@[instance_reducible]
def Cslib.Distributed.ByzantineQuorum.PreparedCert.voters {P : Type u_1} {V : Type u_2} [DecidableEq P] (primary : ℕ → P) (c : PreparedCert P V) :

Full replica quorum {primary c.view} ∪ c.prepares vouching for prepared certificate c.

structure Cslib.Distributed.ByzantineQuorum.ViewChangeMsg (P : Type u_1) (V : Type u_2) :
Type (max u_1 u_2)

A VIEW-CHANGE payload sent by sender for target view carrying prepared certificates pset from views < view ([CL99], §4.4, p. 6).

  • view : ℕ

    New view number v' > 0 requested by sender.

  • sender : P

    Replica signing the VIEW-CHANGE message.

  • pset : Finset (PreparedCert P V)

    Set of prepared certificates from earlier views reported by sender.

theorem Cslib.Distributed.ByzantineQuorum.ViewChangeMsg.ext {P : Type u_1} {V : Type u_2} {x y : ViewChangeMsg P V} (view : x.view = y.view) (sender : x.sender = y.sender) (pset : x.pset = y.pset) :
x = y
@[instance_reducible]
def Cslib.Distributed.ByzantineQuorum.instDecidableEqViewChangeMsg.decEq {P✝ : Type u_1} {V✝ : Type u_2} [DecidableEq P✝] [DecidableEq V✝] (x✝ x✝¹ : ViewChangeMsg P✝ V✝) :
Decidable (x✝ = x✝¹)

A slot assignment (slot, val) computed in the O component of a NEW-VIEW message ([CL99], §4.4, p. 6).

  • slot : ℕ

    Sequence slot re-proposed upon entering the new view.

  • val : Option V

    Value from the highest prepared view in Vset, or none (null no-op) if unprepared.

theorem Cslib.Distributed.ByzantineQuorum.SlotProposal.ext {V : Type u_1} {x y : SlotProposal V} (slot : x.slot = y.slot) (val : x.val = y.val) :
x = y
inductive Cslib.Distributed.ByzantineQuorum.PBFTMsg (P : Type u_1) (V : Type u_2) :
Type (max u_1 u_2)

Authenticated wire messages of normal-case and view-change PBFT ([CL99], §§4.2, 4.4, pp. 4–6).

@[instance_reducible]
def Cslib.Distributed.ByzantineQuorum.instDecidableEqPBFTMsg.decEq {P✝ : Type u_1} {V✝ : Type u_2} [DecidableEq P✝] [DecidableEq V✝] (x✝ x✝¹ : PBFTMsg P✝ V✝) :
Decidable (x✝ = x✝¹)
def Cslib.Distributed.ByzantineQuorum.PBFTMsg.signer {P : Type u_1} {V : Type u_2} (primary : ℕ → P) :
PBFTMsg P V → P

Authenticated signer required for a PBFTMsg under primary schedule primary.

Certificate validation and deterministic NEW-VIEW Oset computation #

def Cslib.Distributed.ByzantineQuorum.PreparedCert.ValidIn {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] (primary : ℕ → P) (f : ℕ) (net : Finset (PBFTMsg P V)) (c : PreparedCert P V) :

c is a valid prepared certificate over network log net when primary c.view sent the matching prePrepare, primary c.view ∉ c.prepares, every q ∈ c.prepares sent a matching prepare, and {primary c.view} ∪ c.prepares has size at least pbftQuorumSize P f.

Instances For
    @[instance_reducible]
    instance Cslib.Distributed.ByzantineQuorum.instDecidablePreparedCertValidIn {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] (primary : ℕ → P) (f : ℕ) (net : Finset (PBFTMsg P V)) (c : PreparedCert P V) :
    def Cslib.Distributed.ByzantineQuorum.ViewChangeMsg.ValidIn {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] (primary : ℕ → P) (f : ℕ) (net : Finset (PBFTMsg P V)) (vc : ViewChangeMsg P V) :

    vc is a valid VIEW-CHANGE message on net when 0 < vc.view, PBFTMsg.viewChange vc ∈ net, and every certificate in vc.pset is valid on net with view < vc.view.

    Instances For
      @[instance_reducible]
      instance Cslib.Distributed.ByzantineQuorum.instDecidableViewChangeValidIn {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] (primary : ℕ → P) (f : ℕ) (net : Finset (PBFTMsg P V)) (vc : ViewChangeMsg P V) :
      Decidable (ViewChangeMsg.ValidIn primary f net vc)

      Select the re-proposed slot value for slot s from the union certs of prepared certificates in Vset ([CL99], §4.4, p. 6): returns some none (null no-op) if certs contains no certificate for slot s, some o if all maximum-view certificates for slot s agree on o, and none only if certs contains conflicting certificates at the same maximum view.

      Compute the O set of SlotProposals for NEW-VIEW from vset ([CL99], §4.4, p. 6, with min-s = 0): empty if vset reports no prepared certificates, and otherwise covering every slot 0 ≤ s ≤ max-s via computeSlotVal.

      def Cslib.Distributed.ByzantineQuorum.NewViewValidIn {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] (primary : ℕ → P) (f : ℕ) (net : Finset (PBFTMsg P V)) (v' : ℕ) (vset : Finset (ViewChangeMsg P V)) (oset : Finset (SlotProposal V)) :

      Validity of NEW-VIEW(v', vset, oset) over net ([CL99], §4.4, p. 6): 0 < v', newView and all corresponding prePrepare messages in oset are on net, every vc ∈ vset is a valid VIEW-CHANGE for v', at least pbftQuorumSize P f distinct replicas contributed to vset, and computeOset vset = some oset.

      Instances For
        @[instance_reducible]
        instance Cslib.Distributed.ByzantineQuorum.instDecidableNewViewValidIn {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] (primary : ℕ → P) (f : ℕ) (net : Finset (PBFTMsg P V)) (v' : ℕ) (vset : Finset (ViewChangeMsg P V)) (oset : Finset (SlotProposal V)) :
        Decidable (NewViewValidIn primary f net v' vset oset)

        Ghost-free replica state and asynchronous PBFT transitions #

        structure Cslib.Distributed.ByzantineQuorum.ReplicaState (P : Type u_1) (V : Type u_2) :
        Type (max u_1 u_2)

        Local operational state of a PBFT replica ([CL99], §§4.2, 4.4).

        • view : ℕ

          Current active view (0 initially).

        • inViewChange : Bool

          true while the replica has halted normal-case processing awaiting NEW-VIEW.

        • targetView : ℕ

          Highest view for which this replica has initiated VIEW-CHANGE or entered NEW-VIEW.

        • accepted : Finset (SlotEntry V)

          Accepted (view, slot, val) pre-prepares.

        • preparedCerts : Finset (PreparedCert P V)

          Valid PreparedCerts assembled by this replica across views.

        • committed : Finset (SlotEntry V)

          Locally committed (view, slot, val) entries (committed-local in §4.2, p. 5).

        theorem Cslib.Distributed.ByzantineQuorum.ReplicaState.ext {P : Type u_1} {V : Type u_2} {x y : ReplicaState P V} (view : x.view = y.view) (inViewChange : x.inViewChange = y.inViewChange) (targetView : x.targetView = y.targetView) (accepted : x.accepted = y.accepted) (preparedCerts : x.preparedCerts = y.preparedCerts) (committed : x.committed = y.committed) :
        x = y
        def Cslib.Distributed.ByzantineQuorum.instDecidableEqReplicaState.decEq {P✝ : Type u_1} {V✝ : Type u_2} [DecidableEq P✝] [DecidableEq V✝] (x✝ x✝¹ : ReplicaState P✝ V✝) :
        Decidable (x✝ = x✝¹)
        @[instance_reducible]

        Effective view watermark targetView (during a view change) or view (during normal case).

        structure Cslib.Distributed.ByzantineQuorum.PBFTState (P : Type u_1) (V : Type u_2) :
        Type (max u_1 u_2)

        Global asynchronous PBFT configuration: transmitted signed network messages and per-replica states.

        • network : Finset (PBFTMsg P V)

          Set of signed messages transmitted on the network (modeling arbitrary delay, reordering, replay, and selective link omission).

        • replicas : P → ReplicaState P V

          Local state of each replica; only entries for i ∉ F represent honest replicas.

        theorem Cslib.Distributed.ByzantineQuorum.PBFTState.ext {P : Type u_1} {V : Type u_2} {x y : PBFTState P V} (network : x.network = y.network) (replicas : x.replicas = y.replicas) :
        x = y

        Initial PBFT global configuration in view 0 with empty logs and network.

        def Cslib.Distributed.ByzantineQuorum.CommittedLocal {P : Type u_1} {V : Type u_2} (st : PBFTState P V) (i : P) (v s : ℕ) (val : Option V) :

        Honest replica i has locally committed (v, s, val) in state st.

        Instances For
          @[instance_reducible]
          instance Cslib.Distributed.ByzantineQuorum.instDecidableCommittedLocal {P : Type u_1} {V : Type u_2} [DecidableEq V] (st : PBFTState P V) (i : P) (v s : ℕ) (val : Option V) :
          Decidable (CommittedLocal st i v s val)
          inductive Cslib.Distributed.ByzantineQuorum.PBFTAction (P : Type u_1) (V : Type u_2) :
          Type (max u_1 u_2)

          Atomic asynchronous step labels of the PBFT protocol.

          @[instance_reducible]
          def Cslib.Distributed.ByzantineQuorum.instDecidableEqPBFTAction.decEq {P✝ : Type u_1} {V✝ : Type u_2} [DecidableEq P✝] [DecidableEq V✝] (x✝ x✝¹ : PBFTAction P✝ V✝) :
          Decidable (x✝ = x✝¹)
          def Cslib.Distributed.ByzantineQuorum.pbftStep {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] (primary : ℕ → P) (f : ℕ) (F : Finset P) (st : PBFTState P V) (act : PBFTAction P V) :

          Computable single-step transition function of asynchronous PBFT under primary schedule primary, fault parameter f, and static Byzantine set F (invalid actions stutter).

          inductive Cslib.Distributed.ByzantineQuorum.PBFTReachable {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] (primary : ℕ → P) (f : ℕ) (F : Finset P) :
          PBFTState P V → Prop

          Inductive reachability of global PBFT states from initPBFTState P V.

          theorem Cslib.Distributed.ByzantineQuorum.PBFTReachable.foldl_steps {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] {primary : ℕ → P} {f : ℕ} {F : Finset P} {st : PBFTState P V} (hst : PBFTReachable primary f F st) (acts : List (PBFTAction P V)) :
          PBFTReachable primary f F (List.foldl (pbftStep primary f F) st acts)

          Fold a finite list of PBFTActions from st preserves PBFTReachable.

          Monotonicity helpers and inductive protocol invariants #

          Within-view non-equivocation, cross-view commit preservation, and SMR safety #

          theorem Cslib.Distributed.ByzantineQuorum.preparedCert_unique_idealAuth {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] {primary : ℕ → P} {f : ℕ} {F : Finset P} (hn : 3 * f < Fintype.card P) (hF : F.card ≤ f) {st : PBFTState P V} (hst : PBFTReachable primary f F st) {c₁ c₂ : PreparedCert P V} (hc₁ : PreparedCert.ValidIn primary f st.network c₁) (hc₂ : PreparedCert.ValidIn primary f st.network c₂) (hv : c₁.view = c₂.view) (hs : c₁.slot = c₂.slot) :
          c₁.val = c₂.val

          Within-view non-equivocation step toward #7506 (after Castro and Liskov, §4.2, p. 4; ideal-authentication checkpoint-free model): under 3 * f < Fintype.card P and F.card ≤ f, any two valid PreparedCerts in a reachable state st for the same view and slot have equal val.

          theorem Cslib.Distributed.ByzantineQuorum.committedLocal_preserves_higher_prepared_idealAuth {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] {primary : ℕ → P} {f : ℕ} {F : Finset P} (hn : 3 * f < Fintype.card P) (hF : F.card ≤ f) {st : PBFTState P V} (hst : PBFTReachable primary f F st) {i₀ : P} (hi₀ : i₀ ∉ F) {v s : ℕ} {val : Option V} (hcom : CommittedLocal st i₀ v s val) {v' : ℕ} :
          v ≤ v' → ∀ {c' : PreparedCert P V}, PreparedCert.ValidIn primary f st.network c' → c'.view = v' → c'.slot = s → c'.val = val

          Cross-view commit-preservation step toward #7506 (after Castro and Liskov, §4.5.1, pp. 6–7; ideal-authentication checkpoint-free model): if 3 * f < Fintype.card P, F.card ≤ f, and some honest replica i₀ ∉ F locally commits (v, s, val) in reachable state st, then every valid PreparedCert c' on st.network at slot s in any view v' ≥ v carries c'.val = val.

          theorem Cslib.Distributed.ByzantineQuorum.pbft_commit_agreement_idealAuth {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] {primary : ℕ → P} {f : ℕ} {F : Finset P} (hn : 3 * f < Fintype.card P) (hF : F.card ≤ f) {st : PBFTState P V} (hst : PBFTReachable primary f F st) {i₁ i₂ : P} (hi₁ : i₁ ∉ F) (hi₂ : i₂ ∉ F) {v₁ v₂ s : ℕ} {val₁ val₂ : Option V} (hcom₁ : CommittedLocal st i₁ v₁ s val₁) (hcom₂ : CommittedLocal st i₂ v₂ s val₂) :
          val₁ = val₂

          Multi-slot total-order SMR commit safety step toward #7506 (after Castro and Liskov, §4.5.1, pp. 6–7; ideal-authentication checkpoint-free model): under 3 * f < Fintype.card P and F.card ≤ f, any two honest replicas i₁, i₂ ∉ F that locally commit (v₁, s, val₁) and (v₂, s, val₂) at sequence slot s (even in distinct views) commit val₁ = val₂.

          def Cslib.Distributed.ByzantineQuorum.executeSlotLog {S : Type u_1} {V : Type u_2} (smInit : S) (smStep : S → V → S) (slotCmd : ℕ → Option V) :
          ℕ → S

          Sequential execution of deterministic state-machine commands smStep : S → V → S across slots 0, ..., k - 1 (none = PBFT null no-op leaving the service state unchanged).

          theorem Cslib.Distributed.ByzantineQuorum.pbft_smr_state_agreement_idealAuth {P : Type u_1} {S : Type u_2} {V : Type u_3} [Fintype P] [DecidableEq P] [DecidableEq V] {primary : ℕ → P} {f : ℕ} {F : Finset P} (hn : 3 * f < Fintype.card P) (hF : F.card ≤ f) {st : PBFTState P V} (hst : PBFTReachable primary f F st) {i₁ i₂ : P} (hi₁ : i₁ ∉ F) (hi₂ : i₂ ∉ F) (smInit : S) (smStep : S → V → S) {views₁ views₂ : ℕ → ℕ} {cmds₁ cmds₂ : ℕ → Option V} {k : ℕ} (h₁ : ∀ s < k, CommittedLocal st i₁ (views₁ s) s (cmds₁ s)) (h₂ : ∀ s < k, CommittedLocal st i₂ (views₂ s) s (cmds₂ s)) :
          executeSlotLog smInit smStep cmds₁ k = executeSlotLog smInit smStep cmds₂ k

          Deterministic state-machine replication state-agreement step toward #7506 (after Castro and Liskov, §§3, 4.5.1, pp. 2–3, 6–7; ideal-authentication checkpoint-free model): if two honest replicas i₁, i₂ ∉ F have committed views views₁, views₂ : ℕ → ℕ and slot commands cmds₁, cmds₂ across all slots < k in reachable state st (3 * f < Fintype.card P, F.card ≤ f), then executing slots 0, ..., k - 1 from smInit yields identical service states at i₁ and i₂.

          Synchronized honest-primary 3-phase liveness #

          theorem Cslib.Distributed.ByzantineQuorum.pbft_honest_primary_three_phase_liveness_idealAuth {P : Type u_1} {V : Type u_2} [Fintype P] [DecidableEq P] [DecidableEq V] {primary : ℕ → P} {f : ℕ} {F : Finset P} (hF : F.card ≤ f) {st : PBFTState P V} (hst : PBFTReachable primary f F st) {v s : ℕ} (val : Option V) (hp_honest : primary v ∉ F) (hactive : ∀ i ∉ F, (st.replicas i).view = v ∧ (st.replicas i).inViewChange = false) (hfresh : ∀ i ∉ F, ∀ e ∈ (st.replicas i).accepted, e.view = v → e.slot = s → False) :
          ∃ (acts : List (PBFTAction P V)), have st' := List.foldl (pbftStep primary f F) st acts; PBFTReachable primary f F st' ∧ ∀ i ∉ F, CommittedLocal st' i v s val

          Synchronized honest-primary 3-phase liveness step toward #7506 (after Castro and Liskov, §§4.2, 4.5.2, pp. 4–5, 7; ideal-authentication checkpoint-free model): from any reachable configuration st (F.card ≤ f) in which primary v ∉ F and every honest replica i ∉ F is active in view v (view = v, inViewChange = false) with fresh slot s, there exists a finite 3-phase normal-case schedule reaching a configuration st' in which every honest replica i ∉ F has locally committed (v, s, val).

          |P| ≤ 3 * f split-brain view-change counterexample (Fin 3, f = 1) #

          theorem Cslib.Distributed.ByzantineQuorum.exists_pbft_splitBrain_fin3 :
          have F := {2}; F.card ≤ 1 ∧ 0 ∉ F ∧ 1 ∉ F ∧ ∃ (primary : ℕ → Fin 3) (st : PBFTState (Fin 3) Bool), PBFTReachable primary 1 F st ∧ CommittedLocal st 0 0 0 (some false) ∧ CommittedLocal st 1 1 0 (some true)

          Sharpness of 3 * f < Fintype.card P for PBFT view-change safety (#7506): on Fin 3 with f = 1 (Fintype.card (Fin 3) = 3 * f) and static Byzantine set F = {2} (F.card = 1 ≤ f), there exist a primary schedule primary and a reachable PBFT state in which honest replicas 0 ∉ F and 1 ∉ F locally commit conflicting client requests some false ≠ some true at sequence slot 0.