← Back to Pull requests

Document the formally verified specifications #495

Closed
unknown closed this pull request without merging on Nov 25, 2026 08:21 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 18:32 UTC
Author

The documentation of intx.hpp gets the specifications of the functions whose RV64 machine code is proved in Lean on the branch fv/main (#447), as @pre and @post with Lean terms. They show on main what is verified: a function without @post is not. @note FV: marks the uses that the proofs do not cover: x += x and the other operators in place with y as the object, a quotient that overlaps the numerator in udivrem_by1() and udivrem_by2(), and operator Int with Int = bool. The README links to lean/README.md on fv/main, which explains the specifications and what they assume, so the details change there without a change of main.

The proofs stay on fv/main: they take hours to build, so main does not check them, and they follow fv/main, not each change of main.

The pipeline

1. include/intx/intx.hpp: the @pre and @post of each function. Trusted: reviewed to state what the function is meant to do.
2. lean/IntxRV/Api.cpp: the instances to verify, compiled by clang 21 to RV64 (-O2 -march=rv64imafd). Automated (scripts/rv_build.sh). The compiler is not trusted: its machine code is what is proved.
3. lean/scripts/rv_gen.py: the machine code of each instance from the object file, linked by lld with its callees and constant data. Automated. Trusted: the code in Lean is the code of the object.
4. The decoding of each word of the code to an instruction of the Sail RISC-V model. Automated, proved in Lean.
5. lean/scripts/rv_api.py: the specification of each instance for the machine code: the arguments and the result in registers and memory by the RISC-V calling convention, the buffers that do not overlap, and the registers and the memory that the function keeps. Automated. Trusted: the translation of the C++ signatures.
6. lean/IntxRV/Api/*.lean: the proof that the machine code, run on the Sail model, returns with the @post. Written for each function, checked by Lean.
7. lean/Checks/: every instance has a proof that uses only the axioms of Lean and the opaque functions of the Sail model (no sorry, native_decide or bv_decide), and the preconditions of its specification hold in a machine state. Automated, checked by Lean.

Also trusted: the Lean kernel and the Sail model with its environment, in which the memory of the buffers is ordinary RAM.

The cost

90 instances of 66 functions are proved, in about 42,000 lines of Lean. On the CI runner of GitHub Actions (4 CPUs, 16 GB):

| build | time |
|---|---|
| all the proofs, with the decode proofs cached | about 3 hours |
| all the proofs and the decode proofs of a new machine code | up to 6 hours |
| a change of one proof | about 10 minutes |

The slowest proof, of udivrem_knuth_normalized(), takes 8 minutes and 11 GB; the decoding of a word of machine code 3-5 seconds and 120 MB.

Diff: 377 lines (+282 / -95) across 4 files Reviewer: chfast Review duration: 828m
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 377 lines diff across 4 files
0.43
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.355
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #495"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 42.9% (MEDIUM) · Higher = larger blast radius
42.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.9% · Safe to merge
16.9%
Repository