verifying-crypto-with-lean/preamble.tex
saymrwulf 45048d4898 Verifying Cryptography with Lean 4: complete 12-chapter curriculum
- 53-page LaTeX/TikZ book (main.pdf + full sources): from zero background
  to reading the real Ed25519/Pasta verification projects
- runnable exercises with sorry-holes + complete solutions for chapters
  2-7, 9, 12; every solution file compiles clean (zero errors, no sorry)
  against Lean v4.30.0-rc2 + Mathlib 5450b53e
- lake project pinned to the same toolchain/Mathlib the solutions were
  verified with; students fetch the Mathlib cache, never build it
- honesty ledger in README: what was machine-checked and how

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 09:44:40 +02:00

181 lines
9 KiB
TeX
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

% ============================================================================
% preamble.tex — shared style for "Verifying Cryptography with Lean 4"
% A didactic identity: warm ink on soft paper, one confident accent, and a
% small family of pedagogical boxes that each mean exactly one thing.
% ============================================================================
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[margin=2.4cm,headsep=0.6cm]{geometry}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning,shapes.geometric,calc,fit,backgrounds,decorations.pathreplacing,shapes.misc}
\usepackage[most]{tcolorbox}
\usepackage{listings}
\usepackage{microtype}
\usepackage{enumitem}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{booktabs}
\usepackage[strings]{underscore} % plain _ works in text; math subscripts unaffected
\usepackage{hyperref}
% ---- palette -------------------------------------------------------------
% Ink is a deep blue-slate; the accent is a warm coral used sparingly; a
% calm teal marks "things that are true / proven". Neutrals carry a faint
% blue bias so nothing reads as unconsidered grey.
\definecolor{ink}{HTML}{1C2430}
\definecolor{ink2}{HTML}{51607A}
\definecolor{paper}{HTML}{FBFAF7}
\definecolor{accent}{HTML}{E4572E} % coral — the one bold colour
\definecolor{accentsoft}{HTML}{FBE7DF}
\definecolor{proven}{HTML}{1E7F5C} % teal-green — proven / correct
\definecolor{provensoft}{HTML}{E1F1EA}
\definecolor{warn}{HTML}{B4690E} % amber — pitfalls
\definecolor{warnsoft}{HTML}{FBEFD8}
\definecolor{codebg}{HTML}{F3F1EC}
\definecolor{rule}{HTML}{DDE2E9}
\definecolor{kw}{HTML}{2B6CB0}
\definecolor{ty}{HTML}{6B46C1}
\definecolor{cmt}{HTML}{718096}
\definecolor{str}{HTML}{2F855A}
\hypersetup{colorlinks=true,linkcolor=accent,urlcolor=kw,citecolor=proven,
pdftitle={Verifying Cryptography with Lean 4},pdfauthor={Fable 5}}
% ---- page furniture ------------------------------------------------------
\pagecolor{paper}
\color{ink}
\pagestyle{fancy}\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[C]{\small\color{ink2}\thepage}
% single header element: chapter title only (no number prefix), no collisions
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead[R]{\small\color{ink2}\scshape\leftmark}
\titleformat{\section}{\Large\bfseries\color{ink}}{\color{accent}\thesection}{0.7em}{}
\titleformat{\subsection}{\large\bfseries\color{ink}}{\color{accent}\thesubsection}{0.6em}{}
\setlength{\parskip}{0.55em}\setlength{\parindent}{0pt}
% ---- listings: Lean 4 and Rust ------------------------------------------
\lstdefinelanguage{Lean}{
morekeywords={theorem,lemma,def,example,by,intro,intros,exact,apply,rw,simp,
omega,decide,ring,constructor,rfl,have,let,fun,match,with,end,namespace,
open,import,structure,inductive,instance,class,where,do,return,if,then,else,
sorry,cases,induction,unfold,calc,show,from,at,using,Prop,Type,Nat,Int,Bool,True,False},
sensitive=true,
morecomment=[l]{--},
morecomment=[s]{/-}{-/},
morestring=[b]",
}
\lstdefinelanguage{RustL}{
morekeywords={fn,let,mut,const,pub,struct,impl,for,in,if,else,match,return,
u8,u16,u32,u64,u128,usize,i32,bool,self,Self,use,mod,where,unsafe,as},
sensitive=true,
morecomment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]",
}
\lstset{
% render the Unicode symbols real Lean code uses
literate={}{{$\neq$}}1 {}{{$\forall$}}1 {}{{$\exists$}}1
{}{{$\to$}}1 {}{{$\leftrightarrow$}}1 {}{{$\wedge$}}1
{}{{$\vee$}}1 {¬}{{$\neg$}}1 {}{{$\leq$}}1 {}{{$\geq$}}1
{}{{$\mathbb{N}$}}1 {}{{$\mathbb{Z}$}}1 {}{{$\ell$}}1
{×}{{$\times$}}1 {}{{$\in$}}1 {}{{$\Sigma$}}1
{α}{{$\alpha$}}1 {β}{{$\beta$}}1 {}{{$\langle$}}1 {}{{$\rangle$}}1
{}{{$\mapsto$}}1 {}{{$\vdash$}}1 {𝔽}{{$\mathbb{F}$}}1
{}{{$_0$}}1 {}{{$_1$}}1 {}{{$_2$}}1 {²}{{$^2$}}1 {}{{$^5$}}1
{·}{{$\cdot$}}1 {}{{$\leftarrow$}}1 {}{{$[\![$}}1 {}{{$]\!]$}}1
{}{{$\circ$}}1 {}{{$\equiv$}}1 {}{{$\mid$}}1 {⁻¹}{{$^{-1}$}}1,
basicstyle=\ttfamily\small\color{ink},
keywordstyle=\color{kw}\bfseries,
commentstyle=\color{cmt}\itshape,
stringstyle=\color{str},
numberstyle=\ttfamily\scriptsize\color{ink2},
backgroundcolor=\color{codebg},
frame=single, framerule=0pt, framesep=8pt,
rulecolor=\color{codebg},
xleftmargin=10pt, xrightmargin=6pt,
breaklines=true, showstringspaces=false,
columns=fullflexible, keepspaces=true,
aboveskip=1em, belowskip=1em,
}
% Inline code: plain styled text (robust in tables/footnotes, unlike lstinline).
% Unicode symbols in inline code are handled by the declarations below.
\newcommand{\lean}[1]{{\ttfamily\small #1}}
\newcommand{\rust}[1]{{\ttfamily\small #1}}
\newcommand{\code}[1]{{\ttfamily\small #1}}
\DeclareUnicodeCharacter{2192}{\ensuremath{\to}} % →
\DeclareUnicodeCharacter{2190}{\ensuremath{\leftarrow}} % ←
\DeclareUnicodeCharacter{2194}{\ensuremath{\leftrightarrow}} % ↔
\DeclareUnicodeCharacter{2200}{\ensuremath{\forall}} % ∀
\DeclareUnicodeCharacter{2203}{\ensuremath{\exists}} % ∃
\DeclareUnicodeCharacter{2227}{\ensuremath{\wedge}} % ∧
\DeclareUnicodeCharacter{2228}{\ensuremath{\vee}} %
\DeclareUnicodeCharacter{00AC}{\ensuremath{\neg}} % ¬
\DeclareUnicodeCharacter{2260}{\ensuremath{\neq}} % ≠
\DeclareUnicodeCharacter{2264}{\ensuremath{\leq}} % ≤
\DeclareUnicodeCharacter{2265}{\ensuremath{\geq}} % ≥
\DeclareUnicodeCharacter{22A2}{\ensuremath{\vdash}} % ⊢
\DeclareUnicodeCharacter{00B7}{\ensuremath{\cdot}} % ·
\DeclareUnicodeCharacter{2115}{\ensuremath{\mathbb{N}}} %
\DeclareUnicodeCharacter{2124}{\ensuremath{\mathbb{Z}}} %
\DeclareUnicodeCharacter{2113}{\ensuremath{\ell}} %
\DeclareUnicodeCharacter{00D7}{\ensuremath{\times}} % ×
\DeclareUnicodeCharacter{2208}{\ensuremath{\in}} % ∈
\DeclareUnicodeCharacter{2211}{\ensuremath{\Sigma}} % ∑
\DeclareUnicodeCharacter{2261}{\ensuremath{\equiv}} % ≡
\DeclareUnicodeCharacter{2223}{\ensuremath{\mid}} %
\DeclareUnicodeCharacter{27E8}{\ensuremath{\langle}} % ⟨
\DeclareUnicodeCharacter{27E9}{\ensuremath{\rangle}} % ⟩
\DeclareUnicodeCharacter{1D53D}{\ensuremath{\mathbb{F}}} % 𝔽
\DeclareUnicodeCharacter{2080}{\ensuremath{{}_0}} % ₀
\DeclareUnicodeCharacter{2081}{\ensuremath{{}_1}} % ₁
\DeclareUnicodeCharacter{2082}{\ensuremath{{}_2}} % ₂
\DeclareUnicodeCharacter{00B2}{\ensuremath{{}^2}} % ²
\DeclareUnicodeCharacter{2075}{\ensuremath{{}^5}} % ⁵
% ---- pedagogical boxes: each means ONE thing ----------------------------
% BIG IDEA — the load-bearing concept of a section.
\newtcolorbox{bigidea}[1][]{enhanced,breakable,colback=accentsoft,
colframe=accent,boxrule=0.4pt,arc=3pt,left=10pt,right=10pt,top=8pt,bottom=8pt,
fonttitle=\bfseries\color{paper},coltitle=paper,title={\faLightbulb\ The big idea},#1}
% TRY IT — a hands-on invitation to run something.
\newtcolorbox{tryit}[1][]{enhanced,breakable,colback=codebg,colframe=ink2,
boxrule=0.4pt,arc=3pt,left=10pt,right=10pt,top=8pt,bottom=8pt,
fonttitle=\bfseries\color{paper},coltitle=paper,title={\faTerminal\ Try it yourself},#1}
% PITFALL — a trap, with its tell.
\newtcolorbox{pitfall}[1][]{enhanced,breakable,colback=warnsoft,colframe=warn,
boxrule=0.4pt,arc=3pt,left=10pt,right=10pt,top=8pt,bottom=8pt,
fonttitle=\bfseries\color{paper},coltitle=paper,title={\faExclamationTriangle\ Pitfall},#1}
% AHA — an intuition that clicks.
\newtcolorbox{aha}[1][]{enhanced,breakable,colback=provensoft,colframe=proven,
boxrule=0.4pt,arc=3pt,left=10pt,right=10pt,top=8pt,bottom=8pt,
fonttitle=\bfseries\color{paper},coltitle=paper,title={\faStar\ Aha},#1}
% CHECKPOINT — end-of-chapter self-check.
\newtcolorbox{checkpoint}[1][]{enhanced,breakable,colback=white,colframe=ink,
boxrule=0.6pt,arc=3pt,left=10pt,right=10pt,top=8pt,bottom=8pt,
fonttitle=\bfseries\color{paper},coltitle=paper,title={\faFlagCheckered\ Checkpoint},#1}
% Poor-man's icons (fontawesome may be absent): draw tiny glyphs with text.
\providecommand{\faLightbulb}{\raisebox{-1pt}{\small$\ast$}}
\providecommand{\faTerminal}{\raisebox{-1pt}{\small\ttfamily>\_}}
\providecommand{\faExclamationTriangle}{\raisebox{-1pt}{\small$\triangle$}}
\providecommand{\faStar}{\raisebox{-1pt}{\small$\star$}}
\providecommand{\faFlagCheckered}{\raisebox{-1pt}{\small$\bowtie$}}
% ---- math shortcuts the whole book uses ---------------------------------
\newcommand{\F}{\mathbb{F}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Fp}{\mathbb{F}_p}
\newcommand{\Zmod}[1]{\mathbb{Z}/#1\mathbb{Z}}
% double-bracket "denotation" delimiters without stmaryrd
\newcommand{\denote}[1]{\ensuremath{[\mkern-3.3mu[ #1 ]\mkern-3.3mu]}}
% exercises
\newcounter{exc}[section]
\newcommand{\exercise}[1]{\refstepcounter{exc}\smallskip\noindent%
{\bfseries\color{accent}Exercise \thechapter.\theexc.}\ #1\smallskip}