Files
2d7e2a6309 proofs: drive Lean library to 0 errors, eliminate native_decide
The lean/ library (112 files) had ~110 type-check errors across 52 files (the
prior "green" status was a grep artifact). It now verifies at 0 errors under
the project's strict setting: `lake env lean -D autoImplicit=false`, all 112
files.

Fixed:
- Quasar/Consensus: replaced `by native_decide` with `by decide` (kernel-checked
  rather than compiler-trusted).
- Vault/KeyIsolation, Bridge/{YieldVault,OmnichainRouter,FillIntegrity},
  Storage/{ZapDB,Replicate}: PRF/string-encoding lemmas, division-bound vault
  accounting, renamed/removed deprecated List lemmas, noncomputable.
- Crypto (Pulsar/Magnetar/Corona/CGGMP21/MLKEM/FROST/FHE/P3Q): missing local
  dependency oleans compiled in dependency order; theorem→noncomputable def for
  Type-valued re-exports; deriving Inhabited for opaque artifact types; dead
  Mathlib imports removed.
- DeFi (AMM/staking/fees/flashloan/HFT/router) + Protocol + GPU + Warp + Trust +
  Compute + Network + Build: Nat-division/AMM-invariant proofs via
  Nat.div_le_of_le_mul / Nat.div_mul_le_self; omega in-scope invariants;
  record-projection opacity; dead tactics; stale Nat.Basic import → Nat.Defs;
  BFT quorum theorems tightened to n=3f+1.

Integrity: no sorry/admit/native_decide remaining (verified); no
proof-by-assumption axiom cheats. Statement changes only tightened false draft
theorems to true invariants. Remaining axioms are trusted-base only (opaque
crypto groups/pairings, RLWE/MLWE/MSIS hardness, FIPS 203/204/205 correctness,
VSS/Paillier, protocol modeling).

Co-authored-by: Hanzo Dev <[email protected]>
2026-06-10 22:34:27 -07:00

104 lines
3.5 KiB
Lean4

/-
Vouch-Based Trust Model
No CA. No global root. Trust flows through attestation chains.
Each vouch bounds the scope of delegated authority.
Maps to:
- hanzo/iam: attestation chains
- lux/node: validator vouch graph
- zoo/contracts: role endorsements
Properties:
- Chain authority is monotonically decreasing
- Unrecognized keys have no authority
- Vouch signatures bind ALL security-relevant fields
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Data.List.Basic
import Mathlib.Tactic
namespace Trust.Vouch
/-- Recognition level: how much we trust this key -/
inductive RecognitionLevel where
| unrecognized -- No trust path
| vouched -- Vouched by someone trusted
| direct -- Directly trusted (root)
deriving DecidableEq, Repr
def RecognitionLevel.rank : RecognitionLevel → Nat
| .unrecognized => 0
| .vouched => 1
| .direct => 2
/-- Unrecognized is minimum recognition -/
theorem unrecognized_min (r : RecognitionLevel) :
RecognitionLevel.rank .unrecognized ≤ RecognitionLevel.rank r := by
cases r <;> simp [RecognitionLevel.rank]
/-- A vouch: one key vouches for another with bounded scope.
The signature MUST bind all fields to prevent replay attacks. -/
structure Vouch where
voucher : Nat -- voucher's public key (abstract)
vouchee : Nat -- who is being vouched for
scope : Nat -- authority bound (abstract)
expires : Nat -- expiry timestamp
/-- Vouch chain authority: foldl min over scope values.
Authority can only NARROW through delegation. -/
def chainAuthority (chain : List Vouch) (top : Nat) : Nat :=
chain.foldl (fun acc v => min acc v.scope) top
/-- foldl over `min · scope` is monotone in its starting accumulator -/
theorem foldl_min_mono (l : List Vouch) : ∀ a b : Nat, a ≤ b →
l.foldl (fun acc v => min acc v.scope) a ≤
l.foldl (fun acc v => min acc v.scope) b := by
induction l with
| nil => intro a b h; simpa using h
| cons hd tl ih =>
intro a b h
simp only [List.foldl_cons]
exact ih _ _ (min_le_min h (le_refl hd.scope))
/-- Adding a vouch can only reduce authority -/
theorem chain_authority_monotone (chain : List Vouch) (v : Vouch) (top : Nat) :
chainAuthority (v :: chain) top ≤ chainAuthority chain top := by
simp only [chainAuthority, List.foldl_cons]
exact foldl_min_mono chain _ _ (Nat.min_le_left top v.scope)
/-- Empty chain gives full authority -/
theorem empty_chain_full (top : Nat) :
chainAuthority [] top = top := by
simp [chainAuthority]
/-- Chain authority is bounded by top -/
theorem chain_bounded (chain : List Vouch) (top : Nat) :
chainAuthority chain top ≤ top := by
induction chain generalizing top with
| nil => simp [chainAuthority]
| cons hd tl ih =>
simp [chainAuthority, List.foldl_cons]
calc chainAuthority tl (min top hd.scope)
≤ min top hd.scope := ih (min top hd.scope)
_ ≤ top := Nat.min_le_left top hd.scope
/-- Chain authority is bounded by every vouch's scope -/
theorem chain_bounded_by_scope (chain : List Vouch) (top : Nat) (v : Vouch)
(hv : v ∈ chain) :
chainAuthority chain top ≤ v.scope := by
induction chain generalizing top with
| nil => exact absurd hv (List.not_mem_nil _)
| cons hd tl ih =>
simp [chainAuthority, List.foldl_cons]
cases List.mem_cons.mp hv with
| inl h =>
subst h
calc chainAuthority tl (min top v.scope)
≤ min top v.scope := chain_bounded tl _
_ ≤ v.scope := Nat.min_le_right top v.scope
| inr h => exact ih (min top hd.scope) h
end Trust.Vouch