Demo Plan Walkthrough

Wolfram + Lean + eBPF/XDP

A closed-loop formal-verification workflow for stateful packet processing

Symbolic discovery → machine-checked proof → executable validation

Wolfram Lean 4 Implementation / infra Milestone gate Rejection / refinement
The Big Idea

One property, three independent representations

Wolfram Language

Explores the state space symbolically. Proposes candidate invariants and finds minimal counterexamples. Fast, but not a proof.

Lean 4

Independently formalizes the model and machine-checks every candidate. Accepts, strengthens, weakens, or rejects. No sorry, no axioms for main properties.

Executable code

A Python reference model plus a real compiled eBPF/XDP program. Differential tests prove the formal model matches what actually runs.

Amp (orchestrator)

Translates between all three, keeps names consistent, tracks invariant status, and turns every counterexample into a permanent regression test.

Research question: can Wolfram-assisted invariant discovery reduce the manual effort of proving realistic XDP programs correct in Lean?

The Subject

A stateful XDP rate limiter

Properties to prove (spec §7)

Memory safety — every packet read within [0, packet_length]
Parser monotonicity — offset never moves backward
Parser boundedness — offset ≤ packet length
Counter monotonicity — counters never silently decrease

No silent overflow — saturating counters, proved
Rate-limit correctness — C ≤ T ⇒ PASS, C > T ⇒ DROP
Packet preservation, determinism, malformed-packet safety
Refinement — model ≡ real XDP program on all vectors

Relevant to DPU / SmartNIC-class systems; described conservatively, not as a vendor implementation.

The Workflow Graph — Overview

Eight phases, one gate, one loop

PHASE 0 · Environment (WSL toolchain)
PHASE 1 · Repo skeleton + assumptions  →  PHASE 2 · Python reference model
▼  (parallel split)
PHASE 3 · Lean formalization
PHASE 4 · Wolfram boundary search
MILESTONE 1 GATE · review stop
PHASE 5 · Closed invariant loop (the heart of the demo)
PHASE 6 · eBPF/XDP + differential tests
PHASE 7 · CI, metrics, docs → Definition of Done
Phase 0

Environment — a deliberate Windows / WSL split

ComponentRuns onStatus
Wolfram Language (wolframscript)Windowsinstalled
Lean 4.32.2 / Lake 5.0Windowsinstalled
Python 3.12 reference modelWindows + WSLinstalled
Clang/LLVM (eBPF target), libbpf, bpftoolWSL Ubuntu-24.04to install
XDP execution via BPF_PROG_TEST_RUNWSL (no NIC attach)planned

Why it works: JSON files under generated/ are the only exchange format between Wolfram, Lean, and the executable — so the OS boundary never leaks into the verification logic.

Verify check: all five toolchains answer a version query before anything else is built.

Phases 1 – 2

Foundation: assumptions first, then a reference model

Phase 1 · Repo skeleton

  • Directory tree from the spec: xdp/, model/, wolfram/, lean/, generated/, scripts/, docs/
  • docs/assumptions.md — every assumption explicit, split into model / eBPF verifier / Linux / DPU classes

Phase 2 · Python reference model

  • Total-function evaluator: evaluate(packet, state) → (result, state)
  • Explicit error status — malformed input never raises, never reads out of bounds
  • Unit tests include truncation at every byte boundary

The reference model is the semantic anchor: Wolfram, Lean, and the eBPF program are all judged against it — and it stays independent of the eBPF implementation.

Phases 3 – 4 (parallel)

Two independent views of the same parser

Phase 3 · Lean 4 formalization

  • Packet.lean, State.lean, Parser.lean — defined independently, not imported from Wolfram output
  • First theorem: successful IPv4 parse ⇒ every accessed header byte lies within the packet boundary
  • Gate: lake build green, zero sorry

Phase 4 · Wolfram boundary search

  • PacketModel.wl, StateTransition.wl — symbolic packets with byte constraints
  • Sweeps packet-length × IHL boundary cases
  • Exports generated/test_vectors.json, replayed against the Python model — actions must agree

Independence is the point: if two teams derive the same safety condition from the same spec, agreement is evidence, not coincidence.

Milestone 1 Gate

A hard stop, on purpose

parser safety proved in Lean · Wolfram vectors agree with Python · concept map documented

The spec forbids building the rate limiter until parser safety is settled. This gate is where the plan is reviewed: representations compared, naming table (packetLengthPacket.lengthdata_end − data) locked in, assumptions re-checked.

Everything after this gate builds on a proven-safe parser.

Phase 5 — The Heart of the Demo

The closed invariant loop

Wolfram: InvariantDiscovery.wl
bounded predicate grammar + reachability → invariants.json
ExportLean.wl → theorem skeletons in GeneratedInvariants.lean
Lean: prove / strengthen / weaken / reject
▼ rejected candidate
Wolfram: CounterexampleSearch.wl
minimize by pkt len › headers › counter › threshold › trace → counterexamples.json
spec refinement + permanent regression vector  ⟲  back to discovery (loop until stable)

Proved results land in invariant_status.json: PROVED / STRENGTHENED / WEAKENED / REJECTED / REDUNDANT — plus proof metrics per theorem.

Why the loop matters

Failed proofs are results, not failures

When Lean rejects a candidate

  • Wolfram hunts for the smallest counterexample
  • The counterexample becomes a permanent regression test
  • The invariant grammar or spec is refined — never weakened just to make a proof pass

What gets measured

  • candidates proposed vs. accepted unmodified
  • strengthened / weakened / rejected counts
  • proof effort with and without Wolfram assistance (Modes A / B / C)
  • translation correctness of Amp-generated Lean skeletons

Every generated theorem keeps its original Wolfram expression alongside the Lean translation, and both are evaluated on test assignments to catch semantic drift in translation.

Phase 6

Back to reality: the compiled XDP program

xdp_rate_limit.bpf.c
compiled with Clang → eBPF, loaded via libbpf
generated/test_vectors.json
same corpus used everywhere
BPF_PROG_TEST_RUN harness (WSL, user-space — no NIC, no root network changes)
action + state compared against Python reference model — zero divergence allowed

This is the refinement property (§7.10) made executable: the thing we proved theorems about and the thing that actually runs must agree on every vector — including every counterexample the loop ever found.

Phase 7 → Done

CI keeps the loop honest

The build fails when…

  • a Lean theorem stops compiling, or sorry appears in final proofs
  • a regression vector changes behavior
  • reference model and XDP program disagree
  • generated invariants go stale or drift

Definition of done (§18)

  • rate limiter builds; models pass all tests
  • core safety properties machine-checked
  • byte-level malformed-packet coverage
  • differential tests green; assumptions documented; artifacts reproducible

Plus conservative relevance docs: this verifies the software class that runs on DPU / SmartNIC platforms — it does not claim anything about proprietary silicon.

Plan: C:\Amp_demos\Xsightlab\DEMO_PLAN.md · Graph: DEMO_PLAN_Workflow.drawio

1 / 12
← Swipe to navigate →