Skip to content

[Lean Squad] feat(fv): Tasks 5+1 — Crc32Sig (11 theorems, 0 sorry) + 3 new research targets (run 75)#72

Open
github-actions[bot] wants to merge 2 commits intomainfrom
lean-squad/crc32sig-research-run75-24986132989-dc8de7cc19d49829
Open

[Lean Squad] feat(fv): Tasks 5+1 — Crc32Sig (11 theorems, 0 sorry) + 3 new research targets (run 75)#72
github-actions[bot] wants to merge 2 commits intomainfrom
lean-squad/crc32sig-research-run75-24986132989-dc8de7cc19d49829

Conversation

@github-actions
Copy link
Copy Markdown

🔬 Lean Squad automated formal verification — run 75

Task 5: CRC-32/ISO-HDLC Signature Formal Verification

Adds formal-verification/lean/FVSquad/Crc32Sig.lean — formal proofs of the
crc32_signature function in src/lib/crc/crc.c (line 151), which the UAVCAN
bootloader
uses to verify firmware-image integrity.

What is proved

The CRC-32/ISO-HDLC algorithm (reflected polynomial 0xEDB88320, LSBIT-first) is
modelled as a List.foldl over bytes, enabling a clean algebraic proof of the key
streaming property.

Theorem Property
crc32sig_nil crc32sig init [] = init — empty buffer identity
crc32sig_singleton crc32sig init [b] = crc32Add init b
crc32sig_cons Unfolding: crc32sig init (b::bs) = crc32sig (crc32Add init b) bs
crc32sig_append Fold/split: crc32sig init (a ++ b) = crc32sig (crc32sig init a) b
crc32sig_append3 Three-part split chains correctly
crc32sig_init_zero UAVCAN init-0 convention
crc32sig_append_nil Appending [] is a no-op
crc32sig_two [a, b] equals chained single-byte steps
crc32sig_split Alias of crc32sig_append (term-mode)
6 examples Concrete values verified by native_decide / simp

Total: 11 theorems (9 named + term alias + 6 examples), 0 sorry.

Correspondence level: exact

UInt8/UInt32 carry the same modular-28/232 arithmetic as C uint8_t/uint32_t.
The -(acc & 1) two's-complement mask is captured by if c &&& 1 != 0.
The model is List.foldl crc32Add init bytes — an exact algebraic description of the
C for loop.

Key proof

theorem crc32sig_append (init : UInt32) (a b : List UInt8) :
    crc32sig init (a ++ b) = crc32sig (crc32sig init a) b := by
  simp [crc32sig, List.foldl_append]

One line — exactly the same proof structure as Crc16Sig and Crc16Fold.


Task 1: New Research Targets

Three new FV candidates identified in TARGETS.md:

# Name File Rationale
36 crc64_add_word fold/split src/lib/crc/crc.c CRC-64-WE; same fold structure; UInt64 model
37 math::isInRange src/lib/mathlib/math/Limits.hpp:91 Pure boolean (min≤val)&&(val≤max)
38 math::constrainFloatToInt16 src/lib/mathlib/math/Limits.hpp:85 Float→int16 clamp; conversion-overflow safety

Files changed

  • formal-verification/lean/FVSquad/Crc32Sig.lean (new)
  • formal-verification/lean/FVSquad.lean — added import FVSquad.Crc32Sig
  • formal-verification/TARGETS.md — crc32 → phase 5, crc16 updated, 3 new targets
  • formal-verification/CORRESPONDENCE.md — Crc32Sig section added, summary table updated

Verification status

lake build passed with Lean 4.29.0. 32 jobs. 0 sorry remain.
Project total: 372 theorems proved, 30 Lean files, 0 sorry.

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

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/lean-squad.md@13377ddf7e35c2b6e47aa58f45acb228fba902c8

github-actions Bot and others added 2 commits April 27, 2026 09:19
Task 5 (Proof Assistance): Add multi-step convergence theorems to SlewRate.lean.
- slewIterate: N-step iterate of slewUpdate
- slewIterate_steady: steady state is preserved under iteration
- slewIterate_converges_up: starting ≤ target, N steps suffice when
  target - current ≤ max_step * N (proved 0-sorry)
- slewIterate_converges_down: starting ≥ target, N steps suffice when
  current - target ≤ max_step * N (proved 0-sorry)
- 4 native_decide spot-checks (0→10 in 4 steps, 10→0 in 2 steps, etc.)

Key fix: replaced ring (Mathlib-only) with omega and simp [Int.mul_add]
for the calc steps in the induction cases.

Task 2 (Informal Spec Extraction): Write informal spec for crc32_signature.
- specs/crc32_informal.md: purpose, preconditions, postconditions, edge cases,
  concrete examples (check value 0xCBF43926 for "123456789"), and formal
  properties suitable for Lean (fold/append, empty identity, determinism)
- Identifies crc32_fold as highest-value target (justifies UAVCAN bootloader
  two-call chaining pattern)

lake build: passed (31 jobs, Lean 4.29.0, 0 sorry)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…h targets (run 75)

Task 5 (Proof Assistance): Add formal-verification/lean/FVSquad/Crc32Sig.lean
- Models and proves properties of crc32_signature (CRC-32/ISO-HDLC, poly 0xEDB88320)
- Used in UAVCAN bootloader for firmware-image integrity
- 11 theorems: nil/singleton/cons/append/append3/init_zero/append_nil/two/split + 6 native_decide examples
- Key result: crc32sig_append — fold/split streaming property (List.foldl_append)
- Lean implementation model: crc32AddBit (1 bit step) + crc32Add (8-bit byte step) + crc32sig (fold)
- Correspondence level: exact (UInt8/UInt32 modular arithmetic matches C uint8_t/uint32_t)
- lake build: passed, Lean 4.29.0, 32 jobs, 0 sorry

Task 1 (Research): Add 3 new research targets to TARGETS.md
- Target 36: crc64_add_word (CRC-64-WE, src/lib/crc/crc.c) — fold/split with UInt64
- Target 37: math::isInRange (Limits.hpp:91) — pure boolean range predicate
- Target 38: math::constrainFloatToInt16 (Limits.hpp:85) — float→int16 clamp safety

Also:
- CORRESPONDENCE.md updated: Crc32Sig section added (exact level), summary table row added
- TARGETS.md: crc32_signature advanced to phase 5 ✅; crc16_signature updated to phase 5 ✅

> 🔄 Partial verification: `lake build` passed with Lean 4.29.0. 0 `sorry` remain.

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.

0 participants