You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.6 KiB

  1. #lang ivy1.7
  2. # ---
  3. # layout: page
  4. # title: Proof of Classic Safety
  5. # ---
  6. include tendermint
  7. include abstract_tendermint
  8. # Here we prove the classic safety property: assuming that every two quorums
  9. # have a well-behaved node in common, no two well-behaved nodes ever disagree.
  10. # The proof is done in two steps: first we prove the the abstract specification
  11. # satisfies the property, and then we show by refinement that this property
  12. # also holds in the concrete specification.
  13. # To see what is checked in the refinement proof, use `ivy_show isolate=classic_safety classic_safety.ivy`
  14. # To see what is checked in the abstract correctness proof, use `ivy_show isolate=abstract_classic_safety classic_safety.ivy`
  15. # To check the whole proof, use `ivy_check classic_safety.ivy`.
  16. # Note that all the verification conditions sent to Z3 for this proof are in
  17. # EPR.
  18. # Classic safety in the abstract model
  19. # ====================================
  20. # We start by proving that classic safety holds in the abstract model.
  21. isolate abstract_classic_safety = {
  22. instantiate abstract_tendermint
  23. invariant [classic_safety] classic_bft.quorum_intersection & decided(N1,R1,V1) & decided(N2,R2,V2) -> V1 = V2
  24. # The notion of choosable value
  25. # -----------------------------
  26. relation choosable(R:round, V:value)
  27. definition choosable(R,V) = exists Q . nset.is_quorum(Q) & forall N . well_behaved(N) & nset.member(N,Q) -> ~left_round(N,R) | precommitted(N,R,V)
  28. # Main invariants
  29. # ---------------
  30. # `classic_safety` is inductive relative to those invariants
  31. invariant [decision_is_quorum_precommit] (exists N1 . decided(N1,R,V)) -> exists Q. nset.is_quorum(Q) & forall N2. well_behaved(N2) & nset.member(N2, Q) -> precommitted(N2,R,V)
  32. invariant [precommitted_is_quorum_prevote] V ~= value.nil & (exists N1 . precommitted(N1,R,V)) -> exists Q. nset.is_quorum(Q) & forall N2. well_behaved(N2) & nset.member(N2, Q) -> prevoted(N2,R,V)
  33. invariant [prevote_unique_per_round] prevoted(N,R,V1) & prevoted(N,R,V2) -> V1 = V2
  34. # This is the core invariant: as long as a precommitted value is still choosable, it remains protected by a lock and prevents any new value from being prevoted:
  35. invariant [locks] classic_bft.quorum_intersection & V ~= value.nil & precommitted(N,R,V) & choosable(R,V) -> locked(N,R,V) & forall R2,V2 . R < R2 & prevoted(N,R2,V2) -> V2 = V | V2 = value.nil
  36. # Supporting invariants
  37. # ---------------------
  38. # The main invariants are inductive relative to those
  39. invariant decided(N,R,V) -> V ~= value.nil
  40. invariant left_round(N,R2) & R1 < R2 -> left_round(N,R1) # if a node left round R2>R1, then it also left R1:
  41. invariant prevoted(N,R2,V2) & R1 < R2 -> left_round(N,R1)
  42. invariant precommitted(N,R2,V2) & R1 < R2 -> left_round(N,R1)
  43. } with round, nset, classic_bft.quorum_intersection_def
  44. # The refinement proof
  45. # ====================
  46. # Now, thanks to the refinement relation that we establish in
  47. # `concrete_tendermint.ivy`, we prove that classic safety transfers to the
  48. # concrete specification:
  49. isolate classic_safety = {
  50. # We instantiate the `tendermint` module providing `abstract_classic_safety` as abstract model.
  51. instantiate tendermint(abstract_classic_safety)
  52. # We prove that if every two quorums have a well-behaved node in common,
  53. # then well-behaved nodes never disagree:
  54. invariant [classic_safety] classic_bft.quorum_intersection & server.decision(N1) ~= value.nil & server.decision(N2) ~= value.nil -> server.decision(N1) = server.decision(N2)
  55. } with value, round, proposers, shim, abstract_classic_safety # here we list all the specifications that we rely on for this proof