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 / tools / e1_combine.sh

369 lines · 24249 bytes Raw Blame History
1#!/bin/bash
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# e1_combine.sh -- E1 numerical closure receipt (one deterministic, content-addressed aggregate).
18#
19# tools/e1_combine.sh --candidate SHA --main SHA --physics SHA --manifest FILE \
20# --gate5 FILE --reduce FILE --transc FILE --mutant-log FILE --campaign-log FILE \
21# --ldst-chip-log FILE --host-rerun FILE --transc-prior FILE [--evidence-dir DIR]
22#
23# Read-only aggregation, in the spirit of tools/gate14_combine.sh. The E1 chip
24# campaign ran on --candidate; the squash merge is --main. This receipt never
25# says the chip ran on main. It binds, and refuses unless every one holds:
26#
27# manifest AIEN_E1_EQUIVALENCE_MANIFEST_V1 from tools/e1_manifest.sh for exactly
28# these two commits; every file's digests are recomputed here from git;
29# every chip-class file equal; a differing host-class file is allowed
30# only because --host-rerun proves the host tier PASSED on main; the
31# rebuilt chip binaries (from main) equal the binary digests the Gate 5,
32# reduce and transc receipts carry.
33# gate5 AIEN_OMEGA_NUMERIC_0_V1: receipt_digest = SHA-256 of the canonical body
34# without it (tools/json_canon.c), named for it, PASS, exit 0, no failures,
35# candidate = run commit = --candidate, physics = lock = --physics, clean trees.
36# reduce E1_REDUCE_GB10_PARITY: file SHA-256 = file name, PASS, exit "0",
37# ops exactly SUM MAX MIN MEAN, 380 cases, 0 mismatches overall and per op,
38# commits and clean flags as above.
39# transc E1-TRANSC-GB10: file SHA-256 = file name, PASS, chip exit 0, ops exactly
40# SIN COS ERF GELU RSQRT, each checked 4294967296 exhaustive, 0 mismatches,
41# 0 unwritten, commits, pins and clean flags as above.
42# prior the earlier E1-TRANSC-GB10 receipt (EXP2 LOG2 SIGMOID TANH, each 4294967296
43# exhaustive, 0 mismatches, PASS, same Physics): its four kernel digests must
44# equal the same four kernels listed in --transc, so the words that ran on the
45# chip then are the words the candidate carries. Its omega commit is recorded,
46# not required to equal --candidate.
47# mutant the MEAN mutant chip log, SHA-256 = file name: MEAN FAIL with mismatches > 0,
48# SUM MAX MIN PASS with 0 mismatches (the chip caught the mutant).
49# campaign the five-step campaign log: names candidate and physics, LDST host and
50# chip PASS, names the Gate 5, reduce, transc and mutant digests above,
51# "E1 MEAN MUTANT: KILLED", final VERDICT PASS, no GB10_COMPLETION_UNCERTAIN.
52# ldst log the LDST chip log: as many "RESULT chip ... verdict=PASS" lines as the
53# campaign's "specs passed", no OMEGA_DEVERR, last VERDICT PASS.
54# host rerun AIEN_E1_HOST_RERUN_V1, SHA-256 = file name, omega_commit = --main, clean
55# tracked tree before and after, every one of the six host lines PASS.
56#
57# On accept prints the receipt digest and, with --evidence-dir, writes
58# <dir>/<digest>.json (pretty, exclusive, 0444; the location is evidence/E1-CLOSURE/).
59# On refuse prints "REFUSED: <reason>" on stderr, writes nothing, exits 1. Exit 2 = usage.
60# Digests make alteration detectable; they are not signatures. Shell + coreutils +
61# git + jq + tools/json_canon.c. No Python.
62
63E1_OMEGA=$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
64E1_GIT=${E1_GIT_DIR:-$E1_OMEGA} # tests point this at a scratch repository
65E1_SCHEMA=AIEN_E1_CLOSURE_V1
66E1_ERR=
67E1_HOST_LINES="GB10-COMPILE NUMERIC-HOST PROGRAM TRANSC MANIFEST HOSTALL"
68
69e1_refuse() { E1_ERR=$1; return 1; }
70
71e1_build_canon() {
72 E1_TMP=$(mktemp -d "${TMPDIR:-/tmp}/e1combine.XXXXXX") || return 1
73 JSON_CANON=$E1_TMP/json_canon
74 "$E1_OMEGA/seed/out/omc" < "$E1_OMEGA/tools/json_canon.om" > "$JSON_CANON" && chmod +x "$JSON_CANON"
75}
76
77e1_sha() { sha256sum -- "$1" | cut -c1-64; }
78
79# e1_copy FILE VAR -- private copy of FILE (so it cannot change between checks).
80e1_copy() {
81 local f=$1 s
82 [ -n "$f" ] || e1_refuse "a required input was not given" || return 1
83 [ -f "$f" ] && [ -r "$f" ] || e1_refuse "cannot read $f" || return 1
84 s=$(mktemp "$E1_TMP/in.XXXXXX") && cp -- "$f" "$s" || e1_refuse "cannot copy $f" || return 1
85 printf -v "$2" '%s' "$s"
86}
87
88e1_json() { # FILE -- valid JSON object
89 "$JSON_CANON" --check < "$1" || e1_refuse "$2 is not valid JSON" || return 1
90 jq -e 'type == "object"' "$1" > /dev/null || e1_refuse "$2 is not a JSON object" || return 1
91}
92
93e1_named_for_sha() { # FILE ORIG LABEL -- file name is its own SHA-256
94 local name; name=$(basename "$2")
95 [ "$name" = "$(e1_sha "$1").${name##*.}" ] || e1_refuse "$3 $2 is not named for its SHA-256" || return 1
96}
97
98# ---- children ----
99
100e1_check_gate5() { # FILE ORIG
101 local s=$1 f=$2 d rc
102 e1_json "$s" "$f" || return 1
103 [ "$(jq -r '.schema // ""' "$s")" = AIEN_OMEGA_NUMERIC_0_V1 ] || e1_refuse "gate5 $f has the wrong schema" || return 1
104 d=$(jq -r '.receipt_digest // ""' "$s")
105 [[ $d =~ ^[0-9a-f]{64}$ ]] || e1_refuse "gate5 $f has no 64-hex receipt_digest" || return 1
106 rc=$(jq -c 'del(.receipt_digest)' "$s" | "$JSON_CANON" --sha256) || e1_refuse "cannot digest gate5 $f" || return 1
107 [ "$rc" = "$d" ] || e1_refuse "gate5 $f receipt_digest does not match its content" || return 1
108 [ "$(basename "$f" .json)" = "$d" ] || e1_refuse "gate5 $f is named for a different digest" || return 1
109 jq -e --arg c "$E1_CAND" --arg p "$E1_PHYS" '
110 .status == "PASS" and .gate_binary_exit_status == 0 and .observed_fail_count == 0
111 and .candidate_git_commit == $c and .run_git_commit == $c
112 and .physics_candidate_git_commit == $p and .physics_lock == $p
113 and .candidate_trees_clean.omega == true and .candidate_trees_clean.physics == true
114 and (.test_results | type) == "array" and (.test_results | length) > 0
115 and (.test_results | length) == .observed_test_count
116 and .observed_pass_count == .observed_test_count
117 and all(.test_results[]; .status == "PASS")
118 and (.hardware_descriptor_digest | type) == "string" and (.hardware_descriptor_digest | test("^[0-9a-f]{64}$"))
119 and (.candidate_binary_sha256 | type) == "string" and (.candidate_binary_sha256 | test("^[0-9a-f]{64}$"))' \
120 "$s" > /dev/null 2>&1 || e1_refuse "gate5 $f does not record a PASS on candidate $E1_CAND / physics $E1_PHYS" || return 1
121 E1_G5_DIGEST=$d
122 E1_G5_BIN=$(jq -r .candidate_binary_sha256 "$s")
123 E1_G5_HW=$(jq -r .hardware_descriptor_digest "$s")
124 E1_G5_TESTS=$(jq -r .observed_test_count "$s")
125}
126
127e1_check_reduce() { # FILE ORIG
128 local s=$1 f=$2
129 e1_json "$s" "$f" || return 1
130 e1_named_for_sha "$s" "$f" reduce || return 1
131 jq -e --arg c "$E1_CAND" --arg p "$E1_PHYS" '
132 .suite == "E1_REDUCE_GB10_PARITY" and .status == "PASS" and .exit_status == "0"
133 and .omega_commit == $c and .physics_commit == $p
134 and .omega_clean_before == true and .omega_clean_after == true
135 and .ops == ["SUM","MAX","MIN","MEAN"]
136 and (.parity_line | test("^RED_GB10_PARITY: PASS ops=SUM,MAX,MIN,MEAN cases=380 mismatches=0$"))
137 and ([.ops[] as $o | .parity_by_op[$o]] | all(type == "string" and test("^RED_GB10_PARITY_[A-Z]+: PASS op=") and test(" mismatches=0( |$)")))
138 and ([.ops[] as $o | .parity_by_op[$o] | capture("cases=(?<n>[0-9]+)") | .n | tonumber] | add) == 380
139 and (.binary_sha256 | type) == "string" and (.binary_sha256 | test("^[0-9a-f]{64}$"))
140 and (.log_sha256 | type) == "string" and (.log_sha256 | test("^[0-9a-f]{64}$"))' \
141 "$s" > /dev/null 2>&1 || e1_refuse "reduce $f does not record SUM/MAX/MIN/MEAN 380 cases 0 mismatches PASS on candidate $E1_CAND / physics $E1_PHYS" || return 1
142 E1_RED_DIGEST=$(e1_sha "$s")
143 E1_RED_BIN=$(jq -r .binary_sha256 "$s")
144}
145
146e1_check_transc() { # FILE ORIG
147 local s=$1 f=$2
148 e1_json "$s" "$f" || return 1
149 e1_named_for_sha "$s" "$f" transc || return 1
150 jq -e --arg c "$E1_CAND" --arg p "$E1_PHYS" '
151 .gate == "E1-TRANSC-GB10" and .verdict == "PASS" and .chip_exit_status == 0
152 and .omega_commit == $c and .physics_commit == $p and .physics_lock_pin == $p
153 and .omega_tree_clean_before == true and .omega_tree_clean_after == true and .omega_commit_unchanged_after == true
154 and .physics_tree_clean_before == true and .physics_tree_clean_after == true and .physics_commit_unchanged_after == true
155 and .ops_requested == ["SIN","COS","ERF","GELU","RSQRT"]
156 and ([.ops[].op] | sort) == (["SIN","COS","ERF","GELU","RSQRT"] | sort) and (.ops | length) == 5
157 and all(.ops[]; .checked == 4294967296 and .exhaustive == true and .mismatches == 0 and .unwritten == 0 and .verdict == "PASS")
158 and (.binary_sha256 | type) == "string" and (.binary_sha256 | test("^[0-9a-f]{64}$"))
159 and (.chip_log_sha256 | type) == "string" and (.chip_log_sha256 | test("^[0-9a-f]{64}$"))' \
160 "$s" > /dev/null 2>&1 || e1_refuse "transc $f does not record five exhaustive 2^32 PASS ops on candidate $E1_CAND / physics $E1_PHYS" || return 1
161 E1_TR_DIGEST=$(e1_sha "$s")
162 E1_TR_BIN=$(jq -r .binary_sha256 "$s")
163 E1_TR_INPUTS=$(jq -r '[.ops[].checked] | add' "$s")
164}
165
166e1_check_transc_prior() { # FILE ORIG (needs e1_check_transc first)
167 local s=$1 f=$2 op a b
168 e1_json "$s" "$f" || return 1
169 e1_named_for_sha "$s" "$f" "transc prior" || return 1
170 jq -e --arg p "$E1_PHYS" '
171 .gate == "E1-TRANSC-GB10" and .verdict == "PASS" and .chip_exit_status == 0
172 and .physics_commit == $p and .physics_lock_pin == $p
173 and .omega_tree_clean_before == true and .omega_tree_clean_after == true
174 and (.omega_commit | test("^[0-9a-f]{40}$"))
175 and ([.ops[].op] | sort) == (["EXP2","LOG2","SIGMOID","TANH"] | sort) and (.ops | length) == 4
176 and all(.ops[]; .checked == 4294967296 and .exhaustive == true and .mismatches == 0 and .unwritten == 0 and .verdict == "PASS")
177 and (.kernels | type) == "array"' "$s" > /dev/null 2>&1 ||
178 e1_refuse "transc prior $f does not record EXP2/LOG2/SIGMOID/TANH exhaustive PASS on physics $E1_PHYS" || return 1
179 for op in EXP2 LOG2 SIGMOID TANH; do
180 a=$(jq -r --arg o "$op" '[.kernels[] | select(.op == $o) | .sha256] | if length == 1 then .[0] else "" end' "$s")
181 b=$(jq -r --arg o "$op" '[.kernels[] | select(.op == $o) | .sha256] | if length == 1 then .[0] else "" end' "$E1_S_TR")
182 [[ $a =~ ^[0-9a-f]{64}$ ]] && [ "$a" = "$b" ] || e1_refuse "transc prior $f: $op kernel digest ($a) is not the candidate kernel ($b)" || return 1
183 done
184 E1_TRP_DIGEST=$(e1_sha "$s")
185 E1_TRP_COMMIT=$(jq -r .omega_commit "$s")
186}
187
188e1_check_mutant() { # FILE ORIG
189 local s=$1 f=$2 m
190 e1_named_for_sha "$s" "$f" mutant || return 1
191 m=$(grep -E '^RED_GB10_PARITY_MEAN: FAIL ' "$s" | grep -oE 'mismatches=[0-9]+' | head -n1 | cut -d= -f2)
192 [ -n "$m" ] && [ "$m" -gt 0 ] || e1_refuse "mutant log $f does not show MEAN failing with mismatches > 0" || return 1
193 for op in SUM MAX MIN; do
194 grep -Eq "^RED_GB10_PARITY_$op: PASS .* mismatches=0( |$)" "$s" || e1_refuse "mutant log $f does not show $op PASS with 0 mismatches" || return 1
195 done
196 grep -q '^E1 Reduce Verdict: FAIL$' "$s" || e1_refuse "mutant log $f lacks the FAIL verdict" || return 1
197 E1_MUT_DIGEST=$(e1_sha "$s")
198 E1_MUT_MISMATCHES=$m
199}
200
201e1_check_campaign() { # FILE ORIG
202 local s=$1 f=$2
203 grep -Eq "^omega $E1_CAND physics $E1_PHYS\$" "$s" || e1_refuse "campaign log $f does not name candidate $E1_CAND and physics $E1_PHYS" || return 1
204 ! grep -q GB10_COMPLETION_UNCERTAIN "$s" || e1_refuse "campaign log $f records an uncertain completion" || return 1
205 grep -Eq '^Gate LDST host: PASSED=[1-9][0-9]* FAILED=0$' "$s" || e1_refuse "campaign log $f lacks LDST host PASS with 0 failures" || return 1
206 grep -Eq '^\[PASS\] ldst: ([0-9]+) of \1 kernels decode' "$s" || e1_refuse "campaign log $f lacks the full ldst nvdisasm decode" || return 1
207 E1_LDST_SPECS=$(grep -E '^specs passed: [0-9]+$' "$s" | head -n1 | cut -d' ' -f3)
208 [ -n "$E1_LDST_SPECS" ] && [ "$E1_LDST_SPECS" -gt 0 ] || e1_refuse "campaign log $f lacks 'specs passed: N'" || return 1
209 grep -q "^Gate 5 PASS: receipt digest $E1_G5_DIGEST\$" "$s" || e1_refuse "campaign log $f does not name the Gate 5 receipt $E1_G5_DIGEST" || return 1
210 grep -Eq "^receipt: .*/$E1_RED_DIGEST\.json status=PASS" "$s" || e1_refuse "campaign log $f does not name the reduce receipt $E1_RED_DIGEST as PASS" || return 1
211 grep -Eq "^RECEIPT .*/$E1_TR_DIGEST\.json\$" "$s" || e1_refuse "campaign log $f does not name the transc receipt $E1_TR_DIGEST" || return 1
212 grep -q "^log sha256: $E1_MUT_DIGEST\$" "$s" || e1_refuse "campaign log $f does not name the mutant log $E1_MUT_DIGEST" || return 1
213 grep -q '^E1 MEAN MUTANT: KILLED$' "$s" || e1_refuse "campaign log $f does not record the MEAN mutant as KILLED" || return 1
214 [ "$(grep -E '^VERDICT ' "$s" | tail -n1)" = "VERDICT PASS" ] || e1_refuse "campaign log $f does not end on VERDICT PASS" || return 1
215 E1_CAMP_DIGEST=$(e1_sha "$s")
216}
217
218e1_check_ldst_log() { # FILE ORIG
219 local s=$1 f=$2 n
220 n=$(grep -cE '^RESULT chip .* verdict=PASS' "$s")
221 [ "$n" = "$E1_LDST_SPECS" ] || e1_refuse "ldst chip log $f has $n PASS results, campaign says $E1_LDST_SPECS" || return 1
222 ! grep -Eq 'verdict=(FAIL|NOT_RUN)' "$s" || e1_refuse "ldst chip log $f has a failed or unrun spec" || return 1
223 ! grep -q OMEGA_DEVERR "$s" || e1_refuse "ldst chip log $f records a device error" || return 1
224 [ "$(grep -E '^VERDICT ' "$s" | tail -n1)" = "VERDICT PASS" ] || e1_refuse "ldst chip log $f does not end on VERDICT PASS" || return 1
225 E1_LDST_DIGEST=$(e1_sha "$s")
226}
227
228e1_check_host_rerun() { # FILE ORIG
229 local s=$1 f=$2 l
230 e1_json "$s" "$f" || return 1
231 e1_named_for_sha "$s" "$f" "host rerun" || return 1
232 jq -e --arg m "$E1_MAIN" '
233 .schema == "AIEN_E1_HOST_RERUN_V1" and .omega_commit == $m
234 and .tracked_tree_clean_before == true and .tracked_tree_clean_after == true
235 and (.lines | type) == "object"' "$s" > /dev/null 2>&1 ||
236 e1_refuse "host rerun $f is not a clean-tree E1 host rerun on main $E1_MAIN" || return 1
237 for l in $E1_HOST_LINES; do
238 [ "$(jq -r --arg l "$l" '.lines[$l] // ""' "$s")" = PASS ] || e1_refuse "host rerun $f: line $l is not PASS" || return 1
239 done
240 E1_HOST_DIGEST=$(e1_sha "$s")
241}
242
243e1_check_manifest() { # FILE ORIG
244 local s=$1 f=$2 n i path cls a b eq ga gb nd
245 e1_json "$s" "$f" || return 1
246 jq -e --arg c "$E1_CAND" --arg m "$E1_MAIN" '
247 .schema == "AIEN_E1_EQUIVALENCE_MANIFEST_V1" and .candidate_git_commit == $c and .main_git_commit == $m
248 and (.files | type) == "array" and (.files | length) > 0
249 and (.rebuilt_chip_binaries | type) == "array"' "$s" > /dev/null 2>&1 ||
250 e1_refuse "manifest $f is not an equivalence manifest for $E1_CAND -> $E1_MAIN with rebuilt binaries" || return 1
251 git -C "$E1_GIT" cat-file -e "$E1_CAND^{commit}" 2>/dev/null || e1_refuse "candidate $E1_CAND is not in this repository" || return 1
252 git -C "$E1_GIT" cat-file -e "$E1_MAIN^{commit}" 2>/dev/null || e1_refuse "main $E1_MAIN is not in this repository" || return 1
253 n=$(jq -r '.files | length' "$s"); nd=0
254 for ((i = 0; i < n; i++)); do
255 path=$(jq -r ".files[$i].path" "$s"); cls=$(jq -r ".files[$i].class" "$s")
256 a=$(jq -r ".files[$i].sha256_candidate" "$s"); b=$(jq -r ".files[$i].sha256_main" "$s"); eq=$(jq -r ".files[$i].equal" "$s")
257 [[ $path =~ ^[A-Za-z0-9._/-]+$ ]] || e1_refuse "manifest $f has an odd path" || return 1
258 ga=$(git -C "$E1_GIT" cat-file -e "$E1_CAND:$path" 2>/dev/null && git -C "$E1_GIT" show "$E1_CAND:$path" | sha256sum | cut -c1-64 || echo ABSENT)
259 gb=$(git -C "$E1_GIT" cat-file -e "$E1_MAIN:$path" 2>/dev/null && git -C "$E1_GIT" show "$E1_MAIN:$path" | sha256sum | cut -c1-64 || echo ABSENT)
260 [ "$a" = "$ga" ] && [ "$b" = "$gb" ] || e1_refuse "manifest $f: digests of $path do not match git" || return 1
261 if [ "$a" = "$b" ]; then [ "$eq" = true ] || e1_refuse "manifest $f: $path equal flag is wrong" || return 1
262 else
263 [ "$eq" = false ] || e1_refuse "manifest $f: $path equal flag is wrong" || return 1
264 [ "$cls" = host ] || e1_refuse "manifest $f: chip artifact $path differs between candidate and main" || return 1
265 nd=$((nd + 1))
266 fi
267 done
268 [ "$(jq -r .chip_files_differ "$s")" = 0 ] || e1_refuse "manifest $f declares differing chip files" || return 1
269 [ "$(jq -r .files_differ "$s")" = "$nd" ] || e1_refuse "manifest $f files_differ count is wrong" || return 1
270 E1_HOST_DIFFER=$nd
271 for pair in "GATE5:$E1_G5_BIN" "REDUCE:$E1_RED_BIN" "TRANSC:$E1_TR_BIN"; do
272 a=$(jq -r --arg g "${pair%%:*}" '[.rebuilt_chip_binaries[] | select(.gate == $g) | .sha256_main] | if length == 1 then .[0] else "" end' "$s")
273 [ "$a" = "${pair#*:}" ] || e1_refuse "manifest $f: rebuilt ${pair%%:*} binary from main ($a) is not the chip-run binary (${pair#*:})" || return 1
274 done
275 E1_LDST_BIN=$(jq -r '[.rebuilt_chip_binaries[] | select(.gate == "LDST") | .sha256_main] | if length == 1 then .[0] else "" end' "$s")
276 [[ $E1_LDST_BIN =~ ^[0-9a-f]{64}$ ]] || e1_refuse "manifest $f: no rebuilt LDST binary digest" || return 1
277 E1_MAN_DIGEST=$(e1_sha "$s")
278 E1_WHOLE_TREE=$(jq -r .whole_tree_identical "$s")
279}
280
281# ---- combine ----
282
283e1_combine() { # TS
284 local ts=$1 body
285 e1_copy "$E1_IN_MANIFEST" S_MAN && e1_copy "$E1_IN_G5" S_G5 && e1_copy "$E1_IN_RED" S_RED &&
286 e1_copy "$E1_IN_TR" S_TR && e1_copy "$E1_IN_MUT" S_MUT && e1_copy "$E1_IN_CAMP" S_CAMP &&
287 e1_copy "$E1_IN_LDST" S_LDST && e1_copy "$E1_IN_HOST" S_HOST && e1_copy "$E1_IN_TRP" S_TRP || return 1
288 E1_S_TR=$S_TR
289 e1_check_gate5 "$S_G5" "$E1_IN_G5" || return 1
290 e1_check_reduce "$S_RED" "$E1_IN_RED" || return 1
291 e1_check_transc "$S_TR" "$E1_IN_TR" || return 1
292 e1_check_transc_prior "$S_TRP" "$E1_IN_TRP" || return 1
293 e1_check_mutant "$S_MUT" "$E1_IN_MUT" || return 1
294 e1_check_campaign "$S_CAMP" "$E1_IN_CAMP" || return 1
295 e1_check_ldst_log "$S_LDST" "$E1_IN_LDST" || return 1
296 e1_check_host_rerun "$S_HOST" "$E1_IN_HOST" || return 1
297 e1_check_manifest "$S_MAN" "$E1_IN_MANIFEST" || return 1
298 body="{\"schema\":\"$E1_SCHEMA\",\"gate\":\"E1_NUMERICAL_CLOSURE\",\"status\":\"PASS\",\"timestamp_utc\":\"$ts\""
299 body+=",\"chip_qualified_candidate_git_commit\":\"$E1_CAND\",\"merged_main_git_commit\":\"$E1_MAIN\""
300 body+=",\"physics_candidate_git_commit\":\"$E1_PHYS\",\"candidate_trees_clean\":{\"omega\":true,\"physics\":true}"
301 body+=",\"chip_ran_on\":\"candidate\",\"whole_repository_trees_identical\":$E1_WHOLE_TREE"
302 body+=",\"e1_artifact_set\":{\"chip_class_byte_identical\":true,\"host_class_files_differ\":$E1_HOST_DIFFER,\"host_tier_rerun_on_main\":\"PASS\",\"manifest_sha256\":\"$E1_MAN_DIGEST\"}"
303 body+=",\"rebuilt_on_main_equals_chip_binary\":{\"GATE5\":\"$E1_G5_BIN\",\"REDUCE\":\"$E1_RED_BIN\",\"TRANSC\":\"$E1_TR_BIN\",\"LDST_main_rebuild\":\"$E1_LDST_BIN\"}"
304 body+=",\"constituents\":{"
305 body+="\"gate5\":{\"schema\":\"AIEN_OMEGA_NUMERIC_0_V1\",\"receipt_digest\":\"$E1_G5_DIGEST\",\"status\":\"PASS\",\"tests\":$E1_G5_TESTS,\"hardware_descriptor_digest\":\"$E1_G5_HW\"}"
306 body+=",\"reduce\":{\"suite\":\"E1_REDUCE_GB10_PARITY\",\"sha256\":\"$E1_RED_DIGEST\",\"status\":\"PASS\",\"ops\":[\"SUM\",\"MAX\",\"MIN\",\"MEAN\"],\"cases\":380,\"mismatches\":0}"
307 body+=",\"mean_mutant\":{\"log_sha256\":\"$E1_MUT_DIGEST\",\"result\":\"KILLED\",\"mean_mismatches\":$E1_MUT_MISMATCHES}"
308 body+=",\"transc\":{\"gate\":\"E1-TRANSC-GB10\",\"sha256\":\"$E1_TR_DIGEST\",\"status\":\"PASS\",\"ops\":[\"SIN\",\"COS\",\"ERF\",\"GELU\",\"RSQRT\"],\"inputs_checked\":$E1_TR_INPUTS,\"per_op\":4294967296,\"exhaustive\":true,\"mismatches\":0}"
309 body+=",\"transc_prior\":{\"gate\":\"E1-TRANSC-GB10\",\"sha256\":\"$E1_TRP_DIGEST\",\"omega_commit\":\"$E1_TRP_COMMIT\",\"status\":\"PASS\",\"ops\":[\"EXP2\",\"LOG2\",\"SIGMOID\",\"TANH\"],\"per_op\":4294967296,\"exhaustive\":true,\"mismatches\":0,\"kernel_digests_equal_candidate\":true}"
310 body+=",\"ldst\":{\"chip_log_sha256\":\"$E1_LDST_DIGEST\",\"status\":\"PASS\",\"specs_passed\":$E1_LDST_SPECS,\"device_errors\":0}"
311 body+=",\"campaign_log_sha256\":\"$E1_CAMP_DIGEST\",\"uncertain_completions\":0"
312 body+=",\"host_rerun\":{\"schema\":\"AIEN_E1_HOST_RERUN_V1\",\"sha256\":\"$E1_HOST_DIGEST\",\"omega_commit\":\"$E1_MAIN\",\"lines\":[$(for l in $E1_HOST_LINES; do printf '"%s",' "$l"; done | sed 's/,$//')],\"status\":\"PASS\"}}"
313 body+=",\"digest_meaning\":\"integrity only, not authenticity: re-hash the constituents named here\"}"
314 E1_DIGEST=$(printf '%s' "$body" | "$JSON_CANON" --sha256) || e1_refuse "combined body is not valid JSON" || return 1
315 E1_RECEIPT="{\"receipt_digest\":\"$E1_DIGEST\",${body#\{}"
316}
317
318e1_write() { # DIR
319 local dir=$1 pretty
320 mkdir -p "$dir" || e1_refuse "cannot create $dir" || return 1
321 pretty=$E1_TMP/combined.pretty
322 printf '%s' "$E1_RECEIPT" | "$JSON_CANON" --pretty > "$pretty" || e1_refuse "cannot format receipt" || return 1
323 "$JSON_CANON" --write-exclusive "$dir/$E1_DIGEST.json" < "$pretty" 2> "$pretty.err" ||
324 e1_refuse "cannot write $dir/$E1_DIGEST.json: $(cat "$pretty.err")" || return 1
325 chmod 0444 "$dir/$E1_DIGEST.json" || e1_refuse "cannot chmod $dir/$E1_DIGEST.json"
326}
327
328e1_dup() { echo "REFUSED: duplicate input $1" >&2; exit 1; }
329e1_usage() { sed -n '4,6p' "${BASH_SOURCE[0]}" | sed 's/^# *//' >&2; exit 2; }
330
331e1_main() {
332 local ev= ts
333 E1_CAND= E1_MAIN= E1_PHYS= E1_IN_MANIFEST= E1_IN_G5= E1_IN_RED= E1_IN_TR= E1_IN_MUT= E1_IN_CAMP= E1_IN_LDST= E1_IN_HOST= E1_IN_TRP=
334 while [ $# -gt 0 ]; do
335 [ $# -ge 2 ] || e1_usage
336 case $1 in
337 --candidate) E1_CAND=${2,,};; --main) E1_MAIN=${2,,};; --physics) E1_PHYS=${2,,};;
338 --manifest) [ -z "$E1_IN_MANIFEST" ] || e1_dup "$1"; E1_IN_MANIFEST=$2;;
339 --gate5) [ -z "$E1_IN_G5" ] || e1_dup "$1"; E1_IN_G5=$2;;
340 --reduce) [ -z "$E1_IN_RED" ] || e1_dup "$1"; E1_IN_RED=$2;;
341 --transc) [ -z "$E1_IN_TR" ] || e1_dup "$1"; E1_IN_TR=$2;;
342 --mutant-log) [ -z "$E1_IN_MUT" ] || e1_dup "$1"; E1_IN_MUT=$2;;
343 --campaign-log) [ -z "$E1_IN_CAMP" ] || e1_dup "$1"; E1_IN_CAMP=$2;;
344 --ldst-chip-log) [ -z "$E1_IN_LDST" ] || e1_dup "$1"; E1_IN_LDST=$2;;
345 --host-rerun) [ -z "$E1_IN_HOST" ] || e1_dup "$1"; E1_IN_HOST=$2;;
346 --transc-prior) [ -z "$E1_IN_TRP" ] || e1_dup "$1"; E1_IN_TRP=$2;;
347 --evidence-dir) ev=$2;;
348 *) e1_usage;;
349 esac
350 shift 2
351 done
352 for c in "$E1_CAND" "$E1_MAIN" "$E1_PHYS"; do
353 [[ $c =~ ^[0-9a-f]{40}$ ]] || { echo "--candidate, --main and --physics must be full 40-hex SHAs" >&2; exit 2; }
354 done
355 e1_build_canon || { echo "REFUSED: cannot build tools/json_canon.c" >&2; exit 1; }
356 trap 'rm -rf "$E1_TMP"' EXIT
357 ts=${E1_TIMESTAMP_UTC:-$(date -u +%Y-%m-%dT%H:%M:%S.%6NZ)} # override: tests only
358 e1_combine "$ts" || { echo "REFUSED: $E1_ERR" >&2; exit 1; }
359 if [ -n "$ev" ]; then
360 e1_write "$ev" || { echo "REFUSED: $E1_ERR" >&2; exit 1; }
361 echo "E1 CLOSURE PASS: receipt $ev/$E1_DIGEST.json"
362 else
363 echo "E1 CLOSURE PASS: receipt digest $E1_DIGEST (not written; no --evidence-dir)"
364 fi
365}
366
367if [ "${BASH_SOURCE[0]}" = "$0" ]; then
368 e1_main "$@"
369fi