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]>
104 lines
3.4 KiB
Lean4
104 lines
3.4 KiB
Lean4
/-
|
|
Authors: Antje Worring, Zach Kelling
|
|
|
|
Liquid Staking and Yield Protocol
|
|
|
|
Staked assets earn yield while remaining liquid.
|
|
Money at rest is put to work — implicit staking of
|
|
idle liquidity in the DEX pools.
|
|
|
|
Maps to:
|
|
- lux/node: validator staking (P-Chain)
|
|
- lux/exchange: LP staking rewards
|
|
- zoo/contracts: liquid staking derivatives
|
|
|
|
Properties:
|
|
- Yield accrual: staked assets earn validator rewards
|
|
- Liquidity: staked assets remain tradeable (liquid derivatives)
|
|
- No impermanent loss on single-sided staking
|
|
- Compounding: rewards auto-compound into staking position
|
|
|
|
Author: Zach Kelling (December 2025)
|
|
-/
|
|
|
|
import Mathlib.Data.Nat.Defs
|
|
import Mathlib.Tactic
|
|
|
|
namespace DeFi.LiquidStaking
|
|
|
|
/-- Staking position -/
|
|
structure Position where
|
|
principal : Nat -- original staked amount
|
|
accrued : Nat -- accumulated rewards
|
|
compounded : Nat -- rewards that have been re-staked
|
|
liquidDerivatives : Nat -- tradeable staking receipt tokens
|
|
stakeDuration : Nat -- blocks staked
|
|
|
|
/-- Yield rate: annual percentage in basis points (e.g., 500 = 5%) -/
|
|
def annualYieldBps : Nat := 500 -- 5% APY baseline
|
|
|
|
/-- Per-block yield (simplified: annual / ~2.6M blocks per year) -/
|
|
def blockYield (principal : Nat) : Nat :=
|
|
principal * annualYieldBps / 26000000
|
|
|
|
/-- Accrue one block of yield -/
|
|
def accrueBlock (p : Position) : Position :=
|
|
let yield := blockYield (p.principal + p.compounded)
|
|
{ p with accrued := p.accrued + yield
|
|
, stakeDuration := p.stakeDuration + 1 }
|
|
|
|
/-- Compound: move accrued rewards into principal -/
|
|
def compound (p : Position) : Position :=
|
|
{ p with compounded := p.compounded + p.accrued
|
|
, accrued := 0 }
|
|
|
|
/-- YIELD ACCRUAL: Accrued rewards only increase -/
|
|
theorem yield_monotone (p : Position) :
|
|
(accrueBlock p).accrued ≥ p.accrued := by
|
|
simp [accrueBlock]
|
|
|
|
/-- LIQUIDITY: Liquid derivatives equal principal (1:1 mint) -/
|
|
def mintDerivatives (p : Position) : Position :=
|
|
{ p with liquidDerivatives := p.principal }
|
|
|
|
theorem derivatives_equal_principal (p : Position) :
|
|
(mintDerivatives p).liquidDerivatives = p.principal := by
|
|
simp [mintDerivatives]
|
|
|
|
/-- COMPOUNDING: After compound, accrued resets to 0 -/
|
|
theorem compound_resets_accrued (p : Position) :
|
|
(compound p).accrued = 0 := by
|
|
simp [compound]
|
|
|
|
/-- COMPOUNDING: After compound, compounded increases -/
|
|
theorem compound_increases_base (p : Position) :
|
|
(compound p).compounded ≥ p.compounded := by
|
|
simp [compound]
|
|
|
|
/-- NO IMPERMANENT LOSS: Single-sided staking has no IL.
|
|
Unlike LP positions, staked assets don't change ratio. -/
|
|
theorem no_impermanent_loss (p : Position) :
|
|
(accrueBlock p).principal = p.principal := by
|
|
simp [accrueBlock]
|
|
|
|
/-- DURATION MONOTONE: Stake duration only increases -/
|
|
theorem duration_monotone (p : Position) :
|
|
(accrueBlock p).stakeDuration > p.stakeDuration := by
|
|
simp [accrueBlock]
|
|
|
|
/-- TOTAL VALUE: principal + compounded + accrued -/
|
|
def totalValue (p : Position) : Nat :=
|
|
p.principal + p.compounded + p.accrued
|
|
|
|
/-- TOTAL VALUE MONOTONE: Accruing never decreases total -/
|
|
theorem value_monotone (p : Position) :
|
|
totalValue (accrueBlock p) ≥ totalValue p := by
|
|
simp [totalValue, accrueBlock]
|
|
|
|
/-- MONEY AT REST: Idle liquidity earns yield.
|
|
DEX pool deposits implicitly stake via the liquid staking layer. -/
|
|
theorem idle_earns (p : Position) (_h : p.principal > 0) :
|
|
totalValue (accrueBlock p) ≥ totalValue p := value_monotone p
|
|
|
|
end DeFi.LiquidStaking
|