interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / protocol / aien-protocols / ext / evaluation.om

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