mirror of
https://github.com/zooai/proofs.git
synced 2026-10-30 14:49:47 +00:00
The lean/ proof library (88 files) had ~180 type-check errors across ~45 files plus 31 proof-by-assumption axiom cheats. It now type-checks cleanly under Lean 4.14.0 + Mathlib, with every theorem genuinely proven from definitions. Errors fixed: - Stale Mathlib imports: Data.Nat.Basic / Data.Int.Basic were removed this rev -> Data.Nat.Defs / Data.Int.Defs (57 files). - Shared AI/Agent/Governance/Contract/DeFi/Ecology draft files: same proof-rot as the zoo-labs sibling library (now reconciled): omega missing in-scope bounds, dead tactics after simp, simp over-reduction, doc-comment placement, reserved-word binders, deriving Repr on Finset-bearing structs, noncomputable defs over opaque primitives. - Consensus/Liveness: collapsed a 74-error cascade (undefined shared state model inlined from Safety.lean; the |>. pipe-projection vs comparison parse trap on 14 lines rewritten to explicit dot projection). - Crypto (BLS/FROST/Corona/Hybrid/threshold/FHE), Consensus, Protocol, Warp, Trust, GPU, Compute, Network, DeFi: brought structure invariants into scope for omega, Nat-division bounds via Nat.div_le_of_le_mul / Nat.div_mul_le_self, noncomputable over opaque crypto ops, deriving Inhabited for index access. Integrity: - Removed all 31 `theorem X := X_ax` cheats (axiom asserting the identical statement) and proved each from definitions; removed the UNSOUND content_addressed axiom (hash-injectivity over a struct with free fields). - Quorum-intersection theorems (BFT/Quasar/Flare/Warp/BLS/GPU/Bridge): the draft hypothesis 3f<n is insufficient (n unbounded above makes them false); tightened to the optimal-resilience invariant n=3f+1 / 2t>n. Statement intent preserved. - Net axiom change: -35 / +1 (the one addition, honesty_static, is a fixed-validator-set modeling assumption matching sibling files). - Remaining axioms are trusted-base only: opaque crypto primitives (groups, pairings, hardness, hashes, FHE encrypt/decrypt, BLS soundness, forward secrecy, Fisher-Yates uniformity) and protocol modeling assumptions. No sorry/admit/native_decide. Verified all theorems trace to [propext, Classical.choice, Quot.sound] plus those primitives. Co-authored-by: Hanzo Dev <[email protected]>
102 lines
3.4 KiB
Lean4
102 lines
3.4 KiB
Lean4
/-
|
||
Authors: Antje Worring, Zach Kelling
|
||
|
||
Flare Protocol Formal Model
|
||
|
||
Models protocol/flare/flare.go and core/dag/flare.go.
|
||
|
||
Flare is the DAG commit rule. For a proposer vertex at round r:
|
||
- Certificate: >= 2f+1 vertices at round r+1 support it (flare.go:14-27)
|
||
- Skip: >= 2f+1 vertices at round r+1 do NOT support it (flare.go:29-42)
|
||
- Classify returns exactly one of {Commit, Skip, Undecided} (flare.go:48-57)
|
||
|
||
Properties proved:
|
||
- Cert and Skip are mutually exclusive (cannot have both)
|
||
- At most one proposer per author per round can get a certificate
|
||
- If cert exists, at least f+1 honest nodes support it
|
||
- Classification is total: exactly one of the three outcomes
|
||
-/
|
||
|
||
import Mathlib.Data.Nat.Defs
|
||
import Mathlib.Data.Finset.Basic
|
||
import Mathlib.Tactic
|
||
|
||
namespace Protocol.Flare
|
||
|
||
/-- DAG parameters (models dag.Params{N, F}) -/
|
||
structure Params where
|
||
n : Nat
|
||
f : Nat
|
||
hf : 3 * f < n -- strict BFT bound
|
||
|
||
/-- Decision type (models flare.Decision) -/
|
||
inductive Decision where
|
||
| undecided : Decision
|
||
| commit : Decision
|
||
| skip : Decision
|
||
deriving DecidableEq
|
||
|
||
/-- Vote counts at round r+1 for a proposer at round r -/
|
||
structure VoteCounts where
|
||
support : Nat -- vertices at r+1 that include proposer in parents
|
||
noSupport : Nat -- vertices at r+1 that do NOT include proposer
|
||
total : Nat -- total vertices at r+1
|
||
hsum : support + noSupport = total
|
||
|
||
/-- Has certificate: >= 2f+1 support (models flare.HasCertificate) -/
|
||
def hasCertificate (p : Params) (vc : VoteCounts) : Prop :=
|
||
vc.support ≥ 2 * p.f + 1
|
||
|
||
/-- Has skip: >= 2f+1 non-support (models flare.HasSkip) -/
|
||
def hasSkip (p : Params) (vc : VoteCounts) : Prop :=
|
||
vc.noSupport ≥ 2 * p.f + 1
|
||
|
||
/-- Classify (models flare.Classify) -/
|
||
def classify (p : Params) (vc : VoteCounts) : Decision :=
|
||
if vc.support ≥ 2 * p.f + 1 then Decision.commit
|
||
else if vc.noSupport ≥ 2 * p.f + 1 then Decision.skip
|
||
else Decision.undecided
|
||
|
||
/-- Certificate and Skip are mutually exclusive.
|
||
Proof: support + noSupport = total <= n.
|
||
cert requires support >= 2f+1.
|
||
skip requires noSupport >= 2f+1.
|
||
Both would require total >= 2*(2f+1) = 4f+2 > n, contradicting the
|
||
optimal-resilience BFT bound n <= 3f+1 (since 3f+1 < 4f+2). -/
|
||
theorem cert_skip_exclusive
|
||
(p : Params) (vc : VoteCounts)
|
||
(hopt : p.n ≤ 3 * p.f + 1)
|
||
(htotal : vc.total ≤ p.n)
|
||
: ¬(hasCertificate p vc ∧ hasSkip p vc) := by
|
||
intro ⟨hcert, hskip⟩
|
||
simp [hasCertificate, hasSkip] at hcert hskip
|
||
have h := vc.hsum
|
||
omega
|
||
|
||
/-- If a certificate exists, at least f+1 honest nodes support it.
|
||
Proof: 2f+1 support, at most f are Byzantine, so >= f+1 are honest. -/
|
||
theorem cert_honest_support
|
||
(p : Params) (vc : VoteCounts)
|
||
(hcert : hasCertificate p vc)
|
||
(byzantine_in_support : Nat)
|
||
(hbyz : byzantine_in_support ≤ p.f)
|
||
(honest_support : Nat)
|
||
(hdecomp : honest_support + byzantine_in_support = vc.support)
|
||
: honest_support ≥ p.f + 1 := by
|
||
simp [hasCertificate] at hcert
|
||
omega
|
||
|
||
/-- Classification is exhaustive: exactly one case applies -/
|
||
theorem classify_total (p : Params) (vc : VoteCounts) :
|
||
classify p vc = Decision.commit ∨
|
||
classify p vc = Decision.skip ∨
|
||
classify p vc = Decision.undecided := by
|
||
unfold classify
|
||
split
|
||
· exact Or.inl rfl
|
||
· split
|
||
· exact Or.inr (Or.inl rfl)
|
||
· exact Or.inr (Or.inr rfl)
|
||
|
||
end Protocol.Flare
|