Part III · Checkpoint 3 CP 3 · 45 min · ProveIt/Checkpoints/Cp3.lean

Checkpoint 3: Fixed-Width Ring Buffer

Prove bounds safety and FIFO queue refinement for a bounded circular buffer.

Checkpoint Spec · Bounded Circular Queue vs. Abstract `List α`
-- SpecQueue: plain `List α` (`enqueue` appends at back, `dequeue` pops front, max `cap`).
-- RingBuf: fixed capacity `cap > 0`, modular index arithmetic `(head + len) % cap`.
-- Prove: (1) zero out-of-bounds indices, (2) `toList (push rb x) = toList rb ++ [x]` when `len < cap`.
Socratic Gate · Commit to a Prediction Unanswered · Locks on commit

In a circular ring buffer of capacity `cap > 0`, why should the state store `(head : Fin cap)` and `(len : Nat)` (`len ≤ cap`) instead of just `(head : Fin cap)` and `(tail : Fin cap)`?

Bringing `Fin`, Modular Arithmetic, and Refinement Together

Kernel network rings (io_uring, DPDK) and telemetry queues use fixed-capacity circular buffers to guarantee zero heap allocation on hot paths. Proving that modular wrap-around (head + i) % cap refines an ordinary List α FIFO queue seals off both out-of-bounds panics and silent wrap-overwrite corruption.

⊢ ProveIt/Checkpoints/Cp3.lean · Modular Slot Safety & Queue Length Invariant
Step 1 / 1
Lean Infoview Open Goal
Hands-On Exercise (ProveIt/Checkpoints/Cp3.lean):

Complete the full array-backed FIFO ring buffer refinement in `ProveIt/Checkpoints/Cp3.lean` and run `lake exe check cp3`.

Finished the Socratic gate, Infoview trace, and playground run?
Record completion in local browser storage to track your 20-unit progress.