-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9392921
commit 48632b9
Showing
7 changed files
with
75 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: leanprover/lean-action@v1 | ||
with: | ||
lake-package-directory: "src" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
-- This module serves as the root of the `CsprConsensusFormal` library. | ||
-- Import modules here that should be built as part of the library. | ||
import «CsprConsensus».Basic | ||
import «CsprConsensus».Network | ||
import «CsprConsensus».Protocol |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Mathlib.Data.Set.Finite | ||
|
||
class StateId (α : Type) extends Inhabited α, BEq α, Repr α, Fintype α | ||
|
||
variable {α : Type} [StateId α] [αFintype : Fintype α] | ||
|
||
structure Node where | ||
id : α | ||
deriving Inhabited, DecidableEq | ||
|
||
theorem Node.mk_injective : @Function.Injective α (@Node α) Node.mk := by apply Node.mk.inj | ||
def Node.mkEmbedding : Function.Embedding α (@Node α) := Function.Embedding.mk Node.mk Node.mk_injective | ||
|
||
instance nodeFintype : Fintype (@Node α) where | ||
elems := Finset.map Node.mkEmbedding αFintype.elems | ||
complete := by | ||
intro x | ||
apply Finset.mem_map.mpr | ||
simp [Node.mkEmbedding] | ||
exists x.id | ||
apply And.intro | ||
· apply αFintype.complete | ||
· rfl | ||
|
||
structure Nodes where | ||
collection : Set (@Node α) | ||
collectionFintype : Fintype collection | ||
invariant : (@Set.toFinset _ collection collectionFintype).card > 3 | ||
|
||
def Nodes.card (nodes : @Nodes α) : Nat := (@Set.toFinset _ nodes.collection nodes.collectionFintype).card | ||
|
||
structure Network where | ||
nodes : @Nodes α | ||
faultTolerance : Nat | ||
invariant : nodes.card > 3 * faultTolerance | ||
def Network.quorumSize (net : @Network α) : Nat := 1 + (net.nodes.card + net.faultTolerance) / 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import CsprConsensus.Network | ||
|
||
class Value (β : Type) extends Inhabited β, BEq β, Repr β | ||
|
||
class Protocol (β : Type) [Value β] where | ||
input : @Network α → @Node α → Option β | ||
output : @Network α -> @Node α -> Option β | ||
is_correct : @Network α -> @Node α -> Prop | ||
/-- continuation for eventual properties -/ | ||
eventually : (@Network α -> Prop) -> Prop | ||
/-- If any correct node outputs v, every corect node will eventually output v -/ | ||
agreement : forall (net : @Network α) (n1 n2 : @Node α) (v : β), | ||
is_correct net n1 -> is_correct net n2 -> | ||
@output α net n1 = some v -> | ||
@eventually α (fun _ => @output α net n2 = some v) | ||
|
||
instance BoolValue : Value Bool := by constructor | ||
|
||
class WBA extends Protocol Bool where | ||
/-- If the correct nodes output b, more than q - f correct validators had input b -/ | ||
validity : 1 = 1 := by rfl -- TODO | ||
/-- If more than q correct validators have input b, the correct nodes eventually output b -/ | ||
weak_termination : 1 = 1 := by rfl -- TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters