Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0fe3176
Build the model on the counted-pulls branch of the Clean fork, and pr…
jotabulacios Nov 2, 2026
0d60015
Let LT answer up to 255 identical queries per row, as the Rust chip d…
jotabulacios Nov 2, 2026
110da5a
Add MIN, a toy ALU operation with the shape of DIVREM, to test counte…
jotabulacios Nov 2, 2026
6b9fb87
Prove LT and MIN sound by finishing order, including a counted MIN on…
jotabulacios Nov 2, 2026
d00a233
Take Clean from the counted-pulls branch of the yetanotherco/clean fo…
jotabulacios Nov 3, 2026
bcf860b
Update formal/README for counted pulls: LT now pulls IS_HALF and MSB1…
jotabulacios Nov 4, 2026
b9fd430
Say what the counted-pulls section of formal/README actually proves. …
jotabulacios Nov 5, 2026
9168d15
Drop the two references to documented per-constraint deltas, which th…
jotabulacios Nov 5, 2026
1fb1cb3
Fail the formal workflow if a modelled circuit or an ensemble theorem…
jotabulacios Nov 5, 2026
3f47a98
Move the Clean pin to 73309694, the counted-pulls branch of the fork …
jotabulacios Nov 6, 2026
4b6127d
Move opselMIN off 7, which is MUL in the prover, to 9, outside the al…
jotabulacios Nov 13, 2026
de0a0b9
Check Counted.Demo.circuit too, and keep each axiom report on one lin…
jotabulacios Nov 13, 2026
030d9b7
Pin Clean by sha in formal/README, count the commits the pin has, and…
jotabulacios Nov 13, 2026
b7f21dc
State the multiplicities LT's completeness actually covers: bytes, no…
jotabulacios Nov 13, 2026
1cc8270
Run the formal workflow on merge-group commits, as the other workflow…
jotabulacios Nov 13, 2026
9e386b2
Drop the three claims the new base makes about LT that this branch re…
jotabulacios Nov 16, 2026
fdd3147
Say what MIN and CMIN prove, put a consumer on each counted bus, and …
jotabulacios Nov 18, 2026
041c1cf
Say in the README that LT cannot share an ensemble with EQ or SHIFT. …
jotabulacios Nov 18, 2026
5e6b2dd
Fail the axiom gate when a report's axiom list does not fit on one li…
jotabulacios Nov 19, 2026
8fe4ba7
Drop the skip that could not skip anything, and say where the flag-by…
jotabulacios Nov 19, 2026
49a7f75
Give ensembleMin the consumer the other two ensembles have, name the …
jotabulacios Nov 19, 2026
06bbb23
Pin Clean at the fork's `pr-base-upstream-main`, and follow the four …
jotabulacios Nov 19, 2026
d21caef
Take the three fixes from review: the merge-group trigger, two lemmas…
jotabulacios Nov 20, 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
64 changes: 62 additions & 2 deletions .github/workflows/formal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,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
Loading
Loading