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
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
---
license: mpl-2.0
library_name: custom
tags:
- code
- sovereign-compute
- snapkitty
- machine-learning
- lean4
- python
---

> Source: [github.com/SNAPKITTYWEST/lean-llm-starter](https://github.com/SNAPKITTYWEST/lean-llm-starter)

# Lean LLM Starter

<p align="center">
  <img
    src="docs/assets/lean-llm-starter-hero.png"
    alt="Lean LLM Starter β€” deterministic Lean 4 verification for LLM-generated proofs"
    width="100%"
  />
</p>

<p align="center">
  <strong>LLMs propose. Lean verifies.</strong>
</p>

A deterministic Lean 4 verification harness for LLM-generated proofs.

This repository treats the language model as an **untrusted proposal engine** and Lean 4 as the **trusted verification kernel**.

The model may suggest a proof.

Lean decides whether the proof is valid.

```text
Operator Intent
      ↓
Prolog Authorization Gate
      ↓
LLM Proof Proposal
      ↓
Schema Validation
      ↓
Lean 4 Parse and Verification
      ↓
Verified Artifact or Deterministic Rejection
```

## Purpose

Most LLM proof systems rely too heavily on the model's own output.

This repository uses a stricter trust boundary:

* The LLM proposes proof artifacts
* Prolog enforces execution and authorization rules
* Lean 4 parses and verifies the proof
* Invalid or incomplete proofs are rejected
* Verification results can be exported into WORM-ready audit records

The goal is not to trust generated mathematics.

The goal is to verify it.

## Architecture

### Lean 4

The Lean layer is the trusted mathematical kernel.

It is responsible for:

* Parsing generated proof artifacts
* Validating theorem structure
* Rejecting unsupported syntax
* Blocking `sorry`
* Rejecting malformed Lean 3 syntax
* Type-checking submitted proofs
* Producing deterministic verification results

### Prolog

The Prolog layer acts as the governance and control surface.

It is responsible for:

* Authorization checks
* Schema validation
* Retry control
* Verification routing
* Execution policy
* Rejection of unauthorized runs

### LLM Inference

The inference layer is intentionally untrusted.

It may use Granite, Llemma, llama.cpp-compatible servers, vLLM-compatible backends, or another local model.

Its only job is to propose proof steps in the expected schema.

It does not determine correctness.

### Evaluation Harness

The evaluation layer runs generated proofs through the Lean kernel and records whether they pass or fail.

The included harness supports MiniF2F-style theorem evaluation and local reproducibility.

## Repository Structure

```text
lean-llm-starter/
β”œβ”€β”€ eval/
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── run_minif2f.py
β”œβ”€β”€ fixtures/
β”‚   └── sample_input.jsonl
β”œβ”€β”€ inference/
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ prompt.txt
β”‚   └── server.py
β”œβ”€β”€ infra/
β”‚   └── verification-loop/
β”‚       β”œβ”€β”€ .env.example
β”‚       └── docker-compose.yml
β”œβ”€β”€ lean4/
β”‚   β”œβ”€β”€ lakefile.toml
β”‚   β”œβ”€β”€ lean-toolchain
β”‚   β”œβ”€β”€ MiniF2F.lean
β”‚   β”œβ”€β”€ VerifyMain.lean
β”‚   └── src/
β”‚       └── SovereignCorpus/
β”‚           β”œβ”€β”€ Bridge/
β”‚           β”‚   β”œβ”€β”€ Granite4Parser.lean
β”‚           β”‚   └── Granite4Schema.lean
β”‚           β”œβ”€β”€ Core.lean
β”‚           └── Tactics/
β”‚               └── PlasmaGate.lean
β”œβ”€β”€ logic/
β”‚   β”œβ”€β”€ sovereign_verification.pl
β”‚   └── verification_loop.pl
β”œβ”€β”€ hf/
β”‚   └── README.md
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Makefile
└── LICENSE
```

## Core Trust Model

The system separates proposal, policy, and proof.

```text
LLM
Untrusted proposal generation

Prolog
Policy, authorization, and orchestration

Lean 4
Trusted proof verification

Audit Layer
Receipt generation and permanent evidence
```

No proof is accepted because an LLM says it is correct.

A proof is accepted only when Lean successfully checks it.

## Included Components

* Lean 4 proof verification kernel
* Granite-style JSON proof schema
* Lean-side parser
* Lean 3 syntax guards
* `sorry` rejection
* Prolog authorization layer
* Prolog retry loop
* Local inference server wrapper
* Dockerized inference runtime
* MiniF2F-style evaluation harness
* Sample JSONL theorem fixture
* Hugging Face publishing structure
* WORM-ready verification output design

## Quick Start

### Build the Lean Project

```bash
cd lean4
lake update
lake build
```

On Windows, when `lake` is not available through the system path:

```powershell
C:\Users\jessi\.elan\bin\lake.exe update
C:\Users\jessi\.elan\bin\lake.exe build
```

### Run the Parser Smoke Test

```bash
cd lean4
lake exe verify -- --parse ../fixtures/sample_input.jsonl
```

### Start the Inference Service

```bash
cd inference
docker build -t lean-llm-inference .
docker run -d \
  -p 8080:8080 \
  --name lean-llm-inference \
  lean-llm-inference
```

### Run the Evaluation Harness

```bash
cd eval
pip install -r requirements.txt
python run_minif2f.py
```

### Start the Verification Infrastructure

```bash
docker compose \
  --env-file infra/verification-loop/.env.example \
  up -d
```

### Run the Prolog Verification Loop

```bash
swipl -g "verify_with_retries(
  'theorem demo : True := by trivial',
  'ED25519_SIG',
  3,
  Result
), writeln(Result), halt" logic/verification_loop.pl
```

## Proof Artifact Schema

Generated proof proposals are exchanged using structured JSON rather than unrestricted model output.

Example shape:

```json
{
  "id": "demo-problem-1",
  "statement": "theorem demo_nonneg (x : ℝ) : x ^ 2 β‰₯ 0",
  "context": [
    "import Mathlib"
  ],
  "tacticHint": "nlinarith",
  "meta": {
    "source": "granite-verifier",
    "operatorSig": "ED25519_SIG_PLACEHOLDER",
    "maxSteps": 30,
    "allowedTactics": [
      "rw",
      "simp_all",
      "norm_num",
      "linarith",
      "nlinarith",
      "aesop",
      "apply",
      "exact",
      "intro",
      "cases",
      "induction",
      "constructor",
      "field_simp",
      "ring_nf",
      "omega"
    ]
  }
}
```

The schema constrains what the model is allowed to submit and gives the verifier a deterministic interface.

## Design Principles

### Evidence Over Confidence

A fluent answer is not evidence.

A Lean-checked proof is.

### Deterministic Rejection

Malformed, incomplete, unauthorized, or unverifiable proof artifacts must fail closed.

### Local-First Verification

The verification kernel can run independently from hosted model providers.

### Separation of Concerns

The model proposes.

The governance layer controls.

The theorem prover verifies.

The audit layer records.

### No Trusted Model Assumption

The architecture does not depend on the LLM being honest, aligned, deterministic, or correct.

## What This Repository Is

This repository is:

* A Lean-backed LLM proof gateway
* A local theorem verification harness
* A structured interface between language models and formal proof
* A foundation for sovereign mathematical agents
* A reproducible proof evaluation environment
* A verification-first AI architecture

## What This Repository Is Not

This repository is not:

* A finished autonomous theorem prover
* A claim that all LLM output is reliable
* A replacement for Lean's kernel
* A guarantee that generated proofs will succeed
* A repository of pretrained model weights
* A system that accepts natural-language confidence as mathematical evidence

## Current Scope

The current implementation provides the verification structure and execution path required to:

1. Receive a theorem or proof request
2. Route it through policy controls
3. Generate a structured proof proposal
4. Parse the proposal
5. Submit it to Lean
6. Accept or reject it deterministically
7. Preserve the result as an auditable artifact

## Future Work

Planned extensions may include:

* Expanded MiniF2F coverage
* Multiple local inference backends
* Stronger proof-step schemas
* Ed25519-signed verification receipts
* Append-only WORM evidence logs
* Proof repair loops
* Tactic allowlists per theorem class
* Resource limits for generated proofs
* Air-gapped execution profiles
* Formal verification of the orchestration layer
* Interactive proof verification UI
* Hugging Face model and Space publication
* Benchmark dashboards
* Multi-model proof proposal comparison

## Hugging Face Readiness

The repository includes:

* Git LFS configuration for model artifacts
* A model card template
* Publishing documentation
* Separation between model weights and verifier code
* Infrastructure suitable for an interactive verification Space

Recommended publication structure:

```text
Repository 1
Lean verification harness

Repository 2
Model weights or adapters

Repository 3
Interactive proof verification Space
```

## Security Model

Generated proof content must be treated as hostile input.

Recommended deployment controls include:

* Container isolation
* Strict tactic allowlists
* CPU and memory limits
* Execution timeouts
* No unrestricted shell access
* No arbitrary imports
* Signed operator requests
* Immutable verification receipts
* Pinned Lean toolchains
* Pinned container images
* Reproducible builds

## Status

This repository is an active verification scaffold.

The Lean project, parser, inference wrapper, Prolog governance layer, evaluation harness, Docker topology, and structured proof interface establish the foundation for deterministic LLM-assisted theorem verification.

The architecture is intentionally conservative:

```text
No proof.
No acceptance.

No evidence.
No claim.
```

## License

Licensed under **MPL-2.0**. Full text: [LICENSE](LICENSE).

## Author

Ahmad Ali Parr
SNAPKITTYWEST
SnapKitty Collective

## Principle

> The language model may propose the mathematics.
> The kernel must prove it.