|
| 1 | +-- SPDX-License-Identifier: MPL-2.0 |
| 2 | +-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 3 | +-- |
| 4 | +||| Layer 5 CAPSTONE: the end-to-end ABI SOUNDNESS CERTIFICATE for k9iser. |
| 5 | +||| |
| 6 | +||| This module does not prove a new domain theorem. It ASSEMBLES the proofs |
| 7 | +||| discharged in the prior layers into a single inhabited certificate value, |
| 8 | +||| demonstrating that the whole ABI contract holds together. The certificate |
| 9 | +||| ties the chain manifest -> ABI proofs (flagship + invariant) -> FFI seam |
| 10 | +||| into one end-to-end soundness statement: |
| 11 | +||| |
| 12 | +||| * MANIFEST -> FLAGSHIP (Layer 2, `K9iser.ABI.Semantics`): the headline |
| 13 | +||| "self-validating K9 contract" property, witnessed on the canonical |
| 14 | +||| positive control `goodConfig` validating `portContract` |
| 15 | +||| (`goodValidates`). |
| 16 | +||| |
| 17 | +||| * DEEPER INVARIANT (Layer 3, `K9iser.ABI.Invariants`): validation is |
| 18 | +||| compositional under CONJUNCTION of contracts, witnessed by the n-ary |
| 19 | +||| bundle control `twoValidatesBundle` (a config validating a two-contract |
| 20 | +||| bundle). |
| 21 | +||| |
| 22 | +||| * FFI SEAM (Layer 4, `K9iser.ABI.FfiSeam`): the ABI<->C encoding is |
| 23 | +||| unambiguous on the wire, carried by `resultToIntInjective`. |
| 24 | +||| |
| 25 | +||| The single inhabited value `abiContractDischarged : ABISound` is built |
| 26 | +||| ONLY from those existing exported witnesses. If any prior layer were |
| 27 | +||| unsound, the corresponding field would fail to typecheck and this value |
| 28 | +||| could not be constructed — so its mere existence is the capstone proof |
| 29 | +||| that every layer is discharged together. |
| 30 | + |
| 31 | +module K9iser.ABI.Capstone |
| 32 | + |
| 33 | +import K9iser.ABI.Types |
| 34 | +import K9iser.ABI.Semantics |
| 35 | +import K9iser.ABI.Invariants |
| 36 | +import K9iser.ABI.FfiSeam |
| 37 | + |
| 38 | +%default total |
| 39 | + |
| 40 | +-------------------------------------------------------------------------------- |
| 41 | +-- The capstone certificate |
| 42 | +-------------------------------------------------------------------------------- |
| 43 | + |
| 44 | +||| End-to-end ABI soundness certificate. Each field is a KEY proven fact from |
| 45 | +||| a distinct prior proof layer; to inhabit the record you must supply a real |
| 46 | +||| witness for every layer simultaneously. |
| 47 | +public export |
| 48 | +record ABISound where |
| 49 | + constructor MkABISound |
| 50 | + ||| Layer 2 (flagship): the canonical positive control validates the |
| 51 | + ||| canonical contract — the "self-validating K9 contract" property. |
| 52 | + flagship : Validates Semantics.portContract Semantics.goodConfig |
| 53 | + ||| Layer 3 (deeper invariant): conjunction of contracts is validated |
| 54 | + ||| compositionally — the canonical bundle control. |
| 55 | + invariant : ValidatesAll Invariants.twoConfig |
| 56 | + [Invariants.replicasContract, Invariants.timeoutContract] |
| 57 | + ||| Layer 4 (FFI seam): the ABI<->C result encoding is injective, so distinct |
| 58 | + ||| ABI outcomes never collide on the wire. |
| 59 | + ffiSeam : (a : Result) -> (b : Result) -> |
| 60 | + resultToInt a = resultToInt b -> a = b |
| 61 | + |
| 62 | +-------------------------------------------------------------------------------- |
| 63 | +-- The single inhabited capstone value |
| 64 | +-------------------------------------------------------------------------------- |
| 65 | + |
| 66 | +||| THE CAPSTONE. Constructed purely from the existing exported witnesses of |
| 67 | +||| each layer: `goodValidates` (Layer 2), `twoValidatesBundle` (Layer 3) and |
| 68 | +||| `resultToIntInjective` (Layer 4). Its existence certifies that the full ABI |
| 69 | +||| contract — manifest through flagship and invariant proofs through the FFI |
| 70 | +||| seam — is discharged as one coherent whole. |
| 71 | +public export |
| 72 | +abiContractDischarged : ABISound |
| 73 | +abiContractDischarged = MkABISound |
| 74 | + goodValidates |
| 75 | + twoValidatesBundle |
| 76 | + resultToIntInjective |
0 commit comments