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 / native / control / src / action.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note OM-CONTROL-659 action contract v1. See ../README.md for the trusted-caller boundary. |
| 3 | note No I/O, authority minting or persistence. Caller serializes and durably commits transitions. |
| 4 | note Record words 0..7: version,state,attempt,limit,generation,epoch,expiry,reserved. |
| 5 | note Words 8..31: operation,request,scope,provider,policy,grant identities, four words each. |
| 6 | note State 1 ready,2 in-flight,3 unknown,4 performed. No timeout implies not performed. |
| 7 | |
| 8 | fn actvalid r view ulong 32 to ulong |
| 9 | if ne get r 0 1 |
| 10 | ret 11 |
| 11 | end |
| 12 | if or lt get r 1 1 gt get r 1 4 |
| 13 | ret 12 |
| 14 | end |
| 15 | if or eq get r 3 0 gt get r 3 1024 |
| 16 | ret 12 |
| 17 | end |
| 18 | if gt get r 2 get r 3 |
| 19 | ret 12 |
| 20 | end |
| 21 | if and ne get r 1 1 eq get r 2 0 |
| 22 | ret 12 |
| 23 | end |
| 24 | if or eq get r 4 0 eq get r 5 0 |
| 25 | ret 12 |
| 26 | end |
| 27 | if or eq get r 6 0 ne get r 7 0 |
| 28 | ret 12 |
| 29 | end |
| 30 | for g ulong 6 |
| 31 | bits = ulong 0 |
| 32 | for j ulong 4 |
| 33 | bits = or bits get r add 8 add mul g 4 j |
| 34 | end |
| 35 | if eq bits 0 |
| 36 | ret 12 |
| 37 | end |
| 38 | end |
| 39 | ret 0 |
| 40 | end |
| 41 | |
| 42 | fn actbind r view ulong 32 c view ulong 32 to ulong |
| 43 | for g ulong 6 |
| 44 | diff = ulong 0 |
| 45 | for j ulong 4 |
| 46 | at = add 8 add mul g 4 j |
| 47 | diff = or diff xor get r at get c at |
| 48 | end |
| 49 | if ne diff 0 |
| 50 | ret add 40 g |
| 51 | end |
| 52 | end |
| 53 | ret 0 |
| 54 | end |
| 55 | |
| 56 | fn actauth r view ulong 32 c view ulong 32 to ulong |
| 57 | if ne get c 0 1 |
| 58 | ret 11 |
| 59 | end |
| 60 | if or ne get c 3 0 or ne get c 6 0 ne get c 7 0 |
| 61 | ret 12 |
| 62 | end |
| 63 | if ne get c 1 1 |
| 64 | ret 30 |
| 65 | end |
| 66 | if ne get r 4 get c 4 |
| 67 | ret 31 |
| 68 | end |
| 69 | if ne get r 5 get c 5 |
| 70 | ret 32 |
| 71 | end |
| 72 | if ge get c 2 get r 6 |
| 73 | ret 33 |
| 74 | end |
| 75 | ret actbind r c |
| 76 | end |
| 77 | |
| 78 | fn actstart r edit ulong 32 c view ulong 32 to ulong |
| 79 | err = actvalid r |
| 80 | if ne err 0 |
| 81 | ret err |
| 82 | end |
| 83 | if eq get r 1 3 |
| 84 | ret 21 |
| 85 | end |
| 86 | if eq get r 1 4 |
| 87 | ret 22 |
| 88 | end |
| 89 | if ne get r 1 1 |
| 90 | ret 20 |
| 91 | end |
| 92 | if ge get r 2 get r 3 |
| 93 | ret 23 |
| 94 | end |
| 95 | err = actauth r c |
| 96 | if ne err 0 |
| 97 | ret err |
| 98 | end |
| 99 | put r 2 add get r 2 1 |
| 100 | put r 1 2 |
| 101 | ret 0 |
| 102 | end |
| 103 | |
| 104 | fn actlost r edit ulong 32 to ulong |
| 105 | err = actvalid r |
| 106 | if ne err 0 |
| 107 | ret err |
| 108 | end |
| 109 | if eq get r 1 3 |
| 110 | ret 0 |
| 111 | end |
| 112 | if ne get r 1 2 |
| 113 | ret 20 |
| 114 | end |
| 115 | put r 1 3 |
| 116 | ret 0 |
| 117 | end |
| 118 | |
| 119 | note A trusted receipt maps outcome 0 unknown,1 definitely not performed,2 performed. |
| 120 | note Not-found or timeout is outcome 0 unless the provider proves absence and quiescence. |
| 121 | note Receipt words 2/3: exact attempt and verification=1. Words 6/7 must be zero. |
| 122 | note Recording an observed outcome is permitted after expiry; another attempt is not. |
| 123 | fn actrecon r edit ulong 32 s view ulong 32 to ulong |
| 124 | err = actvalid r |
| 125 | if ne err 0 |
| 126 | ret err |
| 127 | end |
| 128 | if not or eq get r 1 2 eq get r 1 3 |
| 129 | ret 20 |
| 130 | end |
| 131 | if ne get s 0 1 |
| 132 | ret 11 |
| 133 | end |
| 134 | if or gt get s 1 2 or ne get s 6 0 ne get s 7 0 |
| 135 | ret 12 |
| 136 | end |
| 137 | if ne get s 3 1 |
| 138 | ret 36 |
| 139 | end |
| 140 | if ne get s 2 get r 2 |
| 141 | ret 35 |
| 142 | end |
| 143 | if ne get s 4 get r 4 |
| 144 | ret 31 |
| 145 | end |
| 146 | if ne get s 5 get r 5 |
| 147 | ret 32 |
| 148 | end |
| 149 | err = actbind r s |
| 150 | if ne err 0 |
| 151 | ret err |
| 152 | end |
| 153 | if eq get s 1 0 |
| 154 | put r 1 3 |
| 155 | ret 21 |
| 156 | end |
| 157 | if eq get s 1 1 |
| 158 | put r 1 1 |
| 159 | else |
| 160 | put r 1 4 |
| 161 | end |
| 162 | ret 0 |
| 163 | end |