Demystifying C++ proof: verifying a toy program, end to end
What “proved” means for C++. Layers, matching, and gaps.
Answers. What “proved” means for C++. Layers, matching, and gaps.
0. Question
- The toy program in this series is ByteStore, a checked byte store in C++17. Source file is
checked_store.hpp. - “You proved it in Rocq, so the C++ is correct?” A proof here is a chain of matches; each link is labelled proved, tested, or trusted.
1. Layers
- Between the spec and the compiled binary sit an abstract model, an implementation-shaped model, and the translated source. Proof, tests, and sanitizers each cover different layers.
2. How implementation and model are matched
- Matching pairs a correspondence relation with a simulation over finite histories. Both sides return the same value and end in matching post states.
- Posts 02 and 03 prove the match between the abstract model and the implementation-shaped model. Theorems:
write_simulationandhistory_simulation. - Implementation-shaped model and C++ connect through translation with cpp2v and BRiCk. Checked today are method entry, the guard rule, and branch and return structure.
WriteRefinement.checked_write_refines_modelis independently checked in Rocq. The translated C++ write agrees withModel.writeon return result and full model-observable post-state, on the modeled normal-return paths, under explicit representation and map, vector, and iterator contract assumptions. Record:FULL-VERIFICATION.md. Proof modules: brick-write-proof.
3. Gaps in language, compiler, library, and system
- Language. The C++ standard is prose. Proofs talk about BRiCk formal semantics. BRiCk semantics sits in the trusted base.
- Compiler. Claims cover source. The compiler sits in the trusted base, outside the proof.
- Library. STL
mapandvectorbehaviour enters through contracts. - OS and hardware. Out of scope in
SPEC.md. - Discipline. Run
Print Assumptionson every named theorem. NoAdmitted. One assumption is disclosed. BRiCkcompareNguardedness is assumed.
4. ByteStore steps
- Theorems a reader meets first:
write_live_in_bounds,rejected_write_preserves_store,write_changes_one_byte, andreleased_handle_stays_invalid.
5. Repro
Follow the repro guide in evanmak/security-patch-proof-artifacts, pinned at commit. Work in the directory that holds SPEC.md and checked_store.hpp, with Clang and Rocq 9.2.0 on PATH.
- C++ suite:
CXX="$(command -v clang++)" bash run_cpp.sh - Rocq check:
rocq compile Model.v, thenrocq compile Representation.v, thenrocqchk Model Representation.
Expected. The C++ suite passes the normal run and the ASan/UBSan run. Compilation prints assumption reports of 15 model results and 9 representation results, all closed under the global context.
6. Work still open
- Proven for write, within scope.
checked_write_refines_modelis checked in Rocq for the modeled normal-return paths, under explicit representation and map, vector, and iterator contract assumptions. Record:FULL-VERIFICATION.md. - Still not proven. The binary, the concrete standard library, and the whole store lifecycle.
Sources: SPEC.md · Model.v · Representation.v · repro guide.