-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCapstone.idr
More file actions
71 lines (64 loc) · 3.63 KB
/
Copy pathCapstone.idr
File metadata and controls
71 lines (64 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- SPDX-License-Identifier: MPL-2.0
-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
--
||| Layer 5 — END-TO-END ABI SOUNDNESS CERTIFICATE for Affinescriptiser.
|||
||| This capstone does NOT prove a new domain theorem. It ASSEMBLES the proofs
||| already discharged in the lower layers into ONE inhabited record value. The
||| certificate ties the whole ABI contract together:
|||
||| manifest (the affine-usage model: `Trace` / `AffineOk`)
||| -> Layer 2 FLAGSHIP property : a single program fragment uses every
||| variable at most once (`AffineOk`, witnessed on the canonical
||| positive-control instance `safeTraceAffineOk : AffineOk [0,1,2]`).
||| -> Layer 3 INVARIANT : the composition law — sequencing two affine,
||| variable-disjoint fragments stays affine (`concatAffine`, witnessed
||| on the canonical positive control `composedOk : AffineOk [0,1,2,3]`).
||| -> Layer 4 FFI SEAM : the ABI<->C `Result` encoding is unambiguous, so
||| distinct ABI outcomes never collide on the wire
||| (`resultToIntInjective`).
|||
||| Each field below is filled ONLY from an already-`export`ed witness/theorem of
||| the modules it imports — nothing is re-proved or fabricated here. The single
||| value `abiContractDischarged : ABISound` is therefore the capstone: if ANY
||| prior layer were unsound (the flagship witness, the invariant witness, or the
||| seam injectivity), this value would fail to typecheck and the certificate
||| could not be issued. Genuine composition only: no believe_me, no idris_crash,
||| no assert_total, no postulate, no sorry, no %hint hacks, no asserted equality.
module Affinescriptiser.ABI.Capstone
import Affinescriptiser.ABI.Types
import Affinescriptiser.ABI.Semantics
import Affinescriptiser.ABI.Invariants
import Affinescriptiser.ABI.FfiSeam
%default total
--------------------------------------------------------------------------------
-- The certificate type
--------------------------------------------------------------------------------
||| `ABISound` records the KEY proven facts of the Affinescriptiser ABI, one
||| field per proof layer. Inhabiting it requires a genuine witness of each.
public export
record ABISound where
constructor MkABISound
||| Layer 2 (flagship): the canonical positive-control program fragment
||| [0,1,2] is affine-safe — every variable used at most once.
flagship : AffineOk [0, 1, 2]
||| Layer 3 (invariant): the composition law applied to the canonical
||| disjoint fragments yields an affine-safe sequenced fragment [0,1,2,3].
invariant : AffineOk ([0, 1] ++ [2, 3])
||| Layer 4 (FFI seam): the ABI<->C `Result` encoding is injective, i.e.
||| equal wire integers imply equal ABI outcomes (distinct outcomes never
||| collide). Carried as the full injectivity theorem.
seamInjective : (a, b : Result) -> resultToInt a = resultToInt b -> a = b
--------------------------------------------------------------------------------
-- The capstone value: the whole ABI contract, discharged together
--------------------------------------------------------------------------------
||| THE CAPSTONE. A single inhabited certificate built entirely from the
||| lower-layer exported witnesses:
||| * `flagship` = `safeTraceAffineOk` (Layer 2 positive control)
||| * `invariant` = `composedOk` (Layer 3 composition control)
||| * `seamInjective` = `resultToIntInjective` (Layer 4 seam theorem)
||| Typechecking this value is exactly the end-to-end soundness statement.
public export
abiContractDischarged : ABISound
abiContractDischarged =
MkABISound safeTraceAffineOk composedOk resultToIntInjective