# Check it yourself: What 'Lean-verified' means

Don't take our word for it. Each result here comes with its files and a check guide, and each guide says which checks you can rerun yourself. Some results rest on logs from programs that are not part of this book, or on files available on request; the guide says which. Where your run matches ours, you checked that part rather than trusted it. If something breaks, confuses you or does not match, you are welcome to tell us. We fix mistakes in the open and credit the person who found them. Why a recipe and not our program: https://gocheckyourself.org/how-to-check/

You do not have to trust our results or our programs. This page tells you, step by step, how to check the published files with tools you already have. The full written recipe is the chapter 'Check it yourself: what "Lean-verified" covers' in https://gocheckyourself.org/text/lean-verified-experts.txt.

Every step has the command for Windows PowerShell and for macOS or Linux (bash), the output you should see, and a plain sentence on what a match means and what it does not. If your output is different, the step has failed; do not skip it.

You need: a command line, and Python 3.8 or later (python on Windows, python3 on macOS or Linux) for the steps that run a script. Windows PowerShell 5.1 or later (pwsh also works). Scripts are short; read them before you run them.

## What is known not to work today

- The seven demonstration files are in the book's demos folder (demos/Demo/*.lean); step 3 downloads them, and chapter 3 of the text edition prints each one in full.
- Every demonstration needs Lean (elan). The chapter says leanchecker --fresh takes about 100 seconds and 1 GB per demo; the nanoda step needs Lean 4.35.0 and its own tools. None of this was run here.

## Step 1: Make an empty working folder and say where the files are.

Windows PowerShell:

```powershell
$ProgressPreference = "SilentlyContinue"
$BASE = "https://gocheckyourself.org/data/files/lean-verified"
New-Item -ItemType Directory -Force check-lean-verified | Out-Null
Set-Location check-lean-verified
```

macOS or Linux (bash):

```bash
BASE="https://gocheckyourself.org/data/files/lean-verified"
mkdir -p check-lean-verified && cd check-lean-verified
```

You should see:

```
No output.
```

What a match shows, and what it does not: Nothing; this just makes a folder.

Cost: instant.

## Step 2: Download the list of fingerprints (SHA-256) that the book publishes for its files.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/lean-verified/certificates/SHA256SUMS.txt  ffcf1c2c7578280fae9a3f7b90fda3065fdcbd6ded07bbe55da9cf407190cd1d

Windows PowerShell:

```powershell
New-Item -ItemType Directory -Force certificates | Out-Null
Invoke-WebRequest -UseBasicParsing -UserAgent "Mozilla/5.0" "$BASE/certificates/SHA256SUMS.txt" -OutFile certificates/SHA256SUMS.txt
```

macOS or Linux (bash):

```bash
mkdir -p certificates
curl -fsSL "$BASE/certificates/SHA256SUMS.txt" -o certificates/SHA256SUMS.txt
```

You should see:

```
No output. The file certificates/SHA256SUMS.txt exists. Each line is 64 hex digits, a space, an optional star, and a file path.
```

What a match shows, and what it does not: The list comes from the same site as the files, so by itself it just catches damaged or swapped files, not a site that lies in both places. Compare the list's own SHA-256 (see inputs) with a copy you trust, such as one a friend keeps, or one kept anywhere other than this site.

Cost: instant.

## Step 3: Download the build files (lean-verified-lean.zip), unpack them as a folder called lean next to certificates, and download the seven demonstration files into demos/Demo.

Files used (SHA-256):
- lean-verified-lean.zip, in the book's downloads folder (its address is in the commands below)  5b6d730ccf9ad8c464d49ba19e2e4f503b83aac21ef29552d78cd1d23aa7591c

Windows PowerShell:

```powershell
New-Item -ItemType Directory -Force downloads | Out-Null
$DL = $BASE + '/downloads'
Invoke-WebRequest -UseBasicParsing -UserAgent "Mozilla/5.0" "$DL/lean-verified-lean.zip" -OutFile downloads/lean-verified-lean.zip
"zip sha256: " + (Get-FileHash -Algorithm SHA256 downloads/lean-verified-lean.zip).Hash.ToLower()
Expand-Archive -Force downloads/lean-verified-lean.zip -DestinationPath .
if (Test-Path lean) { Remove-Item -Recurse -Force lean }
Rename-Item lean-verified-lean lean
New-Item -ItemType Directory -Force demos/Demo | Out-Null
foreach ($n in "AddedAxiom","Honest","RedefinedPlus","SkipKernelTC","SmallerNumberSystem","UsesSorry","WrongDefinition") { Invoke-WebRequest -UseBasicParsing -UserAgent "Mozilla/5.0" "$BASE/demos/Demo/$n.lean" -OutFile "demos/Demo/$n.lean" }
```

