Files
proofs/lean/DeFi/Governance.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

85 lines
2.4 KiB
Lean4

/-
Authors: Antje Worring, Zach Kelling
On-Chain DEX Governance
DAO governance for DEX parameters: fee tiers, pool weights,
listing/delisting, upgrade proposals.
Maps to:
- lux/exchange: governance contracts
- lux/node: on-chain parameter updates
Properties:
- Quorum: parameter changes require vote threshold
- Timelock: changes have mandatory delay
- Bounded: parameters stay within safe ranges
- Monotone: governance power ∝ stake
Author: Zach Kelling
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Tactic
namespace DeFi.Governance
inductive ParamChange where
| feeUpdate (newFeeBps : Nat)
| poolWeight (poolId : Nat) (weight : Nat)
| listing (tokenAddr : Nat)
| delisting (tokenAddr : Nat)
| upgrade (implAddr : Nat)
deriving DecidableEq, Repr
structure Proposal where
change : ParamChange
proposer : Nat
votesFor : Nat
votesAgainst : Nat
quorum : Nat
timelockBlocks : Nat
proposedAt : Nat
def passes (p : Proposal) : Bool :=
p.votesFor ≥ p.quorum && p.votesFor > p.votesAgainst
def timelockMet (p : Proposal) (currentBlock : Nat) : Bool :=
currentBlock ≥ p.proposedAt + p.timelockBlocks
def canExecute (p : Proposal) (currentBlock : Nat) : Bool :=
passes p && timelockMet p currentBlock
/-- QUORUM: Below quorum → rejected -/
theorem below_quorum_fails (p : Proposal) (h : p.votesFor < p.quorum) :
passes p = false := by
simp [passes, Nat.not_le.mpr h]
/-- TIMELOCK: Too early → blocked -/
theorem early_execution_blocked (p : Proposal) (block : Nat)
(h : block < p.proposedAt + p.timelockBlocks) :
canExecute p block = false := by
simp [canExecute, timelockMet, Nat.not_le.mpr h, Bool.and_false]
/-- BOTH REQUIRED: Must pass AND timelock for execution -/
theorem both_required (p : Proposal) (block : Nat) (h : canExecute p block = true) :
passes p = true ∧ timelockMet p block = true := by
simp [canExecute, Bool.and_eq_true] at h; exact h
/-- FEE BOUNDS: Fee changes must stay reasonable (< 1%) -/
def feeInBounds (change : ParamChange) : Bool :=
match change with
| .feeUpdate fee => fee ≤ 100 -- max 1%
| _ => true
theorem fee_bounded (fee : Nat) (h : fee > 100) :
feeInBounds (.feeUpdate fee) = false := by
simp [feeInBounds, Nat.not_le.mpr h]
/-- MAJORITY: More for than against -/
theorem majority_required (p : Proposal) (h : passes p = true) :
p.votesFor > p.votesAgainst := by
simp [passes, Bool.and_eq_true, Nat.ble_eq] at h; exact h.2
end DeFi.Governance