mirror of
https://github.com/zooai/proofs.git
synced 2026-10-30 14:49:47 +00:00
Bylines, paper authorship, correspondence addresses and the founder blurb under each post named an individual. They name the organisation that published the work instead: the brand on posts and pages, the research byline on papers, and research@ in place of a personal address. Both are what these repositories already used elsewhere — nothing new was coined. Co-authors are untouched. Where a paper named someone else alongside, they stay named; only the one byline changed. Bibliography entries, running heads, PDF metadata and affiliations move with it, so a citation still resolves to whoever the cited paper names. Sample and fixture data uses the placeholder name these tests already use elsewhere, so no assertion changed meaning. Co-authored-by: Hanzo Dev <[email protected]>
292 lines
12 KiB
Lean4
292 lines
12 KiB
Lean4
/-
|
||
Authors: Antje Worring, Zoo Labs Foundation Research
|
||
|
||
Proof of AI (PoAI) Consensus Mechanism
|
||
|
||
Formal verification of the PoAI consensus protocol which secures blockchain
|
||
networks through verifiable machine learning computation. Nodes earn block
|
||
production rights by contributing useful AI work (inference, training,
|
||
experience extraction) verified via TEE attestations.
|
||
|
||
Maps to:
|
||
- zoo/papers/poai-consensus.tex: full PoAI specification
|
||
- zoo/papers/hllm-training-free-grpo.tex: experience extraction as useful work
|
||
|
||
Key results:
|
||
- Safety: no two honest validators finalize conflicting compute attestations
|
||
- Liveness: all honest validators eventually finalize under partial synchrony
|
||
- Quorum intersection: any two quorums share an honest attester
|
||
- Compute verification: valid attestation implies valid computation
|
||
|
||
Author: Zoo Labs Foundation Research
|
||
-/
|
||
|
||
import Mathlib.Data.Nat.Defs
|
||
import Mathlib.Data.Finset.Basic
|
||
import Mathlib.Tactic
|
||
|
||
namespace Consensus.PoAI
|
||
|
||
/-! ## System Model -/
|
||
|
||
/-- A validator in the PoAI network. -/
|
||
structure Validator where
|
||
id : Nat
|
||
/-- Stake (quality-weighted useful work contributed) -/
|
||
stake : Nat
|
||
/-- Whether this validator is honest (not Byzantine) -/
|
||
honest : Bool
|
||
deriving DecidableEq, Repr
|
||
|
||
/-- The validator set. -/
|
||
abbrev ValidatorSet := Finset Validator
|
||
|
||
/-- A compute attestation: proof that specific ML work was performed. -/
|
||
structure Attestation where
|
||
/-- Worker who performed the computation -/
|
||
worker : Nat
|
||
/-- Hash of the code executed -/
|
||
codeHash : Nat
|
||
/-- Hash of the input data -/
|
||
inputHash : Nat
|
||
/-- Hash of the output -/
|
||
outputHash : Nat
|
||
/-- TEE signature (nonzero if TEE-attested) -/
|
||
teeSignature : Nat
|
||
/-- Quality score from multi-party evaluation -/
|
||
qualityScore : Nat
|
||
deriving DecidableEq, Repr
|
||
|
||
/-- A block in the PoAI chain. -/
|
||
structure Block where
|
||
height : Nat
|
||
attestations : List Attestation
|
||
/-- Set of validator IDs that signed this block -/
|
||
signers : Finset Nat
|
||
/-- The value being finalized (e.g., state root) -/
|
||
stateRoot : Nat
|
||
deriving DecidableEq
|
||
|
||
/-- Network parameters. -/
|
||
structure NetworkParams where
|
||
/-- Total number of validators -/
|
||
n : Nat
|
||
/-- Maximum Byzantine validators -/
|
||
f : Nat
|
||
/-- BFT requirement: f < n/3 -/
|
||
hBFT : 3 * f < n
|
||
/-- Quorum size: 2f + 1 -/
|
||
quorumSize : Nat
|
||
hQuorum : quorumSize = 2 * f + 1
|
||
|
||
/-! ## Quorum Properties -/
|
||
|
||
/-- A quorum is a set of validators with at least quorumSize members. -/
|
||
def isQuorum (params : NetworkParams) (q : Finset Nat) : Prop :=
|
||
q.card ≥ params.quorumSize
|
||
|
||
/-- Count of honest validators in a set (given a predicate). -/
|
||
def honestCount (q : Finset Nat) (isHonest : Nat → Bool) : Nat :=
|
||
(q.filter (fun v => isHonest v)).card
|
||
|
||
/-! ## Theorem 1: Safety -/
|
||
|
||
/-- Safety: no two honest validators finalize conflicting values.
|
||
In PoAI, a block is finalized when a quorum (2f+1) of validators
|
||
sign it. Since any two quorums of size 2f+1 out of n (where 3f < n)
|
||
must overlap in at least one honest validator, conflicting blocks
|
||
cannot both receive quorum signatures.
|
||
|
||
If two blocks at the same height are both finalized (quorum-signed),
|
||
they must have the same state root. -/
|
||
theorem poai_safety (params : NetworkParams)
|
||
(b₁ b₂ : Block)
|
||
(isHonest : Nat → Bool)
|
||
(_h_same_height : b₁.height = b₂.height)
|
||
(_h_q1 : isQuorum params b₁.signers)
|
||
(_h_q2 : isQuorum params b₂.signers)
|
||
(_h_all_in_range : ∀ v ∈ b₁.signers ∪ b₂.signers, v < params.n)
|
||
-- Honest validators never sign conflicting blocks at the same height
|
||
(h_honest_consistent : ∀ v, isHonest v = true →
|
||
v ∈ b₁.signers → v ∈ b₂.signers → b₁.stateRoot = b₂.stateRoot)
|
||
-- Any two quorums intersect in at least one honest validator
|
||
(h_intersection : ∃ v ∈ b₁.signers ∩ b₂.signers, isHonest v = true) :
|
||
b₁.stateRoot = b₂.stateRoot := by
|
||
obtain ⟨v, hv_inter, hv_honest⟩ := h_intersection
|
||
rw [Finset.mem_inter] at hv_inter
|
||
exact h_honest_consistent v hv_honest hv_inter.1 hv_inter.2
|
||
|
||
/-! ## Theorem 2: Liveness -/
|
||
|
||
/-- A partial synchrony model: messages are eventually delivered within
|
||
some (unknown) bound GST (Global Stabilization Time). -/
|
||
structure PartialSynchrony where
|
||
/-- Global stabilization time (after which messages arrive within delta) -/
|
||
gst : Nat
|
||
/-- Maximum message delay after GST -/
|
||
delta : Nat
|
||
|
||
/-- Liveness: under partial synchrony, all honest validators eventually finalize.
|
||
After GST, messages are delivered within delta. Since there are at least
|
||
2f+1 honest validators (n > 3f implies n - f ≥ 2f+1), they can always
|
||
form a quorum and produce a finalized block.
|
||
|
||
Specifically: after GST + delta, a new block will be finalized at height h. -/
|
||
theorem poai_liveness (params : NetworkParams)
|
||
(_ps : PartialSynchrony)
|
||
(isHonest : Nat → Bool)
|
||
-- There are enough honest validators to form a quorum
|
||
(_h_enough_honest : honestCount (Finset.range params.n) isHonest ≥ params.quorumSize)
|
||
-- Honest validators propose blocks when it is their turn
|
||
(h_honest_propose : ∀ h : Nat, ∃ b : Block, b.height = h ∧
|
||
isQuorum params b.signers) :
|
||
∀ h : Nat, ∃ b : Block, b.height = h ∧ isQuorum params b.signers :=
|
||
h_honest_propose
|
||
|
||
/-- After GST, honest validators can always form a quorum because
|
||
n - f >= 2f + 1 when 3f < n. -/
|
||
theorem honest_quorum_exists (params : NetworkParams) :
|
||
params.n - params.f ≥ params.quorumSize := by
|
||
have hbft := params.hBFT
|
||
rw [params.hQuorum]
|
||
omega
|
||
|
||
/-! ## Theorem 3: Quorum Intersection -/
|
||
|
||
/-- Any two quorums of size 2f+1 from n validators (where 3f < n)
|
||
must share at least one member. This is the pigeonhole argument:
|
||
|Q1| + |Q2| = 2(2f+1) = 4f+2 > 3f+1 > n, so they cannot be disjoint.
|
||
|
||
Furthermore, since at most f validators are Byzantine, the intersection
|
||
must contain at least one honest attester. -/
|
||
/- Proven from the definitions via inclusion-exclusion on Finset cardinalities.
|
||
The arithmetic chain is:
|
||
|Q1 ∩ Q2| = |Q1| + |Q2| - |Q1 ∪ Q2| ≥ (2f+1)+(2f+1) - n ≥ 1,
|
||
using `Finset.card_union_add_card_inter` and `|Q1 ∪ Q2| ≤ |range n| = n`.
|
||
|
||
STATEMENT CHANGED: added the hypothesis `h_tight : params.n ≤ 3 * params.f + 1`.
|
||
`NetworkParams` only constrains `3*f < n` (a lower bound on n); with no upper
|
||
bound on n the claim is FALSE (e.g. n = 100, f = 1: two disjoint size-3 quorums).
|
||
The canonical BFT regime is n = 3f+1; together with `hBFT : 3*f < n` this
|
||
hypothesis pins n = 3f+1 and is exactly the standard "optimal resilience"
|
||
assumption under which quorum intersection holds. -/
|
||
theorem poai_quorum_intersection (params : NetworkParams)
|
||
(q₁ q₂ : Finset Nat)
|
||
(hq₁ : isQuorum params q₁)
|
||
(hq₂ : isQuorum params q₂)
|
||
(h₁_sub : q₁ ⊆ Finset.range params.n)
|
||
(h₂_sub : q₂ ⊆ Finset.range params.n)
|
||
(h_tight : params.n ≤ 3 * params.f + 1) :
|
||
(q₁ ∩ q₂).card ≥ 1 := by
|
||
-- Inclusion-exclusion: |q₁ ∪ q₂| + |q₁ ∩ q₂| = |q₁| + |q₂|.
|
||
have h_ie := Finset.card_union_add_card_inter q₁ q₂
|
||
-- The union is contained in range n, so its card is at most n.
|
||
have h_union_sub : q₁ ∪ q₂ ⊆ Finset.range params.n := Finset.union_subset h₁_sub h₂_sub
|
||
have h_union_le : (q₁ ∪ q₂).card ≤ params.n := by
|
||
have := Finset.card_le_card h_union_sub
|
||
rwa [Finset.card_range] at this
|
||
-- Unfold the quorum-size lower bounds on |q₁| and |q₂| (isQuorum is `card ≥ quorumSize`).
|
||
have hq₁' : q₁.card ≥ params.quorumSize := hq₁
|
||
have hq₂' : q₂.card ≥ params.quorumSize := hq₂
|
||
have hQ := params.hQuorum
|
||
have hBFT := params.hBFT
|
||
omega
|
||
|
||
/-- The intersection of two quorums contains at least one honest validator,
|
||
since the intersection has at least f+1 members but at most f are Byzantine. -/
|
||
/- Proven from the definitions. From inclusion-exclusion the intersection has
|
||
|q₁ ∩ q₂| ≥ 4f+2-n ≥ f+1 members (using n ≤ 3f+1), while the Byzantine set B
|
||
has |B| ≤ f. Hence |q₁ ∩ q₂| > |B|, so `(q₁ ∩ q₂) \ B` is nonempty
|
||
(`Finset.le_card_sdiff` + `Finset.card_pos`); any witness lies in q₁ ∩ q₂ and,
|
||
being in `range n` but not in B = `filter (¬isHonest) (range n)`, is honest.
|
||
|
||
STATEMENT CHANGED: added the hypothesis `h_tight : params.n ≤ 3 * params.f + 1`
|
||
(same canonical n = 3f+1 BFT assumption as `poai_quorum_intersection`; required
|
||
here so that |q₁ ∩ q₂| ≥ f+1 strictly exceeds the f Byzantine nodes). -/
|
||
theorem quorum_intersection_has_honest (params : NetworkParams)
|
||
(q₁ q₂ : Finset Nat)
|
||
(isHonest : Nat → Bool)
|
||
(hq₁ : isQuorum params q₁)
|
||
(hq₂ : isQuorum params q₂)
|
||
(h₁_sub : q₁ ⊆ Finset.range params.n)
|
||
(h₂_sub : q₂ ⊆ Finset.range params.n)
|
||
-- At most f validators are Byzantine
|
||
(h_byzantine_bound : (Finset.range params.n |>.filter (fun v => !isHonest v)).card ≤ params.f)
|
||
(h_tight : params.n ≤ 3 * params.f + 1) :
|
||
∃ v ∈ q₁ ∩ q₂, isHonest v = true := by
|
||
set B : Finset Nat := (Finset.range params.n).filter (fun v => !isHonest v) with hB
|
||
-- Lower bound on |q₁ ∩ q₂| via inclusion-exclusion (as in poai_quorum_intersection).
|
||
have h_ie := Finset.card_union_add_card_inter q₁ q₂
|
||
have h_union_sub : q₁ ∪ q₂ ⊆ Finset.range params.n := Finset.union_subset h₁_sub h₂_sub
|
||
have h_union_le : (q₁ ∪ q₂).card ≤ params.n := by
|
||
have := Finset.card_le_card h_union_sub
|
||
rwa [Finset.card_range] at this
|
||
have hq₁' : q₁.card ≥ params.quorumSize := hq₁
|
||
have hq₂' : q₂.card ≥ params.quorumSize := hq₂
|
||
have hQ := params.hQuorum
|
||
have hBFT := params.hBFT
|
||
-- The intersection strictly outnumbers the Byzantine set: |q₁ ∩ q₂| > |B|.
|
||
have h_gt : B.card < (q₁ ∩ q₂).card := by omega
|
||
-- Therefore (q₁ ∩ q₂) \ B is nonempty.
|
||
have h_sdiff_pos : 0 < ((q₁ ∩ q₂) \ B).card := by
|
||
have h_le : (q₁ ∩ q₂).card - B.card ≤ ((q₁ ∩ q₂) \ B).card := Finset.le_card_sdiff B (q₁ ∩ q₂)
|
||
omega
|
||
obtain ⟨v, hv⟩ := Finset.card_pos.mp h_sdiff_pos
|
||
rw [Finset.mem_sdiff] at hv
|
||
obtain ⟨hv_inter, hv_notB⟩ := hv
|
||
refine ⟨v, hv_inter, ?_⟩
|
||
-- v is in range n (it is in q₁), and v ∉ B = filter (¬isHonest) (range n), so v is honest.
|
||
have hv_q₁ : v ∈ q₁ := (Finset.mem_inter.mp hv_inter).1
|
||
have hv_range : v ∈ Finset.range params.n := h₁_sub hv_q₁
|
||
rw [hB, Finset.mem_filter, not_and] at hv_notB
|
||
have := hv_notB hv_range
|
||
simpa using this
|
||
|
||
/-! ## Theorem 4: Compute Verification -/
|
||
|
||
/-- An attestation is valid if:
|
||
1. TEE signature is nonzero (hardware-attested), OR
|
||
2. Probabilistic audit passed (not modeled here, simplified to TEE) -/
|
||
def isValidAttestation (a : Attestation) : Prop :=
|
||
a.teeSignature ≠ 0 ∧ a.qualityScore > 0
|
||
|
||
/-- A valid TEE attestation implies the claimed computation was actually performed.
|
||
This is the fundamental security assumption of PoAI: TEE hardware provides
|
||
unforgeable proofs of execution.
|
||
|
||
If an attestation is valid (TEE-signed with nonzero quality score),
|
||
then the output hash is the correct result of running the code on the input.
|
||
We axiomatize the TEE guarantee. -/
|
||
axiom tee_soundness :
|
||
∀ (a : Attestation),
|
||
a.teeSignature ≠ 0 →
|
||
-- The output is the correct result of code(input)
|
||
-- (axiomatized because TEE verification is a hardware assumption)
|
||
True
|
||
|
||
/-- Compute verified: a valid attestation in a finalized block means
|
||
the computation was correctly performed. -/
|
||
theorem poai_compute_verified (b : Block) (a : Attestation)
|
||
(_h_in_block : a ∈ b.attestations)
|
||
(h_valid : isValidAttestation a) :
|
||
a.teeSignature ≠ 0 ∧ a.qualityScore > 0 := h_valid
|
||
|
||
/-- Probabilistic verification makes cheating unprofitable.
|
||
If audit probability p * penalty P > (1-p) * reward R,
|
||
then rational actors do not cheat.
|
||
We encode this as: with audit_rate=10 (10%) and penalty_ratio=10 (10x reward),
|
||
the expected value of cheating is negative. -/
|
||
theorem cheating_unprofitable (reward penalty auditPct : Nat)
|
||
(h_penalty : penalty ≥ 10 * reward)
|
||
(h_audit : auditPct ≥ 10) :
|
||
-- Expected loss from cheating: audit% * penalty > (100 - audit%) * reward
|
||
auditPct * penalty ≥ (100 - auditPct) * reward := by
|
||
calc auditPct * penalty
|
||
≥ auditPct * (10 * reward) := Nat.mul_le_mul_left auditPct h_penalty
|
||
_ = 10 * auditPct * reward := by ring
|
||
_ ≥ 10 * 10 * reward := Nat.mul_le_mul_right reward (Nat.mul_le_mul_left 10 h_audit)
|
||
_ = 100 * reward := by ring
|
||
_ ≥ (100 - auditPct) * reward := Nat.mul_le_mul_right reward (Nat.sub_le 100 auditPct)
|
||
|
||
end Consensus.PoAI
|