Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.
Rust ai-nativedescription-logicsformal-verificationinfrastructure-as-codeisabelle-languageknowledge-graphleanlean4mcpmcp-serverontologyowlowl2reasoningrustshaclsparqltheorem-proving
Run Dafny at the certificate boundary, decline it, and fix the property it showed was false (#183)
Fabio Rovai410506e61360
diff --git a/Makefile b/Makefileindex 64af2cf4..81119455 100644--- a/Makefile+++ b/Makefile@@ -1,4 +1,4 @@-.PHONY: build test lint audit verify bench bench-pizza bench-ontoaxiom bench-mushroom bench-vision bench-reasoner bench-oaei docker clean demo demo-verify demo-verify-pipeline+.PHONY: build test lint audit verify verify-dafny bench bench-pizza bench-ontoaxiom bench-mushroom bench-vision bench-reasoner bench-oaei docker clean demo demo-verify demo-verify-pipeline# ─── Development ─────────────────────────────────────────────────────────────@@ -44,6 +44,21 @@ verify:cargo kani --harness pat_of_and_render_are_inverse_at_3cargo kani --harness writable_triple_decides_both_positions+# Verify dafny/RuleTable.dfy, a Dafny model of the rule-table grammar in+# src/reason.rs, and then mutate it three times and require every mutation to be+# rejected. Needs `brew install dafny`; Dafny bundles its own Z3. About sixteen+# seconds in total.+#+# NOT part of `check`, and read the next sentence before quoting any output of+# it. The model is a REIMPLEMENTATION, so what verifies is the Dafny and not the+# Rust, which is the opposite of the Kani harnesses above and of Aeneas. It is+# kept because it proves TCB-20's whole-line round trip with no length bound,+# which neither of those can, and because writing it found that TCB-20 was+# documented without the hypothesis it needs. See+# docs/decisions/0014-a-verifier-that-cannot-read-the-code-verifies-a-rewrite.md.+verify-dafny:+ ./dafny/run.sh+check: lint test audit# ─── Benchmarks ──────────────────────────────────────────────────────────────diff --git a/dafny/RuleTable.dfy b/dafny/RuleTable.dfynew file mode 100644index 00000000..54c2fe15--- /dev/null+++ b/dafny/RuleTable.dfy@@ -0,0 +1,676 @@+// TCB-20 without a length bound: the rule-table round trip.+//+// `docs/trusted-computing-base.md` states TCB-20 as `parse_rules(rules_tsv(r)) == r`,+// "in particular a constant never renders to something that reads back as a variable,+// and a variable name never renders to something that reads back as a constant".+// Two things verify part of that today and neither verifies this statement:+//+// * `kani_harnesses::pat_of_and_render_are_inverse_at_2` and `_at_3` prove the+// PER-FIELD half over every byte pattern at a field length of exactly two and+// exactly three bytes. The length is fixed because a symbolic length made CBMC+// reach fifteen gigabytes without a verdict, and the whole-line statement is out+// of reach for a further reason recorded on that page: asserting over+// `body.split('\t')` put CBMC inside `CharSearcher`.+// * Aeneas translates `src/boundary_core.rs` and `aeneas/lean/` proves things about+// it for every input. It does not reach this function. `docs/aeneas-boundary.md`+// says why under "What Aeneas could not handle": `Pat` carries a `String`, and+// Aeneas "has a `String` model but not enough of one". Every other serialisation+// property on the TCB page lost its length bound that way. This one did not.+//+// So this file models the grammar over bytes and proves the whole statement for+// every input: every field length, every field count, every rule table.+//+// WHAT IS MODELLED AND WHAT IS ASSUMED is the only thing that makes the result+// mean anything, and it is stated in+// `docs/decisions/0013-a-verifier-that-cannot-read-the-code-verifies-a-rewrite.md`+// rather than here.+// The short version: this is a REIMPLEMENTATION, so a theorem here is a theorem+// about this file. It is not a theorem about `src/reason.rs`. The decision record+// measures exactly what that is worth.++module RuleTable {++ // An octet. `parse_rules` takes a `&str` and `rules_tsv` returns a `String`, but+ // every discrimination either of them makes is on an ASCII byte: `strip_prefix('?')`,+ // `starts_with('<')`, `starts_with("_:")`, `starts_with('"')`, `split('\t')`,+ // `split('\n')` and `is_ascii_digit`. None of those can straddle a UTF-8 code+ // point, so the byte model loses nothing the function can see. This is the same+ // concession `src/boundary_core.rs` made for Aeneas, and it is a concession: a+ // theorem here is about bytes, and the Rust is about a `&str` whose well-formedness+ // is guaranteed elsewhere.+ newtype byte = x: int | 0 <= x < 256++ const TAB: byte := 9+ const LF: byte := 10+ const CR: byte := 13+ const QUOTE: byte := 34 // "+ const QUESTION: byte := 63 // ?+ const LT: byte := 60 // <+ const COLON: byte := 58 // :+ const UNDERSCORE: byte := 95+ const ZERO: byte := 48+ const NINE: byte := 57++ datatype Option<T> = None | Some(value: T)++ // `Pat` in `src/reason.rs`, and `OOCert.Pat` on the Lean side.+ datatype Pat = Const(bytes: seq<byte>) | Var(name: seq<byte>)++ datatype AtomPat = AtomPat(s: Pat, p: Pat, o: Pat)++ datatype RulePattern = RulePattern(name: seq<byte>, body: seq<AtomPat>, head: AtomPat)++ // ---------------------------------------------------------------------------+ // The field grammar+ // ---------------------------------------------------------------------------++ // The two classifications the Kani harness computes by hand, so that the lemma+ // below is the same statement rather than a paraphrase of it.+ predicate IsNamedVar(f: seq<byte>) {+ |f| > 1 && f[0] == QUESTION+ }++ predicate IsNtTerm(f: seq<byte>) {+ |f| > 0 && (f[0] == LT || f[0] == QUOTE+ || (f[0] == UNDERSCORE && |f| > 1 && f[1] == COLON))+ }++ // `pat_of` in `src/reason.rs`, byte for byte:+ //+ // if let Some(name) = field.strip_prefix('?') {+ // if name.is_empty() { return None; }+ // return Some(Pat::Var(name.to_string()));+ // }+ // if field.starts_with('<') || field.starts_with("_:") || field.starts_with('"') {+ // return Some(Pat::Const(field.to_string()));+ // }+ // None+ //+ // The leading `?` arm does not fall through on an empty name, and neither does+ // this. That matters: a fall-through would make `"?"` a constant.+ function PatOf(f: seq<byte>): Option<Pat> {+ if |f| > 0 && f[0] == QUESTION then+ (if |f| == 1 then None else Some(Var(f[1..])))+ else if IsNtTerm(f) then+ Some(Const(f))+ else+ None+ }++ // `Pat::render`.+ function Render(p: Pat): seq<byte> {+ match p+ case Const(c) => c+ case Var(v) => [QUESTION] + v+ }++ // The image of `PatOf`. A `Pat` the parser can return, as opposed to a `Pat` the+ // Rust type permits. The distinction is the whole content of this file: `Pat` is+ // an enum over two `String`s and nothing in the type stops either of them holding+ // a tab or a leading `?`.+ predicate WellFormedPat(p: Pat) {+ match p+ case Var(v) => |v| > 0+ case Const(c) => IsNtTerm(c)+ }++ // The Kani harness's statement, for every length rather than at two and three.+ //+ // match pat_of(field) {+ // Some(p) => { assert!(named_var || nt_term); assert!(p.render() == field); }+ // None => assert!(!named_var && !nt_term),+ // }+ lemma PatOfClassifies(f: seq<byte>)+ ensures PatOf(f).Some? <==> (IsNamedVar(f) || IsNtTerm(f))+ ensures PatOf(f).Some? ==> Render(PatOf(f).value) == f+ ensures PatOf(f).Some? ==> WellFormedPat(PatOf(f).value)+ {+ if |f| > 0 && f[0] == QUESTION && |f| > 1 {+ assert [QUESTION] + f[1..] == f;+ }+ }++ // The other direction, which the Kani harness does not state at all: rendering a+ // well-formed `Pat` and parsing it back is the identity.+ lemma RenderRoundTripsPat(p: Pat)+ requires WellFormedPat(p)+ ensures PatOf(Render(p)) == Some(p)+ {+ match p+ case Var(v) =>+ var r := [QUESTION] + v;+ assert |r| > 1 && r[0] == QUESTION;+ assert r[1..] == v;+ case Const(c) =>+ assert c[0] != QUESTION;+ }++ // TCB-5's shape at the field level: an accepted variable and an accepted constant+ // are never the same bytes, so the two kinds cannot be confused by a reader that+ // compares fields as opaque strings.+ lemma VariablesAndConstantsDoNotCollide(f: seq<byte>, g: seq<byte>)+ requires PatOf(f).Some? && PatOf(g).Some?+ requires PatOf(f).value.Var? && PatOf(g).value.Const?+ ensures f != g+ {+ assert f[0] == QUESTION;+ assert g[0] != QUESTION;+ }++ // ---------------------------------------------------------------------------+ // Splitting and joining, which is where the Kani route stopped+ // ---------------------------------------------------------------------------++ function IndexOf(s: seq<byte>, b: byte): nat+ ensures IndexOf(s, b) <= |s|+ ensures IndexOf(s, b) < |s| ==> s[IndexOf(s, b)] == b+ ensures forall k :: 0 <= k < IndexOf(s, b) ==> s[k] != b+ {+ if |s| == 0 then 0+ else if s[0] == b then 0+ else 1 + IndexOf(s[1..], b)+ }++ // `str::split(sep)`, and `String.splitOn` on the Lean side: n separators give+ // n+1 fields, empty fields included, so the result is never empty.+ function Split(s: seq<byte>, sep: byte): seq<seq<byte>>+ ensures |Split(s, sep)| > 0+ decreases |s|+ {+ var i := IndexOf(s, sep);+ if i == |s| then [s]+ else [s[..i]] + Split(s[i + 1..], sep)+ }++ function Join(parts: seq<seq<byte>>, sep: byte): seq<byte>+ requires |parts| > 0+ decreases |parts|+ {+ if |parts| == 1 then parts[0]+ else parts[0] + [sep] + Join(parts[1..], sep)+ }++ predicate NoByte(s: seq<byte>, b: byte) {+ forall k :: 0 <= k < |s| ==> s[k] != b+ }++ lemma IndexOfSkipsASeparatorFreePrefix(a: seq<byte>, rest: seq<byte>, sep: byte)+ requires NoByte(a, sep)+ ensures IndexOf(a + [sep] + rest, sep) == |a|+ decreases |a|+ {+ if |a| == 0 {+ assert (a + [sep] + rest)[0] == sep;+ } else {+ var whole := a + [sep] + rest;+ assert whole[0] == a[0] != sep;+ assert whole[1..] == a[1..] + [sep] + rest;+ IndexOfSkipsASeparatorFreePrefix(a[1..], rest, sep);+ }+ }++ // Split and Join are inverse exactly when no field carries the separator. This is+ // the lemma the Kani harnesses could not have: CBMC had to flatten `str::split`,+ // and the TCB page records that doing so measured `CharSearcher` rather than the+ // property. Here it is one induction.+ lemma SplitInvertsJoin(parts: seq<seq<byte>>, sep: byte)+ requires |parts| > 0+ requires forall i :: 0 <= i < |parts| ==> NoByte(parts[i], sep)+ ensures Split(Join(parts, sep), sep) == parts+ decreases |parts|+ {+ if |parts| == 1 {+ assert Join(parts, sep) == parts[0];+ assert IndexOf(parts[0], sep) == |parts[0]| by {+ assert NoByte(parts[0], sep);+ IndexOfIsLengthWhenAbsent(parts[0], sep);+ }+ } else {+ var rest := Join(parts[1..], sep);+ var whole := Join(parts, sep);+ assert whole == parts[0] + [sep] + rest;+ IndexOfSkipsASeparatorFreePrefix(parts[0], rest, sep);+ assert IndexOf(whole, sep) == |parts[0]|;+ assert whole[..|parts[0]|] == parts[0];+ assert whole[|parts[0]| + 1..] == rest;+ SplitInvertsJoin(parts[1..], sep);+ assert Split(whole, sep) == [parts[0]] + parts[1..];+ }+ }++ lemma IndexOfIsLengthWhenAbsent(s: seq<byte>, b: byte)+ requires NoByte(s, b)+ ensures IndexOf(s, b) == |s|+ decreases |s|+ {+ if |s| > 0 {+ IndexOfIsLengthWhenAbsent(s[1..], b);+ }+ }++ // ---------------------------------------------------------------------------+ // Decimal body length+ // ---------------------------------------------------------------------------++ predicate IsDigit(b: byte) { ZERO <= b <= NINE }++ function Digits(n: nat): seq<byte>+ ensures |Digits(n)| > 0+ ensures forall k :: 0 <= k < |Digits(n)| ==> IsDigit(Digits(n)[k])+ decreases n+ {+ if n < 10 then [ZERO + (n as byte)]+ else Digits(n / 10) + [ZERO + ((n % 10) as byte)]+ }++ function ToNat(s: seq<byte>): Option<nat>+ decreases |s|+ {+ if |s| == 0 then None+ else if |s| == 1 then+ (if IsDigit(s[0]) then Some((s[0] - ZERO) as nat) else None)+ else+ match ToNat(s[..|s| - 1])+ case None => None+ case Some(hi) =>+ if IsDigit(s[|s| - 1]) then Some(hi * 10 + (s[|s| - 1] - ZERO) as nat) else None+ }++ lemma DigitsRoundTrip(n: nat)+ ensures ToNat(Digits(n)) == Some(n)+ decreases n+ {+ if n < 10 {+ assert Digits(n) == [ZERO + (n as byte)];+ } else {+ DigitsRoundTrip(n / 10);+ var d := Digits(n);+ assert d == Digits(n / 10) + [ZERO + ((n % 10) as byte)];+ assert |d| > 1;+ assert d[..|d| - 1] == Digits(n / 10);+ assert d[|d| - 1] == ZERO + ((n % 10) as byte);+ }+ }++ // ---------------------------------------------------------------------------+ // The line+ // ---------------------------------------------------------------------------++ function AtomFields(a: AtomPat): seq<seq<byte>> {+ [Render(a.s), Render(a.p), Render(a.o)]+ }++ function BodyFields(body: seq<AtomPat>): seq<seq<byte>>+ ensures |BodyFields(body)| == 3 * |body|+ decreases |body|+ {+ if |body| == 0 then []+ else AtomFields(body[0]) + BodyFields(body[1..])+ }++ // `rules_tsv`, one line, and `OOCert.HornParse.ruleStr`:+ // name TAB bodyLength TAB (s TAB p TAB o)* TAB hs TAB hp TAB ho+ function RuleFields(r: RulePattern): seq<seq<byte>> {+ [r.name, Digits(|r.body|)] + BodyFields(r.body) + AtomFields(r.head)+ }++ function RuleStr(r: RulePattern): seq<byte> {+ Join(RuleFields(r), TAB)+ }++ // The precondition TCB-20 does not state, and the point of this file.+ //+ // `RulePattern` is a name and two `String`s per position, and nothing in the Rust+ // type refuses a tab in any of them. A rule carrying one renders to a line with+ // more fields than it has positions, so it reads back as a DIFFERENT rule or as+ // an error. `RuleIsWritable` is what has to hold for the round trip to be true,+ // and `ATabInANameBreaksTheRoundTrip` below shows it is not decoration.+ predicate PatIsWritable(p: Pat) {+ WellFormedPat(p) && NoByte(Render(p), TAB) && NoByte(Render(p), LF)+ }++ predicate AtomIsWritable(a: AtomPat) {+ PatIsWritable(a.s) && PatIsWritable(a.p) && PatIsWritable(a.o)+ }++ predicate RuleIsWritable(r: RulePattern) {+ |r.name| > 0+ && NoByte(r.name, TAB)+ && NoByte(r.name, LF)+ && (forall i :: 0 <= i < |r.body| ==> AtomIsWritable(r.body[i]))+ && AtomIsWritable(r.head)+ }++ // Sequential rather than a match on a triple of `Option`s, which is both closer+ // to the Rust (`parse_pat(f)?` three times) and markedly cheaper to verify: the+ // tuple-match formulation made `ParseAtomsInvertsRender` time out at thirty+ // seconds, and this one discharges in under two.+ function ParseAtoms(fields: seq<seq<byte>>): Option<seq<AtomPat>>+ decreases |fields|+ {+ if |fields| == 0 then Some([])+ else if |fields| < 3 then None+ else+ var s := PatOf(fields[0]);+ var p := PatOf(fields[1]);+ var o := PatOf(fields[2]);+ if s.None? || p.None? || o.None? then None+ else+ var rest := ParseAtoms(fields[3..]);+ if rest.None? then None+ else Some([AtomPat(s.value, p.value, o.value)] + rest.value)+ }++ lemma ParseAtomsCountsFields(fields: seq<seq<byte>>)+ ensures ParseAtoms(fields).Some? ==> |fields| == 3 * |ParseAtoms(fields).value|+ decreases |fields|+ {+ if |fields| >= 3 {+ ParseAtomsCountsFields(fields[3..]);+ }+ }++ // `parse_rules`, one line. The head-variable-occurs-in-the-body check and the+ // error messages are left out: both are refusals, and a refusal cannot make a+ // round trip succeed that would otherwise fail. What is kept is everything that+ // decides WHICH rule a line denotes.+ function ParseRuleLine(line: seq<byte>): Option<RulePattern> {+ var fields := Split(line, TAB);+ if |fields| < 2 then None+ else if |fields[0]| == 0 then None+ else+ var len := ToNat(fields[1]);+ if len.None? then None+ else+ var m := len.value;+ var rest := fields[2..];+ if |rest| != 3 * m + 3 then None+ else+ var body := ParseAtoms(rest[..3 * m]);+ var head := ParseAtoms(rest[3 * m..]);+ if body.None? || head.None? then None+ else if |head.value| != 1 then None+ else Some(RulePattern(fields[0], body.value, head.value[0]))+ }++ lemma ParseAtomsInvertsRender(body: seq<AtomPat>)+ requires forall i :: 0 <= i < |body| ==> AtomIsWritable(body[i])+ ensures ParseAtoms(BodyFields(body)) == Some(body)+ decreases |body|+ {+ if |body| == 0 {+ assert BodyFields(body) == [];+ } else {+ var a := body[0];+ var tail := BodyFields(body[1..]);+ var f := BodyFields(body);+ assert f == AtomFields(a) + tail;+ assert |f| >= 3;+ assert f[0] == Render(a.s) && f[1] == Render(a.p) && f[2] == Render(a.o);+ assert f[3..] == tail;+ RenderRoundTripsPat(a.s);+ RenderRoundTripsPat(a.p);+ RenderRoundTripsPat(a.o);+ ParseAtomsInvertsRender(body[1..]);+ assert ParseAtoms(tail) == Some(body[1..]);+ assert AtomPat(a.s, a.p, a.o) == a;+ assert [a] + body[1..] == body;+ }+ }++ lemma NoFieldCarriesATab(r: RulePattern)+ requires RuleIsWritable(r)+ ensures forall i :: 0 <= i < |RuleFields(r)| ==> NoByte(RuleFields(r)[i], TAB)+ {+ var f := RuleFields(r);+ forall i | 0 <= i < |f| ensures NoByte(f[i], TAB) {+ if i == 0 {+ assert f[0] == r.name;+ } else if i == 1 {+ assert f[1] == Digits(|r.body|);+ assert forall k :: 0 <= k < |f[1]| ==> IsDigit(f[1][k]);+ } else if i < 2 + 3 * |r.body| {+ BodyFieldAt(r.body, i - 2);+ assert f[i] == BodyFields(r.body)[i - 2];+ } else {+ assert f[i] == AtomFields(r.head)[i - 2 - 3 * |r.body|];+ }+ }+ }++ // Every field of `BodyFields` is a rendering of a position of some atom, so it+ // inherits that atom's writability. Stated as its own induction because the+ // quantifier in `RuleIsWritable` is over ATOMS and the one above is over FIELDS.+ lemma BodyFieldAt(body: seq<AtomPat>, j: nat)+ requires j < 3 * |body|+ requires forall i :: 0 <= i < |body| ==> AtomIsWritable(body[i])+ ensures NoByte(BodyFields(body)[j], TAB)+ ensures NoByte(BodyFields(body)[j], LF)+ decreases |body|+ {+ var f := BodyFields(body);+ assert f == AtomFields(body[0]) + BodyFields(body[1..]);+ if j < 3 {+ assert AtomIsWritable(body[0]);+ } else {+ assert f[j] == BodyFields(body[1..])[j - 3];+ BodyFieldAt(body[1..], j - 3);+ }+ }++ // TCB-20, for every rule table whose fields can be written at all, with no bound+ // on any length and no bound on the body's size.+ lemma RuleStrRoundTrips(r: RulePattern)+ requires RuleIsWritable(r)+ ensures ParseRuleLine(RuleStr(r)) == Some(r)+ {+ var f := RuleFields(r);+ NoFieldCarriesATab(r);+ SplitInvertsJoin(f, TAB);+ assert Split(RuleStr(r), TAB) == f;+ assert |f| == 2 + 3 * |r.body| + 3;+ assert f[0] == r.name;+ assert f[1] == Digits(|r.body|);+ DigitsRoundTrip(|r.body|);+ var rest := f[2..];+ assert rest == BodyFields(r.body) + AtomFields(r.head);+ assert |rest| == 3 * |r.body| + 3;+ assert rest[..3 * |r.body|] == BodyFields(r.body);+ assert rest[3 * |r.body|..] == AtomFields(r.head);+ ParseAtomsInvertsRender(r.body);+ RenderRoundTripsPat(r.head.s);+ RenderRoundTripsPat(r.head.p);+ RenderRoundTripsPat(r.head.o);+ assert ParseAtoms(AtomFields(r.head)) == Some([r.head]) by {+ assert AtomFields(r.head)[3..] == [];+ assert ParseAtoms([]) == Some([]);+ assert [AtomPat(r.head.s, r.head.p, r.head.o)] + [] == [r.head];+ }+ }++ // ---------------------------------------------------------------------------+ // The precondition is not decoration+ // ---------------------------------------------------------------------------++ // `RuleIsWritable` is a real hypothesis, and this is the witness. A rule whose+ // NAME carries a tab renders to a line that reads back as a rule with a different+ // name, silently and with no error. Nothing in `RulePattern`, in `rules_tsv` or in+ // `parse_rules` refuses it: `parse_rules` checks that the name is non-empty and+ // never that it is tab-free, because a name it PARSED could not contain a tab.+ //+ // This is why the theorem above carries a hypothesis and why TCB-20's unconditional+ // phrasing is wrong. The hazard is not live today, and the decision record says+ // exactly why, but the property as written on that page is false and this is the+ // counterexample.+ lemma ATabInANameBreaksTheRoundTrip()+ ensures exists r: RulePattern ::+ |r.name| > 0 && NoByte(RuleStr(r), LF) && ParseRuleLine(RuleStr(r)) != Some(r)+ {+ var c := Const([LT, 120, 62]); // <x>+ var r := RulePattern([97, TAB, 98], [], AtomPat(c, c, c)); // name = "a<tab>b"++ assert |r.name| > 0;+ assert r.name[1] == TAB;+ assert !NoByte(r.name, TAB);+ assert !RuleIsWritable(r);++ // The rendered line carries no line feed, which is all `ParsedRulesAreWritable`+ // needs of it. Every field is a literal here, so this is a computation.+ assert RuleFields(r) == [r.name, Digits(0), [LT, 120, 62], [LT, 120, 62], [LT, 120, 62]];+ assert forall i :: 0 <= i < |RuleFields(r)| ==> NoByte(RuleFields(r)[i], LF);+ JoinAvoidsAByteNoFieldCarries(RuleFields(r), TAB, LF);+ assert NoByte(RuleStr(r), LF);++ // A rule the parser RETURNS is always writable, so a rule that is not writable+ // is not a rule the parser can return, whatever line it is given.+ if ParseRuleLine(RuleStr(r)) == Some(r) {+ ParsedRulesAreWritable(RuleStr(r));+ assert RuleIsWritable(r);+ assert false;+ }+ }++ // The same hazard one level down, in a VARIABLE name rather than a rule name, so+ // that nobody reads the lemma above as being only about the name column. This one+ // matters more, because a variable name is not something a reader thinks of as+ // carrying a separator, and `Pat::Var` is a bare `String`.+ lemma ATabInAVariableBreaksTheRoundTrip()+ ensures exists r: RulePattern ::+ WellFormedPat(r.head.s) && NoByte(RuleStr(r), LF)+ && ParseRuleLine(RuleStr(r)) != Some(r)+ {+ var bad := Var([120, TAB, 121]); // ?x<tab>y+ var c := Const([LT, 120, 62]);+ var r := RulePattern([97], [], AtomPat(bad, c, c));++ assert WellFormedPat(bad);+ assert Render(bad) == [QUESTION, 120, TAB, 121];+ assert Render(bad)[2] == TAB;+ assert !PatIsWritable(bad);+ assert !RuleIsWritable(r);++ assert RuleFields(r)+ == [[97], Digits(0), [QUESTION, 120, TAB, 121], [LT, 120, 62], [LT, 120, 62]];+ assert forall i :: 0 <= i < |RuleFields(r)| ==> NoByte(RuleFields(r)[i], LF);+ JoinAvoidsAByteNoFieldCarries(RuleFields(r), TAB, LF);+ assert NoByte(RuleStr(r), LF);++ if ParseRuleLine(RuleStr(r)) == Some(r) {+ ParsedRulesAreWritable(RuleStr(r));+ assert RuleIsWritable(r);+ assert false;+ }+ }++ lemma JoinAvoidsAByteNoFieldCarries(parts: seq<seq<byte>>, sep: byte, other: byte)+ requires |parts| > 0+ requires sep != other+ requires forall i :: 0 <= i < |parts| ==> NoByte(parts[i], other)+ ensures NoByte(Join(parts, sep), other)+ decreases |parts|+ {+ if |parts| > 1 {+ JoinAvoidsAByteNoFieldCarries(parts[1..], sep, other);+ var rest := Join(parts[1..], sep);+ var whole := parts[0] + [sep] + rest;+ assert Join(parts, sep) == whole;+ forall k | 0 <= k < |whole| ensures whole[k] != other {+ if k < |parts[0]| {+ assert whole[k] == parts[0][k];+ } else if k == |parts[0]| {+ assert whole[k] == sep;+ } else {+ assert whole[k] == rest[k - |parts[0]| - 1];+ }+ }+ }+ }++ // ---------------------------------------------------------------------------+ // What the engine actually writes does satisfy the hypothesis+ // ---------------------------------------------------------------------------++ // The reassuring half, and it is worth proving rather than asserting: anything+ // the parser produced is writable, so rendering it and reading it back is the+ // identity. That is the property TCB-18's re-parse guard leans on, and it is+ // what makes the two counterexamples above latent rather than live: the only+ // rules the engine writes are rules it parsed, or the built-in table, and a+ // parsed rule cannot carry a separator in any position.+ lemma ParsedRulesAreWritable(line: seq<byte>)+ requires ParseRuleLine(line).Some?+ requires NoByte(line, LF)+ ensures RuleIsWritable(ParseRuleLine(line).value)+ {+ var fields := Split(line, TAB);+ SplitFieldsCarryNoSeparator(line, TAB);+ SplitFieldsInheritAbsence(line, TAB, LF);++ var r := ParseRuleLine(line).value;+ var m := ToNat(fields[1]).value;+ var rest := fields[2..];+ var bodyFields := rest[..3 * m];+ var headFields := rest[3 * m..];+ var bodyOpt := ParseAtoms(bodyFields);+ var headOpt := ParseAtoms(headFields);++ assert bodyOpt.Some? && headOpt.Some?;+ assert r.name == fields[0] && r.body == bodyOpt.value && r.head == headOpt.value[0];+ assert |headOpt.value| == 1;+ assert headOpt.value == [r.head];++ assert forall i :: 0 <= i < |bodyFields| ==>+ NoByte(bodyFields[i], TAB) && NoByte(bodyFields[i], LF);+ assert forall i :: 0 <= i < |headFields| ==>+ NoByte(headFields[i], TAB) && NoByte(headFields[i], LF);++ ParsedAtomsAreWritable(bodyFields, bodyOpt.value);+ ParsedAtomsAreWritable(headFields, headOpt.value);+ assert AtomIsWritable(r.head);+ }++ lemma ParsedAtomsAreWritable(fields: seq<seq<byte>>, atoms: seq<AtomPat>)+ requires ParseAtoms(fields) == Some(atoms)+ requires forall i :: 0 <= i < |fields| ==> NoByte(fields[i], TAB) && NoByte(fields[i], LF)+ ensures forall i :: 0 <= i < |atoms| ==> AtomIsWritable(atoms[i])+ decreases |fields|+ {+ if |fields| == 0 {+ assert atoms == [];+ } else {+ PatOfClassifies(fields[0]);+ PatOfClassifies(fields[1]);+ PatOfClassifies(fields[2]);+ var restOpt := ParseAtoms(fields[3..]);+ assert restOpt.Some?;+ var a := AtomPat(PatOf(fields[0]).value, PatOf(fields[1]).value, PatOf(fields[2]).value);+ assert atoms == [a] + restOpt.value;+ // Each position renders back to its own field, and that field carries no+ // separator, so the position is writable.+ assert Render(a.s) == fields[0] && Render(a.p) == fields[1] && Render(a.o) == fields[2];+ assert AtomIsWritable(a);+ ParsedAtomsAreWritable(fields[3..], restOpt.value);+ assert forall i :: 1 <= i < |atoms| ==> atoms[i] == restOpt.value[i - 1];+ }+ }++ lemma SplitFieldsCarryNoSeparator(s: seq<byte>, sep: byte)+ ensures forall i :: 0 <= i < |Split(s, sep)| ==> NoByte(Split(s, sep)[i], sep)+ decreases |s|+ {+ var i := IndexOf(s, sep);+ if i != |s| {+ SplitFieldsCarryNoSeparator(s[i + 1..], sep);+ }+ }++ lemma SplitFieldsInheritAbsence(s: seq<byte>, sep: byte, other: byte)+ requires NoByte(s, other)+ ensures forall i :: 0 <= i < |Split(s, sep)| ==> NoByte(Split(s, sep)[i], other)+ decreases |s|+ {+ var i := IndexOf(s, sep);+ if i != |s| {+ SplitFieldsInheritAbsence(s[i + 1..], sep, other);+ }+ }+}diff --git a/dafny/run.sh b/dafny/run.shnew file mode 100755index 00000000..0358ea2b--- /dev/null+++ b/dafny/run.sh@@ -0,0 +1,94 @@+#!/usr/bin/env bash+#+# Verify dafny/RuleTable.dfy, and then prove that doing so can fail.+#+# OPTIONAL AND SEPARATE, the way the Kani harnesses and aeneas/run.sh are.+# Nothing in `make check`, `cargo build`, `cargo test` or `lean/`'s `lake build`+# calls this script, and nothing it produces is on any of those paths.+# `docs/ci-gates.md` records that, next to Kani and Aeneas, which are under the+# same arrangement and for the same reason.+#+# Needs `brew install dafny` (4.11.0 here) or the equivalent. Dafny bundles its+# own Z3.+#+# WHAT THIS IS AND IS NOT, because the distinction is the whole of decision 0013:+# `RuleTable.dfy` is a REIMPLEMENTATION of the rule-table grammar in+# `src/reason.rs`. Verifying it proves things about the Dafny. It proves nothing+# about the Rust, and no output of this script should ever be quoted as though it+# did. What it is good for is stated in+# `docs/decisions/0013-a-verifier-that-cannot-read-the-code-verifies-a-rewrite.md`.+#+# The second half is the part worth reading. A verification script that only ever+# reports success is indistinguishable from one that verifies nothing, and this+# repository has shipped that shape of defect before: a skipped test reports `ok`.+# So this script MUTATES the specification three times and requires each mutation+# to be REJECTED. If a mutation verifies, the proof was not resting on the thing+# it claims to rest on, and the script fails.+set -euo pipefail++here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+src="$here/RuleTable.dfy"+work="$(mktemp -d)"+trap 'rm -rf "$work"' EXIT++if ! command -v dafny >/dev/null 2>&1; then+ echo "dafny not on PATH. brew install dafny, or see docs/ci-gates.md." >&2+ exit 2+fi++echo "== dafny $(dafny --version)"+echo++echo "== 1. the specification verifies"+dafny verify "$src"+echo++# Each mutation is a `sed`-able edit that removes something the proof depends on.+# The third column is what it is meant to break, so a reader can tell a real+# rejection from an incidental one.+mutate () {+ local name="$1" from="$2" to="$3" breaks="$4"+ python3 - "$src" "$work/mut.dfy" "$from" "$to" <<'PY'+import sys+src, dst, old, new = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]+s = open(src).read()+if old not in s:+ sys.exit("mutation pattern no longer present, this script is stale: " + old)+open(dst, "w").write(s.replace(old, new, 1))+PY+ if dafny verify "$work/mut.dfy" >"$work/out" 2>&1; then+ echo "FAIL: mutation '$name' VERIFIED. It was supposed to break $breaks."+ echo " Either the proof does not depend on that, or the property is vacuous."+ cat "$work/out"+ exit 1+ fi+ echo " ok: '$name' rejected (breaks $breaks)"+ grep -E "finished with" "$work/out" | sed 's/^/ /'+}++echo "== 2. the proof can fail"++# The load-bearing one. TCB-20 is stated unconditionally on+# docs/trusted-computing-base.md and it is FALSE unconditionally: a rule name+# carrying a tab renders to a line that reads back as a different rule. Removing+# the hypothesis that says otherwise must break the round-trip theorem.+mutate "drop the tab-freeness of a rule name" \+ ' && NoByte(r.name, TAB)+' '' \+ "RuleStrRoundTrips and the counterexample lemmas"++# The classification. `pat_of` must not treat a bare '?' as a constant, or a+# variable and a constant stop being distinguishable by their first byte.+mutate "let pat_of read a bare '?' as a constant" \+ 'if |f| == 1 then None else Some(Var(f[1..]))' \+ 'if |f| == 1 then Some(Const(f)) else Some(Var(f[1..]))' \+ "PatOfClassifies and VariablesAndConstantsDoNotCollide"++# The empty-name refusal, which is what makes a parsed rule writable.+mutate "drop the empty-name refusal from ParseRuleLine" \+ 'else if |fields[0]| == 0 then None' \+ 'else if false then None' \+ "ParsedRulesAreWritable"++echo+echo "== done. The specification verifies and all three mutations were rejected."diff --git a/docs/aeneas-boundary.md b/docs/aeneas-boundary.mdindex 350b0849..926e402f 100644--- a/docs/aeneas-boundary.md+++ b/docs/aeneas-boundary.md@@ -220,6 +220,17 @@ needs and all it needs.`core::fmt` and `anyhow`. This is the same shape of obstacle that killed itsKani harness, and the same fix would serve both: lift the classification intoa pure `Option<Pat>` function and leave the messages where they are.+ **That fix was made, and it did not help here.** `pat_of` is that function, it+ landed on 15 September 2026, and Kani verifies it. Aeneas still cannot take it,+ for the unrelated reason at the top of this list: `pat_of` returns+ `Option<Pat>` and `Pat` carries a `String`, so the obstacle is the string model+ rather than the error formatting. Moving it into the byte discipline the rest+ of this module uses would mean `Pat` over `Vec<u8>`, which changes the type+ every rule-table call site names. That was not done, and TCB-20's whole-line+ half is consequently the one serialisation property on+ `docs/trusted-computing-base.md` that still has no unbounded proof about this+ Rust. Dafny proves it unbounded about a REIMPLEMENTATION, which is a different+ claim; decision 0014 measures what that is worth.- **Nothing was silently dropped.** The generated file has no `opaque`declaration, no `axiom` and no `sorry`: `grep -n "opaque\|axiom\|sorry"aeneas/lean/OOBoundary/Generated.lean` is empty. Aeneas reports eight opaquediff --git a/docs/ci-gates.md b/docs/ci-gates.mdindex 15256389..8384db36 100644--- a/docs/ci-gates.md+++ b/docs/ci-gates.md@@ -158,6 +158,13 @@ The other seven files under `python/tests/` have no skip path.`.lake` including Mathlib. `docs/aeneas-boundary.md` reports what they producedwhen they were run here, which is the same arrangement Kani is under and forthe same reason: a gate nobody can run locally is not a gate.+- **Dafny.** `dafny/run.sh` verifies `dafny/RuleTable.dfy` and then mutates it three times and+ requires every mutation to be rejected, so the script fails both when the specification breaks and+ when the proof turns out not to depend on what it claims to. No job runs it, and `make+ verify-dafny` is the only thing that does. It is in the same position as Kani and Aeneas and for+ the same reason. It also proves less than either of those: it is a REIMPLEMENTATION of the+ rule-table grammar rather than the shipped Rust, so nothing it reports is evidence about+ `src/reason.rs`. Decision 0014 says why it is kept anyway.- **The Makefile and CI have drifted.** No workflow invokes `make`. `make check`is `lint test audit`, and its `test` is a bare `cargo test` with no`OO_REQUIRE_FIXTURES`, so a local `make check` is the permissive run whateverdiff --git a/docs/decisions/0014-a-verifier-that-cannot-read-the-code-verifies-a-rewrite.md b/docs/decisions/0014-a-verifier-that-cannot-read-the-code-verifies-a-rewrite.mdnew file mode 100644index 00000000..4aafb3a6--- /dev/null+++ b/docs/decisions/0014-a-verifier-that-cannot-read-the-code-verifies-a-rewrite.md@@ -0,0 +1,234 @@+# 0014. A verifier that cannot read the code verifies a rewrite++Dafny is DECLINED as a dependency. `dafny/RuleTable.dfy` is KEPT, because it earned its place by+finding something, and because a declined tool with nothing to show for the decision is the kind of+entry `docs/reasoning-systems-inventory.md` exists to prevent.++The rule: a proof about a reimplementation of a function is a proof about the reimplementation. It+becomes a proof about the engine only when the engine runs the verified artefact, and the price of+making the engine run this one is measured below and is worse than the disease.++## The defect this prevents++Counting a green verifier as evidence about code it never read.++This is decision 0005's rule applied to a verification tool rather than to a prover. A prover's+`unsat` is testimony about the problem it was given, and the question that matters is whether that+problem is the one we asked. A verified rewrite is testimony about the rewrite, and the question that+matters is whether the rewrite is what ships. For Kani and for Aeneas the answer is yes, by+construction: Kani model-checks the actual `src/reason.rs`, and Aeneas translates the actual+`src/boundary_core.rs`. For Dafny the answer is no unless the generated Rust replaces the+hand-written Rust, and that is a much larger decision than "add a verifier".++## What was actually built and run++Dafny 4.11.0, installed with `brew install dafny` on `arm64-apple-darwin`, using the Z3 it bundles.+Homebrew also pulled Z3 4.16.0 as a formula dependency; nothing here invokes it directly.++`dafny/RuleTable.dfy` is 676 lines modelling the rule-table grammar of `src/reason.rs` over bytes:+`Pat`, `AtomPat`, `RulePattern`, `pat_of`, `Pat::render`, `rules_tsv` for one line, and the part of+`parse_rules` that decides which rule a line denotes. `dafny/run.sh` runs it.++| measurement | value |+|---|---|+| proof obligations | 57 verified, 0 errors |+| `dafny verify` | 7.1s wall, 3.9s user |+| `dafny/run.sh`, verification plus three falsifying mutations | 16.3s wall |+| `dafny build -t:rs` | 7.9s wall, exit 0 |+| Rust generated for the model | 872 lines |+| `dafny_runtime` vendored beside it | 8,590 lines, 9,914 with its own tests |+| third-party crates that runtime pulls | `num`, `once_cell`, `itertools` |+| Rust in `src/reason.rs` the model covers | about 127 lines |++The runtime row and the covered-lines row are the decision. Shipping the verified artefact means+adding roughly 8,600 lines of unverified Rust runtime, plus a bignum library, to the trusted+computing base, in order to verify about 127 lines that are already inside it.++## What it proved that nothing here proved before++TCB-20 is `parse_rules(rules_tsv(r)) == r`. It is addressed today by Kani and by Aeneas, and it is+established by neither.++`kani_harnesses::pat_of_and_render_are_inverse_at_2` and `_at_3` prove the PER-FIELD half over every+byte pattern at a field length of exactly two and exactly three bytes. The length is fixed rather+than symbolic because, as `docs/trusted-computing-base.md` records, a symbolic length made CBMC+reach fifteen gigabytes without a verdict. The whole-line statement was out of reach for a second+reason recorded on the same page: asserting over `body.split('\t')` put CBMC inside `CharSearcher`,+which is both expensive and the wrong function to be measuring.++Aeneas removed the length bound from every other serialisation property on that page and did not+reach this one. `docs/aeneas-boundary.md` says why under "What Aeneas could not handle": `Pat`+carries a `String`, and Aeneas "has a `String` model but not enough of one".++`RuleTable.dfy` proves the whole statement with no bound on field length, on field count, or on the+size of the rule body, and it does so in seven seconds. The split-and-join lemma that CBMC could not+afford is one induction here. That is a real capability difference and it is not a small one.++## And what it found, which is a documentation defect rather than a bug++TCB-20 as written on `docs/trusted-computing-base.md` is FALSE.++`parse_rules(rules_tsv(r)) == r` does not hold for an arbitrary `r: RulePattern`. Nothing in the Rust+type stops `r.name`, or the name inside a `Pat::Var`, from containing a tab or a line feed. A rule+carrying one renders to a line with more fields than it has positions, and that line reads back as a+different rule or as an error. Neither outcome is the identity.++Dafny surfaced this the way a verifier does, by refusing to prove a false thing. The theorem needed a+hypothesis, `RuleIsWritable`, and writing that hypothesis is what made the gap visible.+`ATabInANameBreaksTheRoundTrip` and `ATabInAVariableBreaksTheRoundTrip` are the two witnesses, proved+rather than asserted, and `dafny/run.sh` removes the hypothesis on every run and requires the+round-trip theorem to fail without it. A precondition nobody has tried to drop is a precondition+nobody knows is load-bearing.++**The hazard is latent and it is not live, and saying so is part of the finding.** Only two places+construct a `RulePattern`, and both are closed:++- `src/reason.rs:2740`, inside `parse_rules` itself. Its fields come from splitting a line on tabs,+ so none of them can contain a tab, and the line came from splitting on newlines.+- `src/rulesyntax.rs:179`, in `Import::accept`, which is the front end a user's RIF, SWRL or Datalog+ reaches. It already renders the rule to a `rules.tsv` line, re-parses it with `parse_rules`, and+ refuses the rule unless it comes back identical. That is exactly this theorem's hypothesis,+ enforced at the only site where it could otherwise be violated.++So the correction is to the page, not to the engine. TCB-20 should state the condition and name what+enforces it, and `docs/trusted-computing-base.md` now does. The engine was already right; the+document claimed something stronger than the engine delivers, which by this repository's standards is+its own category of defect.++## Why Dafny is still declined++### The theorem is about the Dafny++This is the whole of it. `RuleTable.dfy` is a second implementation of the grammar, written from+`src/reason.rs` and from `lean/OOCert/HornParse.lean`. Every theorem in it is a theorem about+`RuleTable.PatOf` and `RuleTable.ParseRuleLine`. If the model and the Rust disagree, the theorem is+true of a function the engine does not run, and nothing in the file would notice.++That is the same shape as TCB-30, which records the same exposure for Aeneas, but it is strictly+worse in one respect and the difference decides this. Aeneas's model is DERIVED from the shipped+Rust by a program, and `aeneas/run.sh` re-derives it and fails if it moved, so the model cannot drift+away from the code unnoticed. The Dafny model is derived from the Rust by a person reading it, and+nothing can check that correspondence. A hand transcription that drifts is precisely the failure+`tests/certificate_boundary_proptest.rs` already documents for the TCB-19 leg, where the property+test runs against a transcription of the Lean parser and the transcription's fidelity is an+assumption.++### Closing that gap means shipping the generated Rust, and the trade inverts++Dafny's answer to "your theorem is about the wrong artefact" is to compile the Dafny and run that.+The backend works: `dafny build -t:rs` produced a compiling crate in 7.9 seconds. What it produced is+the problem.++```+pub fn PatOf(f: &Sequence<u8>) -> Rc<Option<Rc<Pat>>>+```++That is not a function `src/reason.rs` can call. `Sequence<u8>` is `dafny_runtime`'s persistent+sequence and not `&str` or `&[u8]`; the result is `Rc<Option<Rc<Pat>>>` and not `Option<Pat>`; and+`f.cardinality()` returns a `DafnyInt`, so every length test and every index in the generated code is+arbitrary-precision arithmetic through `num::BigInt` rather than a `usize`. Calling it needs a+marshalling layer converting `&str` to `Sequence<u8>` on the way in and `Rc<Option<Rc<Pat>>>` to+`Option<Pat>` on the way out, with an allocation and a copy in each direction.++That marshalling layer would be hand-written, unverified, and would sit exactly at the trust boundary+this exercise exists to shrink. The verified parser would be reached only through unverified code+converting into and out of it, which is the same position the parser is in now, one level out.++And the runtime it rests on is 8,590 lines of Rust nobody here has read, with `num`, `once_cell` and+`itertools` behind it. `docs/trusted-computing-base.md` names `oxrdf`'s escaping behaviour as a trust+assumption worth closing. Adding a bignum library to the trusted base of a tab-separated-value parser+is not a trade this document can recommend with a straight face.++Two mitigations exist and neither rescues it. `--features small-int` makes `DafnyInt` an `i128`+instead of a `BigInt`, which shrinks the arithmetic but not the runtime and not the marshalling. And+the model could be narrowed to `seq<uint8>` end to end, which is what it already does; the+`Sequence<u8>` representation is the runtime's, not the model's, and there is no flag that makes it+a `&[u8]`.++### The pure functions worth verifying are the ones already covered++The inventory question was whether Dafny reaches something Kani and Aeneas do not. It does, and the+set is small. Of the thirty properties on the TCB page, Kani proves six at a bound and Aeneas removes+the bound from the serialisation core. What is left unreached and pure is TCB-20's whole-line half,+for which this file supplies an unbounded proof ABOUT A MODEL and no proof about the Rust, and the+interner's TCB-15 to TCB-17, which Aeneas cannot reach because `Interner` is a `HashMap` and which+Dafny would model as a `map` almost for free.++That second one is worth naming precisely so nobody has to rediscover it: an interner's bijectivity+is nearly trivial in Dafny and genuinely out of reach for both of the other two. It is also the same+trade. Verifying a Dafny interner and then shipping `Sequence<u8>` keys through `dafny_runtime`'s+`Map` in place of `HashMap<String, u32>` is a performance and trust decision on the engine's hottest+data structure, taken to close a property that three property tests already sample and that has never+failed.++### The defects that actually bite this codebase are not pure functions++This is the argument that would still hold even if the interop were free.++The verification work already done here covers, in its own words, "five pure functions totalling+about sixty lines", and the honest summary on the TCB page is "this work verified the joint, not the+machine". The defects found in this repository over the last month were not in that joint. The+`rdfs7` defect was a rule concluding a triple no serialiser can write, found by a property test+driving the real entry points. The Lean and Isabelle divergence was a gap in the FORMAT that no+single formalisation could see. The skipped-gate defect was a test that reported `ok` because no+workflow installed its toolchain. A separate review of the daemon paths found that in `serve-http`+and daemon mode the ontology evictor can never evict anything, because the registry it consults is+never populated.++Not one of those is a false theorem about a pure function, and not one of them is reachable by+Dafny without rewriting the surrounding program in Dafny. They are wiring, configuration, format+underspecification and state that is never initialised. Dafny bites on the part of this system that+is already the best covered.++The last of those is worth one more sentence, because it is the clearest case. `evictor_tick` in+`src/registry.rs` returns early unless the registry holds an active entry, and the only thing that+sets one is `OntologyRegistry::load_file`, while `src/server.rs` loads through `GraphStore::load_file`+instead, so in `serve-http` and daemon mode the evictor can never evict anything.+`tests/registry_evictor_wiring_test.rs` pins it, and pins it as a defect rather than as behaviour:+`an_unloaded_registry_never_evicts` fails the day somebody fixes the wiring, and says so.+Nothing about that is a false theorem. Every function involved does what it says. The defect is which+function the other one calls, and there is no property of a pure function whose proof would have+caught it. Decision 0012 reached the same conclusion from the concurrency side on the same day, by a+different route.++## What is kept, and on what terms++`dafny/RuleTable.dfy` and `dafny/run.sh` stay in the tree as a SPECIFICATION and as the evidence for+this record. They are not a gate and must never be described as one.++- Nothing in `make check`, `cargo build`, `cargo test` or `lean/`'s `lake build` reaches them. This+ is the arrangement Kani and Aeneas are already under, for the reason `docs/ci-gates.md` gives: a+ gate nobody can run locally is not a gate. `make verify-dafny` runs it for anyone who has Dafny.+- `docs/ci-gates.md` carries a row for it under "What is still open", so the page cannot imply it+ runs.+- No sentence anywhere may say that TCB-20 is verified. What is verified is that a Dafny model of the+ grammar has the property, and that is what `docs/trusted-computing-base.md` now says, in those+ words, in the same row that reports the Kani bound.++`run.sh` proves it can fail rather than asserting it. It mutates the specification three times and+requires every mutation to be rejected: dropping the tab-freeness hypothesis, letting `pat_of` read a+bare `?` as a constant, and dropping the empty-name refusal. Measured on this tree, those produce two,+two and one error respectively. The script also fails if a mutation VERIFIES, which was tested by+feeding it a mutation that changes nothing and confirming it reports `FAIL` and exits 1, and it fails+if a mutation's pattern is no longer in the file, which was also tested. A verification script whose+only possible outcome is success is the same defect as a test that skips.++## Consequences++1. Dafny joins `docs/reasoning-systems-inventory.md` as declined, with the measured reason rather+ than the general one. The general objection in that table, "each needs the code rewritten in its+ subset", is true of Dafny in a stronger form than of Verus, Creusot and Prusti: those three verify+ Rust written in a dialect, and Dafny does not verify Rust at all. The measurement that matters is+ not that the rewrite is required but what the rewrite costs to run, and that is the 8,590-line+ row in the table above.+2. TCB-20 on `docs/trusted-computing-base.md` gains its missing precondition and a note naming the+ two sites that enforce it. The page previously stated a property that is false as written.+3. `docs/aeneas-boundary.md`'s entry for `parse_pat` under "What Aeneas could not handle" is stale in+ one respect and is corrected: it says the fix would be "to lift the classification into a pure+ `Option<Pat>` function", and that was done on 15 September 2026. `pat_of` exists and Kani verifies+ it. Aeneas still cannot reach it, for the unrelated reason that `Pat` carries a `String`.+4. If the interner is ever verified, this record is the place to start, and the question to answer+ first is not "can Dafny prove it" but "what replaces `HashMap<String, u32>` at run time".+5. Nothing about this decision is permanent. What would change it is a Dafny Rust backend that emits+ ordinary Rust types against no runtime, which does not exist today, or a decision that this+ project's engine should be generated rather than written, which is a different project.diff --git a/docs/decisions/README.md b/docs/decisions/README.mdindex a8c92123..08fe1361 100644--- a/docs/decisions/README.md+++ b/docs/decisions/README.md@@ -13,11 +13,16 @@ and whose benefit is not gets dropped the first time it is inconvenient.| [0007](0007-a-slice-preserves-a-conclusion-or-it-does-not.md) | A slice preserves a conclusion, or it does not | A retrieval slice quietly dropping the conclusion it was asked about || [0008](0008-a-binding-is-data-and-evidence-admits-one-reading.md) | A binding is data, and evidence admits one reading | A certificate format admitting two readings, so two checkers disagree || [0012](0012-concurrency-lives-below-the-certificate.md) | Concurrency lives below the certificate, and a proof cannot follow it there | Adopting a program logic for a hazard that lives in a dependency, and calling the result assurance |+| [0014](0014-a-verifier-that-cannot-read-the-code-verifies-a-rewrite.md) | A verifier that cannot read the code verifies a rewrite | Counting a green verifier as evidence about code it never read |There is no 0004. The decision now numbered 0006 was drafted as 0004 on a branch that never merged,so the number never reached `main`. It is left as a hole rather than reused, because a reused numbermakes an old citation silently come to mean something else.+This table has rows for 0009 to 0011 missing rather than absent. Those records exist in this+directory, there are two numbered 0009, and nobody has written their rows. The gap is recorded here+so that a reader does not conclude from the jump that the numbers were skipped the way 0004 was.+## What this discipline has caughtIn one week of running it against this engine.diff --git a/docs/reasoning-systems-inventory.md b/docs/reasoning-systems-inventory.mdindex e4ce15f2..4936bedd 100644--- a/docs/reasoning-systems-inventory.md+++ b/docs/reasoning-systems-inventory.md@@ -37,6 +37,7 @@ about the file we gave it. The addendum to decision 0005 draws the new line.| Aeneas with Charon | Rust to Lean | Declined. Subset does not contain this codebase. || Verus, Creusot, Prusti | Rust verification | Declined. Each needs the code rewritten in its subset. || Iris, RefinedRust | Concurrent separation logic | Declined. The shared state is inside Oxigraph, and the certificate layer is pure. Below. |+| Dafny 4.11.0 | Verification-aware language | Declined as a dependency, RUN and kept as a specification. It verifies a rewrite, not this code. Below. || Kani | Rust bounded model checker | Being applied to the trusted boundary only. || loom | Rust interleaving explorer | The right tool for the two latent lock defects. Not yet wired in. || TPTP and TSTP | Interchange | Implemented, in both directions. TPTP out, TSTP back in and checked. |@@ -245,6 +246,30 @@ it is a serialiser, a parser and an interner rather than fifty thousand lines. Tis being property-tested and, where it pays, model-checked with Kani. What remains trusted after thatwork will be named explicitly rather than left for a reader to infer.+Dafny belongs in this section rather than beside Verus, and the difference is worth stating because+it makes the objection stronger and not weaker. Verus, Creusot and Prusti verify Rust written in a+dialect, so the artefact that ships is the artefact that was verified. Dafny does not verify Rust at+all. It is a separate language that compiles to one, so the only way a Dafny theorem becomes a+statement about this engine is if the engine runs Dafny's generated Rust.++It was installed and run rather than argued about. `dafny/RuleTable.dfy` models the rule-table+grammar of `src/reason.rs` over bytes and proves TCB-20's round trip with no bound on field length,+field count or body size: 57 obligations, 0 errors, seven seconds. That is a real capability gap+closed. Kani proves only the per-field half and only at field lengths of exactly two and three,+because a symbolic length exhausted CBMC, and Aeneas cannot reach the function at all because `Pat`+carries a `String`. Writing the property out also found that TCB-20 was stated on+`docs/trusted-computing-base.md` without the hypothesis it needs, and is false without it.++It is still declined, for a reason that was measured rather than predicted. Compiling the model+emits 872 lines of Rust against a `dafny_runtime` of 8,590 lines pulling `num`, `once_cell` and+`itertools`, and its entry point takes a `Sequence<u8>` and returns an `Rc<Option<Rc<Pat>>>`, so+every call from `src/reason.rs` would cross a hand-written, unverified marshalling layer sitting at+the precise boundary the work exists to shrink. Verifying about 127 lines by adding roughly 8,600+unverified ones to the trusted base is the wrong direction. The file is kept as a specification and+as the evidence, it is a gate nowhere, and+[decision 0014](decisions/0014-a-verifier-that-cannot-read-the-code-verifies-a-rewrite.md) carries+the numbers and the terms.+## Iris, and the concurrency that is not oursIris is the higher-order concurrent separation logic built in Rocq, and the obvious reason to want itdiff --git a/docs/trusted-computing-base.md b/docs/trusted-computing-base.mdindex 4b858335..fbe9538d 100644--- a/docs/trusted-computing-base.md+++ b/docs/trusted-computing-base.md@@ -203,9 +203,22 @@ against a triple that is not the one the engine used.strictly stricter on three points, all in the refusing direction: it requires a constant to be inN-Triples spelling, it refuses a head variable not bound by the body, and it refuses a carriagereturn. Lean's `patOf` treats any field not starting with `?` as a constant.-- **TCB-20 (render and parse are inverse).** `parse_rules(rules_tsv(r)) == r`. In particular a- constant never renders to something that reads back as a variable, and a variable name never- renders to something that reads back as a constant.+- **TCB-20 (render and parse are inverse).** `parse_rules(rules_tsv(r)) == r` for every rule `r`+ WHOSE FIELDS CAN BE WRITTEN: a non-empty name, and no tab or line feed in the name or in any+ variable name. In particular a constant never renders to something that reads back as a variable,+ and a variable name never renders to something that reads back as a constant.+ **The hypothesis is not decoration, and this entry stated the property without it until 18+ September 2026.** Nothing in `RulePattern` stops `name`, or the `String` inside a `Pat::Var`, from+ carrying a tab. A rule that does renders to a line with more fields than it has positions, so it+ reads back as a different rule or as an error, and neither is the identity.+ It is LATENT rather than live, because only two places build a `RulePattern` and both are closed.+ `parse_rules` itself builds one out of fields it obtained by splitting a line on tabs, so none of+ them can contain one. `Import::accept` in `src/rulesyntax.rs`, which is where a user's RIF, SWRL or+ Datalog arrives, renders the rule and re-parses it with `parse_rules` and refuses it unless it+ comes back identical, which is this hypothesis enforced at the only site that could violate it.+ The correction is therefore to this page and not to the engine. It was found by writing the+ property out in Dafny, where a theorem that needs a hypothesis cannot be stated without one:+ `docs/decisions/0014-a-verifier-that-cannot-read-the-code-verifies-a-rewrite.md`.- **TCB-21 (`rules_tsv` and `ruleStr` agree byte for byte).** The Rust doc comment on `rules_tsv`asserts this of `OOCert.HornParse.ruleStr`. It matters because the JSON report publishes a SHA-256of the Rust rendering, and `oo-horn` decides `entailed` against `entailed_under_supplied_rules` by@@ -288,7 +301,7 @@ of the code with nothing checking it. Nothing here is unbounded-verified, and a| TCB-15, TCB-16, TCB-17 | property | `src/reason.rs` unit property tests | the interner is private || TCB-18 | **enforced** + property | in the code, and proptest | the engine re-parses what it wrote and refuses on mismatch || TCB-19, TCB-21 | property | proptest, plus the REAL checker | property against a transcription of `OOCert.HornParse` in the test file, because a Lean process per case is not a property test. The transcription's fidelity is then an assumption, so one deterministic test puts the adversarial shapes (a numeric rule name, a non-ASCII one, a `??x` variable, a literal spelled exactly like an IRI as a constant, a blank node, an empty-bodied rule) through `oo-horn check` itself and requires the conditional verdict |-| TCB-20 | **proved** + property | `kani_harnesses::pat_of_and_render_are_inverse_at_2` and `_at_3`, proptest | `pat_of` and `Pat::render` are inverse over every byte pattern at two and three bytes. This is the harness the previous version of this page reported as NOT TERMINATING |+| TCB-20 | **proved** at a bound + property, and **proved unbounded of a MODEL** | `kani_harnesses::pat_of_and_render_are_inverse_at_2` and `_at_3`, proptest, `dafny/RuleTable.dfy` | `pat_of` and `Pat::render` are inverse over every byte pattern at two and three bytes. This is the harness the previous version of this page reported as NOT TERMINATING. The WHOLE-LINE statement, which Kani cannot afford because asserting over `body.split('\t')` puts CBMC inside `CharSearcher`, is proved with no length bound and no field-count bound in Dafny, OF A REIMPLEMENTATION AND NOT OF THIS RUST. That distinction is the whole of decision 0014 and the row means nothing without it || TCB-22 | property | proptest | the rule index is a position in a list rendered in the same order, and no rendered line is empty || TCB-23, TCB-24 | property | proptest | the substitution is re-applied from `rules.tsv` independently of the engine || TCB-25 | **enforced** + property | `name_is_safe`, `src/tableaux.rs` unit property tests | the emitter refuses; `concept_string` token counts and `axiom_line` field counts are sampled |@@ -475,6 +488,15 @@ trusted base by a wide margin, and the omission is recorded here rather than qui`pat_of`/`render` are proved inverse, so what is left is exactly the cross-language half.*To close it:* generate both parsers from one grammar, or verify the Rust one against the Leanone as a refinement. Neither was done here.+ The FIRST of those was costed on 18 September 2026 rather than left as a suggestion, and the+ number is discouraging. Dafny is the obvious candidate, since it verifies and then compiles, and+ `dafny/RuleTable.dfy` proves the grammar's round trip unbounded in seven seconds. Compiling that+ model to Rust emits 872 lines that call into a `dafny_runtime` of 8,590 lines, with `num`'s+ bignums behind it, and its entry point takes a `Sequence<u8>` and returns an+ `Rc<Option<Rc<Pat>>>`, so reaching it from `src/reason.rs` needs an unverified marshalling layer+ at the exact boundary the exercise exists to shrink. It generates one of the two parsers and not+ the other, because there is no Lean backend, so it does not answer the cross-language question at+ all. Decision 0014 has the measurements.4. **TCB-8 under `InferenceTarget::DefaultGraph`.** Merging conclusions into the default graph iswhat the caller asked for and it loses the distinction; a later certified run over that store isconditional on a graph that includes inferences. The named-graph path no longer has this problem.