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 / aien-protocols / ext / evaluation.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note protocol/aien-protocols/ext/evaluation.om: pure-Omega port of aien-evaluation-protocol (AEI-1) |
| 3 | note Implements evaluation binding verification, basis-point score validation, |
| 4 | note adaptive sequential stopping decisions, and monotonic round replay guards. |
| 5 | note Compose after si/directives/om2.om, om/tls/sha2.om, and protocol/aien-protocols/core/types.om. |
| 6 | |
| 7 | const EV_OK ulong 0 |
| 8 | const EV_ERR_BINDING ulong 1 |
| 9 | const EV_ERR_SCORE_RANGE ulong 2 |
| 10 | const EV_ERR_SAMPLE_COUNT ulong 3 |
| 11 | const EV_ERR_THRESHOLD ulong 4 |
| 12 | const EV_ERR_DIGEST ulong 5 |
| 13 | const EV_ERR_REPLAY ulong 6 |
| 14 | |
| 15 | const EV_DEC_CONTINUE ulong 1 |
| 16 | const EV_DEC_ACCEPT ulong 2 |
| 17 | const EV_DEC_REJECT ulong 3 |
| 18 | const EV_DEC_INVALID ulong 4 |
| 19 | |
| 20 | const EV_BPS_MAX ulong 10000 |
| 21 | const EV_SAFE_MUL_MAX ulong 1844674407370955 |
| 22 | |
| 23 | text ev_dom_bind "aei1:binding:v1|" |
| 24 | |
| 25 | fn ev_compute_binding eval_id view uchar 16 model_dig view uchar 32 dataset_dig view uchar 32 seed ulong dst edit uchar 32 to void |
| 26 | ctx = new ulong 40 0 |
| 27 | sha256_init ctx |
| 28 | sha256_update ctx ev_dom_bind |
| 29 | sha256_update ctx eval_id |
| 30 | sha256_update ctx model_dig |
| 31 | sha256_update ctx dataset_dig |
| 32 | sb = new uchar 8 0 |
| 33 | slen = pt_put_u64_le sb ulong 0 seed |
| 34 | sha256_update ctx part sb ulong 0 slen |
| 35 | sha256_final ctx dst |
| 36 | end |
| 37 | |
| 38 | fn ev_verify_binding eval_id view uchar 16 model_dig view uchar 32 dataset_dig view uchar 32 seed ulong claimed view uchar 32 to ulong |
| 39 | if uuid_is_nil eval_id |
| 40 | ret EV_ERR_BINDING |
| 41 | end |
| 42 | if or digest_is_zero model_dig digest_is_zero dataset_dig |
| 43 | ret EV_ERR_DIGEST |
| 44 | end |
| 45 | exp = new uchar 32 0 |
| 46 | ev_compute_binding eval_id model_dig dataset_dig seed exp |
| 47 | if not digest_eq exp claimed |
| 48 | ret EV_ERR_BINDING |
| 49 | end |
| 50 | ret EV_OK |
| 51 | end |
| 52 | |
| 53 | fn ev_score_validate passed ulong total ulong pass_bps ulong to ulong |
| 54 | if eq total ulong 0 |
| 55 | ret EV_ERR_SAMPLE_COUNT |
| 56 | end |
| 57 | if gt passed total |
| 58 | ret EV_ERR_SCORE_RANGE |
| 59 | end |
| 60 | if gt pass_bps EV_BPS_MAX |
| 61 | ret EV_ERR_SCORE_RANGE |
| 62 | end |
| 63 | if gt passed EV_SAFE_MUL_MAX |
| 64 | ret EV_ERR_SCORE_RANGE |
| 65 | end |
| 66 | calc = div mul passed EV_BPS_MAX total |
| 67 | if ne calc pass_bps |
| 68 | ret EV_ERR_SCORE_RANGE |
| 69 | end |
| 70 | ret EV_OK |
| 71 | end |
| 72 | |
| 73 | fn ev_adaptive_decide passed ulong total ulong min_n ulong max_n ulong accept_bps ulong reject_bps ulong to ulong |
| 74 | if or eq min_n ulong 0 gt min_n max_n |
| 75 | ret EV_DEC_INVALID |
| 76 | end |
| 77 | if gt passed total |
| 78 | ret EV_DEC_INVALID |
| 79 | end |
| 80 | if or ge reject_bps accept_bps gt accept_bps EV_BPS_MAX |
| 81 | ret EV_DEC_INVALID |
| 82 | end |
| 83 | if gt passed EV_SAFE_MUL_MAX |
| 84 | ret EV_DEC_INVALID |
| 85 | end |
| 86 | if lt total min_n |
| 87 | ret EV_DEC_CONTINUE |
| 88 | end |
| 89 | bps = div mul passed EV_BPS_MAX total |
| 90 | if ge bps accept_bps |
| 91 | ret EV_DEC_ACCEPT |
| 92 | end |
| 93 | if le bps reject_bps |
| 94 | ret EV_DEC_REJECT |
| 95 | end |
| 96 | if ge total max_n |
| 97 | ret EV_DEC_REJECT |
| 98 | end |
| 99 | ret EV_DEC_CONTINUE |
| 100 | end |
| 101 | |
| 102 | fn ev_check_monotonic_round prev_round ulong next_round ulong to ulong |
| 103 | if eq prev_round U64_MAX |
| 104 | ret EV_ERR_REPLAY |
| 105 | end |
| 106 | if ne next_round add prev_round ulong 1 |
| 107 | ret EV_ERR_REPLAY |
| 108 | end |
| 109 | ret EV_OK |
| 110 | end |