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]>
125 lines
4.2 KiB
Lean4
125 lines
4.2 KiB
Lean4
/-
|
||
Authors: Antje Worring, Zach Kelling
|
||
|
||
Treasury Management Properties
|
||
|
||
The DAO treasury holds funds and distributes them via governance.
|
||
All operations require proposal + quorum vote.
|
||
|
||
Maps to:
|
||
- zoo/zoo.vote: treasury management interface
|
||
- zoo/contracts: on-chain treasury
|
||
- zoo/ZIPs: governance proposals (ZIP-003 genesis)
|
||
|
||
Properties:
|
||
- Solvency: treasury balance ≥ 0 (no overdraft)
|
||
- Authorization: all transfers require governance vote
|
||
- Transparency: all operations are recorded
|
||
- Budget: approved spending ≤ available balance
|
||
-/
|
||
|
||
import Mathlib.Data.Nat.Defs
|
||
import Mathlib.Data.List.Basic
|
||
import Mathlib.Tactic
|
||
|
||
namespace Governance.Treasury
|
||
|
||
/-- Treasury operation types -/
|
||
inductive OpType where
|
||
| deposit
|
||
| grant (recipient : Nat) (amount : Nat)
|
||
| investment (target : String) (amount : Nat)
|
||
| burn (amount : Nat)
|
||
deriving DecidableEq, Repr
|
||
|
||
/-- Operation with governance approval -/
|
||
structure TreasuryOp where
|
||
opType : OpType
|
||
proposalId : Nat
|
||
approved : Bool -- passed quorum vote
|
||
executed : Bool -- has been executed
|
||
|
||
/-- Treasury state -/
|
||
structure TreasuryState where
|
||
balance : Nat
|
||
totalDeposited : Nat
|
||
totalGranted : Nat
|
||
totalBurned : Nat
|
||
operations : List TreasuryOp
|
||
|
||
/-- Execute a treasury operation -/
|
||
def execute (s : TreasuryState) (op : TreasuryOp) : TreasuryState :=
|
||
if !op.approved then s -- unapproved ops are no-ops
|
||
else match op.opType with
|
||
| .deposit =>
|
||
{ s with balance := s.balance + 0 } -- deposits handled separately
|
||
| .grant _ amount =>
|
||
if amount ≤ s.balance then
|
||
{ s with balance := s.balance - amount
|
||
, totalGranted := s.totalGranted + amount
|
||
, operations := { op with executed := true } :: s.operations }
|
||
else s
|
||
| .investment _ amount =>
|
||
if amount ≤ s.balance then
|
||
{ s with balance := s.balance - amount
|
||
, operations := { op with executed := true } :: s.operations }
|
||
else s
|
||
| .burn amount =>
|
||
if amount ≤ s.balance then
|
||
{ s with balance := s.balance - amount
|
||
, totalBurned := s.totalBurned + amount
|
||
, operations := { op with executed := true } :: s.operations }
|
||
else s
|
||
|
||
/-- Deposit funds -/
|
||
def deposit (s : TreasuryState) (amount : Nat) : TreasuryState :=
|
||
{ s with balance := s.balance + amount
|
||
, totalDeposited := s.totalDeposited + amount }
|
||
|
||
/-- SOLVENCY: balance never goes negative (Nat ensures this structurally) -/
|
||
theorem solvency (s : TreasuryState) (op : TreasuryOp) :
|
||
(execute s op).balance ≤ s.balance ∨ (execute s op).balance = s.balance := by
|
||
left
|
||
simp only [execute]
|
||
split
|
||
· rfl
|
||
· split <;> first | rfl | (split <;> simp [Nat.sub_le])
|
||
|
||
/-- AUTHORIZATION: unapproved ops don't change state -/
|
||
theorem unapproved_noop (s : TreasuryState) (op : TreasuryOp)
|
||
(h : op.approved = false) :
|
||
execute s op = s := by
|
||
simp [execute, h]
|
||
|
||
/-- BUDGET: grants cannot exceed balance -/
|
||
theorem grant_within_budget (s : TreasuryState) (op : TreasuryOp)
|
||
(recipient amount : Nat)
|
||
(h_type : op.opType = .grant recipient amount)
|
||
(h_approved : op.approved = true) :
|
||
(execute s op).balance ≤ s.balance := by
|
||
simp only [execute, h_approved, h_type, Bool.not_true, Bool.false_eq_true, if_false]
|
||
split <;> simp
|
||
|
||
/-- DEPOSIT INCREASES BALANCE -/
|
||
theorem deposit_increases (s : TreasuryState) (amount : Nat) :
|
||
(deposit s amount).balance = s.balance + amount := by
|
||
simp [deposit]
|
||
|
||
/-- TRANSPARENCY: executed ops are recorded -/
|
||
theorem executed_recorded (s : TreasuryState) (op : TreasuryOp)
|
||
(h : op.approved = true)
|
||
(recipient amount : Nat) (h_type : op.opType = .grant recipient amount)
|
||
(h_funds : amount ≤ s.balance) :
|
||
(execute s op).operations.length > s.operations.length := by
|
||
simp [execute, h, h_type, h_funds, List.length_cons]
|
||
|
||
/-- Empty treasury blocks all grants -/
|
||
theorem empty_blocks_grants (op : TreasuryOp)
|
||
(recipient amount : Nat) (h_type : op.opType = .grant recipient amount)
|
||
(h_amount : amount > 0) (h_approved : op.approved = true) :
|
||
execute ⟨0, 0, 0, 0, []⟩ op = ⟨0, 0, 0, 0, []⟩ := by
|
||
simp only [execute, h_approved, h_type, Bool.not_true, Bool.false_eq_true, if_false]
|
||
rw [if_neg (by omega)]
|
||
|
||
end Governance.Treasury
|