NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Conditional Contextual Refinement (CCR)

Youngju Song, Minki Cho, Dongjae Lee, Chung-Kil HurarXiv 2022 · DOI

Presented at PLDI '22, Conditional Contextual Refinement (CCR) is a formal framework designed for the verification of "open" programs—software modules that interact with external, unknown code. By shifting logical conditions into the operational semantics of the program itself, CCR provides a compositional approach to verifying complex software systems.

The Challenge: Moving Beyond Unconditional Refinement

In formal verification, the standard goal is to prove that a concrete implementation ($P$) "refines" an abstract specification ($A$). The gold standard for this is Contextual Refinement (CR), which is valued for its compositionality: modules can be verified independently and linked later.

However, standard CR is unconditional. It requires that $P$ refines $A$ under any possible context. In practice, most modules only function correctly if their environment adheres to specific rules (e.g., a function requiring a valid pointer). Existing solutions to this problem often struggle with "vertical compositionality" (incremental refinement steps) or forbid complex features like mutual recursion and dynamic memory allocation to maintain mathematical tractability.

The CCR Approach

CCR addresses these limitations by encoding logical conditions directly as executable code within the abstract module. This "operationalizes" the logic, allowing the framework to support pointers, higher-order functions, and cyclic dependencies while maintaining full compositionality.

1. Asm and Grt (Assumptions and Guarantees)

Instead of external predicates, CCR uses two primary constructs:

  • Asm (Assumption): Checks if the context's behavior matches the module's expectations. If the context fails, it triggers Undefined Behavior (UB). In refinement theory, if the implementation triggers UB, the refinement is vacuously true.
  • Grt (Guarantee): Checks if the module itself is behaving as promised. Failure triggers No Behavior (NB), which terminates the program trace and fails the refinement.
Encoding assumptions and guarantees as executable code within abstract modules.

2. Executable Module Semantics (EMS)

The framework is built on EMS, a uni-typed semantics using Interaction Trees. This allows modules to be treated as mathematical objects capable of performing IO, calling external functions, and handling nondeterminism.

3. Ghost Information via Nondeterminism

To handle "ghost state" (logical resources like permissions that do not exist at runtime), CCR utilizes demonic and angelic nondeterminism. By using take and choose operations, modules can simulate the passing of logical resources even when actual function signatures remain simple.

4. Assumption Cancellation Theorem (ACT)

The mathematical foundation of CCR is the ACT. It proves that when two modules are linked such that one's Grt matches the other's Asm, the conditions "cancel out." This results in a standard, unconditional contextual refinement, bridging the gap between conditional verification and final system deployment.

Evaluation and Results

The authors formalized the entire theory and several case studies in 37,329 lines of Coq code. Key evaluations included:

  • Middleware (MW): Verifying systems with multiple implementations and optimizations.
  • Landin’s Knot: Addressing classic challenges involving cyclic dependencies through the heap.
  • Compiler Integration: Building a verified compiler from a C-like language (IMP) to assembly via CompCert, demonstrating that CCR holds from high-level specs down to the hardware level.

During evaluation, the authors used differential testing (comparing implementations against abstractions in OCaml) and discovered two real bugs related to mis-downcasts before the formal proof even began.

Future Directions

While CCR is a significant step forward, it currently only supports sequential programming. The authors identify concurrency—specifically relaxed-memory models—as the primary frontier for future research. Additionally, they aim to improve automation by integrating tactics from frameworks like Iris and to embed assembly language more deeply into the EMS model for tighter CompCertM integration.

Summary updated

BibTeX
@misc{song2022conditional,
  author = {Youngju Song and Minki Cho and Dongjae Lee and Chung-Kil Hur},
  title = {{Conditional Contextual Refinement (CCR)}},
  year = {2022},
  eprint = {2203.07431},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2203.07431},
}
Figure