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