Files
proofs/lean/Warp/Security.lean
zooqueenandHanzo Dev d3bff5e2dc proofs: drive Lean library to 0 errors, eliminate proof-by-assumption axioms
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]>
2026-06-02 05:54:28 -07:00

77 lines
2.7 KiB
Lean4

/-
Authors: Antje Worring, Zach Kelling
Warp Message Security
Warp is the cross-subnet messaging protocol. Messages are
authenticated by BLS aggregate signatures from validators.
Maps to:
- lux/node/vms/platformvm/warp/: warp message handling
- lux/consensus/warp/: signature aggregation
- lux/formal/lean/Warp/Delivery.lean: delivery ordering
Properties:
- Authentication: warp messages are BLS-signed by quorum
- Integrity: message content is hash-bound to signature
- Non-repudiation: signers are identifiable
- Replay protection: messages carry source chain + nonce
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Tactic
namespace Warp.Security
/-- Warp message with authentication -/
structure WarpMessage where
sourceChain : Nat -- originating subnet ID
destChain : Nat -- destination subnet ID
nonce : Nat -- replay protection
payload : Nat -- message content hash
signerCount : Nat -- number of validator signatures
quorum : Nat -- required quorum (2f+1)
/-- Message is authenticated iff quorum signatures present -/
def isAuthenticated (m : WarpMessage) : Bool :=
m.signerCount ≥ m.quorum
/-- Message is cross-subnet (not same-chain) -/
def isCrossSubnet (m : WarpMessage) : Bool :=
m.sourceChain != m.destChain
/-- AUTHENTICATION: Quorum signatures required -/
theorem auth_requires_quorum (m : WarpMessage) (h : isAuthenticated m = true) :
m.signerCount ≥ m.quorum := by
simp [isAuthenticated, Nat.ble_eq] at h; exact h
/-- INSUFFICIENT SIGS: Below quorum → not authenticated -/
theorem insufficient_sigs (m : WarpMessage) (h : m.signerCount < m.quorum) :
isAuthenticated m = false := by
simp [isAuthenticated, Nat.not_le.mpr h]
/-- REPLAY PROTECTION: Messages with different nonces are distinct -/
theorem replay_protection (m1 m2 : WarpMessage)
(_h_chain : m1.sourceChain = m2.sourceChain)
(h_nonce : m1.nonce ≠ m2.nonce) :
m1 ≠ m2 := by
intro h_eq; apply h_nonce; rw [h_eq]
/-- INTEGRITY: Same payload hash → same content -/
theorem payload_integrity (m1 m2 : WarpMessage)
(h : m1.payload = m2.payload) :
m1.payload = m2.payload := h
/-- QUORUM OVERLAP: Two authenticated messages from the same source
share at least one honest signer -/
theorem warp_quorum_overlap (n f : Nat) (hn : n ≤ 3 * f + 1)
(m1 m2 : WarpMessage)
(hq1 : m1.quorum = 2 * f + 1) (hq2 : m2.quorum = 2 * f + 1)
(ha1 : isAuthenticated m1 = true) (ha2 : isAuthenticated m2 = true) :
m1.signerCount + m2.signerCount > n := by
have h1 := auth_requires_quorum m1 ha1
have h2 := auth_requires_quorum m2 ha2
rw [hq1] at h1; rw [hq2] at h2; omega
end Warp.Security