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]>
73 lines
2.1 KiB
Lean4
73 lines
2.1 KiB
Lean4
/-
|
|
Authors: Antje Worring, Zach Kelling
|
|
|
|
DeFi Fee Model
|
|
|
|
Maker-taker with volume tiers. Permissionless.
|
|
No regulatory fee caps (pure DeFi).
|
|
|
|
Maps to:
|
|
- lux/exchange: fee calculation
|
|
- lux/node: fee distribution to validators
|
|
|
|
Properties:
|
|
- Makers ≤ takers (incentivize liquidity)
|
|
- Volume tiers: more volume → lower fees
|
|
- Validator revenue: portion of fees to validators
|
|
- Permissionless: fee schedule is on-chain and transparent
|
|
|
|
Authors: Zach Kelling (Dec 2025), Woo Bin (Mar 2026)
|
|
-/
|
|
|
|
import Mathlib.Data.Nat.Defs
|
|
import Mathlib.Tactic
|
|
|
|
namespace DeFi.FeeModel
|
|
|
|
/-- Fee tier -/
|
|
structure FeeTier where
|
|
minVolume : Nat
|
|
makerBps : Nat
|
|
takerBps : Nat
|
|
deriving DecidableEq, Repr, Inhabited
|
|
|
|
/-- Standard DeFi tiers -/
|
|
def tiers : List FeeTier :=
|
|
[ ⟨0, 15, 30⟩ -- Tier 1
|
|
, ⟨1000000, 10, 25⟩ -- Tier 2: $1M+
|
|
, ⟨10000000, 5, 15⟩ -- Tier 3: $10M+
|
|
, ⟨100000000, 0, 10⟩ -- Tier 4: $100M+ (zero maker)
|
|
]
|
|
|
|
/-- Calculate fee -/
|
|
def fee (tier : FeeTier) (isMaker : Bool) (value : Nat) : Nat :=
|
|
value * (if isMaker then tier.makerBps else tier.takerBps) / 10000
|
|
|
|
/-- MAKER ≤ TAKER -/
|
|
theorem maker_le_taker (t : FeeTier) (v : Nat) (h : t.makerBps ≤ t.takerBps) :
|
|
fee t true v ≤ fee t false v := by
|
|
simp [fee]; exact Nat.div_le_div_right (Nat.mul_le_mul_left v h)
|
|
|
|
/-- TOP TIER ZERO MAKER -/
|
|
theorem top_tier_zero : (tiers[3]!).makerBps = 0 := by simp [tiers]
|
|
|
|
/-- VOLUME DISCOUNT -/
|
|
theorem volume_discount : (tiers[0]!).takerBps > (tiers[3]!).takerBps := by
|
|
simp [tiers]
|
|
|
|
/-- 4 TIERS -/
|
|
theorem four_tiers : tiers.length = 4 := rfl
|
|
|
|
/-- VALIDATOR SHARE: Portion of fees goes to validators who process trades -/
|
|
def validatorShare (totalFee : Nat) (validatorPct : Nat) : Nat :=
|
|
totalFee * validatorPct / 100
|
|
|
|
theorem validator_bounded (totalFee pct : Nat) (h : pct ≤ 100) :
|
|
validatorShare totalFee pct ≤ totalFee := by
|
|
simp only [validatorShare]
|
|
apply Nat.div_le_of_le_mul
|
|
calc totalFee * pct ≤ totalFee * 100 := Nat.mul_le_mul_left _ h
|
|
_ = 100 * totalFee := Nat.mul_comm _ _
|
|
|
|
end DeFi.FeeModel
|