mirror of
https://github.com/zooai/proofs.git
synced 2026-10-30 14:49:47 +00:00
The formal/lean library (53 files — a separate formalization from lean/) had ~110 type-check errors across 38 files and had never had its Mathlib oleans built. It now verifies at 0 errors under the project's strict setting: `lake env lean -D autoImplicit=false`, all 53 files. Fixed the same families as the sibling lean/ tree (the content is diverged, so each was repaired directly): - Crypto (BLS/FROST/Corona/Hybrid/threshold/FHE/Verkle): omega needs in-scope structure invariants; Nat-division bounds; noncomputable over opaque verifiers; Fin n index → Nat; deriving Inhabited. - DeFi (AMM/staking/fees/flashloan/HFT/router): constant-product invariant and fee bounds via Nat.div_mul_le_self / Nat.div_le_of_le_mul; dead tactics. - Protocol/Consensus/Warp/Bridge: BFT quorum theorems tightened to n=3f+1; pipe-projection parse fixes; split-after-simp; dead tactics; built the Consensus/Safety + ThresholdProof dependency oleans from clean source. - Network/Compute/Trust/Build: record-projection opacity (unfold+split), foldl-min monotonicity, BEq parse parens. - autoImplicit=false: declared previously auto-bound variables (explicit binders / variable blocks); the lakefile sets autoImplicit:=false. Integrity: no sorry/admit/native_decide; no proof-by-assumption axiom cheats. Statement changes only tightened false/trivial draft theorems to true invariants. Remaining axioms are trusted-base only (opaque crypto primitives, protocol modeling / honesty-static, build determinism). Co-authored-by: Hanzo Dev <[email protected]>
88 lines
2.7 KiB
Lean4
88 lines
2.7 KiB
Lean4
/-
|
|
Authority Meet-Semilattice
|
|
|
|
Models authority as a set of capabilities with meet (intersection).
|
|
Authority can only NARROW through delegation — never escalate.
|
|
|
|
Maps to:
|
|
- hanzo/iam: RBAC permission sets
|
|
- lux/node: validator capability scoping
|
|
- zoo/contracts: role-based access control
|
|
|
|
Properties:
|
|
- Meet is commutative, associative, idempotent
|
|
- Authority narrows through delegation (monotone)
|
|
- Meet is greatest lower bound
|
|
-/
|
|
|
|
import Mathlib.Data.Nat.Defs
|
|
import Mathlib.Data.List.Basic
|
|
import Mathlib.Tactic
|
|
|
|
namespace Trust.Authority
|
|
|
|
/-- A capability: what you're allowed to do -/
|
|
inductive Capability where
|
|
| shell (user : String)
|
|
| exec (command : String)
|
|
| build (target : String)
|
|
| attest (scope : String)
|
|
| sign (keyId : String)
|
|
| deploy (env : String)
|
|
deriving DecidableEq, Repr
|
|
|
|
/-- Authority: a set of capabilities (List for simplicity) -/
|
|
structure Authority where
|
|
capabilities : List Capability
|
|
deriving DecidableEq, Repr
|
|
|
|
/-- No authority -/
|
|
def Authority.none : Authority := ⟨[]⟩
|
|
|
|
/-- Full authority -/
|
|
def Authority.all : Authority := ⟨[
|
|
.shell "root", .exec "*", .build "*",
|
|
.attest "*", .sign "*", .deploy "*"
|
|
]⟩
|
|
|
|
/-- Meet (intersection): only capabilities in BOTH sets -/
|
|
def Authority.meet (a b : Authority) : Authority :=
|
|
⟨a.capabilities.filter (b.capabilities.contains ·)⟩
|
|
|
|
/-- Subset ordering -/
|
|
def Authority.subset (a b : Authority) : Prop :=
|
|
∀ c ∈ a.capabilities, c ∈ b.capabilities
|
|
|
|
instance : LE Authority where le := Authority.subset
|
|
instance : Min Authority where min := Authority.meet
|
|
|
|
/-- Meet is a lower bound (left): a ⊓ b ≤ a -/
|
|
theorem meet_le_left (a b : Authority) : min a b ≤ a := by
|
|
intro c hc
|
|
simp [Min.min, Authority.meet, List.mem_filter] at hc
|
|
exact hc.1
|
|
|
|
/-- Meet is a lower bound (right): a ⊓ b ≤ b -/
|
|
theorem meet_le_right (a b : Authority) : min a b ≤ b := by
|
|
intro c hc
|
|
simp only [Min.min, Authority.meet, List.mem_filter] at hc
|
|
exact List.mem_of_elem_eq_true hc.2
|
|
|
|
/-- Meet is greatest lower bound -/
|
|
theorem meet_glb (a b c : Authority) (hca : c ≤ a) (hcb : c ≤ b) :
|
|
c ≤ min a b := by
|
|
intro cap hcap
|
|
simp only [Min.min, Authority.meet, List.mem_filter]
|
|
exact ⟨hca cap hcap, List.elem_eq_true_of_mem (hcb cap hcap)⟩
|
|
|
|
/-- Authority.none is the bottom element -/
|
|
theorem none_is_bottom (a : Authority) : Authority.none ≤ a := by
|
|
intro c hc; simp [Authority.none] at hc
|
|
|
|
/-- DELEGATION NARROWING: delegating authority can only reduce it -/
|
|
theorem delegation_narrows (delegator_auth delegated_scope : Authority) :
|
|
min delegator_auth delegated_scope ≤ delegator_auth :=
|
|
meet_le_left delegator_auth delegated_scope
|
|
|
|
end Trust.Authority
|