Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a3bb3ed
Build the model on the counted-pulls branch of the Clean fork, and pr…
jotabulacios Nov 2, 2026
ba66d14
Let LT answer up to 255 identical queries per row, as the Rust chip d…
jotabulacios Nov 2, 2026
6a2a0f8
Add MIN, a toy ALU operation with the shape of DIVREM, to test counte…
jotabulacios Nov 2, 2026
69a6670
Prove LT and MIN sound by finishing order, including a counted MIN on…
jotabulacios Nov 2, 2026
5beca86
Take Clean from the counted-pulls branch of the yetanotherco/clean fo…
jotabulacios Nov 3, 2026
0387aeb
Update formal/README for counted pulls: LT now pulls IS_HALF and MSB1…
jotabulacios Nov 4, 2026
d645f91
Say what the counted-pulls section of formal/README actually proves. …
jotabulacios Nov 5, 2026
d93a057
Drop the two references to documented per-constraint deltas, which th…
jotabulacios Nov 5, 2026
135ed58
Fail the formal workflow if a modelled circuit or an ensemble theorem…
jotabulacios Nov 5, 2026
cb23a3a
Move the Clean pin to 73309694, the counted-pulls branch of the fork …
jotabulacios Nov 6, 2026
d93358e
Move opselMIN off 7, which is MUL in the prover, to 9, outside the al…
jotabulacios Nov 13, 2026
7ebe468
Check Counted.Demo.circuit too, and keep each axiom report on one lin…
jotabulacios Nov 13, 2026
3919110
Pin Clean by sha in formal/README, count the commits the pin has, and…
jotabulacios Nov 13, 2026
83be3ac
State the multiplicities LT's completeness actually covers: bytes, no…
jotabulacios Nov 13, 2026
8e504fa
Run the formal workflow on merge-group commits, as the other workflow…
jotabulacios Nov 13, 2026
3f43438
Drop the three claims the new base makes about LT that this branch re…
jotabulacios Nov 16, 2026
ad21e3e
Say what MIN and CMIN prove, put a consumer on each counted bus, and …
jotabulacios Nov 18, 2026
5bd5e69
Say in the README that LT cannot share an ensemble with EQ or SHIFT. …
jotabulacios Nov 18, 2026
afee5f2
Fail the axiom gate when a report's axiom list does not fit on one li…
jotabulacios Nov 19, 2026
e06322a
Drop the skip that could not skip anything, and say where the flag-by…
jotabulacios Nov 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 66 additions & 2 deletions .github/workflows/formal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
push:
branches: ["main"]
paths: ["formal/**", ".github/workflows/formal.yml"]
# The repository merges through a queue (see `pr_main.yaml` and `gpu-tests.yml`). Without
# this trigger the job runs on the PR but not on the merge-group commit, so a change that
# only breaks the model once combined with another queued PR merges unchecked.
merge_group:
pull_request:
paths: ["formal/**", ".github/workflows/formal.yml"]

Expand Down Expand Up @@ -54,8 +58,68 @@ jobs:
- name: Fetch Mathlib binaries
run: lake exe cache get

- name: Build
run: lake build
# `lake build` only *warns* on a `sorry`, so without this check a sorry anywhere in the
# library merges green, including in declarations the axiom gate below does not reach.
- name: Build, and no sorry anywhere in the library
run: |
set -euo pipefail
log="${RUNNER_TEMP:-/tmp}/build.log"
lake build 2>&1 | tee "$log"
if grep -q "declaration uses 'sorry'" "$log"; then
echo "::error::a declaration uses sorry"
grep -n "declaration uses 'sorry'" "$log"
exit 1
fi

# `LambdaVM/Axioms.lean` is a list of `#print axioms` lines, one per modelled circuit and
# per ensemble theorem. It is not part of the library, so `lake build` does not see it.
- name: No sorry, no axioms beyond the standard three
run: |
set -euo pipefail
report="${RUNNER_TEMP:-/tmp}/axioms.txt"
# The `sed` below needs the opening `[` and the closing `]` of an axiom list on the
# same line to see it at all. `-Dformat.width` is kept as a precaution for a future
# toolchain, not because it is what holds the line together: `#print axioms` ignores
# it on v4.35.0, and emits the same 111-column lines at width 1 as at width 1000.
# The parse check further down is the guard that actually holds.
lake env lean -Dformat.width=1000 LambdaVM/Axioms.lean | tee "$report"

# One report per `#print axioms` line: a renamed or deleted declaration fails here
# instead of quietly dropping out of the check.
expected=$(grep -c '^#print axioms ' LambdaVM/Axioms.lean || true)
got=$(grep -c 'depends on axioms\|does not depend on any axioms' "$report" || true)
if [ "$expected" -ne "$got" ]; then
echo "::error::expected $expected axiom reports, got $got"
exit 1
fi

