Skip to content

Commit dd20493

Browse files
authored
Merge pull request #360 from PhysShell/claude/p037-a1-guarded-transfer
P-037 A1.0 (bootstrap): port the formal kernel and controls onto post-cutover main; re-measure the pre-A1 record
2 parents 63148d0 + afeca38 commit dd20493

39 files changed

Lines changed: 4508 additions & 96 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,64 @@ jobs:
7272
- name: cargo test
7373
run: cargo test
7474

75+
# The P-037 formal kernel (formal/p037-kernel, docs/notes/p037-formal-kernel.md):
76+
# its own workspace root, a member of nothing, wired to nothing — the pure
77+
# guarded-transfer algebra checked twice over the same functions, by plain
78+
# test twins and by Kani proof harnesses. The PR gate is fmt + clippy + the
79+
# twins + the FAST harnesses (value-level laws, the G-A2 floor, the one-step
80+
# lemmas; well under a minute of CBMC in total). The whole-solver harnesses
81+
# take minutes each and run in formal-p037-gate.yml on a schedule / on
82+
# demand — the owner's split after the A0 spike, so the inner loop never
83+
# pays for a proof it does not need on every push.
84+
#
85+
# `toolchain: stable` here is deliberate and matches `rust-core` directly
86+
# above. The pinned rustc that #262 Stage 3 requires is a property of
87+
# action.yml — the CONSUMER-facing distribution surface, where a moving
88+
# toolchain would move what users get — not of this repository's own CI,
89+
# which is where a moving toolchain is supposed to break us first.
90+
formal-p037:
91+
name: formal kernel (fmt + clippy + twins + fast Kani)
92+
runs-on: ubuntu-latest
93+
defaults:
94+
run:
95+
working-directory: formal/p037-kernel
96+
steps:
97+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
98+
- uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # master, 2026-07-10
99+
with:
100+
toolchain: stable
101+
components: rustfmt, clippy
102+
- name: cargo fmt --check
103+
run: cargo fmt --check
104+
- name: cargo clippy (the rust/ workspace lints, copied verbatim)
105+
run: cargo clippy --all-targets
106+
- name: cargo test (the exhaustive / randomized twins)
107+
run: cargo test
108+
- name: install Kani (pinned) and its toolchain bundle
109+
run: |
110+
cargo install --locked kani-verifier --version 0.68.0
111+
cargo kani setup
112+
- name: fast Kani harnesses (value-level laws, floor, one-step lemmas)
113+
run: |
114+
set -e
115+
for h in \
116+
k1_transfer_join_laws k1_transfer_order_is_a_partial_order k1_cells_join_laws \
117+
k2_election_join_laws \
118+
k3_reads_and_contributions_are_monotone \
119+
k4_import_is_monotone_and_conflict_propagates \
120+
k5_collapse_monotone_and_join_morphism \
121+
k6_consume_only_through_a_selected_or_unanimous_must \
122+
k7_no_fabricated_consume \
123+
k8_involutions \
124+
k9_residual_bottom_lemma_all_three_groundings \
125+
k10a_step_is_monotone_in_the_state \
126+
k10e_election_step_is_monotone_in_the_state \
127+
k11_one_step_lax_simulation \
128+
k12a_step_keeps_uncond_coordinates_diagonal; do
129+
echo "== $h"
130+
cargo kani --harness "$h"
131+
done
132+
75133
# P-022 step 7b (#261) — the production OwnIR executable's parity replay, on
76134
# BOTH platforms. The Python half of this contract is gated by the `tests`
77135
# matrix above (`tests/test_cli_ownir_fixtures.py` is auto-discovered like
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: formal-p037-gate
2+
3+
# The heavy half of the P-037 formal kernel's proof harnesses
4+
# (formal/p037-kernel): the whole-solver statements — least fixpoint at the
5+
# full 3-coordinate bound, chaotic = Jacobi, the G-T2a lfp form, G-T2b, and
6+
# Uncond-stays-diagonal at the lfp. Minutes of CBMC each, ~15 minutes in all;
7+
# the owner's ruling after the A0 spike keeps them off the PR gate (ci.yml's
8+
# formal-p037 job runs the fast half on every push) and here, nightly and on
9+
# demand. A red run here is a real finding about the kernel or the contract,
10+
# never a flake to re-run: every harness is deterministic.
11+
12+
permissions:
13+
contents: read
14+
15+
on:
16+
schedule:
17+
- cron: "17 3 * * *"
18+
workflow_dispatch:
19+
20+
jobs:
21+
heavy-kani:
22+
name: formal kernel (whole-solver Kani harnesses)
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 90
25+
defaults:
26+
run:
27+
working-directory: formal/p037-kernel
28+
steps:
29+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
30+
- uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # master, 2026-07-10
31+
with:
32+
toolchain: stable
33+
- name: install Kani (pinned) and its toolchain bundle
34+
run: |
35+
cargo install --locked kani-verifier --version 0.68.0
36+
cargo kani setup
37+
- name: whole-solver harnesses
38+
run: |
39+
set -e
40+
for h in \
41+
k10b_solve_is_a_fixpoint_below_every_fixpoint \
42+
k10c_chaotic_equals_jacobi_on_small_sccs \
43+
k10e_elect_is_a_fixpoint_below_every_fixpoint \
44+
k10e_chaotic_equals_jacobi_on_small_sccs \
45+
k11_lfp_lax_simulation_against_the_collapsed_system_on_small_sccs \
46+
k11b_legacy_observational_compatibility_on_small_sccs \
47+
k11_lfp_lax_simulation_against_today_post_finalization_on_small_sccs \
48+
k12b_lfp_keeps_uncond_coordinates_diagonal_on_small_sccs; do
49+
echo "== $h"
50+
cargo kani --harness "$h"
51+
done
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// FIXED (synthetic conformance, P-037 §8 row 2). `keep: false` reaches the
2+
// Dispose on the only path -> clean.
3+
using System;
4+
using System.IO;
5+
6+
static class GuardedEarlyReturn
7+
{
8+
static void Close(Stream s, bool keep)
9+
{
10+
if (keep)
11+
return;
12+
s.Dispose();
13+
}
14+
15+
static long Fine(string path)
16+
{
17+
var s = File.OpenRead(path);
18+
long len = s.Length;
19+
Close(s, keep: false);
20+
return len;
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// BUGGY (synthetic conformance, P-037 §8 row 2 — the same guard spelled as an
2+
// early return; the two spellings must converge in a guarded summary).
3+
using System;
4+
using System.IO;
5+
6+
static class GuardedEarlyReturn
7+
{
8+
static void Close(Stream s, bool keep)
9+
{
10+
if (keep)
11+
return;
12+
s.Dispose();
13+
}
14+
15+
static long Leak(string path)
16+
{
17+
var s = File.OpenRead(path);
18+
long len = s.Length;
19+
Close(s, keep: true); // returns before the Dispose -> leak
20+
return len;
21+
}
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OWN001
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// FIXED (synthetic conformance, P-037 §8 row 1). The caller passes
2+
// `keep: false`, so `Close` disposes the stream on its only path: the
3+
// obligation moves into the helper and the caller must stay silent.
4+
using System;
5+
using System.IO;
6+
7+
static class Guarded
8+
{
9+
static void Close(Stream s, bool keep)
10+
{
11+
if (!keep)
12+
{
13+
s.Dispose();
14+
}
15+
}
16+
17+
static long Fine(string path)
18+
{
19+
var s = File.OpenRead(path);
20+
long len = s.Length;
21+
Close(s, keep: false); // provably disposes -> clean
22+
return len;
23+
}
24+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// BUGGY (synthetic conformance, P-037 §8 row 1 — the SectorTS `Teardown(bool)`
2+
// shape on an IDisposable parameter).
3+
//
4+
// `Close(s, keep)` disposes its parameter ONLY when `keep == false`. The caller
5+
// passes `keep: true`, so the stream is never disposed on any path -> leak.
6+
// A context-insensitive summary can only say "may consume"; the guarded
7+
// summary of P-037 selects the `no` cell at this call site and keeps the
8+
// obligation with the caller.
9+
using System;
10+
using System.IO;
11+
12+
static class Guarded
13+
{
14+
static void Close(Stream s, bool keep)
15+
{
16+
if (!keep)
17+
{
18+
s.Dispose();
19+
}
20+
}
21+
22+
static long Leak(string path)
23+
{
24+
var s = File.OpenRead(path);
25+
long len = s.Length;
26+
Close(s, keep: true); // provably does NOT dispose -> leak
27+
return len;
28+
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OWN001
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// FIXED (synthetic conformance, P-037 §8 row 8). `Outer(s, stop: true)` becomes
2+
// `Inner(s, keep: false)` -> disposed -> clean.
3+
using System;
4+
using System.IO;
5+
6+
static class GuardedNegation
7+
{
8+
static void Inner(Stream s, bool keep)
9+
{
10+
if (!keep)
11+
{
12+
s.Dispose();
13+
}
14+
}
15+
16+
static void Outer(Stream s, bool stop)
17+
{
18+
Inner(s, !stop);
19+
}
20+
21+
static long Fine(string path)
22+
{
23+
var s = File.OpenRead(path);
24+
long len = s.Length;
25+
Outer(s, stop: true);
26+
return len;
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// BUGGY (synthetic conformance, P-037 §8 row 8 — the wrapper NEGATES the flag
2+
// on the edge: `Inner(s, !stop)`; the cells swap).
3+
using System;
4+
using System.IO;
5+
6+
static class GuardedNegation
7+
{
8+
static void Inner(Stream s, bool keep)
9+
{
10+
if (!keep)
11+
{
12+
s.Dispose();
13+
}
14+
}
15+
16+
static void Outer(Stream s, bool stop)
17+
{
18+
Inner(s, !stop); // stop == false => keep == true
19+
}
20+
21+
static long Leak(string path)
22+
{
23+
var s = File.OpenRead(path);
24+
long len = s.Length;
25+
Outer(s, stop: false); // Inner(s, keep: true) never disposes -> leak
26+
return len;
27+
}
28+
}

0 commit comments

Comments
 (0)