<!-- description: Explore partial equivalence relations for quotients, axiom-free proof transfer, constant-time relational contracts, and session choreographies. -->

# Surface quotients, relational contracts, and session choreographies

> Design for axiom-free quotient/Trocq transfer, relational information-flow and
> constant-time contracts, and deadlock-free dependent session choreographies
> beyond the [first-release subset](../../language/first-release/#release-boundary).

## Scope and boundary

These prototypes use the [minimal CIC profile](../../assurance/verification-strategy/#research-and-semantic-boundaries)
to check three kinds of specification. Quotients and proof transfer relate
mathematical interfaces to concrete representations. Relational contracts compare
observations from two executions. Session choreographies describe communication
for both endpoints and support static checks for deadlock freedom.

<a id="surface-quotients-adaptt-and-trocq-transfer"></a>

## Surface quotients, AdapTT casts, and Trocq transfer

- **Axiom-free Setoid/PER quotients (`QT-per`):** A surface `record Quotient<Name>(<Rep> ...)`
  declaration containing an equivalence relation `definition` and proved `Sym`/`Trans`
  `lemma`s elaborates into a partial equivalence relation (`PER`) on `Rep` paired with
  respectfulness obligations (`Respectful f`) discharged by `<Op>Respectful` proofs for
  every lifted operation `definition`. Non-respectful operations (`non_respectful_mod_refused`
  or unproved `<Op>Respectful`) and unproved symmetry/transitivity obligations are refused.
- **AdapTT functorial representation casts (`QT-cast`):** Representation changes between an
  erased mathematical view and a packed runtime representation use `record RepCast<Name>(Src, Dst)`
  declarations lowering to explicit `RepCast A B` records. Each cast preserves its declared
  representation invariant (`invariant true` / `<Cast>Preserves`), sequential casts compose
  associatively via `cast_comp` (`cast_id_left`, `cast_comp_assoc`), and mismatched
  `target_type != source_type` compositions are refused. Any erasure or change to a runtime
  representation requires its own lowering evidence.
- **Trocq witness hierarchy without axioms (`QT-trocq`):** Following Trocq's modular
  parametricity hierarchy, parametric relations carry a class index
  `R0 <= R1 <= R2a <= R2b <= R3 <= R4` (`R0`: bare relation, `R1`: left map,
  `R2a`/`R2b`: split/full relation bounds, `R3`: retraction, `R4`: full
  equivalence/split surjection). `record TrocqTransfer<Name>(Src, Dst, <Class>, <Polarity>, <Eq>)`
  declarations drive polarity analysis (`PolarityAnalyzer`, `flip_class` across arrows)
  to request the weakest sufficient witness class, refuse insufficient witnesses (e.g., `R1`
  for `R2a`/`R2b`/`R4`), and emit closed-context CIC transfer terms (`transfer_prop_r2a`,
  `transfer_prop_r2b`, `transfer_equiv_r4`) checked under Rocq 9.3.0 and `rocqchk` with zero axioms.
- **Surface `.hf` lowering contract:** `lower_surface_quotient_module` and
  `check_quotient_surface` in [quotient_transfer.py](https://github.com/symbiogenesis/HoldFast/blob/main/tools/toolchain/quotient_transfer.py)
  parse real `.hf` modules via the Menhir `--surface` parser without modifying the core
  grammar, lower `Quotient*`, lifted `definition`, `RepCast*`, and `TrocqTransfer*` items into
  checked `QuotientElaborator` obligations, and replay the emitted Gallina against
  [quotient_transfer.v](https://github.com/symbiogenesis/HoldFast/blob/main/tools/rocq/quotient_transfer.v) in Rocq 9.3.0 + `rocqchk`,
  closing `QT-per`, `QT-trocq`, and `QT-cast`. [Quotient transfer tests](https://github.com/symbiogenesis/HoldFast/blob/main/tools/tests/test_holdfast_quotient_transfer.py)

<a id="relational-and-information-flow-contracts"></a>

## Relational contracts and constant-time information flow

The proposed surface adds `Public <= Secret` labels, `relational ensures`
and policy-gated `declassify(expr, policy_id)` to single-execution contracts.
The prototype checks the modeled commands and observations below. The
[target integration item](../../plan/#q25eq) owns the TAL lowering.

- **Noninterference:** Expressions and commands typed under `CTIfcTyped` (including
  bounded `SRepeat` loops and `SLoad`) with a label environment bridged to
  `GradedDomains.SecurityBase` (`sec_to_graded_le`, `sec_to_graded_join`) satisfy
  `low_equiv` preservation (`typed_noninterference`).
- **Constant-time leakage trace:** Operational semantics instruments an explicit
  leakage trace `LeakTrace` recording `EvBranch bool` and `EvAddr nat`. Programs
  accepted by the constant-time typing rules have equal modeled traces from
  low-equivalent initial states (`ct_leakage_equiv`). The secret-branch control
  exhibits distinct branch observations when public data agrees
  (`secret_branch_breaks_ct`).
- **Product-program elaboration:** Self-composition generates a deterministic
  single-program product goal checked directly by Rocq (`product_soundness` and
  `DeclassIfcTyped` / `declassify_delimited_noninterference` for authorized
  releases). The emitted obligation manifest records what target lowering must prove.

<a id="dependent-session-types-and-choreographies"></a>

## Dependent linear session types and choreographies

The session prototype models dual local endpoints and a single global
choreography for both endpoints. Its `CopyRingService` example covers the
commit/cancel protocol under `R-12-097`.

- **Session constructors and duality:** Endpoints use `SSend(ty, prio, k)`,
  `SRecv(ty, prio, k)`, `SOffer(prio, left, right)`, `SSelect(prio, left, right)`,
  and `SEnd`, with total involution `dual_involutive` and payload predicates `PayloadPred`.
- **Priority-based deadlock freedom:** Every communication action carries a
  strictly increasing natural priority `prio`. Priority-ordered dual endpoints
  guarantee progress (`prio_ordered_no_deadlock`, and across multiple channels
  `multichannel_min_prio_progress` vs `priority_cycle_deadlocks`): either endpoints
  terminate or a synchronized communication step is enabled.
- **Endpoint projection (EPP):** Projecting a well-formed two-party global
  choreography (`project A g` and `project B g`) produces exact syntactic duals
  (`project_binary_dual`). Linear endpoint checking requires consumption through
  `SEnd` on each represented branch, including those for normal, error and
  cancellation outcomes.
  The Rocq emitter admits exactly two branches per choice so the certificate
  covers the complete declared choice.

## Proof obligations

| Obligation | Required artifact and refusal predicate |
| --- | --- |
| `QT-per` | Prove symmetry/transitivity of user `PER` quotients (`qmap_respects`) and reject any lifted operation lacking `Respectful` proof (`non_respectful_mod_refused`). |
| `QT-trocq` | Prove `R0`–`R4` weakening, polarity flipping (`flip_involutive_sym`), and minimal-class property transfer (`transfer_prop_r2a`, `transfer_prop_r2b`, `transfer_equiv_r4`) without univalence/funext; reject insufficient witness class. |
| `QT-cast` | Prove `RepCast` identity (`cast_id_left`) and associative composition coherence (`cast_comp_assoc`) for representation transport. |
| `RIFC-noninterference` | Prove `low_equiv` preservation across `CTIfcTyped` expressions/commands (`typed_noninterference`, bridged to `GradedDomains.SecurityBase`); reject implicit or explicit `Secret -> Public` leaks. |
| `RIFC-ct-trace` | Prove identical `LeakTrace` (`EvBranch`, `EvAddr`) across low-equivalent runs (`ct_leakage_equiv`, `product_soundness`); reject secret-dependent branches (`secret_branch_breaks_ct`) or table indices. |
| `RIFC-declassify` | Require explicit policy capability matching `declassify` site (`DeclassIfcTyped`, `declassify_delimited_noninterference`) and log an explicit assumption/policy manifest; reject unauthorized declassification. |
| `SC-duality` | Prove `dual_involutive` and endpoint-linear consumption to `SEnd` along every normal/cancel branch; reject double-send, use-after-close, or unclosed handles. |
| `SC-deadlock-free` | Prove strictly increasing channel priorities guarantee progress (`prio_ordered_no_deadlock`, `multichannel_min_prio_progress`); reject priority cycles (`priority_cycle_deadlocks`) or inversions across multiple channels. |
| `SC-epp` | Prove binary global choreography projection yields exact dual session types (`project_binary_dual`), including `CopyRingService` commit/cancel flows (`copy_ring_projection_dual`, `copy_ring_deadlock_free`). |

## Qualification and implementation artifacts

| Component | Artifact | Role |
| --- | --- | --- |
| Rocq quotient/Trocq mechanization | [quotient_transfer.v](https://github.com/symbiogenesis/HoldFast/blob/main/tools/rocq/quotient_transfer.v) | Zero-axiom `QuotientTransfer` PER, `RepCast`, and `R0`–`R4` Trocq transfer proofs (`rocqchk`) |
| Quotient/Trocq surface lowering | [quotient_transfer.py](https://github.com/symbiogenesis/HoldFast/blob/main/tools/toolchain/quotient_transfer.py) | Surface `.hf` AST lowering (`lower_surface_quotient_module`), polarity analyzer, cast composer, and axiom-free Gallina emitter |
| Representation-transfer trial | [proof_transfer_trial.v](https://github.com/symbiogenesis/HoldFast/blob/main/tools/rocq/proof_transfer_trial.v) · [proof_transfer_trial.py](https://github.com/symbiogenesis/HoldFast/blob/main/tools/toolchain/proof_transfer_trial.py) | Bounded CoqEAL/Trocq comparison over copy-service FIFO rings under minimal CIC (`rocqchk`) |
| Rocq relational/IFC mechanization | [relational_ifc.v](https://github.com/symbiogenesis/HoldFast/blob/main/tools/rocq/relational_ifc.v) | Zero-axiom `RelationalIFC` noninterference, product-program, and CT `LeakTrace` proofs (`rocqchk`) |
| Relational/IFC prototype | [relational_ifc.py](https://github.com/symbiogenesis/HoldFast/blob/main/tools/toolchain/relational_ifc.py) | Secret/public & CT verifier and product-program Gallina builder |
| Rocq session mechanization | [session_choreography.v](https://github.com/symbiogenesis/HoldFast/blob/main/tools/rocq/session_choreography.v) | Zero-axiom `SessionChoreography` EPP duality, priority deadlock-freedom, and `CopyRingService` proofs (`rocqchk`) |
| Session/choreography prototype | [session_types.py](https://github.com/symbiogenesis/HoldFast/blob/main/tools/toolchain/session_types.py) | Global choreography projector, linear endpoint checker, and priority cycle detector |
| Qualification tracks | [Q25ep](../../assurance/completion-log/#q25ep-qualify-surface-per-quotients-adaptt-casts-and-trocq-transfer) · [Q25eq](../../plan/#q25eq) · [Q25er](../../assurance/completion-log/#q25er-qualify-priority-ordered-linear-session-choreographies) | Quotient transfer, relational IFC, and session choreographies |
