Files
proofs/formal/lean/DeFi/Governance.lean
zeekay c86eec94cb merge: absorb /Users/z/work/zoo/formal into proofs (de-duplicate)
Local zoo/formal was a stale parallel checkout that pointed at
zoo-labs/formal (non-existent); the canonical remote is
zooai/proofs. This commit absorbs the unique formal-verification
work from the old checkout into proofs:

- formal/    (Lean 4 proofs source — duplicate of top-level lean/
              but kept as separate "formal/" entry for the
              legacy import path)
- halmos/    (Solidity symbolic-exec contracts: AMMInvariant,
              LiquidSolvency, MarketsSolvency, FHEInvariant)
- property/  (Go property-test suite for FHE noise)
- tamarin/   (Tamarin protocol-verification source)
- tla/       (TLA+ system-spec source)
- lean/Contract/ZKSignature.lean  (unique, not in proofs/lean)
- lean/Crypto/ZKSignature.lean    (unique, not in proofs/lean)
- FORMAL_VERIFICATION.md (preserved from the old README)
- LLM-formal.md          (preserved from the old LLM.md)

The duplicate folder /Users/z/work/zoo/formal is now deleted on
disk. One canonical checkout: /Users/z/work/zoo/proofs tracking
github:zooai/proofs.
2026-05-12 21:13:00 -07:00

83 lines
2.4 KiB
Lean4

/-
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