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 / gen / protocol / gencheck.c

833 lines · 42407 bytes Raw Blame History
1/*
2 * gencheck.c -- strict validator of the GEN protocol manifest (aien-spark/omega#476).
3 * Manifest: tests/one_layer/generalization/protocol.json (schema omega.gen.protocol.v1), the machine copy of
4 * docs/one_layer/GEN_PROTOCOL_V1.md. Family rules: tests/one_layer/generalization/families/FAMSIG_V1.md,
5 * through famsig_lib.h (the same code as famsig). Deterministic: no clock, no randomness, no environment.
6 *
7 * gencheck manifest <protocol.json> <root>
8 * Parse the manifest with a strict JSON reader (ASCII only; duplicate keys, unknown keys, missing keys
9 * and wrong types are refused), check every frozen v1 constant, re-hash every pinned file under <root>,
10 * check the dev split (task list = META ids = case directories, families = META signatures) and, once
11 * the corpus META is frozen, apply the disjointness rule R1..R8 over dev + corpus.
12 * Record-set manifests (C and D) are re-hashed once their paths and digests are set.
13 * gencheck run-ready <protocol.json> <root>
14 * Everything `manifest` checks with nothing pending: any null field, any interface file missing from
15 * <root>, or no `interfaces` entry named by retrieval.contract (genret-cli-v3) refuses. Required before
16 * the seal is opened and before the run; there is no "pending merge" continue.
17 * gencheck open <protocol.json> <root> <OPEN>
18 * The seal-open check (custodian, in a clean checkout of the OPEN commit; reducer, on protocol.json taken
19 * from that commit): everything `manifest` checks with nothing pending (every interface file present,
20 * corpus META, prefix, both record sets, HELDOUT.pub and tasks digests set), and the OPEN receipt
21 * ("gen-open 1", omega_commit, protocol_sha256, tasks_sha256, heldout_pub_sha256) matches protocol.json.
22 * gencheck split <protocol.json> <root> <SPLIT> <HELDOUT.pub>
23 * Everything `manifest` checks, then (reviewer, after the seal): SPLIT parses (gen-split 1), HELDOUT.pub
24 * parses (gen-heldout-pub 1) and matches SPLIT (split_sha256, famlist_sha256, task ids, counts), the
25 * held-out count and minimum family count of the manifest hold, and R1..R8 pass over dev + corpus +
26 * SPLIT. Fails closed when splits.heldout.pub_sha256 or tasks_sha256 is null in the manifest. Held-out
27 * signatures are never printed.
28 * Output: "ok ..." lines on stdout, then "GENCHECK PASS" (exit 0). A refusal prints "gencheck: FAIL <reason>"
29 * on stderr and "GENCHECK FAIL" on stdout (exit 1). Usage errors exit 2.
30 */
31#include "famsig_lib.h"
32#include <dirent.h>
33#include <stdarg.h>
34#include <sys/stat.h>
35
36#define GC_MAXENT 1024
37#define GC_PATH 192
38#define GC_DEPTH 8
39
40typedef struct {
41 char path[GC_PATH]; /* e.g. splits.dev.tasks[3] */
42 char norm[GC_PATH]; /* indices replaced: splits.dev.tasks[] */
43 char type; /* o a s i n b z (object array string integer number bool null) */
44 char *raw; /* string contents, number text, true/false/null; NULL for o and a */
45} Ent;
46
47static Ent ent[GC_MAXENT];
48static int nent;
49
50static void gc_fail(const char *fmt, ...) __attribute__((format(printf, 1, 2), noreturn));
51static void gc_fail(const char *fmt, ...)
52{
53 va_list ap;
54 va_start(ap, fmt);
55 fputs("gencheck: FAIL ", stderr);
56 vfprintf(stderr, fmt, ap);
57 fputc('\n', stderr);
58 va_end(ap);
59 printf("GENCHECK FAIL\n");
60 exit(1);
61}
62
63/* ---------- strict JSON reader ---------- */
64
65typedef struct { const char *s; size_t i, n; } Jp;
66
67static void j_ws(Jp *p) { while (p->i < p->n && (p->s[p->i] == ' ' || p->s[p->i] == '\n' || p->s[p->i] == '\t')) p->i++; }
68
69static Ent *j_add(const char *path, const char *norm, char type, char *raw)
70{
71 if (nent >= GC_MAXENT) gc_fail("json: more than %d values", GC_MAXENT);
72 Ent *e = &ent[nent++];
73 snprintf(e->path, sizeof e->path, "%s", path);
74 snprintf(e->norm, sizeof e->norm, "%s", norm);
75 e->type = type;
76 e->raw = raw;
77 return e;
78}
79
80static char *j_string(Jp *p)
81{
82 if (p->i >= p->n || p->s[p->i] != '"') gc_fail("json: expected string at byte %zu", p->i);
83 p->i++;
84 char *out = malloc(p->n + 1);
85 size_t k = 0;
86 for (;;) {
87 if (p->i >= p->n) gc_fail("json: unterminated string");
88 char c = p->s[p->i++];
89 if (c == '"') break;
90 if (c == '\\') {
91 if (p->i >= p->n) gc_fail("json: bad escape");
92 char e = p->s[p->i++];
93 if (e != '"' && e != '\\' && e != '/') gc_fail("json: escape \\%c not allowed (only \\\" \\\\ \\/)", e);
94 out[k++] = e;
95 continue;
96 }
97 if ((unsigned char)c < 0x20 || (unsigned char)c > 0x7e) gc_fail("json: non-printable byte in string at %zu", p->i - 1);
98 out[k++] = c;
99 }
100 out[k] = 0;
101 return out;
102}
103
104static int j_isdig(char c) { return c >= '0' && c <= '9'; }
105
106static void j_value(Jp *p, const char *path, const char *norm, int depth);
107
108static void j_object(Jp *p, const char *path, const char *norm, int depth)
109{
110 j_add(path, norm, 'o', NULL);
111 p->i++;
112 char *keys[128];
113 int nk = 0;
114 j_ws(p);
115 if (p->i < p->n && p->s[p->i] == '}') gc_fail("json: empty object at %s", path[0] ? path : "(root)");
116 for (;;) {
117 j_ws(p);
118 char *k = j_string(p);
119 size_t kl = strlen(k);
120 if (kl < 1 || kl > 40) gc_fail("json: key length at %s", path);
121 for (size_t i = 0; i < kl; i++)
122 if (!((k[i] >= 'a' && k[i] <= 'z') || j_isdig(k[i]) || k[i] == '_')) gc_fail("json: key \"%s\" is not [a-z0-9_]", k);
123 for (int i = 0; i < nk; i++)
124 if (!strcmp(keys[i], k)) gc_fail("json: duplicate key \"%s\" in %s", k, path[0] ? path : "(root)");
125 if (nk == 128) gc_fail("json: too many keys in %s", path);
126 keys[nk++] = k;
127 j_ws(p);
128 if (p->i >= p->n || p->s[p->i] != ':') gc_fail("json: expected ':' after \"%s\"", k);
129 p->i++;
130 char cp[GC_PATH], cn[GC_PATH];
131 if (snprintf(cp, sizeof cp, "%s%s%s", path, path[0] ? "." : "", k) >= (int)sizeof cp ||
132 snprintf(cn, sizeof cn, "%s%s%s", norm, norm[0] ? "." : "", k) >= (int)sizeof cn) gc_fail("json: path too long");
133 j_value(p, cp, cn, depth + 1);
134 j_ws(p);
135 if (p->i < p->n && p->s[p->i] == ',') { p->i++; continue; }
136 if (p->i < p->n && p->s[p->i] == '}') { p->i++; break; }
137 gc_fail("json: expected ',' or '}' in %s", path[0] ? path : "(root)");
138 }
139 for (int i = 0; i < nk; i++) free(keys[i]);
140}
141
142static void j_array(Jp *p, const char *path, const char *norm, int depth)
143{
144 j_add(path, norm, 'a', NULL);
145 p->i++;
146 j_ws(p);
147 if (p->i < p->n && p->s[p->i] == ']') gc_fail("json: empty array at %s", path);
148 char cn[GC_PATH];
149 if (snprintf(cn, sizeof cn, "%s[]", norm) >= (int)sizeof cn) gc_fail("json: path too long");
150 for (int idx = 0;; idx++) {
151 char cp[GC_PATH];
152 if (snprintf(cp, sizeof cp, "%s[%d]", path, idx) >= (int)sizeof cp) gc_fail("json: path too long");
153 j_ws(p);
154 j_value(p, cp, cn, depth + 1);
155 j_ws(p);
156 if (p->i < p->n && p->s[p->i] == ',') { p->i++; continue; }
157 if (p->i < p->n && p->s[p->i] == ']') { p->i++; break; }
158 gc_fail("json: expected ',' or ']' in %s", path);
159 }
160}
161
162static void j_value(Jp *p, const char *path, const char *norm, int depth)
163{
164 if (depth > GC_DEPTH) gc_fail("json: nesting deeper than %d", GC_DEPTH);
165 j_ws(p);
166 if (p->i >= p->n) gc_fail("json: unexpected end");
167 char c = p->s[p->i];
168 if (c == '{') { j_object(p, path, norm, depth); return; }
169 if (c == '[') { j_array(p, path, norm, depth); return; }
170 if (c == '"') { j_add(path, norm, 's', j_string(p)); return; }
171 static const char *const lit[3] = {"true", "false", "null"};
172 for (int i = 0; i < 3; i++) {
173 size_t l = strlen(lit[i]);
174 if (p->n - p->i >= l && !memcmp(p->s + p->i, lit[i], l)) {
175 p->i += l;
176 j_add(path, norm, i < 2 ? 'b' : 'z', strdup(lit[i]));
177 return;
178 }
179 }
180 /* number: -?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)? */
181 size_t st = p->i;
182 int isint = 1;
183 if (p->s[p->i] == '-') p->i++;
184 if (p->i < p->n && p->s[p->i] == '0') p->i++;
185 else if (p->i < p->n && p->s[p->i] >= '1' && p->s[p->i] <= '9') while (p->i < p->n && j_isdig(p->s[p->i])) p->i++;
186 else gc_fail("json: bad value at %s", path);
187 if (p->i < p->n && p->s[p->i] == '.') {
188 isint = 0; p->i++;
189 if (p->i >= p->n || !j_isdig(p->s[p->i])) gc_fail("json: bad number at %s", path);
190 while (p->i < p->n && j_isdig(p->s[p->i])) p->i++;
191 }
192 if (p->i < p->n && (p->s[p->i] == 'e' || p->s[p->i] == 'E')) {
193 isint = 0; p->i++;
194 if (p->i < p->n && (p->s[p->i] == '+' || p->s[p->i] == '-')) p->i++;
195 if (p->i >= p->n || !j_isdig(p->s[p->i])) gc_fail("json: bad number at %s", path);
196 while (p->i < p->n && j_isdig(p->s[p->i])) p->i++;
197 }
198 char *raw = strndup(p->s + st, p->i - st);
199 j_add(path, norm, isint ? 'i' : 'n', raw);
200}
201
202/* ---------- schema omega.gen.protocol.v1 ---------- */
203
204typedef struct { const char *norm, *types; } Key;
205
206static const Key schema[] = {
207 {"", "o"},
208 {"schema", "s"}, {"revision", "i"}, {"issue", "s"}, {"doc", "s"}, {"question", "s"},
209 {"config", "o"}, {"config.name", "s"}, {"config.params", "s"}, {"config.masking", "b"},
210 {"config.harness_kind", "s"}, {"config.writer", "s"}, {"config.reader", "s"},
211 {"conditions", "a"}, {"conditions[]", "o"}, {"conditions[].name", "s"},
212 {"conditions[].prefix_examples", "i"}, {"conditions[].retrieval", "s"},
213 {"retrieval", "o"}, {"retrieval.contract", "s"}, {"retrieval.record_schema", "s"}, {"retrieval.k", "i"},
214 {"retrieval.cap_bytes", "i"}, {"retrieval.mode", "s"}, {"retrieval.query", "s"},
215 {"retrieval.c_pool_excludes_prefix", "b"}, {"retrieval.length_match_abs_bytes", "i"},
216 {"retrieval.length_match_frac", "n"}, {"retrieval.length_match_min_matched_frac", "n"},
217 {"generation", "o"}, {"generation.primary", "s"}, {"generation.max_tokens", "i"},
218 {"generation.max_rounds", "i"}, {"generation.attempts", "i"}, {"generation.attempt1_temperature", "i"},
219 {"generation.sampled_temperature", "n"}, {"generation.sampled_top_p", "n"}, {"generation.seed_base", "i"},
220 {"generation.seed_attempt_stride", "i"}, {"generation.retries", "i"}, {"generation.retry_pause_s", "i"},
221 {"generation.order", "s"}, {"generation.sets", "a"}, {"generation.sets[]", "s"},
222 {"gates", "o"}, {"gates.greedy", "o"}, {"gates.greedy.tasks", "s"}, {"gates.greedy.condition", "s"},
223 {"gates.greedy.repeats", "i"}, {"gates.g0", "o"}, {"gates.g0.script", "s"}, {"gates.g0.task", "s"},
224 {"gates.g0.condition", "s"}, {"gates.g0.seeds", "i"}, {"gates.g0.repeat", "i"}, {"gates.g0.otherwise", "s"},
225 {"gates.g0.seed_values", "a"}, {"gates.g0.seed_values[]", "i"}, {"generation.in_flight", "i"},
226 {"decision", "o"}, {"decision.schema", "s"}, {"decision.primary", "s"}, {"decision.controls", "a"},
227 {"decision.controls[]", "s"}, {"decision.delta", "n"}, {"decision.alpha", "n"}, {"decision.test", "s"},
228 {"decision.ci", "s"}, {"decision.z95", "n"}, {"decision.z90", "n"}, {"decision.fail_control", "s"},
229 {"decision.sanity_ab_max", "i"}, {"decision.verdicts", "a"}, {"decision.verdicts[]", "s"},
230 {"decision.vectors", "s"}, {"decision.floor_max", "i"}, {"decision.ceiling_min", "i"},
231 {"splits", "o"},
232 {"splits.dev", "o"}, {"splits.dev.count", "i"}, {"splits.dev.meta", "s"}, {"splits.dev.meta_sha256", "s"},
233 {"splits.dev.cases", "s"}, {"splits.dev.pack_sha256", "s"}, {"splits.dev.tasks", "a"},
234 {"splits.dev.tasks[]", "s"}, {"splits.dev.families", "a"}, {"splits.dev.families[]", "s"},
235 {"splits.corpus", "o"}, {"splits.corpus.count_target", "i"}, {"splits.corpus.meta", "s"},
236 {"splits.corpus.meta_sha256", "sz"},
237 {"splits.heldout", "o"}, {"splits.heldout.count", "i"}, {"splits.heldout.min_families", "i"},
238 {"splits.heldout.pub_sha256", "sz"}, {"splits.heldout.tasks_sha256", "sz"},
239 {"splits.heldout.near_dup_threshold", "n"},
240 {"record_sets", "o"}, {"record_sets.prefix_ids", "az"}, {"record_sets.prefix_ids[]", "s"},
241 {"record_sets.prefix_sha256", "sz"}, {"record_sets.raw_manifest_sha256", "sz"},
242 {"record_sets.abstraction_manifest_sha256", "sz"}, {"record_sets.raw_manifest", "sz"},
243 {"record_sets.abstraction_manifest", "sz"},
244 {"pins", "a"}, {"pins[]", "o"}, {"pins[].path", "s"}, {"pins[].sha256", "s"},
245 {"interfaces", "a"}, {"interfaces[]", "o"}, {"interfaces[].name", "s"}, {"interfaces[].path", "s"},
246 {"interfaces[].commit", "s"}, {"interfaces[].sha256", "s"},
247};
248#define NSCHEMA ((int)(sizeof schema / sizeof schema[0]))
249
250/* frozen v1 values: any other value is a change that needs a new revision (protocol section 15) */
251typedef struct { const char *path, *raw; } Fixed;
252static const Fixed fixed[] = {
253 {"schema", "omega.gen.protocol.v1"}, {"revision", "1"}, {"issue", "aien-spark/omega#476"},
254 {"doc", "docs/one_layer/GEN_PROTOCOL_V1.md"},
255 {"config.name", "A"}, {"config.params", "tools/exp445/PARAMS"}, {"config.masking", "false"},
256 {"config.harness_kind", "oscir"}, {"config.writer", "omegese"}, {"config.reader", "tools/exp445/reader.sh"},
257 {"conditions[0].name", "A"}, {"conditions[0].prefix_examples", "1"}, {"conditions[0].retrieval", "none"},
258 {"conditions[1].name", "B"}, {"conditions[1].prefix_examples", "14"}, {"conditions[1].retrieval", "none"},
259 {"conditions[2].name", "C"}, {"conditions[2].prefix_examples", "14"}, {"conditions[2].retrieval", "raw"},
260 {"conditions[3].name", "D"}, {"conditions[3].prefix_examples", "14"}, {"conditions[3].retrieval", "abstraction"},
261 {"retrieval.contract", "genret-cli-v3"}, {"retrieval.record_schema", "gen-record-1"}, {"retrieval.k", "3"},
262 {"retrieval.cap_bytes", "4096"}, {"retrieval.mode", "normal"}, {"retrieval.query", "requirement+prompt"},
263 {"retrieval.c_pool_excludes_prefix", "true"}, {"retrieval.length_match_abs_bytes", "256"},
264 {"retrieval.length_match_frac", "0.15"}, {"retrieval.length_match_min_matched_frac", "0.5"}, {"generation.in_flight", "1"},
265 {"generation.primary", "attempt1_round1_functional"}, {"generation.max_tokens", "3072"},
266 {"generation.max_rounds", "2"}, {"generation.attempts", "3"}, {"generation.attempt1_temperature", "0"},
267 {"generation.sampled_temperature", "0.7"}, {"generation.sampled_top_p", "0.8"},
268 {"generation.seed_base", "476000"}, {"generation.seed_attempt_stride", "1000"}, {"generation.retries", "2"},
269 {"generation.retry_pause_s", "5"}, {"generation.order", "attempt,task,condition"},
270 {"generation.sets[0]", "<c>-<attempt>"}, {"generation.sets[1]", "<c>-<attempt>-final"},
271 {"gates.greedy.tasks", "dev"}, {"gates.greedy.condition", "B"}, {"gates.greedy.repeats", "2"},
272 {"gates.g0.script", "tools/exp445/sampling-gate.sh"}, {"gates.g0.task", "devgen01"}, {"gates.g0.condition", "B"},
273 {"gates.g0.seeds", "8"}, {"gates.g0.repeat", "1"}, {"gates.g0.otherwise", "UNAVAILABLE"},
274 {"gates.g0.seed_values[0]", "476901"}, {"gates.g0.seed_values[1]", "476902"}, {"gates.g0.seed_values[2]", "476903"},
275 {"gates.g0.seed_values[3]", "476904"}, {"gates.g0.seed_values[4]", "476905"}, {"gates.g0.seed_values[5]", "476906"},
276 {"gates.g0.seed_values[6]", "476907"}, {"gates.g0.seed_values[7]", "476908"},
277 {"decision.schema", "omega.gen.decision.v1"}, {"decision.primary", "attempt1_round1_functional"},
278 {"decision.controls[0]", "A"}, {"decision.controls[1]", "B"}, {"decision.controls[2]", "C"},
279 {"decision.delta", "0.10"}, {"decision.alpha", "0.05"}, {"decision.test", "mcnemar_exact_one_sided"},
280 {"decision.ci", "newcombe10"}, {"decision.z95", "1.959963984540054"}, {"decision.z90", "1.644853626951472"},
281 {"decision.fail_control", "C"}, {"decision.sanity_ab_max", "2"},
282 {"decision.verdicts[0]", "INVALID"}, {"decision.verdicts[1]", "PASS"}, {"decision.verdicts[2]", "FAIL"},
283 {"decision.verdicts[3]", "INCONCLUSIVE"},
284 {"decision.vectors", "tests/one_layer/generalization/stats_vectors.tsv"}, {"decision.floor_max", "3"},
285 {"decision.ceiling_min", "57"},
286 {"splits.dev.count", "10"}, {"splits.dev.meta", "tests/one_layer/generalization/dev/META"},
287 {"splits.dev.cases", "tests/one_layer/generalization/dev/tasks/cases"},
288 {"splits.corpus.count_target", "48"}, {"splits.corpus.meta", "tests/one_layer/generalization/corpus/META"},
289 {"splits.heldout.count", "60"}, {"splits.heldout.min_families", "6"}, {"splits.heldout.near_dup_threshold", "0.5"},
290};
291#define NFIXED ((int)(sizeof fixed / sizeof fixed[0]))
292
293/* exact array lengths */
294static const struct { const char *path; int len; } fixed_len[] = {
295 {"conditions", 4}, {"generation.sets", 2}, {"decision.controls", 3}, {"decision.verdicts", 4},
296 {"gates.g0.seed_values", 8},
297};
298
299/* files that must be pinned (protocol section 13); more may be pinned */
300static const char *const must_pin[] = {
301 "docs/one_layer/GEN_PROTOCOL_V1.md",
302 "docs/one_layer/OMEGESE.md",
303 "tests/one_layer/acceptance/HARNESS_INTERFACE_V2.md",
304 "tests/one_layer/generalization/dev/META",
305 "tests/one_layer/generalization/dev/gen_expected.c",
306 "tests/one_layer/generalization/dev/pack_dev.sh",
307 "tests/one_layer/generalization/families/FAMSIG_V1.md",
308 "tests/one_layer/generalization/stats_vectors.tsv",
309 "tools/exp445/PARAMS",
310 "tools/exp445/arms/common.md",
311 "tools/exp445/arms/omegese.md",
312 "tools/exp445/reader.sh",
313 "tools/exp445/sampling-gate.sh",
314 "tools/exp445/weights.A.sha256",
315 "tools/gen/protocol/famsig.c",
316 "tools/gen/protocol/famsig_lib.h",
317 "tools/gen/protocol/gencheck.c",
318 "tools/gen/protocol/genjac.c",
319 "tools/gen/protocol/genstats.c",
320};
321
322static Ent *get(const char *path)
323{
324 for (int i = 0; i < nent; i++)
325 if (!strcmp(ent[i].path, path)) return &ent[i];
326 return NULL;
327}
328
329static const char *str(const char *path)
330{
331 Ent *e = get(path);
332 if (!e || e->type != 's') gc_fail("%s: missing or not a string", path);
333 return e->raw;
334}
335
336static int count_elems(const char *path)
337{
338 char pre[GC_PATH + 2];
339 snprintf(pre, sizeof pre, "%s[", path);
340 size_t pl = strlen(pre);
341 int n = 0;
342 for (int i = 0; i < nent; i++)
343 if (!strncmp(ent[i].path, pre, pl) && strchr(ent[i].path + pl, ']') && !strchr(strchr(ent[i].path + pl, ']') + 1, '.') &&
344 !strchr(strchr(ent[i].path + pl, ']') + 1, '['))
345 n++;
346 return n;
347}
348
349static int hex64(const char *s) { return fs_hex64_ok(s); }
350
351static int safe_rel(const char *p)
352{
353 size_t n = strlen(p);
354 if (n < 1 || n > 160 || p[0] == '/') return 0;
355 const char *c = p;
356 while (*c) {
357 const char *e = strchr(c, '/');
358 size_t l = e ? (size_t)(e - c) : strlen(c);
359 if (l == 0 || (l == 1 && c[0] == '.') || (l == 2 && c[0] == '.' && c[1] == '.')) return 0;
360 for (size_t i = 0; i < l; i++) {
361 char ch = c[i];
362 if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || j_isdig(ch) || ch == '.' || ch == '_' || ch == '-')) return 0;
363 }
364 c += l;
365 if (*c == '/') c++;
366 }
367 return 1;
368}
369
370static const char *root;
371static int strict; /* run-ready and open modes: nothing may be pending */
372
373static int file_sha(const char *rel, char out[65])
374{
375 char full[4096];
376 snprintf(full, sizeof full, "%s/%s", root, rel);
377 struct stat st;
378 if (stat(full, &st) || !S_ISREG(st.st_mode)) return -1;
379 size_t len;
380 char *b = fs_slurp(full, &len);
381 if (!b) return -1;
382 unsigned char d[32];
383 sha256_hash((const unsigned char *)b, len, d);
384 fs_hex(d, out);
385 free(b);
386 return 0;
387}
388
389static int cmp_cstr(const void *a, const void *b) { return strcmp(*(char *const *)a, *(char *const *)b); }
390
391static void read_meta(const char *rel, FsSet *set, int want_split)
392{
393 char full[4096], err[512];
394 snprintf(full, sizeof full, "%s/%s", root, rel);
395 if (fs_read(full, set, err, sizeof err)) gc_fail("%s", err);
396 if (set->is_split) gc_fail("%s: a gen-split file where gen-meta was expected", rel);
397 for (int i = 0; i < set->n; i++)
398 if (set->m[i].split != want_split) gc_fail("%s: task %s has split %s, expected %s", rel, set->m[i].id, fs_split[set->m[i].split], fs_split[want_split]);
399}
400
401static int split_index(const char *s)
402{
403 for (int i = 0; i < FS_NSPLIT; i++)
404 if (!strcmp(fs_split[i], s)) return i;
405 return -1;
406}
407
408/* ---------- manifest ---------- */
409
410static FsSet dev, corpus;
411static int corpus_frozen;
412
413static void check_manifest(const char *json_path)
414{
415 size_t len;
416 char *b = fs_slurp(json_path, &len);
417 if (!b) gc_fail("cannot read %s", json_path);
418 if (strlen(b) != len) gc_fail("json: NUL byte");
419 for (size_t i = 0; i < len; i++)
420 if (b[i] != '\n' && b[i] != '\t' && ((unsigned char)b[i] < 0x20 || (unsigned char)b[i] > 0x7e)) gc_fail("json: byte 0x%02x at %zu (ASCII only)", (unsigned char)b[i], i);
421 Jp p = {b, 0, len};
422 j_ws(&p);
423 if (p.i >= p.n || b[p.i] != '{') gc_fail("json: top level must be an object");
424 j_value(&p, "", "", 0);
425 j_ws(&p);
426 if (p.i != p.n) gc_fail("json: trailing bytes after the top-level object");
427
428 /* every value is a known key of the right type */
429 for (int i = 0; i < nent; i++) {
430 int k;
431 for (k = 0; k < NSCHEMA; k++)
432 if (!strcmp(schema[k].norm, ent[i].norm)) break;
433 if (k == NSCHEMA) gc_fail("unknown key %s", ent[i].path);
434 if (!strchr(schema[k].types, ent[i].type)) gc_fail("%s: type %c, expected %s", ent[i].path, ent[i].type, schema[k].types);
435 }
436 /* every object has every key its schema lists */
437 for (int i = 0; i < nent; i++) {
438 if (ent[i].type != 'o') continue;
439 size_t nl = strlen(ent[i].norm);
440 for (int k = 0; k < NSCHEMA; k++) {
441 const char *kn = schema[k].norm;
442 const char *rest;
443 if (nl == 0) rest = kn;
444 else if (!strncmp(kn, ent[i].norm, nl) && kn[nl] == '.') rest = kn + nl + 1;
445 else continue;
446 if (!*rest || strchr(rest, '.') || strchr(rest, '[')) continue;
447 char want[GC_PATH * 2];
448 if (snprintf(want, sizeof want, "%s%s%.*s", ent[i].path, nl ? "." : "", GC_PATH, rest) >= (int)sizeof want) gc_fail("json: path too long");
449 if (!get(want)) gc_fail("missing key %s", want);
450 }
451 }
452 printf("ok schema omega.gen.protocol.v1: %d values, no unknown, missing or duplicate key\n", nent);
453
454 for (int i = 0; i < NFIXED; i++) {
455 Ent *e = get(fixed[i].path);
456 if (!e) gc_fail("missing frozen value %s", fixed[i].path);
457 if (!e->raw || strcmp(e->raw, fixed[i].raw)) gc_fail("%s changed: \"%s\", frozen v1 value \"%s\" (a change is a new revision)", fixed[i].path, e->raw ? e->raw : "(container)", fixed[i].raw);
458 }
459 for (size_t i = 0; i < sizeof fixed_len / sizeof fixed_len[0]; i++)
460 if (count_elems(fixed_len[i].path) != fixed_len[i].len) gc_fail("%s: %d elements, frozen %d", fixed_len[i].path, count_elems(fixed_len[i].path), fixed_len[i].len);
461 printf("ok %d frozen v1 values\n", NFIXED);
462
463 /* pins: ascending unique safe paths, each file present with that sha256 */
464 int np = count_elems("pins");
465 char prev[GC_PATH] = "";
466 for (int i = 0; i < np; i++) {
467 char kp[64], ks[64], sha[65];
468 snprintf(kp, sizeof kp, "pins[%d].path", i);
469 snprintf(ks, sizeof ks, "pins[%d].sha256", i);
470 const char *path = str(kp), *want = str(ks);
471 if (!safe_rel(path)) gc_fail("%s: unsafe path \"%s\"", kp, path);
472 if (i && strcmp(prev, path) >= 0) gc_fail("pins: \"%s\" not strictly ascending (duplicate or out of order)", path);
473 snprintf(prev, sizeof prev, "%s", path);
474 if (!hex64(want)) gc_fail("%s: not 64 lowercase hex", ks);
475 if (file_sha(path, sha)) gc_fail("pinned file missing: %s", path);
476 if (strcmp(sha, want)) gc_fail("digest drift: %s is %s, pinned %s", path, sha, want);
477 }
478 for (size_t k = 0; k < sizeof must_pin / sizeof must_pin[0]; k++) {
479 int found = 0;
480 for (int i = 0; i < np && !found; i++) {
481 char kp[64];
482 snprintf(kp, sizeof kp, "pins[%d].path", i);
483 found = !strcmp(str(kp), must_pin[k]);
484 }
485 if (!found) gc_fail("pins: required file %s is not pinned", must_pin[k]);
486 }
487 printf("ok %d pinned files re-hashed, no drift\n", np);
488
489 /* interfaces of other GEN parts: verified when the file is present in this tree */
490 int ni = count_elems("interfaces");
491 for (int i = 0; i < ni; i++) {
492 char k[64], sha[65];
493 snprintf(k, sizeof k, "interfaces[%d].name", i);
494 const char *name = str(k);
495 for (int j = 0; j < i; j++) {
496 char k2[64];
497 snprintf(k2, sizeof k2, "interfaces[%d].name", j);
498 if (!strcmp(str(k2), name)) gc_fail("interfaces: duplicate name %s", name);
499 }
500 snprintf(k, sizeof k, "interfaces[%d].path", i);
501 const char *path = str(k);
502 if (!safe_rel(path)) gc_fail("%s: unsafe path", k);
503 snprintf(k, sizeof k, "interfaces[%d].commit", i);
504 const char *commit = str(k);
505 if (strlen(commit) != 40 || strspn(commit, "0123456789abcdef") != 40) gc_fail("%s: not a 40-hex commit", k);
506 snprintf(k, sizeof k, "interfaces[%d].sha256", i);
507 const char *want = str(k);
508 if (!hex64(want)) gc_fail("%s: not 64 lowercase hex", k);
509 if (file_sha(path, sha)) {
510 if (strict) gc_fail("interface %s: %s is not in this tree (every interface must be present at seal-open)", name, path);
511 printf("ok interface %s: %s not in this tree (pending merge), pinned %.16s...\n", name, path, want);
512 continue;
513 }
514 if (strcmp(sha, want)) gc_fail("digest drift: interface %s file %s is %s, pinned %s", name, path, sha, want);
515 printf("ok interface %s: %s matches\n", name, path);
516 }
517
518 /* dev split */
519 const char *devmeta = str("splits.dev.meta");
520 char sha[65];
521 if (file_sha(devmeta, sha)) gc_fail("dev META missing: %s", devmeta);
522 const char *dms = str("splits.dev.meta_sha256");
523 if (!hex64(dms)) gc_fail("splits.dev.meta_sha256: not 64 lowercase hex");
524 if (strcmp(sha, dms)) gc_fail("digest drift: %s is %s, splits.dev.meta_sha256 %s", devmeta, sha, dms);
525 if (!hex64(str("splits.dev.pack_sha256"))) gc_fail("splits.dev.pack_sha256: not 64 lowercase hex");
526 read_meta(devmeta, &dev, split_index("dev"));
527 int nt = count_elems("splits.dev.tasks");
528 if (nt != 10) gc_fail("splits.dev.tasks: %d tasks, frozen 10", nt);
529 for (int i = 0; i < nt; i++) {
530 char k[64];
531 snprintf(k, sizeof k, "splits.dev.tasks[%d]", i);
532 const char *id = str(k);
533 if (!fs_task_id_ok(id)) gc_fail("%s: bad task id", k);
534 if (i) {
535 char k2[64];
536 snprintf(k2, sizeof k2, "splits.dev.tasks[%d]", i - 1);
537 if (strcmp(str(k2), id) >= 0) gc_fail("splits.dev.tasks: duplicate or unsorted task id %s", id);
538 }
539 }
540 /* META ids, sorted */
541 if (dev.n != nt) gc_fail("dev META has %d tasks, splits.dev.tasks %d", dev.n, nt);
542 char **mids = malloc(sizeof(char *) * (size_t)dev.n);
543 for (int i = 0; i < dev.n; i++) mids[i] = dev.m[i].id;
544 qsort(mids, (size_t)dev.n, sizeof *mids, cmp_cstr);
545 for (int i = 0; i < nt; i++) {
546 char k[64];
547 snprintf(k, sizeof k, "splits.dev.tasks[%d]", i);
548 if (strcmp(mids[i], str(k))) gc_fail("dev META task ids differ from splits.dev.tasks (%s vs %s)", mids[i], str(k));
549 if (i && !strcmp(mids[i], mids[i - 1])) gc_fail("dev META: duplicate task id %s", mids[i]);
550 }
551 free(mids);
552 /* case directories */
553 char full[4096];
554 snprintf(full, sizeof full, "%s/%s", root, str("splits.dev.cases"));
555 DIR *d = opendir(full);
556 if (!d) gc_fail("cannot open %s", str("splits.dev.cases"));
557 char *cases[256];
558 int nc = 0;
559 struct dirent *de;
560 while ((de = readdir(d))) {
561 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) continue;
562 if (nc == 256) gc_fail("too many case directories");
563 cases[nc++] = strdup(de->d_name);
564 }
565 closedir(d);
566 qsort(cases, (size_t)nc, sizeof *cases, cmp_cstr);
567 if (nc != nt) gc_fail("dev cases: %d directories, splits.dev.tasks %d", nc, nt);
568 for (int i = 0; i < nc; i++) {
569 char k[64];
570 snprintf(k, sizeof k, "splits.dev.tasks[%d]", i);
571 if (strcmp(cases[i], str(k))) gc_fail("dev case directory %s does not match splits.dev.tasks (%s)", cases[i], str(k));
572 free(cases[i]);
573 }
574 /* families = distinct META signatures, ascending */
575 char *sigs[64];
576 int ns = 0;
577 for (int i = 0; i < dev.n; i++) {
578 int seen = 0;
579 for (int j = 0; j < ns; j++) seen |= !strcmp(sigs[j], dev.m[i].sig);
580 if (!seen) { if (ns == 64) gc_fail("too many dev families"); sigs[ns++] = dev.m[i].sig; }
581 }
582 qsort(sigs, (size_t)ns, sizeof *sigs, cmp_cstr);
583 int nf = count_elems("splits.dev.families");
584 if (nf != ns) gc_fail("splits.dev.families: %d listed, dev META has %d families", nf, ns);
585 for (int i = 0; i < nf; i++) {
586 char k[64];
587 snprintf(k, sizeof k, "splits.dev.families[%d]", i);
588 if (strcmp(str(k), sigs[i])) gc_fail("splits.dev.families[%d] is %s, dev META gives %s", i, str(k), sigs[i]);
589 }
590 printf("ok dev split: %d tasks = META ids = case directories, %d families = META signatures\n", nt, nf);
591 for (int i = 0; i < nf; i++) { char tok[24]; fs_token(sigs[i], tok); printf("ok dev family %s %s\n", tok, sigs[i]); }
592
593 /* corpus split: frozen once meta_sha256 is set */
594 Ent *cm = get("splits.corpus.meta_sha256");
595 if (cm->type == 'z') {
596 corpus_frozen = 0;
597 const char *pre[] = {"record_sets.prefix_ids", "record_sets.prefix_sha256", "record_sets.raw_manifest_sha256",
598 "record_sets.abstraction_manifest_sha256", "record_sets.raw_manifest", "record_sets.abstraction_manifest"};
599 for (int i = 0; i < 6; i++)
600 if (get(pre[i])->type != 'z') gc_fail("%s is set while the corpus META is not frozen", pre[i]);
601 FsSet both = {0};
602 char err[512];
603 snprintf(full, sizeof full, "%s/%s", root, devmeta);
604 if (fs_read(full, &both, err, sizeof err)) gc_fail("%s", err);
605 if (fs_rule(&both, stdout, 0)) gc_fail("disjointness rule fails on the dev split");
606 printf("ok corpus split: pending (splits.corpus.meta_sha256 null until GEN-3 freezes it)\n");
607 } else {
608 corpus_frozen = 1;
609 const char *cmeta = str("splits.corpus.meta");
610 if (!hex64(cm->raw)) gc_fail("splits.corpus.meta_sha256: not 64 lowercase hex");
611 if (file_sha(cmeta, sha)) gc_fail("corpus META missing: %s", cmeta);
612 if (strcmp(sha, cm->raw)) gc_fail("digest drift: %s is %s, splits.corpus.meta_sha256 %s", cmeta, sha, cm->raw);
613 read_meta(cmeta, &corpus, split_index("corpus"));
614 FsSet both = {0};
615 char err[512];
616 snprintf(full, sizeof full, "%s/%s", root, devmeta);
617 if (fs_read(full, &both, err, sizeof err)) gc_fail("%s", err);
618 snprintf(full, sizeof full, "%s/%s", root, cmeta);
619 if (fs_read(full, &both, err, sizeof err)) gc_fail("%s", err);
620 if (fs_rule(&both, stdout, 0)) gc_fail("disjointness rule (R1..R8) fails on dev + corpus");
621 printf("ok corpus split: %d tasks, dev + corpus pass R1..R8\n", corpus.n);
622 Ent *pi = get("record_sets.prefix_ids");
623 if (pi->type == 'a') {
624 int n = count_elems("record_sets.prefix_ids");
625 if (n != 14) gc_fail("record_sets.prefix_ids: %d ids, frozen 14", n);
626 for (int i = 0; i < n; i++) {
627 char k[64];
628 snprintf(k, sizeof k, "record_sets.prefix_ids[%d]", i);
629 const char *id = str(k);
630 int in = 0;
631 for (int j = 0; j < corpus.n; j++) in |= !strcmp(corpus.m[j].id, id);
632 if (!in) gc_fail("%s: %s is not a corpus task", k, id);
633 for (int j = 0; j < i; j++) {
634 char k2[64];
635 snprintf(k2, sizeof k2, "record_sets.prefix_ids[%d]", j);
636 if (!strcmp(str(k2), id)) gc_fail("record_sets.prefix_ids: duplicate %s", id);
637 }
638 }
639 }
640 }
641 const char *opt[] = {"splits.heldout.pub_sha256", "splits.heldout.tasks_sha256", "record_sets.prefix_sha256",
642 "record_sets.raw_manifest_sha256", "record_sets.abstraction_manifest_sha256"};
643 for (int i = 0; i < 5; i++) {
644 Ent *e = get(opt[i]);
645 if (e->type == 's' && !hex64(e->raw)) gc_fail("%s: not 64 lowercase hex", opt[i]);
646 }
647 /* C and D record-set manifests: path and digest both null (not frozen) or both set and re-hashed */
648 static const char *const rs[2][2] = {{"record_sets.raw_manifest", "record_sets.raw_manifest_sha256"},
649 {"record_sets.abstraction_manifest", "record_sets.abstraction_manifest_sha256"}};
650 for (int i = 0; i < 2; i++) {
651 Ent *p = get(rs[i][0]), *h = get(rs[i][1]);
652 if ((p->type == 'z') != (h->type == 'z')) gc_fail("%s and %s must both be null or both be set", rs[i][0], rs[i][1]);
653 if (p->type == 'z') continue;
654 if (!safe_rel(p->raw)) gc_fail("%s: unsafe path", rs[i][0]);
655 if (file_sha(p->raw, sha)) gc_fail("record-set manifest missing: %s", p->raw);
656 if (strcmp(sha, h->raw)) gc_fail("digest drift: record-set manifest %s is %s, %s %s", p->raw, sha, rs[i][1], h->raw);
657 printf("ok record set %s re-hashed\n", p->raw);
658 }
659}
660
661/* ---------- split (reviewer, after the seal) ---------- */
662
663static void check_split(const char *split_path, const char *pub_path)
664{
665 if (!corpus_frozen) gc_fail("split check needs the frozen corpus META (splits.corpus.meta_sha256 is null)");
666 if (get("splits.heldout.pub_sha256")->type != 's' || get("splits.heldout.tasks_sha256")->type != 's')
667 gc_fail("split check needs splits.heldout.pub_sha256 and tasks_sha256 anchored in protocol.json (fail closed on null)");
668 FsSet hs = {0};
669 char err[512];
670 if (fs_read(split_path, &hs, err, sizeof err)) gc_fail("%s", err);
671 if (!hs.is_split || hs.n == 0) gc_fail("%s: not a gen-split file with task lines", split_path);
672 int nfam;
673 char *fl = fs_famlist(&hs, &nfam);
674 unsigned char dg[32];
675 char famsha[65];
676 sha256_hash((const unsigned char *)fl, strlen(fl), dg);
677 fs_hex(dg, famsha);
678 free(fl);
679
680 size_t len;
681 char *b = fs_slurp(pub_path, &len);
682 if (!b) gc_fail("cannot read %s", pub_path);
683 if (strlen(b) != len || len == 0 || b[len - 1] != '\n') gc_fail("HELDOUT.pub: must be text ending in a newline");
684 for (size_t i = 0; i < len; i++)
685 if (b[i] != '\n' && ((unsigned char)b[i] < 0x20 || (unsigned char)b[i] > 0x7e)) gc_fail("HELDOUT.pub: byte 0x%02x", (unsigned char)b[i]);
686 unsigned char pd[32];
687 char pubsha[65];
688 sha256_hash((const unsigned char *)b, len, pd);
689 fs_hex(pd, pubsha);
690 char *lines[4096];
691 int nl = 0;
692 for (char *s = b; *s;) {
693 char *e = strchr(s, '\n');
694 *e = 0;
695 if (nl == 4096) gc_fail("HELDOUT.pub: too many lines");
696 lines[nl++] = s;
697 s = e + 1;
698 }
699 static const char *const head[] = {"tasks_sha256 ", "split_sha256 ", "famlist_sha256 "};
700 if (nl < 6 || strcmp(lines[0], "gen-heldout-pub 1")) gc_fail("HELDOUT.pub: line 1 must be \"gen-heldout-pub 1\"");
701 for (int i = 0; i < 3; i++)
702 if (strncmp(lines[1 + i], head[i], strlen(head[i])) || !hex64(lines[1 + i] + strlen(head[i])))
703 gc_fail("HELDOUT.pub: line %d must be \"%s<64 hex>\"", 2 + i, head[i]);
704 const char *p_tasks = lines[1] + 13, *p_split = lines[2] + 13, *p_fam = lines[3] + 15;
705 int n_tasks, n_fams;
706 char tail;
707 if (sscanf(lines[4], "tasks %d%c", &n_tasks, &tail) != 1 || n_tasks < 1) gc_fail("HELDOUT.pub: line 5 must be \"tasks <n>\"");
708 if (sscanf(lines[5], "families %d%c", &n_fams, &tail) != 1 || n_fams < 1) gc_fail("HELDOUT.pub: line 6 must be \"families <m>\"");
709 char chk[64];
710 snprintf(chk, sizeof chk, "tasks %d", n_tasks);
711 if (strcmp(chk, lines[4])) gc_fail("HELDOUT.pub: line 5 not canonical");
712 snprintf(chk, sizeof chk, "families %d", n_fams);
713 if (strcmp(chk, lines[5])) gc_fail("HELDOUT.pub: line 6 not canonical");
714 if (nl != 6 + n_tasks) gc_fail("HELDOUT.pub: %d task lines, tasks %d", nl - 6, n_tasks);
715 for (int i = 0; i < n_tasks; i++) {
716 const char *l = lines[6 + i];
717 if (strncmp(l, "task ", 5) || !fs_task_id_ok(l + 5)) gc_fail("HELDOUT.pub: line %d must be \"task <task_id>\"", 7 + i);
718 if (i && strcmp(lines[5 + i] + 5, l + 5) >= 0) gc_fail("HELDOUT.pub: task ids not strictly ascending at %s", l + 5);
719 }
720
721 if (strcmp(p_split, hs.split_sha256)) gc_fail("split_sha256 mismatch: SPLIT is %s, HELDOUT.pub says %s", hs.split_sha256, p_split);
722 if (strcmp(p_fam, famsha)) gc_fail("famlist_sha256 mismatch: SPLIT gives %s, HELDOUT.pub says %s", famsha, p_fam);
723 if (n_tasks != hs.n) gc_fail("HELDOUT.pub tasks %d, SPLIT has %d", n_tasks, hs.n);
724 if (n_fams != nfam) gc_fail("HELDOUT.pub families %d, SPLIT has %d", n_fams, nfam);
725 for (int i = 0; i < hs.n; i++)
726 if (strcmp(hs.m[i].id, lines[6 + i] + 5)) gc_fail("HELDOUT.pub task %s differs from SPLIT task %s", lines[6 + i] + 5, hs.m[i].id);
727 int want_n = atoi(get("splits.heldout.count")->raw), want_f = atoi(get("splits.heldout.min_families")->raw);
728 if (hs.n != want_n) gc_fail("held-out split has %d tasks, protocol requires %d", hs.n, want_n);
729 if (nfam < want_f) gc_fail("held-out split has %d families, protocol requires at least %d", nfam, want_f);
730 Ent *e = get("splits.heldout.pub_sha256");
731 if (strcmp(e->raw, pubsha)) gc_fail("digest drift: HELDOUT.pub is %s, splits.heldout.pub_sha256 %s", pubsha, e->raw);
732 e = get("splits.heldout.tasks_sha256");
733 if (strcmp(e->raw, p_tasks)) gc_fail("tasks_sha256 mismatch: HELDOUT.pub %s, protocol %s", p_tasks, e->raw);
734 printf("ok HELDOUT.pub matches SPLIT: %d tasks, %d families, split and famlist digests\n", hs.n, nfam);
735
736 FsSet all = {0};
737 char full[4096];
738 snprintf(full, sizeof full, "%s/%s", root, str("splits.dev.meta"));
739 if (fs_read(full, &all, err, sizeof err)) gc_fail("%s", err);
740 snprintf(full, sizeof full, "%s/%s", root, str("splits.corpus.meta"));
741 if (fs_read(full, &all, err, sizeof err)) gc_fail("%s", err);
742 if (fs_read(split_path, &all, err, sizeof err)) gc_fail("%s", err);
743 if (fs_rule(&all, stdout, 0)) gc_fail("disjointness rule (R1..R8) fails on dev + corpus + SPLIT");
744 printf("ok dev + corpus + SPLIT pass R1..R8\n");
745}
746
747
748/* ---------- open (custodian, seal-open step; reducer, before reducing) ---------- */
749
750static void check_frozen(void)
751{
752 for (int i = 0; i < nent; i++)
753 if (ent[i].type == 'z') gc_fail("not run-ready: %s is null", ent[i].path);
754 int found = 0, ni = count_elems("interfaces");
755 for (int i = 0; i < ni; i++) {
756 char k[64];
757 snprintf(k, sizeof k, "interfaces[%d].name", i);
758 found |= !strcmp(str(k), str("retrieval.contract"));
759 }
760 if (!found) gc_fail("interfaces: the retrieval contract %s is not pinned", str("retrieval.contract"));
761
762 printf("ok run-ready: no null field, every interface present and matching, %s pinned\n", str("retrieval.contract"));
763}
764
765static void check_open(const char *json_path, const char *open_path)
766{
767 size_t jl;
768 char *jb = fs_slurp(json_path, &jl);
769 if (!jb) gc_fail("cannot read %s", json_path);
770 unsigned char d[32];
771 char jsha[65];
772 sha256_hash((const unsigned char *)jb, jl, d);
773 fs_hex(d, jsha);
774 free(jb);
775
776 size_t len;
777 char *b = fs_slurp(open_path, &len);
778 if (!b) gc_fail("cannot read %s", open_path);
779 if (strlen(b) != len || len == 0 || b[len - 1] != '\n') gc_fail("OPEN: must be text ending in a newline");
780 char *ln[8];
781 int nl = 0;
782 for (char *s = b; *s;) {
783 char *e = strchr(s, '\n');
784 *e = 0;
785 if (nl == 8) gc_fail("OPEN: more than 5 lines");
786 ln[nl++] = s;
787 s = e + 1;
788 }
789 if (nl != 5 || strcmp(ln[0], "gen-open 1")) gc_fail("OPEN: must be exactly 5 lines starting \"gen-open 1\"");
790 static const char *const key[4] = {"omega_commit ", "protocol_sha256 ", "tasks_sha256 ", "heldout_pub_sha256 "};
791 const char *val[4];
792 for (int i = 0; i < 4; i++) {
793 size_t kl = strlen(key[i]);
794 if (strncmp(ln[1 + i], key[i], kl)) gc_fail("OPEN: line %d must start \"%s\"", 2 + i, key[i]);
795 val[i] = ln[1 + i] + kl;
796 }
797 if (strlen(val[0]) != 40 || strspn(val[0], "0123456789abcdef") != 40) gc_fail("OPEN: omega_commit must be 40 lowercase hex");
798 for (int i = 1; i < 4; i++)
799 if (!hex64(val[i])) gc_fail("OPEN: %smust be 64 lowercase hex", key[i]);
800 if (strcmp(val[1], jsha)) gc_fail("OPEN: protocol_sha256 %s, protocol.json is %s", val[1], jsha);
801 if (strcmp(val[2], get("splits.heldout.tasks_sha256")->raw)) gc_fail("OPEN: tasks_sha256 differs from splits.heldout.tasks_sha256");
802 if (strcmp(val[3], get("splits.heldout.pub_sha256")->raw)) gc_fail("OPEN: heldout_pub_sha256 differs from splits.heldout.pub_sha256");
803 printf("ok OPEN matches protocol.json %.16s...\n", jsha);
804 free(b);
805}
806
807int main(int argc, char **argv)
808{
809 if (argc == 4 && !strcmp(argv[1], "manifest")) {
810 root = argv[3];
811 check_manifest(argv[2]);
812 } else if (argc == 4 && !strcmp(argv[1], "run-ready")) {
813 root = argv[3];
814 strict = 1;
815 check_manifest(argv[2]);
816 check_frozen();
817 } else if (argc == 5 && !strcmp(argv[1], "open")) {
818 root = argv[3];
819 strict = 1;
820 check_manifest(argv[2]);
821 check_frozen();
822 check_open(argv[2], argv[4]);
823 } else if (argc == 6 && !strcmp(argv[1], "split")) {
824 root = argv[3];
825 check_manifest(argv[2]);
826 check_split(argv[4], argv[5]);
827 } else {
828 fprintf(stderr, "usage: gencheck manifest <protocol.json> <root> | run-ready <protocol.json> <root> | open <protocol.json> <root> <OPEN> | split <protocol.json> <root> <SPLIT> <HELDOUT.pub>\n");
829 return 2;
830 }
831 printf("GENCHECK PASS\n");
832 return 0;
833}