Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/studio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ jobs:
node tools/live_proof.mjs --check
export PATH="$HOME/.elan/bin:$PATH"
cd proof && lake build && lake env lean PrismLive/Axioms.lean | tee axioms.txt
test "$(grep -c 'depends on axioms: \[propext, Quot.sound\]' axioms.txt)" = 3
test "$(grep -c 'depends on axioms: \[propext, Quot.sound\]' axioms.txt)" = 4
# The exporter is fixed by the commit shell/kernel/lean/manifest.json names, built with the toolchain
# studio/proof pins: those two are everything the cached binary depends on.
- name: Cache the Lean exporter the in-tab library is written with
Expand Down
6 changes: 6 additions & 0 deletions CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ model does not sanction.
| --- | --- | --- |
| `FA-83` | `build` | Stateful preview parsing and checking transmit source only under disclosed source-bound or turn-scoped revocable hosted permission |

## in-tab-is-not-guarantee

| ID | Level | Statement |
| --- | --- | --- |
| `FA-91` | `build` | A guarantee whose conditions say is not or != is proved in the tab when it holds: Lean's kernel proves it below and above the value and joins the two with a lemma it checks |

## in-tab-kernel-verdict

| ID | Level | Statement |
Expand Down
1 change: 1 addition & 0 deletions app/product.json
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@
"text": "A verdict is decided by the guest from what the tab derived, Lean's kernel in the tab judges every theorem with no server, and local obligations hold on every request.",
"ids": [
"FA-86",
"FA-91",
"LL-01",
"LL-02"
],
Expand Down
9 changes: 8 additions & 1 deletion app/src/Features.lex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,13 @@
body: "crates/conformance/tests/in_tab_kernel_verdict.rs::in_tab_kernel_verdict_fa_86"
}

definition{
name: testFA91,
parameters: [],
result: String,
body: "crates/conformance/tests/in_tab_kernel_verdict.rs::in_tab_is_not_guarantee_fa_91"
}

definition{
name: testLL01,
parameters: [],
Expand Down Expand Up @@ -1629,7 +1636,7 @@
name: featureProof,
parameters: [],
result: Foundation.Arch::Feature,
body: (record Foundation.Arch::Feature {statement := "Proof (FA-86, LL-01, LL-02): A verdict is decided by the guest from what the tab derived, Lean's kernel in the tab judges every theorem with no server, and local obligations hold on every request.", calls := (cons "InTabKernel::verdictCode" (cons "InTabKernelProtocol::dispatchVerdict" (nil String))), acceptance := (cons "Features::testFA86" (cons "Features::testLL01" (cons "Features::testLL02" (nil String))))})
body: (record Foundation.Arch::Feature {statement := "Proof (FA-86, FA-91, LL-01, LL-02): A verdict is decided by the guest from what the tab derived, Lean's kernel in the tab judges every theorem with no server, and local obligations hold on every request.", calls := (cons "InTabKernel::verdictCode" (cons "InTabKernelProtocol::dispatchVerdict" (nil String))), acceptance := (cons "Features::testFA86" (cons "Features::testFA91" (cons "Features::testLL01" (cons "Features::testLL02" (nil String)))))})
}

