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 / crumbs / src / sealed.rs

365 lines · 11741 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//! Crumb v1 sealed contract: everything the learner never sees.
17//!
18//! A `SealedCrumb` is a pure function of (family, generator version, seed,
19//! generation parameters): regenerating it reproduces the identical bytes and
20//! digests. Occurrence-level facts (which population the mixer drew it into,
21//! when it was shown) live in the ledger record, not here.
22//!
23//! `Debug` is redacted: logging a sealed record by accident prints only its
24//! digest, never labels or held-out data.
25
26use crate::canon::Enc;
27use crate::digest::{
28 digest, CrumbDigest, Digest, Domain, GeneratorInstanceDigest, SealedRecordDigest,
29};
30use crate::program::Program;
31use crate::provenance::Provenance;
32use serde::{Deserialize, Serialize};
33
34pub const SEALED_SCHEMA_VERSION: u16 = 1;
35
36/// Capability rungs of the progression. Builder vocabulary; never sent to a learner.
37#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
38pub enum Rung {
39 SingleTransformation = 1,
40 TwoTransformations = 2,
41 RepeatedTransformation = 3,
42 ConditionalTransformation = 4,
43 MultiInputRelation = 5,
44 Recurrence = 6,
45 State = 7,
46 Composition = 8,
47 Symmetry = 9,
48 Modularity = 10,
49 Invariance = 11,
50 MultiStepAlgorithm = 12,
51 LatentVariables = 13,
52 NoisyObservation = 14,
53 PartialObservation = 15,
54 CounterexampleSearch = 16,
55 TheoryFormation = 17,
56}
57
58impl Rung {
59 pub const ALL: [Rung; 17] = [
60 Rung::SingleTransformation,
61 Rung::TwoTransformations,
62 Rung::RepeatedTransformation,
63 Rung::ConditionalTransformation,
64 Rung::MultiInputRelation,
65 Rung::Recurrence,
66 Rung::State,
67 Rung::Composition,
68 Rung::Symmetry,
69 Rung::Modularity,
70 Rung::Invariance,
71 Rung::MultiStepAlgorithm,
72 Rung::LatentVariables,
73 Rung::NoisyObservation,
74 Rung::PartialObservation,
75 Rung::CounterexampleSearch,
76 Rung::TheoryFormation,
77 ];
78}
79
80/// What kind of generator family produced the crumb.
81#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
82pub enum SourceFamily {
83 Capability = 1,
84 Composition = 2,
85 Ambiguous = 3,
86 RabbitHole = 4,
87 Frontier = 5,
88 CleanRoomPhysics = 6,
89}
90
91/// The five secret populations the mixer draws from.
92#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
93pub enum Population {
94 Fundamental = 1,
95 Composition = 2,
96 Ambiguous = 3,
97 RabbitHole = 4,
98 Frontier = 5,
99}
100
101impl Population {
102 pub const ALL: [Population; 5] = [
103 Population::Fundamental,
104 Population::Composition,
105 Population::Ambiguous,
106 Population::RabbitHole,
107 Population::Frontier,
108 ];
109}
110
111#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
112pub enum TruthStatus {
113 /// Every labeled output is established by exact computation.
114 Verified = 1,
115 /// Outputs rest on an unproven claim. Never used for labeled examples.
116 Conjectural = 2,
117 /// No truth claim.
118 None = 3,
119}
120
121/// Rabbit-hole mechanisms. Rabbit holes deceive; they never lie.
122#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
123pub enum AdversarialClass {
124 /// A: visible examples favour a simple wrong rule; held-outs break it.
125 SimpleWrongRule = 1,
126 /// B: several programs fit the visible examples exactly; held-outs distinguish.
127 MultiFit = 2,
128 /// C: an irrelevant input dimension correlates with the answer only in the visible sample.
129 SpuriousDimension = 3,
130 /// D: a finite prefix imitates a simpler process, then diverges.
131 PrefixDiverges = 4,
132 /// E: an arbitrary complex generator produces an elegant-looking prefix.
133 ElegantArbitrary = 5,
134 /// F: the visible evidence cannot separate several hypotheses.
135 InsufficientEvidence = 6,
136 /// G: noisy observations; exact interpolation is the wrong objective.
137 Noisy = 7,
138}
139
140#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
141pub enum DecoyStatus {
142 Clean,
143 RabbitHole(AdversarialClass),
144 NoStructure,
145}
146
147#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
148pub enum KnownSolution {
149 /// A generating program in the CPG1 format is known.
150 Known(Program),
151 /// The generator is known, but not as a CPG1 chain.
152 KnownOutsideProgramFormat,
153 /// Nobody knows (frontier material).
154 UnknownToHumanity,
155 /// The outputs have no compact structure by construction.
156 NoCompactStructure,
157}
158
159#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
160pub enum VerificationMethod {
161 /// Outputs are the generator's own exact evaluation.
162 ExactGeneratorEvaluation = 1,
163 /// Outputs recomputed by an independent routine and cross-checked.
164 IndependentRecomputation = 2,
165 /// Bounded exact computation of a finite instance.
166 FiniteExactComputation = 3,
167}
168
169/// Held-out tiers.
170#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
171pub enum HeldoutTier {
172 Interpolation = 0,
173 Extrapolation = 1,
174 Adversarial = 2,
175}
176
177impl HeldoutTier {
178 pub const ALL: [HeldoutTier; 3] = [
179 HeldoutTier::Interpolation,
180 HeldoutTier::Extrapolation,
181 HeldoutTier::Adversarial,
182 ];
183}
184
185#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
186pub struct LaneExample {
187 pub input: Vec<u64>,
188 pub output: Vec<u64>,
189}
190
191#[derive(Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
192pub struct Heldouts {
193 pub interpolation: Vec<LaneExample>,
194 pub extrapolation: Vec<LaneExample>,
195 pub adversarial: Vec<LaneExample>,
196}
197
198impl Heldouts {
199 pub fn tier(&self, t: HeldoutTier) -> &[LaneExample] {
200 match t {
201 HeldoutTier::Interpolation => &self.interpolation,
202 HeldoutTier::Extrapolation => &self.extrapolation,
203 HeldoutTier::Adversarial => &self.adversarial,
204 }
205 }
206
207 pub fn encode(&self, e: &mut Enc) {
208 for t in HeldoutTier::ALL {
209 let set = self.tier(t);
210 e.u32(set.len() as u32);
211 for ex in set {
212 e.u64s(&ex.input).u64s(&ex.output);
213 }
214 }
215 }
216
217 pub fn digest(&self) -> Digest {
218 let mut e = Enc::new();
219 self.encode(&mut e);
220 digest(Domain::HeldoutSet, &e.finish())
221 }
222
223 pub fn len(&self) -> usize {
224 self.interpolation.len() + self.extrapolation.len() + self.adversarial.len()
225 }
226
227 pub fn is_empty(&self) -> bool {
228 self.len() == 0
229 }
230}
231
232/// Opaque capability identifier (BLAKE3 of the capability's defining bytes).
233pub type CapabilityId = Digest;
234
235#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
236pub struct SealedCrumb {
237 pub schema_version: u16,
238 pub crumb_digest: CrumbDigest,
239
240 pub family_id: u32,
241 pub family_key: String,
242 pub mechanism: String,
243 pub generator_version: String,
244 pub generator_code_digest: Digest,
245 pub seed: u64,
246 pub heldout_seed: u64,
247 pub generation_parameters: Vec<u8>,
248 pub generator_instance_digest: GeneratorInstanceDigest,
249
250 pub verification_method: VerificationMethod,
251 pub difficulty: u16,
252 pub rung: Rung,
253 pub required_capabilities: Vec<CapabilityId>,
254 pub provides_capability: Option<CapabilityId>,
255
256 pub provenance: Provenance,
257 pub source_family: SourceFamily,
258 pub truth_status: TruthStatus,
259 pub decoy_status: DecoyStatus,
260 pub known_solution: KnownSolution,
261 /// Programs that fit the visible examples as well as the truth does.
262 pub alternatives: Vec<Program>,
263 /// Indices of visible examples carrying observation noise.
264 pub noisy_visible: Vec<u32>,
265 /// Inclusive input range the family draws from (lane 0).
266 pub expected_domain: (u64, u64),
267 pub topic_internal: String,
268
269 pub heldouts: Heldouts,
270}
271
272impl std::fmt::Debug for SealedCrumb {
273 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
274 write!(f, "SealedCrumb(<redacted {}>)", self.digest().short())
275 }
276}
277
278impl std::fmt::Debug for Heldouts {
279 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
280 write!(f, "Heldouts(<redacted {} examples>)", self.len())
281 }
282}
283
284impl std::fmt::Debug for LaneExample {
285 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
286 f.write_str("LaneExample(<redacted>)")
287 }
288}
289
290impl SealedCrumb {
291 pub fn to_bytes(&self) -> Vec<u8> {
292 let mut e = Enc::new();
293 e.bytes(b"CRS1")
294 .u16(self.schema_version)
295 .digest(&self.crumb_digest);
296 e.u32(self.family_id)
297 .str(&self.family_key)
298 .str(&self.mechanism)
299 .str(&self.generator_version);
300 e.digest(&self.generator_code_digest)
301 .u64(self.seed)
302 .u64(self.heldout_seed);
303 e.blob(&self.generation_parameters)
304 .digest(&self.generator_instance_digest);
305 e.u8(self.verification_method as u8)
306 .u16(self.difficulty)
307 .u8(self.rung as u8);
308 e.u32(self.required_capabilities.len() as u32);
309 for c in &self.required_capabilities {
310 e.digest(c);
311 }
312 match &self.provides_capability {
313 Some(c) => e.u8(1).digest(c),
314 None => e.u8(0),
315 };
316 e.u8(self.provenance.class as u8)
317 .u8(self.provenance.uses_human_constants as u8)
318 .u8(self.provenance.uses_human_ontology as u8);
319 e.u8(self.source_family as u8).u8(self.truth_status as u8);
320 match self.decoy_status {
321 DecoyStatus::Clean => e.u8(0),
322 DecoyStatus::RabbitHole(c) => e.u8(1).u8(c as u8),
323 DecoyStatus::NoStructure => e.u8(2),
324 };
325 match &self.known_solution {
326 KnownSolution::Known(p) => e.u8(1).blob(&p.to_bytes()),
327 KnownSolution::KnownOutsideProgramFormat => e.u8(2),
328 KnownSolution::UnknownToHumanity => e.u8(3),
329 KnownSolution::NoCompactStructure => e.u8(4),
330 };
331 e.u32(self.alternatives.len() as u32);
332 for p in &self.alternatives {
333 e.blob(&p.to_bytes());
334 }
335 e.u32(self.noisy_visible.len() as u32);
336 for i in &self.noisy_visible {
337 e.u32(*i);
338 }
339 e.u64(self.expected_domain.0)
340 .u64(self.expected_domain.1)
341 .str(&self.topic_internal);
342 self.heldouts.encode(&mut e);
343 e.finish()
344 }
345
346 /// Commits to metadata, held-outs and provenance. Never enters learner space.
347 pub fn digest(&self) -> SealedRecordDigest {
348 digest(Domain::SealedRecord, &self.to_bytes())
349 }
350}
351
352/// GeneratorInstanceDigest = BLAKE3(family_id || generator_version || seed || canonical parameters).
353pub fn generator_instance_digest(
354 family_id: u32,
355 generator_version: &str,
356 seed: u64,
357 params: &[u8],
358) -> GeneratorInstanceDigest {
359 let mut e = Enc::new();
360 e.u32(family_id)
361 .str(generator_version)
362 .u64(seed)
363 .blob(params);
364 digest(Domain::GeneratorInstance, &e.finish())
365}