omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / protocol / interplane / v03 / crossveil.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note protocol/interplane/v03/crossveil.om: pure-Omega port of interplane-crossveil (v0.3.0). |
| 3 | note Runtime decision pipeline, RequestLedger replay/duplicate detection, exposure & session limits, |
| 4 | note and negative-control fault-injection variants (V2, V4, V6) matching interplane-conformance. |
| 5 | note Compose after si/directives/om2.om. |
| 6 | |
| 7 | const CV_DEC_AUTHORIZED ulong 0 |
| 8 | const CV_DEC_REQUIRES_APPROVAL ulong 1 |
| 9 | const CV_DEC_DENIED ulong 2 |
| 10 | |
| 11 | const CV_EXP_TRUSTED ulong 0 |
| 12 | const CV_EXP_MIXED ulong 1 |
| 13 | const CV_EXP_UNTRUSTED ulong 2 |
| 14 | |
| 15 | const CV_CTL_NONE ulong 0 |
| 16 | const CV_CTL_V2_CLAIMED_APPROVAL ulong 2 |
| 17 | const CV_CTL_V4_EFFECT_BYPASS ulong 4 |
| 18 | const CV_CTL_V6_NO_REPLAY_CHECK ulong 6 |
| 19 | |
| 20 | const CV_ERR_OK ulong 0 |
| 21 | const CV_ERR_DUPLICATE_REQ ulong 1 |
| 22 | const CV_ERR_SESSION_LIMIT ulong 2 |
| 23 | const CV_ERR_UNTRUSTED_EFFECT ulong 3 |
| 24 | const CV_ERR_DENIED_BY_AUTHORITY ulong 4 |
| 25 | |
| 26 | const CV_MAX_LEDGER ulong 32 |
| 27 | |
| 28 | note RequestLedger: tracks seen request_ids in ledger[32], count in lcnt[1]. |
| 29 | fn cv_ledger_has ledger view ulong 32 lcnt ulong req_id ulong to bool |
| 30 | if gt lcnt CV_MAX_LEDGER |
| 31 | ret true |
| 32 | end |
| 33 | i = ulong 0 |
| 34 | while lt i lcnt bound 32 |
| 35 | if eq get ledger i req_id |
| 36 | ret true |
| 37 | end |
| 38 | i = add i ulong 1 |
| 39 | end |
| 40 | ret false |
| 41 | end |
| 42 | |
| 43 | fn cv_ledger_record ledger edit ulong 32 lcnt edit ulong 1 req_id ulong to ulong |
| 44 | n = get lcnt 0 |
| 45 | if cv_ledger_has ledger n req_id |
| 46 | ret CV_ERR_DUPLICATE_REQ |
| 47 | end |
| 48 | if ge n CV_MAX_LEDGER |
| 49 | ret CV_ERR_SESSION_LIMIT |
| 50 | end |
| 51 | put ledger n req_id |
| 52 | put lcnt 0 add n ulong 1 |
| 53 | ret CV_ERR_OK |
| 54 | end |
| 55 | |
| 56 | note Negative-control before_step hook (V6 resets ledger so replay slips through). |
| 57 | fn cv_before_step ctl ulong lcnt edit ulong 1 to void |
| 58 | if eq ctl CV_CTL_V6_NO_REPLAY_CHECK |
| 59 | put lcnt 0 ulong 0 |
| 60 | end |
| 61 | end |
| 62 | |
| 63 | note Pipeline decision step: |
| 64 | note req_id: unique request identifier |
| 65 | note is_effect: 1 if capability mutates world/spawns process, 0 if read-only |
| 66 | note exposure: CV_EXP_TRUSTED / MIXED / UNTRUSTED |
| 67 | note claims_approval: 1 if untrusted input claims pre-approval (MUST be ignored!) |
| 68 | note auth_decision: authoritative runtime decision (CV_DEC_*) |
| 69 | note ctl: negative-control variant (CV_CTL_NONE in production) |
| 70 | note Returns decision in res[0] (CV_DEC_*), reason in res[1] (CV_ERR_*). |
| 71 | fn cv_pipeline_step ledger edit ulong 32 lcnt edit ulong 1 ctx view ulong 6 res edit ulong 2 to void |
| 72 | req_id = get ctx 0 |
| 73 | is_effect = get ctx 1 |
| 74 | exposure = get ctx 2 |
| 75 | claims_app = get ctx 3 |
| 76 | auth_dec = get ctx 4 |
| 77 | ctl = get ctx 5 |
| 78 | |
| 79 | cv_before_step ctl lcnt |
| 80 | |
| 81 | rc = cv_ledger_record ledger lcnt req_id |
| 82 | if ne rc CV_ERR_OK |
| 83 | put res 0 CV_DEC_DENIED |
| 84 | put res 1 rc |
| 85 | ret |
| 86 | end |
| 87 | |
| 88 | dec = auth_dec |
| 89 | rsn = CV_ERR_OK |
| 90 | if eq dec CV_DEC_DENIED |
| 91 | rsn = CV_ERR_DENIED_BY_AUTHORITY |
| 92 | end |
| 93 | |
| 94 | note Exposure gate: untrusted exposure with effect capability cannot be auto-authorized |
| 95 | if and eq is_effect ulong 1 eq exposure CV_EXP_UNTRUSTED |
| 96 | if eq dec CV_DEC_AUTHORIZED |
| 97 | dec = CV_DEC_REQUIRES_APPROVAL |
| 98 | rsn = CV_ERR_UNTRUSTED_EFFECT |
| 99 | end |
| 100 | end |
| 101 | |
| 102 | note Negative-control fault injection (only active when ctl != CV_CTL_NONE): |
| 103 | note V2: mistakenly honors untrusted claims_approval |
| 104 | if and eq ctl CV_CTL_V2_CLAIMED_APPROVAL eq claims_app ulong 1 |
| 105 | if ne dec CV_DEC_AUTHORIZED |
| 106 | dec = CV_DEC_AUTHORIZED |
| 107 | rsn = CV_ERR_OK |
| 108 | end |
| 109 | end |
| 110 | note V4: mistakenly auto-authorizes effect capabilities |
| 111 | if and eq ctl CV_CTL_V4_EFFECT_BYPASS eq is_effect ulong 1 |
| 112 | if ne dec CV_DEC_AUTHORIZED |
| 113 | dec = CV_DEC_AUTHORIZED |
| 114 | rsn = CV_ERR_OK |
| 115 | end |
| 116 | end |
| 117 | |
| 118 | put res 0 dec |
| 119 | put res 1 rsn |
| 120 | end |