Skip to content

Commit 8504ad4

Browse files
committed
P-037 B1: own-guarded, the guarded shadow read over the A2 facts
A new workspace crate that computes a guarded summary per (method, parameter) coordinate from the A2 sidecar, the legacy body and the functions[] records, and classifies it against a legacy MOS dump it is handed. Every lattice operation, the election import, the edge read, the branch mask and the call-site application are p037_kernel's; the crate defines none of them. Shadow only: nothing on the production path reads it (docs/notes/p037-phase-b1-shadow.md §0). Fail closed (§0.9): an ambiguous join, a missing record or sidecar, an unresolved callee, an unmapped ordinal (A17), a bound failure or an unsupported placement is NO_GUARDED_EVIDENCE(reason), and a forward into such a coordinate taints its caller callee-first. Acceptance controls (tests/acceptance.rs) run on facts the extractor produced from the B0 probes, the ctor-initializer shape and a B1 fixture file: A15 probe outcomes, the K7 witness on the adapter, A13, the record-absence boundary, WF, A12 fault injection, A2/A5 edges and selection, the N4 required read, A14, and both classifiers (G13). Architecture: own-guarded's one workspace edge is own-ir, and a new dag.rs guard reads every package's dependencies of every kind so that only own-guarded names p037-kernel, only own-shadow may name own-guarded, and no production crate reaches either. Demonstrated to fire on own-bridge -> own-guarded (G1) and a second crate naming the kernel (G2). Size: own-guarded is 894 counted lines (cap 900). The first formatted draft measured 1107; de-duplication brought it under, with no formatting changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KmiyfrkaG9sJruTcshM2oq
1 parent 667873e commit 8504ad4

11 files changed

Lines changed: 2926 additions & 1 deletion

File tree

‎rust/Cargo.lock‎

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[workspace]
1010
resolver = "2"
11-
members = ["crates/own-ir", "crates/own-syntax", "crates/own-cfg", "crates/own-diagnostics", "crates/own-analysis", "crates/own-lowered", "crates/own-bridge", "crates/own-shadow", "crates/own-cli"]
11+
members = ["crates/own-ir", "crates/own-syntax", "crates/own-cfg", "crates/own-diagnostics", "crates/own-analysis", "crates/own-lowered", "crates/own-guarded", "crates/own-bridge", "crates/own-shadow", "crates/own-cli"]
1212

1313
[workspace.package]
1414
edition = "2021"

