Skip to content

Prove RISC-V instructions match Clean model: shifts, comparisons and branch conditions. - #1033

Open
nicole-graus wants to merge 12 commits into
formal/clean-modelfrom
formal/riscv-sail
Open

nicole-graus wants to merge 12 commits into
formal/clean-modelfrom
formal/riscv-sail

Conversation

@nicole-graus

@nicole-graus nicole-graus commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Proves, instruction by instruction, that the Clean model in formal/ computes what the official RISC-V spec says.

PR Size: 175 of the 217 files (~176k of ~177.8k lines) are the generated Sail model in sail-riscv-lean/LeanRV64D/; GitHub collapses them (.gitattributes) and CI checks they match their pinned sources. The hand-written part is ~1.8k lines, mostly formal-riscv/.

What's in it

  • formal-riscv/: one chain of three proofs per instruction:
    1. Sail.lean: Sail's execute_* is a pure function (*Pure).
    2. Bridge.lean: *Pure, read as a natural, is the Clean model's function (shiftResult, ltBit, eqBit).
    3. Alu.lean: an ALU bus message with the instruction's flags carries that result, using Alu.Guarantees.
  • Covered: SLL/SRL/SRA (+ immediate and word versions), SLT/SLTU (+ immediate), and the conditions of BEQ/BNE/BLT/BGE/BLTU/BGEU. 22 *_alu_matches_sail theorems, no sorry.
  • sail-riscv-lean/: the Sail RISC-V model in Lean, generated from pinned commits of riscv/sail-riscv and rems-project/sail (PINS, scripts/generate.sh). It replaces opencompl/sail-riscv-lean, which is no longer updated. The Sail compiler is pinned to fix(lean): split variants exceeding runtime constructor limits rems-project/sail#1823 (not merged yet), which splits the instruction type so it compiles on Lean v4.35.0; PINS will move to Sail's main once it is merged.
  • .github/workflows/sail-riscv-lean.yml: regenerates the model and fails if it differs from the committed one.

Not covered yet

  • PC and register file: needs the CPU in Clean. The theorems assume the CPU sends the right operands (ha, hb).
  • Word shifts: only the low 32 bits; the sign extension is done by CPU32.
  • Branches: only the condition, not the jump target.

Notes

@nicole-graus

Copy link
Copy Markdown
Collaborator Author

/ai-review

@github-actions

Copy link
Copy Markdown

Codex Code Review

No actionable issues found in the PR changes during static review. No builds or tests were run, as requested.

@github-actions

Copy link
Copy Markdown

AI Review

PR #1033 · 216 changed files

Warning: the diff was truncated before review.

Findings

No non-rejected structured findings were reported.

Reviewer Lanes

Lane Model Prompt Status Findings

Native Codex and Claude reviews run separately and post their own comments. They are not included in this structured provenance report.

Raw lane outputs, candidates, final issues, and model metrics are uploaded as workflow artifacts.

@nicole-graus
nicole-graus marked this pull request as ready for review November 17, 2026 14:25
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