Seal.lean
Lean 4 source, lean/DataMiningAsObservation/Seal.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
Seal.lean. Chapter 0 section 0.12 and chapter 8 section 8.8, the seal.
A seal records a commit and the hash of a file. A later reader recomputes the hash. If the
two hashes differ the file has changed, since a hash is a function of its input. If they
agree the reader has evidence and not proof, since a fixed-length digest of longer inputs
cannot be injective. Both halves are checked here for an arbitrary hash function.
-/
import Mathlib
namespace DMO.Seal
variable {File Digest : Type*}
/-- **A changed hash proves a changed file.** -/
theorem changed_of_hash_ne (h : File → Digest) {a b : File} (hne : h a ≠ h b) : a ≠ b :=
fun e => hne (congrArg h e)
/-- An unchanged file has an unchanged hash, so the seal never accuses an untouched file. -/
theorem hash_eq_of_eq (h : File → Digest) {a b : File} (e : a = b) : h a = h b :=
congrArg h e
/-- **An equal hash is evidence, not proof.** Any digest with fewer values than there are
files sends two distinct files to the same digest. -/
theorem exists_collision [Fintype File] [Fintype Digest] (h : File → Digest)
(hcard : Fintype.card Digest < Fintype.card File) : ∃ a b : File, a ≠ b ∧ h a = h b :=
Fintype.exists_ne_map_eq_of_card_lt h hcard
end DMO.Seal