Files
proofs/lean/Build/Reproducibility.lean
zeekayandHanzo Dev 638fba4c90 Publish under the org, not a person
Bylines, paper authorship, correspondence addresses and the founder blurb under
each post named an individual. They name the organisation that published the
work instead: the brand on posts and pages, the research byline on papers, and
research@ in place of a personal address. Both are what these repositories
already used elsewhere — nothing new was coined.

Co-authors are untouched. Where a paper named someone else alongside, they stay
named; only the one byline changed. Bibliography entries, running heads,
PDF metadata and affiliations move with it, so a citation still resolves to
whoever the cited paper names.

Sample and fixture data uses the placeholder name these tests already use
elsewhere, so no assertion changed meaning.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-01 08:58:14 -07:00

109 lines
3.8 KiB
Lean4

/-
Authors: Antje Worring, Zoo Labs Foundation Research
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]
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
rw [isReproducible, List.all_eq_true] at h
rw [nonReproCount, List.length_eq_zero, List.filter_eq_nil_iff]
intro a ha
simp [h a ha]
end Build.Reproducibility