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 / research / atemporal / at1 / evaluator / src / main.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! at1-eval: the AT-1 Agent 4 adversarial evaluator (std-only Rust, no Cargo). |
| 17 | //! Build: rustc --edition 2021 -O src/main.rs -o build/at1-eval |
| 18 | |
| 19 | mod big; |
| 20 | mod case; |
| 21 | mod corpus; |
| 22 | mod dd; |
| 23 | mod hidden; |
| 24 | mod judge; |
| 25 | mod model; |
| 26 | mod mutants; |
| 27 | mod qualify; |
| 28 | mod rat; |
| 29 | mod result; |
| 30 | mod scan; |
| 31 | mod sha256; |
| 32 | mod synth; |
| 33 | mod text; |
| 34 | mod verify; |
| 35 | |
| 36 | use std::fs; |
| 37 | use std::process::exit; |
| 38 | |
| 39 | fn usage() -> ! { |
| 40 | eprintln!( |
| 41 | "usage: at1-eval <command> ... |
| 42 | case <file> [--why] validate an AT1_CASE_V1 file (refusal: one stderr line, exit 2) |
| 43 | shadow <case> print the shadow model's values for a case |
| 44 | verify [--case F] [--oracle-record] <result> verify a result (exit 0 PASS, 1 FAIL, 3 INCONCLUSIVE) |
| 45 | splice <engine-result> <oracle-record> <out> runner role: splice the four reference families |
| 46 | synth-engine <case> <out> [mutant] honest synthetic engine (or a named mutant) |
| 47 | synth-oracle <case> <out> [mutant] honest synthetic oracle record (or a named oracle mutant) |
| 48 | corpus-gen <dir> write the public corpus and MANIFEST.tsv |
| 49 | corpus-check <dir> check the corpus on disk is byte-identical to the generator |
| 50 | selftest KAT digests, hand tables, codec rows, honest controls |
| 51 | mutants <out.tsv> build the mutant kill receipt |
| 52 | qualify --cases D --engine CMD --oracle CMD [--out D] [--limit N] run candidates on a corpus |
| 53 | hidden-gen <seed-hex-64> <outdir> generate the hidden set from a private seed |
| 54 | hidden-commit <dir> print the manifest commitment of a case directory |
| 55 | scan-clock <object>... instruction scan for counter reads and raw syscalls |
| 56 | sha256 <file>... plain SHA-256 of files" |
| 57 | ); |
| 58 | exit(64) |
| 59 | } |
| 60 | |
| 61 | fn read(p: &str) -> Vec<u8> { |
| 62 | match fs::read(p) { |
| 63 | Ok(b) => b, |
| 64 | Err(e) => { |
| 65 | eprintln!("at1-eval: cannot read {}: {}", p, e); |
| 66 | exit(66) |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | fn write(p: &str, b: &[u8]) { |
| 71 | if let Some(parent) = std::path::Path::new(p).parent() { |
| 72 | let _ = fs::create_dir_all(parent); |
| 73 | } |
| 74 | if let Err(e) = fs::write(p, b) { |
| 75 | eprintln!("at1-eval: cannot write {}: {}", p, e); |
| 76 | exit(73) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | pub fn print_report(rep: &verify::Report) { |
| 81 | for f in &rep.findings { |
| 82 | println!("{} {} {}", if f.sev == verify::Sev::Fail { "FAIL" } else { "INCONCLUSIVE" }, f.code, f.detail); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | fn main() { |
| 87 | let a: Vec<String> = std::env::args().collect(); |
| 88 | if a.len() < 2 { |
| 89 | usage(); |
| 90 | } |
| 91 | let args: Vec<&str> = a[2..].iter().map(|s| s.as_str()).collect(); |
| 92 | match a[1].as_str() { |
| 93 | "case" => { |
| 94 | if args.is_empty() { |
| 95 | usage(); |
| 96 | } |
| 97 | match case::validate_bytes(&read(args[0])) { |
| 98 | Ok(c) => println!("AT1_CASE_OK {} {} {}", c.case_id, c.acceptance_id, c.file_sha256), |
| 99 | Err((code, why)) => { |
| 100 | eprintln!("AT1_CASE_REFUSED {}", code.code()); |
| 101 | if args.contains(&"--why") { |
| 102 | println!("{}", why); |
| 103 | } |
| 104 | exit(2) |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | "shadow" => { |
| 109 | if args.is_empty() { |
| 110 | usage(); |
| 111 | } |
| 112 | let c = match case::validate_bytes(&read(args[0])) { |
| 113 | Ok(c) => c, |
| 114 | Err((code, _)) => { |
| 115 | eprintln!("AT1_CASE_REFUSED {}", code.code()); |
| 116 | exit(2) |
| 117 | } |
| 118 | }; |
| 119 | let sh = model::shadow(&c, &model::Mods::default(), false); |
| 120 | println!("kernel_dim {} trivial {} interacting_exact {} ideal_exact {}", sh.kernel_dim, sh.trivial, sh.interacting_exact, sh.ideal_exact); |
| 121 | println!("povm_residual {} ({:.17e})", model::show(&sh.povm_residual), sh.povm_residual.q.to_f64()); |
| 122 | for k in 0..c.m { |
| 123 | let ide = &sh.ideal[k]; |
| 124 | let p = if sh.trivial { "undefined".to_string() } else { model::show(&sh.p[k]) }; |
| 125 | let pa = match sh.pauli.get(k).and_then(|x| x.as_ref()) { |
| 126 | Some(s) => format!("{} {} {}", model::show(&s[0][0]), model::show(&s[1][0]), model::show(&s[2][0])), |
| 127 | None => "undefined".into(), |
| 128 | }; |
| 129 | println!("k {} {} p {} status {} pauli+ {} ideal+ {} {} {}", k, c.labels[k], p, sh.status[k].text(), pa, model::show(&ide[0][0]), model::show(&ide[1][0]), model::show(&ide[2][0])); |
| 130 | } |
| 131 | } |
| 132 | "verify" => { |
| 133 | let mut case_file: Option<Vec<u8>> = None; |
| 134 | let mut role = verify::Role::Candidate; |
| 135 | let mut file: Option<&str> = None; |
| 136 | let mut i = 0; |
| 137 | while i < args.len() { |
| 138 | match args[i] { |
| 139 | "--case" => { |
| 140 | i += 1; |
| 141 | case_file = Some(read(args.get(i).copied().unwrap_or_else(|| usage()))); |
| 142 | } |
| 143 | "--oracle-record" => role = verify::Role::Oracle, |
| 144 | f => file = Some(f), |
| 145 | } |
| 146 | i += 1; |
| 147 | } |
| 148 | let rep = verify::verify(&read(file.unwrap_or_else(|| usage())), case_file.as_deref(), role); |
| 149 | print_report(&rep); |
| 150 | println!("AT1_VERIFY {} outcome {} codes {}", rep.status(), rep.derived_outcome, if rep.derived_codes.is_empty() { "none".into() } else { rep.derived_codes.join(",") }); |
| 151 | exit(match rep.status() { |
| 152 | "PASS" => 0, |
| 153 | "FAIL" => 1, |
| 154 | _ => 3, |
| 155 | }) |
| 156 | } |
| 157 | "splice" => { |
| 158 | if args.len() != 3 { |
| 159 | usage(); |
| 160 | } |
| 161 | let e = result::parse(&read(args[0])).unwrap_or_else(|m| { |
| 162 | eprintln!("at1-eval: engine result does not parse: {}", m); |
| 163 | exit(1) |
| 164 | }); |
| 165 | let o = result::parse(&read(args[1])).unwrap_or_else(|m| { |
| 166 | eprintln!("at1-eval: oracle record does not parse: {}", m); |
| 167 | exit(1) |
| 168 | }); |
| 169 | match synth::splice(&e, &o) { |
| 170 | Ok(r) => write(args[2], &r.bytes()), |
| 171 | Err(m) => { |
| 172 | eprintln!("at1-eval: splice refused: {}", m); |
| 173 | exit(1) |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | "synth-engine" | "synth-oracle" => { |
| 178 | if args.len() < 2 { |
| 179 | usage(); |
| 180 | } |
| 181 | let c = case::validate_bytes(&read(args[0])).unwrap_or_else(|(code, _)| { |
| 182 | eprintln!("AT1_CASE_REFUSED {}", code.code()); |
| 183 | exit(2) |
| 184 | }); |
| 185 | let name = args.get(2).copied().unwrap_or("honest"); |
| 186 | let r = if a[1] == "synth-engine" { |
| 187 | let em = mutants::engine_mut(name).unwrap_or_else(|| { |
| 188 | eprintln!("at1-eval: unknown engine mutant {}", name); |
| 189 | exit(64) |
| 190 | }); |
| 191 | synth::engine_result(&c, &em, &format!("at1-eval synth-engine {}", name)) |
| 192 | } else { |
| 193 | let om = mutants::oracle_mut(name).unwrap_or_else(|| { |
| 194 | eprintln!("at1-eval: unknown oracle mutant {}", name); |
| 195 | exit(64) |
| 196 | }); |
| 197 | synth::oracle_record(&c, &om, &format!("at1-eval synth-oracle {}", name)) |
| 198 | }; |
| 199 | write(args[1], &r.bytes()); |
| 200 | } |
| 201 | "corpus-gen" => { |
| 202 | if args.len() != 1 { |
| 203 | usage(); |
| 204 | } |
| 205 | let dir = args[0]; |
| 206 | let mut man = String::from("# path\tclass\texpected tool response (every parser must give it; refusals: one stderr line, exit 2)\n"); |
| 207 | for r in corpus::public_rows() { |
| 208 | write(&format!("{}/{}", dir, r.path), &r.bytes); |
| 209 | man.push_str(&format!("{}\t{}\t{}\n", r.path, r.class, r.expect)); |
| 210 | } |
| 211 | write(&format!("{}/MANIFEST.tsv", dir), man.as_bytes()); |
| 212 | println!("corpus: {} files written to {}", corpus::public_rows().len(), dir); |
| 213 | } |
| 214 | "corpus-check" => { |
| 215 | if args.len() != 1 { |
| 216 | usage(); |
| 217 | } |
| 218 | let mut bad = 0; |
| 219 | let rows = corpus::public_rows(); |
| 220 | for r in &rows { |
| 221 | let p = format!("{}/{}", args[0], r.path); |
| 222 | if fs::read(&p).ok().as_deref() != Some(r.bytes.as_slice()) { |
| 223 | println!("DIFFERS {}", r.path); |
| 224 | bad += 1; |
| 225 | } |
| 226 | } |
| 227 | println!("corpus-check: {} files, {} differ", rows.len(), bad); |
| 228 | exit(if bad == 0 { 0 } else { 1 }) |
| 229 | } |
| 230 | "selftest" => exit(qualify::selftest()), |
| 231 | "mutants" => { |
| 232 | if args.len() != 1 { |
| 233 | usage(); |
| 234 | } |
| 235 | exit(mutants::receipt(args[0])) |
| 236 | } |
| 237 | "qualify" => exit(qualify::qualify(&args)), |
| 238 | "hidden-gen" => { |
| 239 | if args.len() != 2 { |
| 240 | usage(); |
| 241 | } |
| 242 | exit(hidden::generate(args[0], args[1])) |
| 243 | } |
| 244 | "hidden-commit" => { |
| 245 | if args.len() != 1 { |
| 246 | usage(); |
| 247 | } |
| 248 | exit(hidden::commit(args[0])) |
| 249 | } |
| 250 | "scan-clock" => exit(scan::main(&args)), |
| 251 | "sha256" => { |
| 252 | for p in &args { |
| 253 | println!("{} {}", sha256::sha256_hex(&read(p)), p); |
| 254 | } |
| 255 | } |
| 256 | _ => usage(), |
| 257 | } |
| 258 | } |