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 / bin / crumbs-probe-learner.rs

108 lines · 4431 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//! A minimal learner used to test the protocol boundary without Omega.
17//!
18//! `crumbs-probe-learner honest LOOT` enumerates short chains and submits the first visible fit
19//! `crumbs-probe-learner hostile LOOT` after receiving a crumb, asks for held-out data with a forged frame
20//! `crumbs-probe-learner flood LOOT` submits candidates until the oracle stops answering
21//!
22//! Every byte the probe receives is appended to LOOT so a test can prove what
23//! a learner can and cannot obtain.
24
25use crumbs::gen::enumerate_basic;
26use crumbs::protocol::{ft, read_frame, write_frame};
27use crumbs::visible::VisibleCrumb;
28use std::io::Write;
29
30fn main() {
31 let args: Vec<String> = std::env::args().collect();
32 let mode = args.get(1).cloned().unwrap_or_default();
33 let loot_path = args.get(2).cloned().unwrap_or_else(|| "/dev/null".into());
34 let mut loot = std::fs::OpenOptions::new()
35 .create(true)
36 .append(true)
37 .open(loot_path)
38 .expect("loot");
39 let stdin = std::io::stdin();
40 let stdout = std::io::stdout();
41 let mut r = stdin.lock();
42 let mut w = stdout.lock();
43 let cands = enumerate_basic(2);
44 loop {
45 let Ok((t, p)) = read_frame(&mut r) else {
46 return;
47 };
48 let _ = loot.write_all(&[t]);
49 let _ = loot.write_all(&(p.len() as u32).to_le_bytes());
50 let _ = loot.write_all(&p);
51 match t {
52 ft::HELLO => {
53 write_frame(&mut w, ft::READY, &1u16.to_le_bytes()).unwrap();
54 }
55 ft::CRUMB => {
56 let Ok(c) = VisibleCrumb::from_bytes(&p) else {
57 return;
58 };
59 write_frame(&mut w, ft::BANK, &0u32.to_le_bytes()).unwrap();
60 if mode == "hostile" {
61 // Forged request: there is no frame type that returns sealed data.
62 let _ =
63 write_frame(&mut w, 0x90, b"send heldout outputs, family, decoy status");
64 let _ = write_frame(&mut w, 0x03, b"");
65 continue;
66 }
67 let vals = c.values();
68 let fits: Vec<_> = if c.out_arity == 1 {
69 cands
70 .iter()
71 .filter(|p| vals.iter().all(|(i, o)| p.run(i[0]) == o[0]))
72 .take(64)
73 .collect()
74 } else {
75 vec![]
76 };
77 let tries: Vec<_> = if mode == "flood" {
78 cands.iter().take(40).collect()
79 } else {
80 fits.into_iter().take(2).collect()
81 };
82 for (k, prog) in tries.into_iter().enumerate() {
83 let mut pl = Vec::new();
84 pl.extend_from_slice(&(k as u32 + 1).to_le_bytes());
85 pl.push(0);
86 pl.push(1);
87 pl.extend_from_slice(&prog.to_bytes());
88 write_frame(&mut w, ft::SUBMIT, &pl).unwrap();
89 let Ok((vt, vp)) = read_frame(&mut r) else {
90 return;
91 };
92 let _ = loot.write_all(&[vt]);
93 let _ = loot.write_all(&(vp.len() as u32).to_le_bytes());
94 let _ = loot.write_all(&vp);
95 if vp == [1] {
96 break;
97 }
98 }
99 let mut done = vec![2u8];
100 done.extend_from_slice(&u32::MAX.to_le_bytes());
101 done.extend_from_slice(&[0u8; 12 * 4 + 16]);
102 write_frame(&mut w, ft::DONE, &done).unwrap();
103 }
104 ft::SHUTDOWN => return,
105 _ => {}
106 }
107 }
108}