‎rust/crates/own-diagnostics/tests/dag.rs‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ fn allowed_edges() -> HashMap<&'static str, BTreeSet<&'static str>> {
8989
// one's. Only entry-point crates may depend on `own-bridge`, and this is
9090
// the one the constraint below names.
9191
m.insert("own-cli", ["own-ir", "own-bridge"].into_iter().collect());
92+
// P-037 B1 (#304): the guarded SHADOW read. Its one workspace edge is the
93+
// fact contract; its other dependency, the formal kernel, lives outside
94+
// this workspace and is locked by `p037_kernel_reaches_only_the_shadow`.
95+
m.insert("own-guarded", std::iter::once("own-ir").collect());
9296
// own-analysis CONSTRUCTS diagnostics and consumes the cfg lowering. It reads
9397
// the effect type through `own_cfg::Effect`, NOT the parser — so there is no
9498
// production own-syntax edge (own-syntax is a dev-only edge for its tests).
@@ -274,3 +278,84 @@ fn own_ir_is_a_leaf() {
274278
"own-ir is the leaf — it must depend on no workspace crate, got {deps:?}"
275279
);
276280
}
281+
282+
/// Every package's dependency names, of every kind (normal, dev, build) and
283+
/// from anywhere (workspace, path or registry): the B1 guard needs to see the
284+
/// `p037-kernel` path dependency that `workspace_edges` filters out.
285+
fn all_deps() -> HashMap<String, BTreeSet<String>> {
286+
let manifest = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
287+
let out = Command::new(env!("CARGO"))
288+
.args([
289+
"metadata",
290+
"--no-deps",
291+
"--format-version",
292+
"1",
293+
"--manifest-path",
294+
manifest,
295+
])
296+
.output()
297+
.expect("cargo metadata runs");
298+
let meta: Value = serde_json::from_slice(&out.stdout).expect("metadata JSON parses");
299+
let mut all = HashMap::new();
300+
for pkg in meta["packages"].as_array().expect("packages") {
301+
let deps = pkg["dependencies"].as_array().expect("dependencies array");
302+
let names = deps
303+
.iter()
304+
.filter_map(|d| d["name"].as_str())
305+
.map(str::to_owned);
306+
all.insert(
307+
pkg["name"].as_str().expect("pkg name").to_owned(),
308+
names.collect(),
309+
);
310+
}
311+
all
312+
}
313+
314+
#[test]
315+
fn p037_kernel_reaches_only_the_shadow() {
316+
// P-037 B1 (docs/notes/p037-phase-b1-shadow.md §0, N1): `own-guarded` is
317+
// the ONLY crate that names the formal kernel, `own-shadow` the only one
318+
// that names `own-guarded`, and nothing on the production path reaches
319+
// either, directly or transitively. `own-bridge -> own-guarded` is phase
320+
// C and is not authorized here.
321+
let all = all_deps();
322+
for (krate, deps) in &all {
323+
if krate != "own-guarded" {
324+
assert!(
325+
!deps.contains("p037-kernel"),
326+
"{krate} names p037-kernel (B1: own-guarded only)"
327+
);
328+
}
329+
if krate != "own-shadow" {
330+
assert!(
331+
!deps.contains("own-guarded"),
332+
"{krate} names own-guarded (B1: own-shadow only)"
333+
);
334+
}
335+
}
336+
let production = [
337+
"own-ir",
338+
"own-syntax",
339+
"own-cfg",
340+
"own-diagnostics",
341+
"own-lowered",
342+
"own-analysis",
343+
"own-bridge",
344+
"own-cli",
345+
];
346+
for root in production {
347+
let mut seen = BTreeSet::new();
348+
let mut stack = vec![root.to_owned()];
349+
while let Some(k) = stack.pop() {
350+
for d in all.get(&k).into_iter().flatten() {
351+
assert!(
352+
d != "own-guarded" && d != "p037-kernel",
353+
"{root} reaches {d} through {k}: the production path must not see the guarded shadow"
354+
);
355+
if seen.insert(d.clone()) {
356+
stack.push(d.clone());
357+
}
358+
}
359+
}
360+
}
361+
}

‎rust/crates/own-guarded/Cargo.toml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# P-037 B1 (#304): the guarded SHADOW read. It computes guarded summaries from
2+
# A2's sidecar, the legacy body and the `functions[]` records, reusing the
3+
# formal kernel's algebra instead of re-implementing it, and classifies every
4+
# difference against the legacy MOS it is handed. Contract:
5+
# docs/notes/p037-phase-b1-shadow.md.
6+
#
7+
# Shadow only. Nothing in the production path reads it: `own-shadow` (an
8+
# entry-point-class oracle crate) is its one allowed consumer, and
9+
# `own-bridge -> own-guarded` is phase C, NOT pre-authorized. Both are asserted
10+
# by own-diagnostics/tests/dag.rs and scripts/p037_proof_boundary.py.
11+
#
12+
# The ONLY Rust crate allowed to depend on `p037-kernel`. The kernel lives
13+
# outside this workspace on purpose (its own [workspace] root), so this path
14+
# dependency is invisible to the workspace-internal DAG map; the dedicated
15+
# guard in dag.rs reads every package's dependencies to see it.
16+
[package]
17+
name = "own-guarded"
18+
version = "0.1.0"
19+
edition.workspace = true
20+
rust-version.workspace = true
21+
license.workspace = true
22+
publish.workspace = true
23+
description = "P-037 B1 guarded shadow read: guarded summaries over the A2 sidecar via the p037 kernel, classified against the legacy MOS (shadow only)"
24+
25+
[dependencies]
26+
serde_json = { workspace = true }
27+
own-ir = { path = "../own-ir" }
28+
p037-kernel = { path = "../../../formal/p037-kernel" }
29+
30+
[lints]
31+
workspace = true

0 commit comments

Comments
 (0)