macOS or Linux (bash):

```bash
mkdir -p downloads
DL="$BASE"'/downloads'
curl -fsSL "$DL/lean-verified-lean.zip" -o downloads/lean-verified-lean.zip
echo "zip sha256: $( (sha256sum downloads/lean-verified-lean.zip 2>/dev/null || shasum -a 256 downloads/lean-verified-lean.zip) | cut -c1-64 )"
unzip -q -o downloads/lean-verified-lean.zip
rm -rf lean; mv lean-verified-lean lean
mkdir -p demos/Demo
for n in AddedAxiom Honest RedefinedPlus SkipKernelTC SmallerNumberSystem UsesSorry WrongDefinition; do curl -fsSL "$BASE/demos/Demo/$n.lean" -o "demos/Demo/$n.lean"; done
```

You should see:

```
zip sha256: 5b6d730ccf9ad8c464d49ba19e2e4f503b83aac21ef29552d78cd1d23aa7591c
```

What a match shows, and what it does not: The zip is not in the fingerprint list, so its hash is given here and in the machine-readable file; compare it with a copy you trust.

Cost: seconds.

## Step 4: Compare the SHA-256 fingerprint of every downloaded file with the published list.

Files used (SHA-256):
- https://gocheckyourself.org/data/files/lean-verified/certificates/SHA256SUMS.txt  ffcf1c2c7578280fae9a3f7b90fda3065fdcbd6ded07bbe55da9cf407190cd1d

Windows PowerShell:

```powershell
$ok = 0; $bad = 0
Get-Content certificates/SHA256SUMS.txt | Where-Object { $_.Trim() } | ForEach-Object {
  $h = $_.Substring(0,64).ToLower()
  $rel = ($_ -replace '^[0-9a-fA-F]{64} [ *]','') -replace '^\./',''
  $f = Get-FileHash -Algorithm SHA256 -LiteralPath $rel -ErrorAction SilentlyContinue
  if ($f -and $f.Hash.ToLower() -eq $h) { $ok++ } else { $bad++; "NOT OK: $rel" }
}
"$ok OK, $bad not OK"
```

macOS or Linux (bash):

```bash
# Linux: sha256sum.  macOS: use "shasum -a 256 -c" instead of "sha256sum -c".
if command -v sha256sum >/dev/null; then C="sha256sum -c"; else C="shasum -a 256 -c"; fi
$C certificates/SHA256SUMS.txt 2>&1 | grep -v ": OK$" ; echo "$($C certificates/SHA256SUMS.txt 2>/dev/null | grep -c ": OK$") OK"
```

You should see:

```
PowerShell prints the line "10 OK, 0 not OK". bash prints "10 OK" and nothing else.
```

What a match shows, and what it does not: A match shows that your files are exactly the files the list names. What the files say is tested by the other steps of this recipe. 

Cost: seconds.

## Step 5: HEAVY: for each demo name run the three Lean commands (needs Lean through elan, and the seven demonstration files from step 3 in demos/Demo/).

Commands (same on both platforms; not run by us unless stated):

```
# from the lean folder of the book, for each of: Honest AddedAxiom UsesSorry SmallerNumberSystem RedefinedPlus WrongDefinition SkipKernelTC
lake build Demo.<Name>
lake env leanchecker Demo.<Name>
lake env leanchecker --fresh Demo.<Name>
```

You should see:

```
Per the chapter's table: the build prints the axiom report; leanchecker prints nothing and exits 0 when it accepts (exit 1 and a message when it rejects; the kernel-check-off demo is rejected).
```

What a match shows, and what it does not: It shows which check catches which kind of fault in a small file. It shows nothing about other files.

Cost: about 100 seconds and 1 GB per demo for the fresh mode.

