Skip to content

Prove table soundness from a finishing order of channels and of message classes - #2

Open
jotabulacios wants to merge 3 commits into
pr1-counted-pullsfrom
pr2-staged-channels
Open

jotabulacios wants to merge 3 commits into
pr1-counted-pullsfrom
pr2-staged-channels

Conversation

@jotabulacios

@jotabulacios jotabulacios commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1: the base of this PR is pr1-counted-pulls, so the diff below is this PR's own work —
one new file, plus 40 lines of Balance.lean and one import.

Why

OrderedChannel orders tables: a table may not both pull from a channel and owe requirements on
it. Two shapes a VM needs break that.

The first has no workaround. A table that both pulls from a channel and pushes to it, on different
messages, is not a cycle: what it reads and what it writes are disjoint. The ALU bus is the
example — a division table pulls the LT and MUL results it needs and pushes its own DIVREM
results, all on one bus. Ordering whole channels cannot express that, and giving each operation a
channel of its own costs a channel per operation.

The second is a table whose requirements on one channel follow from its guarantees on another:
LT pulls IS_HALF with multiplicity μ, and μ ≤ 255 is known only because the same table
pulls ARE_BYTES[μ, 0]. This one does have a workaround, unrolling the counted pull into N pulls
of multiplicity one, at N interactions per row instead of one.

This PR orders channels, and then stages: a channel together with a class of its messages.
finished lists them newest first, and a component's requirements on one may use its guarantees on
those finished before it. By induction from the oldest, every one's requirements hold, so by
consistency its guarantees hold, and every table's spec follows. Balance is message by message
(BalancedUpTo.filter_msg), so a stage balances by itself; a whole channel is the stage whose
class is every message.

What

  • Component.RequirementsAfter / StagedRequirements, with
    Ensemble.channelGuarantees_of_staged and Ensemble.tableSoundness_of_staged.
  • A refinement down to message classes: a Stage is a channel together with a class of messages, so
    one channel can be finished in several steps (byte lookups before the rows that use them).
    RequirementsAfterOn / StagedRequirementsOn, with guaranteesOn_of_stagedOn and
    tableSoundness_of_stagedOn.
  • BalancedUpTo.filter_msg in Balance.lean: balance holds message by message, so it restricts to
    any class of messages.

Both staged theorems take their per-channel balance from
EnsembleWitness.balancedChannels_of_balanced, the same named step that OrderedChannel.lean and
Vm.lean use, rather than inlining the derivation over the ensemble's channels.

Both forms are kept: the plain one is the simpler statement for an ensemble whose channels finish
whole, the staged-on one is what a VM ensemble needs.
requirementsAfterOn_of_requirementsAfter relates them.

Scope

Both theorems require ens.verifier = .empty F PublicIO. For an ensemble of tables this is free:
Ensemble.verifier defaults to the empty program, so the hypothesis is discharged by rfl. It is
not free for a VM. Ensemble.addVm propagates the VM's verifier, which pushes the initial state
and pulls the final one on the very channel being staged, and neither StagedRequirements nor
StagedRequirementsOn says anything about what a verifier owes — the hypothesis is what lets the
proofs use interactionsWith_of_verifier_empty. So the finishing order covers table ensembles,
while OrderedChannel, which carries OrderedChannelRefl channel ens.verifier, remains the path
that handles a verifier. Lifting the restriction means stating what a verifier owes on a staged
channel, which this PR does not do.

Checks

  • lake build clean, zero warnings.
  • lake build CleanTests passes.
  • No sorry, no native_decide in this PR's own files.

Open point

tableSoundness_of_staged concludes only ens.TableSoundness balance. The per-channel guarantees
it proves on the way are exported separately as channelGuarantees_of_staged /
guaranteesOn_of_stagedOn, which is what a caller that needs both uses.

…ge classes.

A table's requirements on a channel may follow from its guarantees on channels finished before it,
not only from its constraints. A counted pull needs this: its multiplicity bound comes from a
lookup on another channel, which OrderedChannel can't express. Component.StagedRequirements states
it for a finishing order, and Ensemble.tableSoundness_of_staged proves soundness by induction from
the oldest channel.

A stage is a channel together with a class of its messages. A table that pulls some messages of a
channel and pushes others, like a division chip pulling LT and MUL results and pushing DIVREM
results on the ALU bus, is not a cycle when the classes are finished in order.
Ensemble.tableSoundness_of_stagedOn proves soundness from a finishing order of stages; balance is
message by message, so each stage balances by itself (BalancedUpTo.filter_msg). Genuine cycles
still have no valid order.
…ma too.

Both staged soundness theorems inlined the same derivation over the ensemble's channels
that `balancedChannels_of_balanced` names, which is the pattern just removed from
`OrderedChannel.lean` and `Vm.lean`. All four call sites now go through the lemma, and
`Balance.balancedUpTo_of_balanced` is applied in one place.
…eady does.

`Component.StagedRequirements` has `@[circuit_norm]` nil and cons lemmas, so a caller
discharging `∀ component ∈ ens.tables, component.StagedRequirements finished` with
`simp [circuit_norm]` gets the list unfolded. `StagedRequirementsOn` had neither, so the
identical proof over stages left a stuck goal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant