interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-campaign-verifier / src / lib.rs

144 lines · 5430 bytes Raw Blame History
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//! Independent verifier for campaign C1 (`docs/campaigns/c1/SPEC.md`).
17//!
18//! Consumes a frozen evidence bundle and the frozen spec directory, and emits PASS/FAIL per
19//! check. It links no crate under test: every judgement is rebuilt from raw bundle files.
20
21pub mod bundle;
22pub mod ids;
23pub mod kv;
24pub mod placement;
25pub mod report;
26
27use bundle::Manifest;
28use kv::{KvCensus, KvEvent, ReportedKvMetrics};
29use placement::{OpRecord, PlacementSpec, WitnessEvent};
30use report::{CheckResult, Report};
31use serde::de::DeserializeOwned;
32use serde::Deserialize;
33use std::collections::BTreeMap;
34use std::fs;
35use std::path::Path;
36
37pub fn load_json<T: DeserializeOwned>(path: &Path) -> Result<T, String> {
38 let text = fs::read_to_string(path).map_err(|e| format!("{}: {e}", path.display()))?;
39 serde_json::from_str(&text).map_err(|e| format!("{}: {e}", path.display()))
40}
41
42pub fn load_jsonl<T: DeserializeOwned>(path: &Path) -> Result<Vec<T>, String> {
43 let text = fs::read_to_string(path).map_err(|e| format!("{}: {e}", path.display()))?;
44 text.lines()
45 .enumerate()
46 .filter(|(_, line)| !line.trim().is_empty())
47 .map(|(n, line)| {
48 serde_json::from_str(line).map_err(|e| format!("{}:{}: {e}", path.display(), n + 1))
49 })
50 .collect()
51}
52
53pub fn load_toml<T: DeserializeOwned>(path: &Path) -> Result<T, String> {
54 let text = fs::read_to_string(path).map_err(|e| format!("{}: {e}", path.display()))?;
55 toml::from_str(&text).map_err(|e| format!("{}: {e}", path.display()))
56}
57
58#[derive(Debug, Deserialize)]
59struct KvContract {
60 profiles: BTreeMap<String, KvProfile>,
61}
62
63#[derive(Debug, Deserialize)]
64struct KvProfile {
65 num_blocks: u32,
66}
67
68/// Pool size comes from the frozen contract, never from the code under test.
69fn contract_pool_total(manifest: &Manifest, spec_dir: &Path) -> Result<u32, String> {
70 let contract: KvContract = load_toml(&spec_dir.join("kv_contract.toml"))?;
71 contract
72 .profiles
73 .get(&manifest.kv_profile)
74 .map(|p| p.num_blocks)
75 .ok_or_else(|| format!("kv_profile {} not in kv_contract.toml", manifest.kv_profile))
76}
77
78fn check_kv(bundle: &Path, pool_total: u32, report: &mut Report) -> Result<(), String> {
79 let events: Vec<KvEvent> = load_jsonl(&bundle.join("kv_allocations.jsonl"))?;
80 let census: KvCensus = load_json(&bundle.join("kv_census.json"))?;
81 let metrics: ReportedKvMetrics = load_json(&bundle.join("kv_metrics.json"))?;
82
83 let (state, replay_violations) = kv::replay(pool_total, &events);
84 report.push(CheckResult::from_violations(
85 "KV journal replay (identity, isolation, idempotent release)",
86 replay_violations,
87 ));
88 report.push(CheckResult::from_violations(
89 "KV census conservation",
90 kv::check_census_conservation(&census),
91 ));
92 report.push(CheckResult::from_violations(
93 "KV replay == raw census",
94 kv::check_replay_matches_census(&state, &census),
95 ));
96 report.push(CheckResult::from_violations(
97 "KV replay == reported metrics",
98 kv::check_replay_matches_metrics(&state, &metrics),
99 ));
100 Ok(())
101}
102
103fn check_placement(bundle: &Path, spec_dir: &Path) -> Result<Vec<String>, String> {
104 let spec: PlacementSpec = load_toml(&spec_dir.join("placement.toml"))?;
105 let records: Vec<OpRecord> = load_jsonl(&bundle.join("op_records.jsonl"))?;
106 let witness: Vec<WitnessEvent> = load_jsonl(&bundle.join("witness.jsonl"))?;
107 Ok(placement::check_placement(&spec, &records, &witness))
108}
109
110/// Runs every implemented check. A missing or unreadable input is itself a FAIL.
111pub fn verify_bundle(bundle: &Path, spec_dir: &Path) -> Report {
112 let mut report = Report::default();
113
114 report.push(CheckResult::from_violations(
115 "bundle integrity (sha256sums)",
116 bundle::check_sha256sums(bundle),
117 ));
118
119 let manifest = load_json::<Manifest>(&bundle.join("manifest.json"));
120 report.push(CheckResult::from_violations(
121 "manifest binds frozen spec",
122 match &manifest {
123 Ok(m) => bundle::check_manifest_against_spec(m, spec_dir),
124 Err(e) => vec![e.clone()],
125 },
126 ));
127
128 let pool_total = manifest.and_then(|m| contract_pool_total(&m, spec_dir));
129 match pool_total {
130 Ok(total) => {
131 if let Err(e) = check_kv(bundle, total, &mut report) {
132 report.push(CheckResult::from_violations("KV evidence present", vec![e]));
133 }
134 }
135 Err(e) => report.push(CheckResult::from_violations("KV contract profile", vec![e])),
136 }
137
138 report.push(CheckResult::from_violations(
139 "device placement (dispatch record == witness == placement.toml)",
140 check_placement(bundle, spec_dir).unwrap_or_else(|e| vec![e]),
141 ));
142
143 report
144}