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 / gpu / nvidia / native / arboris / digest.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Derive the host witness from the exact bytes of a fenced, serialized |
| 3 | note Arboris step. Arena framing is header words 0..14, logical topology, |
| 4 | note parameters and active input state, in little-endian order. Padding and |
| 5 | note guard VAs are outside the commitment. The kernel and output use SHA-256 |
| 6 | note over their unpadded code and state bytes respectively. |
| 7 | fn ar_hash_mapping ctx edit ulong 40 tok long bytes ulong to bool |
| 8 | buf = new uchar 4096 0 |
| 9 | start = ulong 0 |
| 10 | while lt start bytes bound 0x10000000 |
| 11 | take = sub bytes start |
| 12 | if gt take 4096 |
| 13 | take = ulong 4096 |
| 14 | end |
| 15 | if ne mapread tok start buf 0 take long take |
| 16 | ret false |
| 17 | end |
| 18 | sha256_update ctx part buf 0 take |
| 19 | start = add start take |
| 20 | end |
| 21 | ret true |
| 22 | end |
| 23 | |
| 24 | fn ar_hash_header ctx edit ulong 40 m view ulong 16 to void |
| 25 | header = new uchar 120 0 |
| 26 | for i ulong 15 |
| 27 | for j ulong 8 |
| 28 | put header add mul i 8 j uchar and shr get m i mul j 8 255 |
| 29 | end |
| 30 | end |
| 31 | sha256_update ctx header |
| 32 | end |
| 33 | |
| 34 | fn ar_logical_state m view ulong 16 to ulong |
| 35 | if eq get m 0 arboris_magic |
| 36 | ret mul mul get m 1 get m 4 2 |
| 37 | end |
| 38 | ret get m 11 |
| 39 | end |
| 40 | |
| 41 | fn ar_input_code_digests m view ulong 16 receipt edit uchar 96 to bool |
| 42 | topo = get m 9 |
| 43 | state = ar_logical_state m |
| 44 | if eq get m 0 arboris_magic |
| 45 | topo = mul topology_words m 4 |
| 46 | else |
| 47 | if ne get m 0 arboris_sparse_magic |
| 48 | ret false |
| 49 | end |
| 50 | end |
| 51 | if eq get ar_code_bytes 0 0 |
| 52 | ret false |
| 53 | end |
| 54 | ctx = new ulong 40 0 |
| 55 | sha256_init ctx |
| 56 | ar_hash_header ctx m |
| 57 | if not ar_hash_mapping ctx get ar_maps 1 topo |
| 58 | ret false |
| 59 | end |
| 60 | if not ar_hash_mapping ctx get ar_maps 2 get m 10 |
| 61 | ret false |
| 62 | end |
| 63 | if not ar_hash_mapping ctx get ar_maps add 3 get m 6 state |
| 64 | ret false |
| 65 | end |
| 66 | sha256_final ctx part receipt 0 32 |
| 67 | sha256_init ctx |
| 68 | if not ar_hash_mapping ctx get gbmem 4 get ar_code_bytes 0 |
| 69 | ret false |
| 70 | end |
| 71 | sha256_final ctx part receipt 32 32 |
| 72 | ret true |
| 73 | end |
| 74 | |
| 75 | fn ar_step_digests m view ulong 16 seq ulong hashes edit uchar 96 to bool |
| 76 | if or eq seq 0 ne seq get ar_fenced_seq 0 |
| 77 | ret false |
| 78 | end |
| 79 | if or ne seq get nvret 0 ne seq get nvput 0 |
| 80 | ret false |
| 81 | end |
| 82 | if or ne get nvfault 0 0 not ar_device_receipt get ar_maps 5 seq |
| 83 | ret false |
| 84 | end |
| 85 | if not ar_snapshot_matches m |
| 86 | ret false |
| 87 | end |
| 88 | receipt = new uchar 96 0 |
| 89 | if not ar_input_code_digests m receipt |
| 90 | ret false |
| 91 | end |
| 92 | ctx = new ulong 40 0 |
| 93 | sha256_init ctx |
| 94 | if not ar_hash_mapping ctx get ar_maps sub ulong 4 get m 6 ar_logical_state m |
| 95 | ret false |
| 96 | end |
| 97 | sha256_final ctx part receipt 64 32 |
| 98 | for i ulong 96 |
| 99 | put hashes i get receipt i |
| 100 | end |
| 101 | ret true |
| 102 | end |