# `-Dformat.width` above is a width, not a guarantee: a long enough axiom list still
# wraps, and then the `sed` below finds no closing `]` and extracts nothing, while the
# count above still matches because the phrase sits on the report's first line. So
# require that every report with an axiom list was actually parsed.
withaxioms=$(grep -c 'depends on axioms' "$report" || true)
parsed=$(sed -n 's/.*depends on axioms: \[\(.*\)\]/\1/p' "$report" | wc -l | tr -d ' ')
if [ "$withaxioms" -ne "$parsed" ]; then
echo "::error::$withaxioms reports carry an axiom list but only $parsed fit on one line; raise -Dformat.width"
exit 1
fi

if grep -q 'sorryAx' "$report"; then
echo "::error::a modelled circuit or ensemble theorem depends on sorry"
exit 1
fi

unexpected=$(
sed -n 's/.*depends on axioms: \[\(.*\)\]/\1/p' "$report" \
| tr ',' '\n' | sed 's/[[:space:]]//g; /^$/d' | sort -u \
| grep -vxF -e propext -e Classical.choice -e Quot.sound || true
)
if [ -n "$unexpected" ]; then
echo "::error::axioms outside propext, Classical.choice, Quot.sound: $(echo $unexpected)"
exit 1
fi

echo "$expected declarations checked, no sorry, no extra axioms"

- name: Export is up to date
run: |
Expand Down
3 changes: 3 additions & 0 deletions formal/LambdaVM.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ public import LambdaVM.Tables.Eq
public import LambdaVM.Tables.Shift
public import LambdaVM.Ensembles.EqLookup
public import LambdaVM.Channels.Counted
public import LambdaVM.Tables.MinToy
public import LambdaVM.Ensembles.LtStaged
public import LambdaVM.Ensembles.CountedSameBus
53 changes: 53 additions & 0 deletions formal/LambdaVM/Axioms.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module

public import LambdaVM

/-!
# Axiom check

Every circuit of the model and every ensemble theorem must rest on nothing beyond Lean's three
standard axioms: `propext`, `Classical.choice`, `Quot.sound`. In particular none of them may
depend on `sorryAx`.

`#print axioms` reports transitively, so a declaration reached by one already listed needs no
line of its own. The templates and the two static tables below are *not* reached by any of them,
which is why they are listed explicitly. The `sorry` check on `lake build` in the workflow is the
backstop for everything else in the library.

`.github/workflows/formal.yml` runs this file with `lake env lean` and fails if any report
names `sorryAx` or an axiom outside those three. It also counts the `#print axioms` lines
here and requires one report for each, so a declaration that stops existing fails the build
rather than silently dropping out of the check. Add a line for every new circuit, ensemble
soundness theorem or global row theorem.
-/

-- The modelled chips. Each `circuit` bundles its own soundness and completeness proofs.
#print axioms LambdaVM.LT.circuit
#print axioms LambdaVM.EQ.circuit
#print axioms LambdaVM.SHIFT.circuit
#print axioms LambdaVM.MinToy.circuit
#print axioms LambdaVM.CountedMin.circuit
#print axioms LambdaVM.Counted.Demo.circuit

-- The ensembles.
#print axioms LambdaVM.Ensembles.eq_rows_correct
#print axioms LambdaVM.Ensembles.LtStaged.tableSoundness
#print axioms LambdaVM.Ensembles.LtStaged.tableSoundness_withMin
#print axioms LambdaVM.CountedMin.tableSoundness

-- The templates the chips are built from. They are `FormalAssertion`s that nothing above
-- reaches, so without these lines a `sorry` in one of them would pass the check.
#print axioms LambdaVM.IsBit.circuit
#print axioms LambdaVM.Add.circuit
#print axioms LambdaVM.IsByteCheck.circuit
#print axioms LambdaVM.AreBytesCheck.circuit

-- The two static tables no modelled chip pulls; only `Export.lean` reads them. Printing the
-- table covers its `guarantees_iff`.
#print axioms LambdaVM.Bitwise.isB20Table
#print axioms LambdaVM.Bitwise.msb8Table

-- This model's own counted channel: the instance that closes the gap under a bounded balance,
-- and the counterexample showing the gap is real without one.
#print axioms LambdaVM.Counted.consistentUpTo
#print axioms LambdaVM.Counted.not_consistent
17 changes: 16 additions & 1 deletion formal/LambdaVM/Buses/Alu.lean
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ def shiftResult (word signed direction x s : ℕ) : ℕ :=
else if signed = 0 then x >>> k
else sra64 x k

/-- `opsel` of MIN: a toy operation for the counted-pulls PoC, not an RV64IM op. It has the shape
of DIVREM: its chip pulls LT on this bus and pushes its own result on the same bus.

