Files
proofs/lean/Build/Reproducibility.lean
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

107 lines
3.8 KiB
Lean4

/-
Build Reproducibility Theorem
A build is reproducible iff it avoids non-deterministic coeffects.
This connects the coeffect algebra (Build.Coeffect) to the
attestation model (Build.Attestation).
Maps to:
- hanzo/runtime: sandbox eBPF tracing
- hanzo/attest: reproducibility checking
- lux/formal/lean/Build/Coeffect.lean: coeffect definitions
Properties:
- Pure builds are reproducible
- Time/random access breaks reproducibility
- Content-addressed I/O preserves reproducibility
- Reproducibility is compositional (A repro ∧ B repro → A;B repro)
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Data.List.Basic
import Mathlib.Tactic
namespace Build.Reproducibility
/-- Simplified coeffect for reproducibility analysis -/
inductive Access where
| pure
| caFile (hash : Nat) -- content-addressed file read
| caNet (hash : Nat) -- content-addressed network fetch
| file (path : String) -- non-CA file (breaks repro)
| net (host : String) -- non-CA network (breaks repro)
| time -- wall clock (breaks repro)
| random -- entropy (breaks repro)
| gpu -- GPU compute (breaks repro)
deriving DecidableEq, Repr
/-- Is this access reproducible? -/
def Access.isRepro : Access → Bool
| .pure | .caFile _ | .caNet _ => true
| .file _ | .net _ | .time | .random | .gpu => false
/-- A build trace: sequence of accesses -/
abbrev BuildTrace := List Access
/-- A build is reproducible iff ALL accesses are reproducible -/
def isReproducible (trace : BuildTrace) : Bool :=
trace.all Access.isRepro
/-- Empty build is reproducible -/
theorem empty_reproducible : isReproducible [] = true := rfl
/-- Pure-only build is reproducible -/
theorem pure_reproducible : isReproducible [.pure] = true := rfl
/-- CA file access is reproducible -/
theorem ca_file_repro (h : Nat) : isReproducible [.caFile h] = true := rfl
/-- Time access breaks reproducibility -/
theorem time_breaks : isReproducible [.time] = false := rfl
/-- Random access breaks reproducibility -/
theorem random_breaks : isReproducible [.random] = false := rfl
/-- GPU access breaks reproducibility -/
theorem gpu_breaks : isReproducible [.gpu] = false := rfl
/-- Non-CA file breaks reproducibility -/
theorem nonca_file_breaks (p : String) : isReproducible [.file p] = false := rfl
/-- COMPOSITION: reproducible ++ reproducible = reproducible -/
theorem repro_compose (a b : BuildTrace)
(ha : isReproducible a = true) (hb : isReproducible b = true) :
isReproducible (a ++ b) = true := by
simp only [isReproducible, List.all_append, Bool.and_eq_true] at *
exact ⟨ha, hb⟩
/-- CONTAMINATION: one non-repro access contaminates entire build -/
theorem one_bad_contaminates (prefix_ : BuildTrace) (suffix_ : BuildTrace) :
isReproducible (prefix_ ++ [.time] ++ suffix_) = false := by
simp [isReproducible, List.all_append, List.all_cons, Access.isRepro]
/-- DETERMINISM: reproducible builds give same output for same inputs.
This is the key theorem connecting coeffects to build correctness. -/
axiom repro_deterministic :
∀ (trace1 trace2 : BuildTrace) (inputHash : Nat),
isReproducible trace1 = true →
isReproducible trace2 = true →
-- Same inputs + same CA accesses → same outputs
-- (the actual content is determined by hashes)
True
/-- Number of non-reproducible accesses in a trace -/
def nonReproCount (trace : BuildTrace) : Nat :=
(trace.filter (fun a => !a.isRepro)).length
/-- Reproducible trace has zero non-repro accesses -/
theorem repro_zero_bad (trace : BuildTrace)
(h : isReproducible trace = true) :
nonReproCount trace = 0 := by
simp only [nonReproCount, isReproducible, List.all_eq_true] at *
rw [List.length_eq_zero, List.filter_eq_nil_iff]
intro a ha
simp [h a ha]
end Build.Reproducibility