Yaohui Chen

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_simulation and history_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_model is independently checked in Rocq. The translated C++ write agrees with Model.write on 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 map and vector behaviour enters through contracts.
  • OS and hardware. Out of scope in SPEC.md.
  • Discipline. Run Print Assumptions on every named theorem. No Admitted. One assumption is disclosed. BRiCk compareN guardedness is assumed.

4. ByteStore steps

SPEC.md spec Model.v abstract model Representation.v implementation- shaped model cpp2v on unchanged checked_store.hpp checked_write.v + BRiCk lemmas tests.cpp conformance evidence SPEC.md spec Model.v abstract model Representation.v implementation-shaped model cpp2v on unchanged checked_store.hpp checked_write.v + BRiCk lemmas tests.cpp conformance evidence
  • Theorems a reader meets first: write_live_in_bounds, rejected_write_preserves_store, write_changes_one_byte, and released_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.

  1. C++ suite: CXX="$(command -v clang++)" bash run_cpp.sh
  2. Rocq check: rocq compile Model.v, then rocq compile Representation.v, then rocqchk 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_model is 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.