The value is deliberately outside the prover's `alu_op` enum (`prover/src/tables/types.rs`, which
ends at `MUL = 7`, `DIVREM = 8`), so the toy cannot collide with a real opsel once MUL and DIVREM
are modelled on this bus. -/
def opselMIN : ℕ := 9

/-- What a puller learns. One clause per `opsel`, selected by the flag byte read as a natural.
Each clause takes as hypotheses exactly the `[[assumptions]]` of its chip's spec: the words the
caller must have range-checked. The words a chip range-checks itself need no hypothesis. -/
Expand All @@ -90,7 +98,14 @@ def Guarantees (m : Msg (F p)) : Prop :=
(∀ w s d : ℕ, w < 2 → s < 2 → d < 2 →
m.flags.val = opselSHIFT + w + 32 * s + 64 * d →
m.outLo.val < 2^32 ∧ m.outHi.val < 2^32 ∧
dword m.outLo m.outHi = shiftResult w s d (dword m.in1Lo m.in1Hi) (m.in2Lo.val % 256))
dword m.outLo m.outHi = shiftResult w s d (dword m.in1Lo m.in1Hi) (m.in2Lo.val % 256)) ∧
-- MIN (toy, see `opselMIN`): flags = opsel(MIN), out = the unsigned minimum;
-- assumes `IS_WORD` on both words of both operands, as the global antecedent did before the
-- per-opsel refactor
(m.flags.val = opselMIN →
m.in1Lo.val < 2^32 → m.in1Hi.val < 2^32 → m.in2Lo.val < 2^32 → m.in2Hi.val < 2^32 →
m.outLo.val < 2^32 ∧ m.outHi.val < 2^32 ∧
dword m.outLo m.outHi = min (dword m.in1Lo m.in1Hi) (dword m.in2Lo m.in2Hi))

def channel : Channel (F p) Msg where
name := "ALU"
Expand Down
36 changes: 35 additions & 1 deletion formal/LambdaVM/Channels/Counted.lean
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ nonzero multiplicity as a push; `not_consistent` shows the gap is real: over Gol
`2 ≤ N ≤ 255` and a channel with some message whose guarantee is false, the counted channel is
not `Consistent`, so it cannot be finished in a `SoundEnsemble` until that premise carries the
bound. With `N = 1` the counted channel is `Normal`, hence `Consistent`; it is still a channel of
its own, not `channel.toRaw`.
its own, not `channel.toRaw`. With the bounded balance `BalancedUpTo N` of the modified Clean
(the fork's `counted-pulls`, which `lakefile.toml` pins by sha at `73309694`), `consistentUpTo`
closes the gap.

This file's `counted` is **not** the fork's `Channel.counted`, which is what `Tables/Lt.lean`,
`Tables/MinToy.lean` and `Ensembles/CountedSameBus.lean` pull on. On an out-of-range pull this
file charges the guarantee, like a push; the fork forbids the multiplicity instead. Only
`Demo.circuit` below uses this one. See the README, "Counted pulls".
-/

namespace LambdaVM.Counted
Expand Down Expand Up @@ -277,6 +284,33 @@ theorem not_consistent (N : ℕ) (hN : 2 ≤ N) (hN' : N ≤ 255)
convert h
simp [ProvableType.fromElements_toElements]

/-- With the bounded balance of the modified Clean (`BalancedUpTo N`, the premise `not_consistent`
asks for), the counted channel is consistent: a pull of `1, …, N` is matched by an interaction
that is not such a pull, and that interaction's requirement is the guarantee. -/
instance consistentUpTo (N : ℕ) (channel : Channel (F p) Message) :
(counted N channel).ConsistentUpTo N where
consistent interactions data balanced reqs a a_mem := by
obtain ⟨ a_channel, - ⟩ := reqs a a_mem
by_cases a_pull : a.PullUpTo N
case neg =>
rcases a with ⟨ _, a_direction, a_mult, a_msg, a_size ⟩
subst a_channel
simp only [Interaction.Guarantees, counted]
exact fun h_direction h_count => absurd ⟨ h_direction, h_count ⟩ a_pull
obtain ⟨ b, b_mem, b_msg, b_ne_zero, b_not_pull ⟩ := balanced.matchedUpTo a a_mem a_pull
obtain ⟨ b_channel, b_reqs ⟩ := reqs b b_mem
rcases a with ⟨ _, a_direction, a_mult, a_msg, a_size ⟩
rcases b with ⟨ _, b_direction, b_mult, b_msg', b_size ⟩
subst a_channel b_channel
simp only at b_msg
subst b_msg
simp only [Interaction.Guarantees, Interaction.Requirements, Interaction.msgVector,
counted] at b_reqs ⊢
intro _ _
cases b_direction with
| push => exact b_reqs b_ne_zero
| pull => exact b_reqs b_ne_zero (b_not_pull rfl)

end LambdaVM.Counted

/-! ## A deduplicated row
Expand Down
Loading
Loading