Two levels of spec and refinement between them
How the high level and implementation level specs connect, and what the proof between them gives.
This series verifies one small C++ program end to end: ByteStore.
Answers. How the high level and implementation level specs connect, and what the proof between them gives.
1. Two levels, two jobs
- SPEC.md states what must hold in security terms; the implementation level states preconditions, postconditions, and invariants close to code. The high level sits too far from code to check. The implementation level alone says little about security.
2. Two models of the same store
- Abstract model (Model.v): a dense list of optional buffers, tombstones for released slots. Simple to state properties over; wasteful as a data structure.
- Implementation-shaped model (Representation.v, 291 lines): an
FMapListovernatthat stores only live entries, with explicitsparse_limitandsparse_next. The shape matches the C++std::map. - The counter records allocation history; map size counts live entries only, so it can sit below the counter.
3. Relation between abstract and implementation-shaped
related s mis a record of three equations:sparse_limit m = limit s·sparse_next m = next_id s·∀ id, sparse_lookup m id = lookup s id.empty_relatedstates that the empty stores are related.related_well_formedstates that related stores within the limit give a well-formed map. A well-formed map has no duplicate keys. Every live ID is belowsparse_next.
4. Simulation. Return values and post states
One shape, four theorems: write_simulation · read_simulation · release_simulation · allocate_simulation. Same result on both sides; both sides end related.
history_simulationfolds the same shape over any finite operation history. Replies and final states match throughout.rejected_sparse_writestates that a write in the implementation-shaped model returningfalseis exactly(false, m). Rejection is stateless on both sides.- Write in the implementation-shaped model goes through
put_byte, which returnsNoneout of bounds.
5. Benefits and limits
Benefits
- The simulation theorems match each operation on the implementation-shaped model to the abstract model, with the same result and post-state.
Limits
- C++ sits outside this proof; model and code connect by translation and partial lemmas. See Post 04.
- Write refinement is checked (Post 04; verification record). The binary, the concrete standard library, and the whole lifecycle stay open.
Sources: Representation.v · Model.v · SPEC.md.