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 / src / physics0 / controls / pd0_receipt.om

108 lines · 3060 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note src/physics0/controls/pd0_receipt.om: Append-only O_EXCL verifier receipt writer.
3note A receipt is never overwritten: <dir>/<kind>-<16 hex of input_hash>-<n>.receipt, n counted up from 0.
4note The build prepends PD0_VERIFIER_COMMIT (text, the short commit) the way the C build passed -DPD0_VERIFIER_COMMIT.
5
6text REC_SL "/"
7text REC_DA "-"
8text REC_EXT ".receipt"
9text REC_K1 "kind: "
10text REC_K1C "\nverifier_commit: "
11text REC_K1H "\ninput_sha256: "
12text REC_K2 "\ncode: "
13text REC_K2N "\nname: "
14text REC_K3 "\nrecorder: STAND_IN\nrange_check: STAND_IN\n"
15
16text REC_HEX "0123456789abcdef"
17
18global rc_dir uchar 512
19global rc_dir_len ulong 1
20global rc_hex uchar 64
21
22fn pd0_receipt_dir d view uchar * to void
23n = len d
24if gt n ulong 511
25n = ulong 511
26end
27for i ulong n bound 512
28put rc_dir i get d i
29end
30put rc_dir_len 0 n
31ret
32end
33
34fn rc_path_dir path edit uchar 1024 to ulong
35p = ulong 0
36n = get rc_dir_len 0
37for i ulong n bound 512
38put path p get rc_dir i
39p = add p 1
40end
41ret p
42end
43
44fn rc_body body edit uchar 4096 kind view uchar * code int extra view uchar * to ulong
45bp = pd0_buf_str edit body ulong 0 ulong 4096 REC_K1
46bp = pd0_buf_str edit body bp ulong 4096 kind
47bp = pd0_buf_str edit body bp ulong 4096 REC_K1C
48bp = pd0_buf_str edit body bp ulong 4096 PD0_VERIFIER_COMMIT
49bp = pd0_buf_str edit body bp ulong 4096 REC_K1H
50for i ulong 64
51bp = pd0_buf_ch edit body bp ulong 4096 get rc_hex i
52end
53bp = pd0_buf_str edit body bp ulong 4096 REC_K2
54bp = pd0_buf_i64 edit body bp ulong 4096 long code
55bp = pd0_buf_str edit body bp ulong 4096 REC_K2N
56bp = pd0v_name_buf edit body bp ulong 4096 code
57bp = pd0_buf_str edit body bp ulong 4096 REC_K3
58el = len extra
59if gt el ulong 0
60bp = pd0_buf_str edit body bp ulong 4096 extra
61if ne get extra sub el 1 uchar 10
62bp = pd0_buf_ch edit body bp ulong 4096 uchar 10
63end
64end
65ret bp
66end
67
68fn rc_path path edit uchar 1024 kind view uchar * n ulong to ulong
69p = rc_path_dir edit path
70p = pd0_buf_str edit path p ulong 1023 REC_SL
71p = pd0_buf_str edit path p ulong 1023 kind
72p = pd0_buf_str edit path p ulong 1023 REC_DA
73for i ulong 16
74p = pd0_buf_ch edit path p ulong 1023 get rc_hex i
75end
76p = pd0_buf_str edit path p ulong 1023 REC_DA
77p = pd0_buf_u64 edit path p ulong 1023 n
78ret pd0_buf_str edit path p ulong 1023 REC_EXT
79end
80
81note extra: appended after the fixed lines; a newline is added when it does not end with one (empty = none)
82fn pd0_receipt_write kind view uchar * h view uchar 32 code int extra view uchar * to int
83for i ulong 32
84b = get h i
85put rc_hex mul i 2 get REC_HEX ulong shr b 4
86put rc_hex add mul i 2 1 get REC_HEX ulong and b uchar 15
87end
88path = new uchar 1024 0
89body = new uchar 4096 0
90for n ulong 100000
91p = rc_path edit path kind n
92note O_WRONLY|O_CREAT|O_EXCL = 1|64|128 = 193, mode 0444 = 292
93fd = fopen path 0 p int 193 int 292
94if ge fd long 0
95bp = rc_body edit body kind code extra
96w = write int fd body 0 bp
97c = fclose int fd
98if ne w long bp
99ret PD0V_RECEIPT_IO
100end
101ret 0
102end
103if ne fd long -17
104ret PD0V_RECEIPT_IO
105end
106end
107ret PD0V_RECEIPT_IO
108end