Files
zooqueenandHanzo Dev ac9676a47a proofs: drive formal/lean library to 0 errors
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]>
2026-06-02 09:31:40 -07:00

105 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-min is monotone in the starting accumulator -/
theorem foldl_min_mono (chain : List Vouch) : ∀ {a b : Nat}, a ≤ b →
chain.foldl (fun acc v => min acc v.scope) a ≤
chain.foldl (fun acc v => min acc v.scope) b := by
induction chain with
| nil => intro a b h; simpa using h
| cons hd tl ih =>
intro a b h
simp only [List.foldl_cons]
exact ih (by omega)
/-- 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 =>
rw [List.mem_cons] at hv
simp only [chainAuthority, List.foldl_cons]
cases 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