Skip to content

[Lean Squad] feat(formal-verification): WrapBin proofs (20 theorems, latent C++ bug confirmed) + REPORT.md update (run 61)#59

Closed
github-actions[bot] wants to merge 1 commit intomainfrom
lean-squad/wrapbin-proofs-report-run61-24769158406-ab94247f4cd5886f
Closed

[Lean Squad] feat(formal-verification): WrapBin proofs (20 theorems, latent C++ bug confirmed) + REPORT.md update (run 61)#59
github-actions[bot] wants to merge 1 commit intomainfrom
lean-squad/wrapbin-proofs-report-run61-24769158406-ab94247f4cd5886f

Conversation

@github-actions
Copy link
Copy Markdown

Summary

Tasks 5 (Proof Assistance) + 10 (Project Report) — Run 61

New: WrapBin.lean (20 theorems, 0 sorry) — formal verification of ObstacleMath::wrap_bin. Updated: REPORT.md (314 theorems, 23 files).

Key finding: Latent C++ truncation-mod bug confirmed

wrap_bin(bin, bin_count) computes (bin + bin_count) % bin_count. C++ truncation-toward-zero mod returns negative results for some negative inputs:

Formally proved by wrapBinCpp_bug_general: for any n > 1, wrapBinCpp(-1, n) = -1.

Current callers are safe (formally proved via wrapBinOffset_valid).

Two models

Model Semantics Result
wrapBin Lean % (Euclidean) Correct for ALL integer inputs
wrapBinCpp Int.tmod (C++ truncation) Bug confirmed

Key theorems (20, 0 sorry)

  • wrapBin_range, wrapBin_nonneg, wrapBin_lt_count: full range proof
  • wrapBin_identity: identity on valid inputs
  • wrapBinCpp_bug_general: C++ returns -1 for input -1 when n > 1
  • wrapBin_eq_wrapBinCpp_valid: models agree on non-negative inputs
  • wrapBinOffset_valid: get_offset_bin_index caller formally safe

Verification

lake build passed with Lean 4.29.0. 0 sorry in WrapBin.lean. 23 total files, 9 pre-existing sorry unchanged.


🔬 Generated by Lean Squad automated formal verification agent (run 61, workflow 24769158406).

Generated by 📐 Lean Squad, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/lean-squad.md@215d2d398def782d44e589268d89f949c7c7db9f

…onfirmed) + REPORT.md update (run 61)

Add WrapBin.lean: formal verification of ObstacleMath::wrap_bin from
src/lib/collision_prevention/ObstacleMath.cpp.

Key results:
- 20 theorems, 0 sorry, verified by lake build with Lean 4.29.0
- Two models: wrapBin (Euclidean %, provably safe for all Int) and wrapBinCpp
  (Int.tmod, faithfully models C++ truncation-toward-zero semantics)
- wrapBin_range / wrapBin_nonneg / wrapBin_lt_count: full range proof
- wrapBinCpp_bug_general: formally proves C++ wrap_bin(-1, n) = -1 for n > 1
  (negative index — latent bug confirmed by proof)
- wrapBin_eq_wrapBinCpp_valid: both models agree on non-negative inputs
- wrapBinOffset_valid: get_offset_bin_index call site is formally safe despite bug
- tmod_neg1_gt1 (private): key lemma for the bug proof using Int.tmod match reduction

Also add wrap_bin_informal.md informal spec (preconditions, postconditions,
edge cases, examples table, C++ bug analysis).

Update REPORT.md for run 61:
- Status: 259 → 314 theorems, 123 → 141 examples, 6 → 9 sorry, 20 → 23 files
- Add Layer 4 WrapBin, Layer 6 CommanderArming, Layer 8 Atmosphere sections
- Add Bug 3 finding (wrap_bin latent C++ truncation bug)
- Add runs 55-61 timeline entries
- Update file inventory table with Atmosphere, CommanderArming, WrapBin rows

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant