Yaohui Chen

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 FMapList over nat that stores only live entries, with explicit sparse_limit and sparse_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 m is 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_related states that the empty stores are related. related_well_formed states that related stores within the limit give a well-formed map. A well-formed map has no duplicate keys. Every live ID is below sparse_next.

4. Simulation. Return values and post states

Abstract model Model.v · store s Implementation-shaped model Representation.v · sparse store m related write write Abstract model store s′ after write Implementation-shaped model sparse store m′ after write related

One shape, four theorems: write_simulation · read_simulation · release_simulation · allocate_simulation. Same result on both sides; both sides end related.

  • history_simulation folds the same shape over any finite operation history. Replies and final states match throughout.
  • rejected_sparse_write states that a write in the implementation-shaped model returning false is exactly (false, m). Rejection is stateless on both sides.
  • Write in the implementation-shaped model goes through put_byte, which returns None out 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.