definition{
Expand Down
34 changes: 32 additions & 2 deletions crates/conformance/tests/in_tab_kernel_verdict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ fn in_tab_kernel_verdict_fa_86() {
);
// A run that skipped, filtered or lost a test is not the oracle.
for required in [
"# tests 7",
"# pass 7",
"# tests 8",
"# pass 8",
"# fail 0",
"# cancelled 0",
"# skipped 0",
Expand Down Expand Up @@ -53,3 +53,33 @@ fn rule_judge_fa_90() {
assert_eq!(theorems, vectors);
assert!(theorems >= 9);
}

/// `FA-91`: A guarantee whose conditions say is not or != is proved in the tab when it holds: Lean's kernel proves it below and above the value and joins the two with a lemma it checks
#[test]
fn in_tab_is_not_guarantee_fa_91() {
// The suite runs prism.prove as the studio runs it, with the shipped Lean kernel and library and the pinned
// guest; FA-86's test above reads the same report and holds the counts.
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(2)
.expect("repository root")
.to_path_buf();
let output = Command::new("node")
.args(["--test", "--test-reporter=tap"])
.arg(root.join("studio/tools/in_tab_kernel_verdict.test.mjs"))
.output()
.expect("the locked SDK supplies Node");
let report = String::from_utf8_lossy(&output.stdout);
assert!(
output.status.success(),
"{report}\n{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(
report.lines().any(|line| line
== "ok 8 - a guarantee that says is not is proved when it holds, below and above the value, and refused when it does not"),
"the is-not guarantee test did not pass: {report}"
);
let regions = include_str!("../../../studio/proof/PrismLive/Regions.lean");
assert!(regions.contains("theorem ruleHolds_split"));
}
6 changes: 3 additions & 3 deletions crates/conformance/tests/live_lexlean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ fn read(path: &str) -> String {
}

/// The studio workflow builds the proofs and refuses any axiom beyond propext and
/// Quot.sound for all three theorems, so the claim is checked where it is made.
/// Quot.sound for all four theorems, so the claim is checked where it is made.
fn built_and_axioms_checked(theorem: &str) {
let workflow = read(".github/workflows/studio.yml");
assert!(
workflow.contains("cd proof && lake build && lake env lean PrismLive/Axioms.lean"),
"the studio workflow no longer builds the proofs and prints their axioms"
);
assert!(
workflow.contains(r#"depends on axioms: \[propext, Quot.sound\]' axioms.txt)" = 3"#),
"the studio workflow no longer requires exactly propext and Quot.sound of all three theorems"
workflow.contains(r#"depends on axioms: \[propext, Quot.sound\]' axioms.txt)" = 4"#),
"the studio workflow no longer requires exactly propext and Quot.sound of all four theorems"
);
let axioms = read("studio/proof/PrismLive/Axioms.lean");
assert!(
Expand Down
9 changes: 9 additions & 0 deletions features/suites/in-tab-is-not-guarantee.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: in-tab-is-not-guarantee

@FA-91 @build
Scenario: A guarantee whose conditions say is not or != is proved in the tab when it holds: Lean's kernel proves it below and above the value and joins the two with a lemma it checks
Given the parking-fee fixture, whose fourth guarantee is always premium over eight hours unless the vehicle is a motorcycle
When prism.prove proves it in this process with the shipped Lean kernel and library and the pinned guest
Then every guarantee is proved and the guest says proved, on propext and Quot.sound
And the same guarantee for every vehicle but a car, which a motorcycle breaks, is refused and named
And ruleHolds_split, proved in studio/proof, joins the halves, and the kernel refuses a join with the wrong value
6 changes: 6 additions & 0 deletions model/ids.toml
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,9 @@ id = "FA-90"
level = "build"
suite = "rule-judge"
statement = "A published app's answer is decided by the rule judge in Foundry's Prism kernel: the first rule whose conditions all hold decides, otherwise decides when none does, and a request outside the fields' bounds is refused"

[[id]]
id = "FA-91"
level = "build"
suite = "in-tab-is-not-guarantee"
statement = "A guarantee whose conditions say is not or != is proved in the tab when it holds: Lean's kernel proves it below and above the value and joins the two with a lemma it checks"
1 change: 1 addition & 0 deletions studio/proof/PrismLive/Axioms.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ import PrismLive.VerdantRegions
#print axioms PrismLive.Kernel.regionCheck_sound
#print axioms VerdantR.all_hold
#print axioms PrismLive.Kernel.ruleJudge_sound
#print axioms PrismLive.Kernel.ruleHolds_split
58 changes: 58 additions & 0 deletions studio/proof/PrismLive/Regions.lean
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,64 @@ theorem ruleJudge_sound (P : List Nat) (p : Property) (hc : wordsCheck P p = tru
exact hin
exact regionCheck_sound _ _ _ _ hreg p (by simp) x hbox


/-! ## A guarantee that says `is not`

`wordsCheck` reads a guarantee's conditions as one box, and a box cannot say `is not` (op 5): it keeps every value of
the field, so a true guarantee such as "always premium when hours > 8 and the vehicle is not a motorcycle" is
checked over motorcycles too, and refused. Such a guarantee is the two guarantees "below the value" and "above it":
a whole number other than `v` is less than `v` or greater. `ruleHolds_split` joins proofs of the two halves into a
proof of the guarantee as written, so each half is checked as a box and nothing is widened. -/

/-- The guarantee holds of an app's words: no in-bounds request breaks it (`ruleJudge_sound`'s conclusion). -/
def RuleHolds (P : List Nat) (p : Property) : Prop :=
∀ x : List Nat,
rulesEnd (P ++ x) (4 + multiply 2 (word (P ++ x) 1)) (word (P ++ x) (3 + multiply 2 (word (P ++ x) 1)))
+ word (P ++ x) 1 = (P ++ x).length →
ruleInBounds (P ++ x) 0 (word (P ++ x) 1)
(rulesEnd (P ++ x) (4 + multiply 2 (word (P ++ x) 1)) (word (P ++ x) (3 + multiply 2 (word (P ++ x) 1)))) = true →
breaksWith p x (ruleOutcome (P ++ x) (4 + multiply 2 (word (P ++ x) 1))
(word (P ++ x) (3 + multiply 2 (word (P ++ x) 1))) (word (P ++ x) (2 + multiply 2 (word (P ++ x) 1)))
(rulesEnd (P ++ x) (4 + multiply 2 (word (P ++ x) 1)) (word (P ++ x) (3 + multiply 2 (word (P ++ x) 1))))) = false

theorem ruleJudge_holds (P : List Nat) (p : Property) (hc : wordsCheck P p = true) : RuleHolds P p :=
fun x hlen hin => ruleJudge_sound P p hc x hlen hin

theorem allHold_append (x : List Nat) : ∀ (l r : List Cond), allHold (l ++ r) x = (allHold l x && allHold r x)
| [], r => by simp [allHold]
| c :: l, r => by
simp only [List.cons_append, allHold]
split <;> simp [allHold_append x l r]

/-- A field is not `v` exactly when it is below `v` or above it. -/
theorem condHolds_ne (f v : Nat) (x : List Nat) :
condHolds ⟨f, 5, v⟩ x = (condHolds ⟨f, 0, v⟩ x || condHolds ⟨f, 2, v⟩ x) := by
simp only [condHolds, opHolds]
by_cases e : get x f = v
· simp [e]
· by_cases l : get x f < v
· simp [e, l]
· have : v < get x f := by omega
simp [e, l, this]

theorem allHold_ne_split (pre post : List Cond) (f v : Nat) (x : List Nat) :
allHold (pre ++ ⟨f, 5, v⟩ :: post) x =
(allHold (pre ++ ⟨f, 0, v⟩ :: post) x || allHold (pre ++ ⟨f, 2, v⟩ :: post) x) := by
simp only [allHold_append, allHold, condHolds_ne f v x]
cases allHold pre x <;> cases condHolds ⟨f, 0, v⟩ x <;> cases condHolds ⟨f, 2, v⟩ x <;> simp

/-- A guarantee with `field is not v` holds when it holds below `v` and above `v`. -/
theorem ruleHolds_split (P : List Nat) (a : Bool) (pre post : List Cond) (f v po : Nat)
(h0 : RuleHolds P ⟨a, pre ++ ⟨f, 0, v⟩ :: post, po⟩) (h2 : RuleHolds P ⟨a, pre ++ ⟨f, 2, v⟩ :: post, po⟩) :
RuleHolds P ⟨a, pre ++ ⟨f, 5, v⟩ :: post, po⟩ := fun x hlen hin => by
have b0 := h0 x hlen hin
have b2 := h2 x hlen hin
rw [breaksWith_eq] at b0 b2 ⊢
simp only [allHold_ne_split pre post f v x]
simp only [bad] at b0 b2 ⊢
revert b0 b2
cases allHold (pre ++ ⟨f, 0, v⟩ :: post) x <;> cases allHold (pre ++ ⟨f, 2, v⟩ :: post) x <;> simp

end PrismLive.Kernel

/-!
Expand Down
Binary file modified studio/shell/kernel/lean/library.ndjson.gz
Binary file not shown.
15 changes: 9 additions & 6 deletions studio/shell/kernel/lean/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
"Bool.and",
"Bool.or",
"ite",
"instDecidableEqBool"
"instDecidableEqBool",
"PrismLive.Kernel.ruleJudge_holds",
"PrismLive.Kernel.ruleHolds_split",
"PrismLive.Kernel.RuleHolds"
]
},
"glue": {
Expand All @@ -51,17 +54,17 @@
},
"library": {
"file": "library.ndjson.gz",
"sha256": "a22cb8e581310c1c4a03e120e277dd99d37c66f8159188e866f68177836aa560",
"bytes": 7834171
"sha256": "c124f47e55c23b095ed7650548768456ef48e37d2f3824d8ede735488c1ad6c0",
"bytes": 8111283
},
"binding": {
"schema": "prism/in-tab-library-binding/1",
"lean": "f054605aea4b840552cca2e725580bffd1e1b704",
"kernel": "4b48480b9c03ae4aa3bf1a37256b59bff2d41d6cf452a2f8aa9de41a28ccd118",
"loader": "3f482f95c28fb0c74027552d6c4519f8916e48cd1d5b0bd202f318ca8c027a4a",
"library": "a22cb8e581310c1c4a03e120e277dd99d37c66f8159188e866f68177836aa560",
"declarations": 2113,
"sentToTheKernel": 1932,
"library": "c124f47e55c23b095ed7650548768456ef48e37d2f3824d8ede735488c1ad6c0",
"declarations": 2126,
"sentToTheKernel": 1945,
"judgedBy": "check_whole, every declaration, in this kernel"
}
}
23 changes: 21 additions & 2 deletions studio/shell/prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,27 @@ function leanWorker(self) {
const P = declare("def", at + "words", app(C("List", [0]), Nat), list(Nat, words.map(nat)));
const p = declare("def", at + "guarantee", C(K + "Property"), app(C(K + "Property.mk"), C(g.always ? "Bool.true" : "Bool.false"), list(C(K + "Cond"), g.when.map(cond)), nat(g.outcome)));
const T = C("Bool.true");
const checked = declare("thm", at + "checked", app(C("Eq", [one]), Bool, app(C(K + "wordsCheck"), P, p), T), app(C("Eq.refl", [one]), Bool, T));
declare("thm", at + "holds", instantiate(lib.types.get(known(K + "ruleJudge_sound")), [P, p, checked]), app(C(K + "ruleJudge_sound"), P, p, checked));
const check = (q, tag) => declare("thm", at + "checked" + tag, app(C("Eq", [one]), Bool, app(C(K + "wordsCheck"), P, q), T), app(C("Eq.refl", [one]), Bool, T));
// A box cannot say `is not` (op 5), so `wordsCheck` would read such a guarantee over every value of the field.
// It is proved below the value and above it instead, each as a box, and `ruleHolds_split` joins the two.
if (!g.when.some(([, op]) => op === 5)) {
const checked = check(p, "");
declare("thm", at + "holds", instantiate(lib.types.get(known(K + "ruleJudge_sound")), [P, p, checked]), app(C(K + "ruleJudge_sound"), P, p, checked));
return out.join("\n") + "\n";
}
const Cond = C(K + "Cond"), always = C(g.always ? "Bool.true" : "Bool.false"), po = nat(g.outcome);
let halves = 0;
const proof = (when) => {
const j = when.findIndex(([, op]) => op === 5);
if (j < 0) {
const tag = "." + halves++, q = declare("def", at + "half" + tag, C(K + "Property"), app(C(K + "Property.mk"), always, list(Cond, when.map(cond)), po));
return app(C(K + "ruleJudge_holds"), P, q, check(q, tag));
}
const pre = when.slice(0, j), post = when.slice(j + 1), [f, , v] = when[j];
return app(C(K + "ruleHolds_split"), P, always, list(Cond, pre.map(cond)), list(Cond, post.map(cond)), nat(f), nat(v), po,
proof([...pre, [f, 0, v], ...post]), proof([...pre, [f, 2, v], ...post]));
};
declare("thm", at + "holds", app(C(K + "RuleHolds"), P, p), proof(g.when));
return out.join("\n") + "\n";
};
async function open({ manifest, glue, wasm, library }) {
Expand Down
34 changes: 34 additions & 0 deletions studio/tools/in_tab_kernel_verdict.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,37 @@ test('the pinned guest, the bytes the studio runs, answers every vector of the c
assert.deepEqual(await verdictWithGuest({ dispatch }, proved.input), { ok: true, code: 0, verdict: 'proved' });
assert.deepEqual(await verdictWithGuest({ dispatch }, { ...structuredClone(proved.input), leanAccepted: 0 }), { ok: true, code: 3, verdict: 'refused' });
});

// FA-91. prism.prove, as the studio runs it, in this process: its worker's own source, the shipped Lean kernel and
// library, and the pinned guest. A browser's Worker, blob URLs and file fetch are played by the stand-ins below.
test('a guarantee that says is not is proved when it holds, below and above the value, and refused when it does not', async () => {
const { prove } = await import('../shell/prism.js');
const parts = new WeakMap(), Native = globalThis.Blob;
globalThis.Blob = class extends Native { constructor(p, o) { super(p, o); parts.set(this, p); } };
// The worker's source is read back from its URL; the kernel's loader is imported, and under Node it needs a file.
const os = await import('node:os'), path = await import('node:path'), { pathToFileURL } = await import('node:url');
URL.createObjectURL = (b) => { const bytes = Buffer.concat(parts.get(b).map((p) => Buffer.from(typeof p === 'string' ? p : new Uint8Array(p.buffer ?? p, p.byteOffset ?? 0, p.byteLength)))); if (bytes[0] === 0x28) return 'data:text/javascript;base64,' + bytes.toString('base64'); const f = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'lean-')), 'glue.mjs'); fs.writeFileSync(f, bytes); return pathToFileURL(f).href; };
URL.revokeObjectURL = () => {};
const net = globalThis.fetch;
globalThis.fetch = async (u) => (String(u).startsWith('file:') ? new Response(fs.readFileSync(new URL(u))) : net(u));
globalThis.Worker = class { constructor(url) { const heard = new Set(); this.self = { postMessage: (data) => setTimeout(() => heard.forEach((on) => on({ data }))) }; this.addEventListener = (k, on) => k === 'message' && heard.add(on); this.removeEventListener = (_, on) => heard.delete(on); this.terminate = () => {}; new Function('self', Buffer.from(url.split(',')[1], 'base64').toString())(this.self); } postMessage(data) { setTimeout(() => this.self.onmessage({ data })); } };
const module = await WebAssembly.compile(fs.readFileSync(new URL('../shell/kernel/guest.wasm', import.meta.url)));
const guest = { dispatch: async (request) => {
const { memory, holo_alloc, holo_run } = (await WebAssembly.instantiate(module, {})).exports, at = holo_alloc(request.length);
new Uint8Array(memory.buffer, at, request.length).set(request);
const packed = BigInt.asUintN(64, BigInt(holo_run(at, request.length)));
return new Uint8Array(memory.buffer, Number(packed >> 32n), Number(packed & 0xffffffffn)).slice();
} };
const { validateSpec } = await import('../shell/prism/spec.mjs');
const fixture = JSON.parse(read('./fixtures/specs/parking-fee.json')), parking = validateSpec(fixture.spec ?? fixture);
// INV-004: always premium over eight hours unless the vehicle is a motorcycle. Read as one box it covers
// motorcycles too, which park free, and was refused; it holds, below `motorcycle` and above it.
assert.ok(parking.properties[3].when.some((c) => c.op === 'is not'));
const r = await prove(parking, { guest });
assert.equal(r.ok, true, r.error);
assert.deepEqual([r.record.verdict, r.record.axioms ?? ['Quot.sound', 'propext']], ['proved', ['Quot.sound', 'propext']]);
// The same guarantee for every vehicle but a car does not hold (a motorcycle parks free), and is refused.
const broken = { ...parking, properties: parking.properties.map((p, i) => (i === 3 ? { ...p, when: [p.when[0], { field: 'vehicle', op: 'is not', value: 'car' }] } : p)) };
const no = await prove(broken, { guest });
assert.equal(no.ok, false); assert.match(no.error, new RegExp("Lean's kernel refused " + parking.properties[3].id + '$'));
});
2 changes: 1 addition & 1 deletion v2/in-tab-kernel/REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ the verdict's job, from the axiom report below.

## In a browser tab (Chromium 156, desktop)

`web/bench.html` in a module worker, served with no isolation headers (`crossOriginIsolated` false, no
`web/bench.html` (removed since; it is at 20fac93) in a module worker, served with no isolation headers (`crossOriginIsolated` false, no
`SharedArrayBuffer`) and with the worker's network closed (`connect-src 'none'`). Summary in `evidence/browser.json`.

| What | Result |
Expand Down
Loading
Loading