Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

aeneas: prove the certificate boundary unbounded, and record what that costs (#154)

Fabio Rovai90efc85124fa
diff --git a/README.md b/README.md
index f8cb8c4a..4068c3a0 100644
--- a/README.md
+++ b/README.md
@@ -278,7 +278,7 @@ Every line above is worth less if this section is missing, so it is here rather
nobody opens. These are the load-bearing limits, and none of them is hypothetical.
**The Rust engine is not verified.** The theorems are conditional on it reporting the run
-faithfully. That boundary is twenty-nine properties: `make verify` bounded-model-checks six, and
+faithfully. That boundary is thirty properties: `make verify` bounded-model-checks six, and
five are enforced by the engine rather than observed of a dependency, two properties being in both
counts. Two are irreducible, because they are about an execution and not a function: that
`asserted.tsv` is the graph reasoned over, and that `derivations.tsv` covers every triple added.
@@ -468,6 +468,7 @@ a Protégé-style inspector. No JVM. No Protégé.
| Derivation certificates and the Lean checkers | [docs/lean-certificates.md](docs/lean-certificates.md) |
| Which axioms a conclusion rests on, and provenance semirings | [docs/explanation.md](docs/explanation.md) |
| What the Lean proofs assume about the Rust | [docs/trusted-computing-base.md](docs/trusted-computing-base.md) |
+| Aeneas at the Rust/Lean boundary: what it proves, and what it costs | [docs/aeneas-boundary.md](docs/aeneas-boundary.md) |
| Which gates a green CI tick actually ran | [docs/ci-gates.md](docs/ci-gates.md) |
| First-order export, TPTP and Common Logic | [docs/first-order-export.md](docs/first-order-export.md) |
| Every reasoning system, and why each was used or refused | [docs/reasoning-systems-inventory.md](docs/reasoning-systems-inventory.md) |
diff --git a/aeneas/.gitignore b/aeneas/.gitignore
new file mode 100644
index 00000000..4203e50f
--- /dev/null
+++ b/aeneas/.gitignore
@@ -0,0 +1 @@
+/.toolchain/
diff --git a/aeneas/lean/.gitignore b/aeneas/lean/.gitignore
new file mode 100644
index 00000000..4080d07d
--- /dev/null
+++ b/aeneas/lean/.gitignore
@@ -0,0 +1 @@
+/.lake/
diff --git a/aeneas/lean/OOBoundary.lean b/aeneas/lean/OOBoundary.lean
new file mode 100644
index 00000000..f263570d
--- /dev/null
+++ b/aeneas/lean/OOBoundary.lean
@@ -0,0 +1,4 @@
+import OOBoundary.Generated
+import OOBoundary.Spec
+import OOBoundary.Proofs
+import OOBoundary.Axioms
diff --git a/aeneas/lean/OOBoundary/Axioms.lean b/aeneas/lean/OOBoundary/Axioms.lean
new file mode 100644
index 00000000..0874f13b
--- /dev/null
+++ b/aeneas/lean/OOBoundary/Axioms.lean
@@ -0,0 +1,76 @@
+import OOBoundary.Proofs
+
+/-!
+# The axiom footprint of this workspace, measured rather than assumed
+
+`lean/` pins every headline theorem to `[propext, Classical.choice, Quot.sound]`
+with a `#guard_msgs`-checked `#print axioms`, and the pin has no exceptions.
+This directory is a DIFFERENT workspace on a different Lean with Mathlib and
+eight more packages behind it, so its footprint is its own question and is
+answered here rather than assumed to be the same.
+
+Every line below is checked by `#guard_msgs`, so a change in what these theorems
+rest on breaks `lake build` in this directory instead of quietly widening the
+trust surface. `docs/aeneas-boundary.md` reproduces the result and says what it
+does and does not mean.
+-/
+
+namespace OOBoundary
+
+/-- info: 'OOBoundary.starts_with_byte_eq' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms starts_with_byte_eq
+
+/-- info: 'OOBoundary.writable_triple_bytes_eq' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms writable_triple_bytes_eq
+
+/-- info: 'OOBoundary.field_fits_the_format_eq' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms field_fits_the_format_eq
+
+/-- info: 'OOBoundary.field_fits_the_format_iff' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms field_fits_the_format_iff
+
+/-- info: 'OOBoundary.name_is_safe_bytes_eq' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms name_is_safe_bytes_eq
+
+/-- info: 'OOBoundary.name_is_safe_bytes_iff' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms name_is_safe_bytes_iff
+
+/-- info: 'OOBoundary.term_fits_the_format_eq' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms term_fits_the_format_eq
+
+/-- info: 'OOBoundary.push_asserted_line_bytes_ok' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms push_asserted_line_bytes_ok
+
+/-- info: 'OOBoundary.push_triple_fields_bytes_ok' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms push_triple_fields_bytes_ok
+
+/-- info: 'OOBoundary.push_asserted_line_bytes_refuses' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms push_asserted_line_bytes_refuses
+
+/-- info: 'OOBoundary.push_triple_fields_bytes_refuses' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms push_triple_fields_bytes_refuses
+
+/-- info: 'OOBoundary.asserted_line_reads_back' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms asserted_line_reads_back
+
+/-- info: 'OOBoundary.triple_fields_adds_exactly_three_fields' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms triple_fields_adds_exactly_three_fields
+
+/-- info: 'OOBoundary.triple_fields_are_the_three_terms' depends on axioms: [propext, Classical.choice, Quot.sound] -/
+#guard_msgs in
+#print axioms triple_fields_are_the_three_terms
+
+end OOBoundary
diff --git a/aeneas/lean/OOBoundary/Generated.lean b/aeneas/lean/OOBoundary/Generated.lean
new file mode 100644
index 00000000..57703d6e
--- /dev/null
+++ b/aeneas/lean/OOBoundary/Generated.lean
@@ -0,0 +1,311 @@
+-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS
+-- [oo_boundary]
+import Aeneas
+open Aeneas Aeneas.Std Result ControlFlow Error
+set_option linter.dupNamespace false
+set_option linter.hashCommand false
+set_option linter.unusedVariables false
+set_option linter.style.whitespace false
+set_option linter.style.setOption false
+set_option linter.style.longLine false
+
+/- You can set the `maxHeartbeats` value with the `-max-heartbeats` CLI option -/
+set_option maxHeartbeats 1000000
+
+/- You can set the `maxRecDepth` value with the `-max-recdepth` CLI option -/
+set_option maxRecDepth 2048
+
+namespace OOBoundary
+
+/-- [oo_boundary::boundary_core::Position]
+ Source: 'src/../../../src/boundary_core.rs', lines 33:0-37:1
+ Visibility: public -/
+@[discriminant isize]
+inductive boundary_core.Position where
+| Subject : boundary_core.Position
+| Predicate : boundary_core.Position
+| Object : boundary_core.Position
+
+/-- [oo_boundary::boundary_core::{impl core::clone::Clone for oo_boundary::boundary_core::Position}::clone]:
+ Source: 'src/../../../src/boundary_core.rs', lines 32:9-32:14
+ Visibility: public -/
+def boundary_core.Position.Insts.CoreCloneClone.clone
+ (self : boundary_core.Position) : Result boundary_core.Position := do
+ ok self
+
+/-- Trait implementation: [oo_boundary::boundary_core::{impl core::clone::Clone for oo_boundary::boundary_core::Position}]
+ Source: 'src/../../../src/boundary_core.rs', lines 32:9-32:14 -/
+@[reducible]
+def boundary_core.Position.Insts.CoreCloneClone : core.clone.Clone
+ boundary_core.Position := {
+ clone := boundary_core.Position.Insts.CoreCloneClone.clone
+}
+
+/-- Trait implementation: [oo_boundary::boundary_core::{impl core::marker::Copy for oo_boundary::boundary_core::Position}]
+ Source: 'src/../../../src/boundary_core.rs', lines 32:16-32:20 -/
+@[reducible]
+def boundary_core.Position.Insts.CoreMarkerCopy : core.marker.Copy
+ boundary_core.Position := {
+ cloneInst := boundary_core.Position.Insts.CoreCloneClone
+}
+
+/-- [oo_boundary::boundary_core::{impl core::fmt::Debug for oo_boundary::boundary_core::Position}::fmt]:
+ Source: 'src/../../../src/boundary_core.rs', lines 32:22-32:27
+ Visibility: public -/
+def boundary_core.Position.Insts.CoreFmtDebug.fmt
+ (self : boundary_core.Position) (f : core.fmt.Formatter) :
+ Result ((core.result.Result Unit core.fmt.Error) × core.fmt.Formatter)
+ := do
+ match self with
+ | boundary_core.Position.Subject =>
+ core.fmt.Formatter.write_str f (toStr "Subject")
+ | boundary_core.Position.Predicate =>
+ core.fmt.Formatter.write_str f (toStr "Predicate")
+ | boundary_core.Position.Object =>
+ core.fmt.Formatter.write_str f (toStr "Object")
+
+/-- Trait implementation: [oo_boundary::boundary_core::{impl core::fmt::Debug for oo_boundary::boundary_core::Position}]
+ Source: 'src/../../../src/boundary_core.rs', lines 32:22-32:27 -/
+@[reducible]
+def boundary_core.Position.Insts.CoreFmtDebug : core.fmt.Debug
+ boundary_core.Position := {
+ fmt := boundary_core.Position.Insts.CoreFmtDebug.fmt
+}
+
+/-- Trait implementation: [oo_boundary::boundary_core::{impl core::marker::StructuralPartialEq for oo_boundary::boundary_core::Position}]
+ Source: 'src/../../../src/boundary_core.rs', lines 32:29-32:38 -/
+@[reducible]
+def boundary_core.Position.Insts.CoreMarkerStructuralPartialEq :
+ core.marker.StructuralPartialEq boundary_core.Position := {
+}
+
+/-- [oo_boundary::boundary_core::{impl core::cmp::PartialEq<oo_boundary::boundary_core::Position> for oo_boundary::boundary_core::Position}::eq]:
+ Source: 'src/../../../src/boundary_core.rs', lines 32:29-32:38
+ Visibility: public -/
+def boundary_core.Position.Insts.CoreCmpPartialEqPosition.eq
+ (self : boundary_core.Position) (other : boundary_core.Position) :
+ Result Bool
+ := do
+ let self1 := read_discriminant self
+ let other1 := read_discriminant other
+ ok (self1 = other1)
+
+/-- Trait implementation: [oo_boundary::boundary_core::{impl core::cmp::PartialEq<oo_boundary::boundary_core::Position> for oo_boundary::boundary_core::Position}]
+ Source: 'src/../../../src/boundary_core.rs', lines 32:29-32:38 -/
+@[reducible]
+def boundary_core.Position.Insts.CoreCmpPartialEqPosition : core.cmp.PartialEq
+ boundary_core.Position boundary_core.Position := {
+ eq := boundary_core.Position.Insts.CoreCmpPartialEqPosition.eq
+}
+
+/-- [oo_boundary::boundary_core::{impl core::cmp::Eq for oo_boundary::boundary_core::Position}::assert_fields_are_eq]:
+ Source: 'src/../../../src/boundary_core.rs', lines 32:40-32:42
+ Visibility: public -/
+def boundary_core.Position.Insts.CoreCmpEq.assert_fields_are_eq
+ (self : boundary_core.Position) : Result Unit := do
+ ok ()
+
+/-- Trait implementation: [oo_boundary::boundary_core::{impl core::cmp::Eq for oo_boundary::boundary_core::Position}]
+ Source: 'src/../../../src/boundary_core.rs', lines 32:40-32:42 -/
+@[reducible]
+def boundary_core.Position.Insts.CoreCmpEq : core.cmp.Eq boundary_core.Position
+ := {
+ partialEqInst := boundary_core.Position.Insts.CoreCmpPartialEqPosition
+ assert_fields_are_eq :=
+ boundary_core.Position.Insts.CoreCmpEq.assert_fields_are_eq
+}
+
+/-- [oo_boundary::boundary_core::starts_with_byte]:
+ Source: 'src/../../../src/boundary_core.rs', lines 58:0-60:1
+ Visibility: public -/
+def boundary_core.starts_with_byte
+ (s : Slice Std.U8) (b : Std.U8) : Result Bool := do
+ let b1 ← core.slice.Slice.is_empty s
+ if b1
+ then ok false
+ else let i ← Slice.index_usize s 0#usize
+ ok (i = b)
+
+/-- [oo_boundary::boundary_core::writable_triple_bytes]:
+ Source: 'src/../../../src/boundary_core.rs', lines 53:0-55:1
+ Visibility: public -/
+def boundary_core.writable_triple_bytes
+ (subject : Slice Std.U8) (predicate : Slice Std.U8) : Result Bool := do
+ let b ← boundary_core.starts_with_byte subject 34#u8
+ if b
+ then ok false
+ else boundary_core.starts_with_byte predicate 60#u8
+
+/-- [oo_boundary::boundary_core::field_fits_the_format]: loop body 0:
+ Source: 'src/../../../src/boundary_core.rs', lines 72:4-79:1
+ Visibility: public -/
+@[rust_loop_body]
+def boundary_core.field_fits_the_format_loop.body
+ (f : Slice Std.U8) (i : Std.Usize) :
+ Result (ControlFlow Std.Usize Bool)
+ := do
+ let i1 := Slice.len f
+ if i < i1
+ then
+ let i2 ← Slice.index_usize f i
+ if i2 = 9#u8
+ then ok (done false)
+ else
+ if i2 = 10#u8
+ then ok (done false)
+ else
+ if i2 = 13#u8
+ then ok (done false)
+ else let i3 ← i + 1#usize
+ ok (cont i3)
+ else ok (done true)
+
+/-- [oo_boundary::boundary_core::field_fits_the_format]: loop 0:
+ Source: 'src/../../../src/boundary_core.rs', lines 72:4-79:1
+ Visibility: public -/
+@[rust_loop]
+def boundary_core.field_fits_the_format_loop
+ (f : Slice Std.U8) (i : Std.Usize) : Result Bool := do
+ loop
+ (fun i1 => boundary_core.field_fits_the_format_loop.body f i1)
+ i
+
+/-- [oo_boundary::boundary_core::field_fits_the_format]:
+ Source: 'src/../../../src/boundary_core.rs', lines 67:0-79:1
+ Visibility: public -/
+def boundary_core.field_fits_the_format (f : Slice Std.U8) : Result Bool := do
+ let b ← core.slice.Slice.is_empty f
+ if b
+ then ok false
+ else boundary_core.field_fits_the_format_loop f 0#usize
+
+/-- [oo_boundary::boundary_core::term_fits_the_format]:
+ Source: 'src/../../../src/boundary_core.rs', lines 85:0-90:1
+ Visibility: public -/
+def boundary_core.term_fits_the_format (t : Slice Std.U8) : Result Bool := do
+ let b ← boundary_core.field_fits_the_format t
+ if b
+ then
+ let i ← Slice.index_usize t 0#usize
+ if i = 60#u8
+ then ok true
+ else
+ if i = 34#u8
+ then ok true
+ else
+ if i = 95#u8
+ then
+ let i1 := Slice.len t
+ if i1 > 1#usize
+ then let i2 ← Slice.index_usize t 1#usize
+ ok (i2 = 58#u8)
+ else ok false
+ else ok false
+ else ok false
+
+/-- [oo_boundary::boundary_core::name_is_safe_bytes]: loop body 0:
+ Source: 'src/../../../src/boundary_core.rs', lines 104:4-111:1
+ Visibility: public -/
+@[rust_loop_body]
+def boundary_core.name_is_safe_bytes_loop.body
+ («name» : Slice Std.U8) (i : Std.Usize) :
+ Result (ControlFlow Std.Usize Bool)
+ := do
+ let i1 := Slice.len «name»
+ if i < i1
+ then
+ let i2 ← Slice.index_usize «name» i
+ if i2 = 32#u8
+ then ok (done false)
+ else
+ if i2 = 9#u8
+ then ok (done false)
+ else
+ if i2 = 10#u8
+ then ok (done false)
+ else
+ if i2 = 13#u8
+ then ok (done false)
+ else let i3 ← i + 1#usize
+ ok (cont i3)
+ else ok (done true)
+
+/-- [oo_boundary::boundary_core::name_is_safe_bytes]: loop 0:
+ Source: 'src/../../../src/boundary_core.rs', lines 104:4-111:1
+ Visibility: public -/
+@[rust_loop]
+def boundary_core.name_is_safe_bytes_loop
+ («name» : Slice Std.U8) (i : Std.Usize) : Result Bool := do
+ loop
+ (fun i1 => boundary_core.name_is_safe_bytes_loop.body «name» i1)
+ i
+
+/-- [oo_boundary::boundary_core::name_is_safe_bytes]:
+ Source: 'src/../../../src/boundary_core.rs', lines 99:0-111:1
+ Visibility: public -/
+def boundary_core.name_is_safe_bytes
+ («name» : Slice Std.U8) : Result Bool := do
+ let b ← core.slice.Slice.is_empty «name»
+ if b
+ then ok false
+ else boundary_core.name_is_safe_bytes_loop «name» 0#usize
+
+/-- [oo_boundary::boundary_core::push_asserted_line_bytes]:
+ Source: 'src/../../../src/boundary_core.rs', lines 124:0-146:1
+ Visibility: public -/
+def boundary_core.push_asserted_line_bytes
+ (out : alloc.vec.Vec Std.U8) (s : Slice Std.U8) (p : Slice Std.U8)
+ (o : Slice Std.U8) :
+ Result ((core.result.Result Unit boundary_core.Position) × (alloc.vec.Vec
+ Std.U8))
+ := do
+ let b ← boundary_core.term_fits_the_format s
+ if b
+ then
+ let b1 ← boundary_core.term_fits_the_format p
+ if b1
+ then
+ let b2 ← boundary_core.term_fits_the_format o
+ if b2
+ then
+ let out1 ← alloc.vec.Vec.extend_from_slice core.clone.CloneU8 out s
+ let out2 ← alloc.vec.Vec.push out1 9#u8
+ let out3 ← alloc.vec.Vec.extend_from_slice core.clone.CloneU8 out2 p
+ let out4 ← alloc.vec.Vec.push out3 9#u8
+ let out5 ← alloc.vec.Vec.extend_from_slice core.clone.CloneU8 out4 o
+ let out6 ← alloc.vec.Vec.push out5 10#u8
+ ok (core.result.Result.Ok (), out6)
+ else ok (core.result.Result.Err boundary_core.Position.Object, out)
+ else ok (core.result.Result.Err boundary_core.Position.Predicate, out)
+ else ok (core.result.Result.Err boundary_core.Position.Subject, out)
+
+/-- [oo_boundary::boundary_core::push_triple_fields_bytes]:
+ Source: 'src/../../../src/boundary_core.rs', lines 151:0-173:1
+ Visibility: public -/
+def boundary_core.push_triple_fields_bytes
+ (out : alloc.vec.Vec Std.U8) (s : Slice Std.U8) (p : Slice Std.U8)
+ (o : Slice Std.U8) :
+ Result ((core.result.Result Unit boundary_core.Position) × (alloc.vec.Vec
+ Std.U8))
+ := do
+ let b ← boundary_core.term_fits_the_format s
+ if b
+ then
+ let b1 ← boundary_core.term_fits_the_format p
+ if b1
+ then
+ let b2 ← boundary_core.term_fits_the_format o
+ if b2
+ then
+ let out1 ← alloc.vec.Vec.push out 9#u8
+ let out2 ← alloc.vec.Vec.extend_from_slice core.clone.CloneU8 out1 s
+ let out3 ← alloc.vec.Vec.push out2 9#u8
+ let out4 ← alloc.vec.Vec.extend_from_slice core.clone.CloneU8 out3 p
+ let out5 ← alloc.vec.Vec.push out4 9#u8
+ let out6 ← alloc.vec.Vec.extend_from_slice core.clone.CloneU8 out5 o
+ ok (core.result.Result.Ok (), out6)
+ else ok (core.result.Result.Err boundary_core.Position.Object, out)
+ else ok (core.result.Result.Err boundary_core.Position.Predicate, out)
+ else ok (core.result.Result.Err boundary_core.Position.Subject, out)
+
+end OOBoundary
diff --git a/aeneas/lean/OOBoundary/Proofs.lean b/aeneas/lean/OOBoundary/Proofs.lean
new file mode 100644
index 00000000..8feb2295
--- /dev/null
+++ b/aeneas/lean/OOBoundary/Proofs.lean
@@ -0,0 +1,621 @@
+import OOBoundary.Spec
+
+/-!
+# The boundary functions do what the certificate format needs
+
+Every theorem here is about `OOBoundary.boundary_core.*`, which is Aeneas's
+translation of `src/boundary_core.rs`, and every one is stated for EVERY input.
+That is the only reason this directory exists.
+`tests/certificate_boundary_proptest.rs` samples these properties and the Kani
+harnesses in `src/reason.rs` prove several of them for every byte pattern at a
+term length of at most four bytes. Nothing below has a length bound
+and nothing below has a shape bound.
+
+The decision procedures are stated as equations `f x = ok (spec x)` rather than
+as Hoare triples. An equation says three things at once where a triple says one:
+the model never fails, it never diverges, and its result is the specification.
+For a function whose whole job is to decide whether a byte string is safe to
+write, "it returns the right answer and it always returns" is the claim worth
+making.
+
+The proof style is deliberately explicit. The first attempt drove the loop
+inductions with large `simp` calls and they either failed to fire or ran out of
+steps inside the `partial_fixpoint` unfolding of `loop`. What works is to prove
+one equation per BODY outcome first, with no `loop` in sight, and then let the
+induction rewrite with those. It is more lines and it is predictable.
+-/
+
+-- `autoImplicit` turns a typo into a universe-polymorphic variable and the
+-- error into a puzzle three screens away. It also hid, for one build, the fact
+-- that `ok` was not in scope.
+set_option autoImplicit false
+
+-- The generated file sets these too, and the setting is file-local. The loop
+-- inductions rewrite under a `partial_fixpoint` unfolding, which is what needs
+-- the depth.
+set_option maxRecDepth 40000
+set_option maxHeartbeats 1000000
+
+namespace OOBoundary
+
+open Aeneas Aeneas.Std Result ControlFlow Error OOBoundary.Spec
+
+/-! ## The leading-byte tests -/
+
+/-- `starts_with_byte` is the head of the list, on EVERY input including the
+empty one. The empty case is the one the bounded harness cannot reach:
+`writable_triple_decides_both_positions` fixes both terms at four bytes, so it
+never evaluates this function on an empty slice at all. -/
+theorem starts_with_byte_eq (s : Slice U8) (b : U8) :
+ boundary_core.starts_with_byte s b = ok (decide (s.val[0]? = some b)) := by
+ unfold boundary_core.starts_with_byte
+ cases hs : s.val with
+ | nil => simp [core.slice.Slice.is_empty, Slice.length, hs]
+ | cons x xs =>
+ have hne : ¬ (s.length = 0) := by simp [Slice.length, hs]
+ have hidx : Slice.index_usize s 0#usize = ok x := by
+ simp [Slice.index_usize, hs]
+ simp [core.slice.Slice.is_empty, hidx, hs]
+
+/-- The guard that closed the unwritable-conclusion defect decides both
+positions for terms of EVERY length, the empty term included.
+`writable_triple_decides_both_positions` (Kani) proves this at exactly four
+bytes per term; this is the same statement with the bound removed.
+
+Note what it says about an EMPTY subject: `"".starts_with('"')` is false, so an
+empty subject passes. That is not a hole, because `term_fits_the_format` refuses
+an empty term and every certificate path runs both guards, but it is exactly the
+kind of edge a fixed-length model check cannot see. -/
+theorem writable_triple_bytes_eq (subject predicate : Slice U8) :
+ boundary_core.writable_triple_bytes subject predicate
+ = ok (writableTriple subject.val predicate.val) := by
+ unfold boundary_core.writable_triple_bytes writableTriple
+ simp only [starts_with_byte_eq]
+ by_cases h : subject.val[0]? = some 34#u8 <;> simp [h]
+
+/-! ## The separator scans
+
+Two loops and two inductions, and the inductions are the whole content. A
+property test draws a few hundred byte strings and a Kani harness fixes the
+length; these cover every list of bytes there is. -/
+
+section FieldScan
+
+private theorem field_body_end (f : Slice U8) (i : Usize) (hge : f.val.length ≤ i.val) :
+ boundary_core.field_fits_the_format_loop.body f i = ok (done true) := by
+ unfold boundary_core.field_fits_the_format_loop.body
+ have hcmp : ¬ (i < Slice.len f) := by simp only [Slice.len]; scalar_tac
+ rw [if_neg hcmp]
+
+private theorem field_body_sep (f : Slice U8) (i : Usize) (hlt : i.val < f.val.length)
+ (hsep : isTsvSeparator f.val[i.val] = true) :
+ boundary_core.field_fits_the_format_loop.body f i = ok (done false) := by
+ unfold boundary_core.field_fits_the_format_loop.body
+ have hcmp : (i < Slice.len f) := by simp only [Slice.len]; scalar_tac
+ obtain ⟨xi, hidx, hxi⟩ :=
+ WP.spec_imp_exists (Slice.index_usize_spec f i (by scalar_tac))
+ rw [← hxi] at hsep
+ unfold isTsvSeparator at hsep
+ simp only [Bool.or_eq_true, decide_eq_true_eq] at hsep
+ have hcases : xi = 9#u8 ∨ xi = 10#u8 ∨ xi = 13#u8 := by tauto
+ rcases hcases with h | h | h <;> simp [hcmp, hidx, h]
+
+private theorem field_body_step (f : Slice U8) (i : Usize) (hlt : i.val < f.val.length)
+ (hsep : isTsvSeparator f.val[i.val] = false) :
+ ∃ j : Usize, j.val = i.val + 1
+ ∧ boundary_core.field_fits_the_format_loop.body f i = ok (cont j) := by
+ unfold boundary_core.field_fits_the_format_loop.body
+ have hcmp : (i < Slice.len f) := by simp only [Slice.len]; scalar_tac
+ obtain ⟨xi, hidx, hxi⟩ :=
+ WP.spec_imp_exists (Slice.index_usize_spec f i (by scalar_tac))
+ rw [← hxi] at hsep
+ have hmax : i.val + (1#usize).val ≤ Usize.max := by
+ have hb := f.property; scalar_tac
+ obtain ⟨j, hj, hjv⟩ := WP.spec_imp_exists (Usize.add_spec (x := i) (y := 1#usize) hmax)
+ refine ⟨j, by simpa using hjv, ?_⟩
+ unfold isTsvSeparator at hsep
+ simp only [Bool.or_eq_false_iff, decide_eq_false_iff_not] at hsep
+ obtain ⟨⟨h9, h10⟩, h13⟩ := hsep
+ simp [hcmp, hidx, h9, h10, h13, hj]
+
+private theorem field_loop_eq (f : Slice U8) :
+ ∀ (k : Nat) (i : Usize), f.val.length - i.val ≤ k →
+ boundary_core.field_fits_the_format_loop f i
+ = ok ((f.val.drop i.val).all (fun b => !isTsvSeparator b)) := by
+ intro k
+ induction k with
+ | zero =>
+ intro i hk
+ have hge : f.val.length ≤ i.val := by omega
+ unfold boundary_core.field_fits_the_format_loop
+ rw [loop]
+ simp only [field_body_end f i hge, bind_ok]
+ rw [List.drop_eq_nil_of_le hge]
+ simp
+ | succ k ih =>
+ intro i hk
+ by_cases hlt : i.val < f.val.length
+ · have hdrop : f.val.drop i.val = f.val[i.val] :: f.val.drop (i.val + 1) :=
+ List.drop_eq_getElem_cons hlt
+ by_cases hsep : isTsvSeparator f.val[i.val] = true
+ · unfold boundary_core.field_fits_the_format_loop
+ rw [loop]
+ simp only [field_body_sep f i hlt hsep, bind_ok, hdrop, List.all_cons, hsep,
+ Bool.not_true, Bool.false_and]
+ · simp only [Bool.not_eq_true] at hsep
+ obtain ⟨j, hjv, hbody⟩ := field_body_step f i hlt hsep
+ have hrec := ih j (by omega)
+ unfold boundary_core.field_fits_the_format_loop at hrec ⊢
+ rw [loop]
+ simp only [hbody, bind_ok, hrec, hjv, hdrop, List.all_cons, hsep,
+ Bool.not_false, Bool.true_and]
+ · have hge : f.val.length ≤ i.val := by omega
+ unfold boundary_core.field_fits_the_format_loop
+ rw [loop]
+ simp only [field_body_end f i hge, bind_ok]
+ rw [List.drop_eq_nil_of_le hge]
+ simp
+
+end FieldScan
+
+/-- TCB-4, unbounded: the format half of the term guard accepts a field IF AND
+ONLY IF it is non-empty and carries no tab, line feed or carriage return. -/
+theorem field_fits_the_format_eq (f : Slice U8) :
+ boundary_core.field_fits_the_format f = ok (fieldFits f.val) := by
+ unfold boundary_core.field_fits_the_format fieldFits
+ cases hf : f.val with
+ | nil => simp [core.slice.Slice.is_empty, Slice.length, hf]
+ | cons x xs =>
+ have hne : ¬ (f.length = 0) := by simp [Slice.length, hf]
+ have hloop := field_loop_eq f f.val.length 0#usize (by simp)
+ simp [core.slice.Slice.is_empty, hloop, hf]
+
+/-- The `iff` form, which is what "accepts exactly the fields that survive the
+format" means, and what the property test can only sample. -/
+theorem field_fits_the_format_iff (f : Slice U8) :
+ boundary_core.field_fits_the_format f = ok true
+ ↔ (f.val ≠ [] ∧ ∀ b ∈ f.val, b ≠ 9#u8 ∧ b ≠ 10#u8 ∧ b ≠ 13#u8) := by
+ rw [field_fits_the_format_eq, Result.ok.injEq]
+ constructor
+ · intro hb
+ unfold fieldFits at hb
+ simp only [Bool.and_eq_true, Bool.not_eq_true', List.isEmpty_eq_false_iff,
+ List.all_eq_true] at hb
+ obtain ⟨hne, hall⟩ := hb
+ refine ⟨hne, fun b hbm => ?_⟩
+ have := hall b hbm
+ simp only [isTsvSeparator, Bool.or_eq_false_iff,
+ decide_eq_false_iff_not] at this
+ exact ⟨this.1.1, this.1.2, this.2⟩
+ · rintro ⟨hne, hall⟩
+ have : fieldFits f.val = true := by
+ unfold fieldFits
+ simp only [Bool.and_eq_true, Bool.not_eq_true', List.isEmpty_eq_false_iff,
+ List.all_eq_true]
+ refine ⟨hne, fun b hbm => ?_⟩
+ obtain ⟨h9, h10, h13⟩ := hall b hbm
+ simp [isTsvSeparator, h9, h10, h13]
+ rw [this]
+
+section NameScan
+
+private theorem name_body_end (f : Slice U8) (i : Usize) (hge : f.val.length ≤ i.val) :
+ boundary_core.name_is_safe_bytes_loop.body f i = ok (done true) := by
+ unfold boundary_core.name_is_safe_bytes_loop.body
+ have hcmp : ¬ (i < Slice.len f) := by simp only [Slice.len]; scalar_tac
+ rw [if_neg hcmp]
+
+private theorem name_body_sep (f : Slice U8) (i : Usize) (hlt : i.val < f.val.length)
+ (hsep : isDlSeparator f.val[i.val] = true) :
+ boundary_core.name_is_safe_bytes_loop.body f i = ok (done false) := by
+ unfold boundary_core.name_is_safe_bytes_loop.body
+ have hcmp : (i < Slice.len f) := by simp only [Slice.len]; scalar_tac
+ obtain ⟨xi, hidx, hxi⟩ :=
+ WP.spec_imp_exists (Slice.index_usize_spec f i (by scalar_tac))
+ rw [← hxi] at hsep
+ unfold isDlSeparator isTsvSeparator at hsep
+ simp only [Bool.or_eq_true, decide_eq_true_eq] at hsep
+ have hcases : xi = 32#u8 ∨ xi = 9#u8 ∨ xi = 10#u8 ∨ xi = 13#u8 := by tauto
+ rcases hcases with h | h | h | h <;> simp [hcmp, hidx, h]
+
+private theorem name_body_step (f : Slice U8) (i : Usize) (hlt : i.val < f.val.length)
+ (hsep : isDlSeparator f.val[i.val] = false) :
+ ∃ j : Usize, j.val = i.val + 1
+ ∧ boundary_core.name_is_safe_bytes_loop.body f i = ok (cont j) := by
+ unfold boundary_core.name_is_safe_bytes_loop.body
+ have hcmp : (i < Slice.len f) := by simp only [Slice.len]; scalar_tac
+ obtain ⟨xi, hidx, hxi⟩ :=
+ WP.spec_imp_exists (Slice.index_usize_spec f i (by scalar_tac))
+ rw [← hxi] at hsep
+ have hmax : i.val + (1#usize).val ≤ Usize.max := by
+ have hb := f.property; scalar_tac
+ obtain ⟨j, hj, hjv⟩ := WP.spec_imp_exists (Usize.add_spec (x := i) (y := 1#usize) hmax)
+ refine ⟨j, by simpa using hjv, ?_⟩
+ unfold isDlSeparator isTsvSeparator at hsep
+ simp only [Bool.or_eq_false_iff, decide_eq_false_iff_not] at hsep
+ obtain ⟨h32, ⟨h9, h10⟩, h13⟩ := hsep
+ simp [hcmp, hidx, h32, h9, h10, h13, hj]
+
+private theorem name_loop_eq (f : Slice U8) :
+ ∀ (k : Nat) (i : Usize), f.val.length - i.val ≤ k →
+ boundary_core.name_is_safe_bytes_loop f i
+ = ok ((f.val.drop i.val).all (fun b => !isDlSeparator b)) := by
+ intro k
+ induction k with
+ | zero =>
+ intro i hk
+ have hge : f.val.length ≤ i.val := by omega
+ unfold boundary_core.name_is_safe_bytes_loop
+ rw [loop]
+ simp only [name_body_end f i hge, bind_ok]
+ rw [List.drop_eq_nil_of_le hge]
+ simp
+ | succ k ih =>
+ intro i hk
+ by_cases hlt : i.val < f.val.length
+ · have hdrop : f.val.drop i.val = f.val[i.val] :: f.val.drop (i.val + 1) :=
+ List.drop_eq_getElem_cons hlt
+ by_cases hsep : isDlSeparator f.val[i.val] = true
+ · unfold boundary_core.name_is_safe_bytes_loop
+ rw [loop]
+ simp only [name_body_sep f i hlt hsep, bind_ok, hdrop, List.all_cons, hsep,
+ Bool.not_true, Bool.false_and]
+ · simp only [Bool.not_eq_true] at hsep
+ obtain ⟨j, hjv, hbody⟩ := name_body_step f i hlt hsep
+ have hrec := ih j (by omega)
+ unfold boundary_core.name_is_safe_bytes_loop at hrec ⊢
+ rw [loop]
+ simp only [hbody, bind_ok, hrec, hjv, hdrop, List.all_cons, hsep,
+ Bool.not_false, Bool.true_and]
+ · have hge : f.val.length ≤ i.val := by omega
+ unfold boundary_core.name_is_safe_bytes_loop
+ rw [loop]
+ simp only [name_body_end f i hge, bind_ok]
+ rw [List.drop_eq_nil_of_le hge]
+ simp
+
+end NameScan
+
+/-- TCB-25, unbounded. The DL certificate refuses a SPACE as well as the three
+bytes the rest of the format refuses, because `concept_string` in
+`src/tableaux.rs` is space separated inside a field that is tab separated
+outside it. -/
+theorem name_is_safe_bytes_eq (n : Slice U8) :
+ boundary_core.name_is_safe_bytes n = ok (nameIsSafe n.val) := by
+ unfold boundary_core.name_is_safe_bytes nameIsSafe
+ cases hn : n.val with
+ | nil => simp [core.slice.Slice.is_empty, Slice.length, hn]
+ | cons x xs =>
+ have hne : ¬ (n.length = 0) := by simp [Slice.length, hn]
+ have hloop := name_loop_eq n n.val.length 0#usize (by simp)
+ simp [core.slice.Slice.is_empty, hloop, hn]
+
+/-- TCB-25 as an `iff`: `name_is_safe` accepts a name IF AND ONLY IF the name is
+non-empty and contains no space, tab, line feed or carriage return. This is the
+theorem the sampled cases in `tcb_25_name_is_safe_refuses_every_separator` can
+only support. -/
+theorem name_is_safe_bytes_iff (n : Slice U8) :
+ boundary_core.name_is_safe_bytes n = ok true
+ ↔ (n.val ≠ [] ∧ ∀ b ∈ n.val, b ≠ 32#u8 ∧ b ≠ 9#u8 ∧ b ≠ 10#u8 ∧ b ≠ 13#u8) := by
+ rw [name_is_safe_bytes_eq, Result.ok.injEq]
+ constructor
+ · intro hb
+ unfold nameIsSafe at hb
+ simp only [Bool.and_eq_true, Bool.not_eq_true', List.isEmpty_eq_false_iff,
+ List.all_eq_true] at hb
+ obtain ⟨hne, hall⟩ := hb
+ refine ⟨hne, fun b hbm => ?_⟩
+ have := hall b hbm
+ simp only [isDlSeparator, isTsvSeparator, Bool.or_eq_false_iff,
+ decide_eq_false_iff_not] at this
+ exact ⟨this.1, this.2.1.1, this.2.1.2, this.2.2⟩
+ · rintro ⟨hne, hall⟩
+ have : nameIsSafe n.val = true := by
+ unfold nameIsSafe
+ simp only [Bool.and_eq_true, Bool.not_eq_true', List.isEmpty_eq_false_iff,
+ List.all_eq_true]
+ refine ⟨hne, fun b hbm => ?_⟩
+ obtain ⟨h32, h9, h10, h13⟩ := hall b hbm
+ simp [isDlSeparator, isTsvSeparator, h32, h9, h10, h13]
+ rw [this]
+
+/-! ## The term guard -/
+
+/-- TCB-4 and TCB-5 together, unbounded: a term is written IF AND ONLY IF it is
+non-empty, carries no separator, and is in one of the three N-Triples spellings.
+-/
+theorem term_fits_the_format_eq (t : Slice U8) :
+ boundary_core.term_fits_the_format t = ok (termFits t.val) := by
+ unfold boundary_core.term_fits_the_format termFits ntriplesLeadingByte
+ rw [field_fits_the_format_eq]
+ by_cases hf : fieldFits t.val = true
+ · have hpos : 0 < t.val.length := by
+ unfold fieldFits at hf
+ simp only [Bool.and_eq_true, Bool.not_eq_true', List.isEmpty_eq_false_iff] at hf
+ cases h : t.val with
+ | nil => exact absurd h hf.1
+ | cons _ _ => simp
+ obtain ⟨x0, h0, hx0⟩ :=
+ WP.spec_imp_exists (Slice.index_usize_spec t 0#usize (by scalar_tac))
+ have hg0 : t.val[0]! = x0 := by
+ rw [hx0]; simp [hpos]
+ rw [bind_tc_ok, if_pos (by simpa using hf), h0, bind_tc_ok, hf, Bool.true_and, hg0]
+ by_cases h60 : x0 = 60#u8
+ · rw [if_pos h60]; simp [h60]
+ · by_cases h34 : x0 = 34#u8
+ · rw [if_neg h60, if_pos h34]; simp [h34]
+ · by_cases h95 : x0 = 95#u8
+ · by_cases hlen : 1 < t.val.length
+ · obtain ⟨x1, h1, hx1⟩ :=
+ WP.spec_imp_exists (Slice.index_usize_spec t 1#usize (by scalar_tac))
+ have hg1 : t.val[1]! = x1 := by
+ rw [hx1]; simp [hlen]
+ have hgt : (Slice.len t > 1#usize) := by simp only [Slice.len]; scalar_tac
+ rw [if_neg h60, if_neg h34, if_pos h95, if_pos hgt, h1, bind_tc_ok]
+ simp [h95, hlen, hx1]
+ · have hgt : ¬ (Slice.len t > 1#usize) := by simp only [Slice.len]; scalar_tac
+ rw [if_neg h60, if_neg h34, if_pos h95, if_neg hgt]
+ simp [h95, hlen]
+ · rw [if_neg h60, if_neg h34, if_neg h95]
+ simp [h60, h34, h95]
+ · simp only [Bool.not_eq_true] at hf
+ rw [bind_tc_ok, if_neg (by simp [hf]), hf]
+ simp
+
+/-! ## The writers
+
+Three claims: what the buffer gains when the writer accepts, what it does NOT
+gain when the writer refuses, and what a reader splitting on the separators gets
+back. The middle one is the all-or-nothing discipline, and it is the one that
+cannot be seen by looking at the output file, because a half-line in a buffer
+looks like a whole line to everything downstream. -/
+
+private theorem clone_any (cl : U8 → Result U8) (hcl : ∀ x, cl x = ok x)
+ (s : Slice U8) : Slice.clone cl s = ok s := by
+ obtain ⟨s', he, hp⟩ :=
+ WP.spec_imp_exists (Slice.clone_spec (clone := cl) (s := s) (fun x _ => hcl x))
+ rw [he, ← hp]
+
+/-- Both spellings of the `u8` clone, because `core.clone.CloneU8` is reducible
+and the goal carries whichever one the elaborator left behind. -/
+private theorem clone_u8_inst (s : Slice U8) :
+ Slice.clone core.clone.CloneU8.clone s = ok s := clone_any _ (fun _ => rfl) s
+
+private theorem clone_u8_lifted (s : Slice U8) :
+ Slice.clone (liftFun1 core.clone.impls.CloneU8.clone) s = ok s :=
+ clone_any _ (fun _ => rfl) s
+
+private theorem extend_u8 (v : alloc.vec.Vec U8) (s : Slice U8)
+ (h : v.val.length + s.val.length ≤ Usize.max) :
+ ∃ v', alloc.vec.Vec.extend_from_slice core.clone.CloneU8 v s = ok v'
+ ∧ v'.val = v.val ++ s.val := by
+ unfold alloc.vec.Vec.extend_from_slice
+ have hd : v.length + s.length ≤ Usize.max := by
+ simpa [alloc.vec.Vec.length, Slice.length] using h
+ rw [dif_pos hd]
+ -- The `match h' : ... with` is DEPENDENT, so neither `rw` nor `simp` can
+ -- reach the discriminant. `split` can, and the equation it hands back is an
+ -- ordinary hypothesis that `rw` has no trouble with.
+ split
+ next s' heq =>
+ rw [clone_u8_lifted, Result.match.ok] at heq
+ injection heq with hs'
+ subst hs'
+ exact ⟨_, rfl, by simp⟩
+ next eff k heq =>
+ rw [clone_u8_lifted, Result.match.ok] at heq
+ simp at heq
+ next heq =>
+ rw [clone_u8_lifted, Result.match.ok] at heq
+ simp at heq
+
+private theorem push_u8 (v : alloc.vec.Vec U8) (x : U8) (h : v.val.length < Usize.max) :
+ ∃ v', alloc.vec.Vec.push v x = ok v' ∧ v'.val = v.val ++ [x] :=
+ WP.spec_imp_exists (alloc.vec.Vec.push_spec v x h)
+
+/-- When every term fits the format, the buffer gains exactly
+`s TAB p TAB o LF` and nothing else. Every length, every byte pattern.
+`asserted_line_round_trips_at_0` to `_at_4` (Kani) prove this at term lengths
+zero to four. -/
+theorem push_asserted_line_bytes_ok (out : alloc.vec.Vec U8) (s p o : Slice U8)
+ (hs : termFits s.val = true) (hp : termFits p.val = true) (ho : termFits o.val = true)
+ (hcap : out.val.length + s.val.length + p.val.length + o.val.length + 2 < Usize.max) :
+ ∃ out', boundary_core.push_asserted_line_bytes out s p o
+ = ok (core.result.Result.Ok (), out')
+ ∧ out'.val = out.val ++ assertedLine s.val p.val o.val := by
+ unfold boundary_core.push_asserted_line_bytes
+ rw [term_fits_the_format_eq, bind_tc_ok, if_pos hs,
+ term_fits_the_format_eq, bind_tc_ok, if_pos hp,
+ term_fits_the_format_eq, bind_tc_ok, if_pos ho]
+ -- `omega` cannot see through `Usize.max`, so it is never shown it: every
+ -- capacity side condition below goes through these two, and the arithmetic
+ -- `omega` does is over list lengths alone.
+ have hlt' : ∀ n : Nat,
+ n ≤ out.val.length + s.val.length + p.val.length + o.val.length + 2 → n < Usize.max :=
+ fun n hn => Nat.lt_of_le_of_lt hn hcap
+ have hle' : ∀ n : Nat,
+ n ≤ out.val.length + s.val.length + p.val.length + o.val.length + 2 → n ≤ Usize.max :=
+ fun n hn => Nat.le_of_lt (Nat.lt_of_le_of_lt hn hcap)
+ obtain ⟨v1, h1, e1⟩ := extend_u8 out s (hle' _ (by omega))
+ obtain ⟨v2, h2, e2⟩ := push_u8 v1 9#u8 (by simp only [e1, List.length_append]; exact hlt' _ (by omega))
+ obtain ⟨v3, h3, e3⟩ := extend_u8 v2 p (by simp only [e2, e1, List.length_append, List.length_cons, List.length_nil]; exact hle' _ (by omega))
+ obtain ⟨v4, h4, e4⟩ := push_u8 v3 9#u8 (by simp only [e3, e2, e1, List.length_append, List.length_cons, List.length_nil]; exact hlt' _ (by omega))
+ obtain ⟨v5, h5, e5⟩ := extend_u8 v4 o (by simp only [e4, e3, e2, e1, List.length_append, List.length_cons, List.length_nil]; exact hle' _ (by omega))
+ obtain ⟨v6, h6, e6⟩ := push_u8 v5 10#u8 (by simp only [e5, e4, e3, e2, e1, List.length_append, List.length_cons, List.length_nil]; exact hlt' _ (by omega))
+ rw [h1, bind_tc_ok, h2, bind_tc_ok, h3, bind_tc_ok, h4, bind_tc_ok, h5, bind_tc_ok,
+ h6, bind_tc_ok]
+ exact ⟨v6, rfl, by simp [assertedLine, e6, e5, e4, e3, e2, e1]⟩
+
+/-- The same for the three-fields writer. -/
+theorem push_triple_fields_bytes_ok (out : alloc.vec.Vec U8) (s p o : Slice U8)
+ (hs : termFits s.val = true) (hp : termFits p.val = true) (ho : termFits o.val = true)
+ (hcap : out.val.length + s.val.length + p.val.length + o.val.length + 3 < Usize.max) :
+ ∃ out', boundary_core.push_triple_fields_bytes out s p o
+ = ok (core.result.Result.Ok (), out')
+ ∧ out'.val = out.val ++ tripleFields s.val p.val o.val := by
+ unfold boundary_core.push_triple_fields_bytes
+ rw [term_fits_the_format_eq, bind_tc_ok, if_pos hs,
+ term_fits_the_format_eq, bind_tc_ok, if_pos hp,
+ term_fits_the_format_eq, bind_tc_ok, if_pos ho]
+ -- `omega` cannot see through `Usize.max`, so it is never shown it: every
+ -- capacity side condition below goes through these two, and the arithmetic
+ -- `omega` does is over list lengths alone.
+ have hlt' : ∀ n : Nat,
+ n ≤ out.val.length + s.val.length + p.val.length + o.val.length + 3 → n < Usize.max :=
+ fun n hn => Nat.lt_of_le_of_lt hn hcap
+ have hle' : ∀ n : Nat,
+ n ≤ out.val.length + s.val.length + p.val.length + o.val.length + 3 → n ≤ Usize.max :=
+ fun n hn => Nat.le_of_lt (Nat.lt_of_le_of_lt hn hcap)
+ obtain ⟨v1, h1, e1⟩ := push_u8 out 9#u8 (hlt' _ (by omega))
+ obtain ⟨v2, h2, e2⟩ := extend_u8 v1 s (by simp only [e1, List.length_append, List.length_cons, List.length_nil]; exact hle' _ (by omega))
+ obtain ⟨v3, h3, e3⟩ := push_u8 v2 9#u8 (by simp only [e2, e1, List.length_append, List.length_cons, List.length_nil]; exact hlt' _ (by omega))
+ obtain ⟨v4, h4, e4⟩ := extend_u8 v3 p (by simp only [e3, e2, e1, List.length_append, List.length_cons, List.length_nil]; exact hle' _ (by omega))
+ obtain ⟨v5, h5, e5⟩ := push_u8 v4 9#u8 (by simp only [e4, e3, e2, e1, List.length_append, List.length_cons, List.length_nil]; exact hlt' _ (by omega))
+ obtain ⟨v6, h6, e6⟩ := extend_u8 v5 o (by simp only [e5, e4, e3, e2, e1, List.length_append, List.length_cons, List.length_nil]; exact hle' _ (by omega))
+ rw [h1, bind_tc_ok, h2, bind_tc_ok, h3, bind_tc_ok, h4, bind_tc_ok, h5, bind_tc_ok,
+ h6, bind_tc_ok]
+ exact ⟨v6, rfl, by simp [tripleFields, e6, e5, e4, e3, e2, e1]⟩
+
+/-- All or nothing. A term that does not fit makes the writer refuse, and the
+buffer it hands back is the buffer it was given, byte for byte. No prefix of the
+line is appended before the refusal, so a refused line cannot leave a fragment
+for the next line to run into.
+
+There is no capacity hypothesis here, unlike the two above, because refusing
+allocates nothing. -/
+theorem push_asserted_line_bytes_refuses (out : alloc.vec.Vec U8) (s p o : Slice U8)
+ (h : termFits s.val = false ∨ termFits p.val = false ∨ termFits o.val = false) :
+ ∃ pos, boundary_core.push_asserted_line_bytes out s p o
+ = ok (core.result.Result.Err pos, out) := by
+ unfold boundary_core.push_asserted_line_bytes
+ rw [term_fits_the_format_eq, bind_tc_ok]
+ by_cases hs : termFits s.val = true
+ · rw [if_pos hs, term_fits_the_format_eq, bind_tc_ok]
+ by_cases hp : termFits p.val = true
+ · rw [if_pos hp, term_fits_the_format_eq, bind_tc_ok]
+ have ho : termFits o.val = false := by
+ rcases h with h | h | h
+ · rw [h] at hs; exact absurd hs (by simp)
+ · rw [h] at hp; exact absurd hp (by simp)
+ · exact h
+ rw [if_neg (by simp [ho])]
+ exact ⟨_, rfl⟩
+ · simp only [Bool.not_eq_true] at hp
+ rw [if_neg (by simp [hp])]
+ exact ⟨_, rfl⟩
+ · simp only [Bool.not_eq_true] at hs
+ rw [if_neg (by simp [hs])]
+ exact ⟨_, rfl⟩
+
+/-- The same for the three-fields writer. -/
+theorem push_triple_fields_bytes_refuses (out : alloc.vec.Vec U8) (s p o : Slice U8)
+ (h : termFits s.val = false ∨ termFits p.val = false ∨ termFits o.val = false) :
+ ∃ pos, boundary_core.push_triple_fields_bytes out s p o
+ = ok (core.result.Result.Err pos, out) := by
+ unfold boundary_core.push_triple_fields_bytes
+ rw [term_fits_the_format_eq, bind_tc_ok]
+ by_cases hs : termFits s.val = true
+ · rw [if_pos hs, term_fits_the_format_eq, bind_tc_ok]
+ by_cases hp : termFits p.val = true
+ · rw [if_pos hp, term_fits_the_format_eq, bind_tc_ok]
+ have ho : termFits o.val = false := by
+ rcases h with h | h | h
+ · rw [h] at hs; exact absurd hs (by simp)
+ · rw [h] at hp; exact absurd hp (by simp)
+ · exact h
+ rw [if_neg (by simp [ho])]
+ exact ⟨_, rfl⟩
+ · simp only [Bool.not_eq_true] at hp
+ rw [if_neg (by simp [hp])]
+ exact ⟨_, rfl⟩
+ · simp only [Bool.not_eq_true] at hs
+ rw [if_neg (by simp [hs])]
+ exact ⟨_, rfl⟩
+
+/-! ## What the reader gets back
+
+The writer's job is done only if a reader splitting the file on its separators
+recovers the terms that went in. These are the theorems about that, and they are
+the reason `Spec.splitOnByte` exists. -/
+
+/-- A term the guard accepts carries no separator. -/
+theorem no_separator_of_termFits {l : List U8} (h : termFits l = true) :
+ 9#u8 ∉ l ∧ 10#u8 ∉ l ∧ 13#u8 ∉ l := by
+ unfold termFits fieldFits at h
+ simp only [Bool.and_eq_true, List.all_eq_true] at h
+ obtain ⟨⟨_, hall⟩, _⟩ := h
+ refine ⟨?_, ?_, ?_⟩ <;> intro hm <;>
+ simpa [isTsvSeparator] using hall _ hm
+
+/-- TCB-1, unbounded: an accepted line is exactly one record, and that record
+splits on TAB into exactly the three terms that went in. Every length, and no
+assumption that the terms came from a generator. -/
+theorem asserted_line_reads_back (s p o : List U8)
+ (hs : termFits s = true) (hp : termFits p = true) (ho : termFits o = true) :
+ splitOnByte 10#u8 (assertedLine s p o) = [s ++ 9#u8 :: (p ++ 9#u8 :: o), []]
+ ∧ splitOnByte 9#u8 (s ++ 9#u8 :: (p ++ 9#u8 :: o)) = [s, p, o] := by
+ obtain ⟨hs9, hs10, _⟩ := no_separator_of_termFits hs
+ obtain ⟨hp9, hp10, _⟩ := no_separator_of_termFits hp
+ obtain ⟨ho9, ho10, _⟩ := no_separator_of_termFits ho
+ constructor
+ · have hshape : assertedLine s p o = (s ++ 9#u8 :: (p ++ 9#u8 :: o)) ++ 10#u8 :: [] := by
+ simp [assertedLine]
+ have hno : 10#u8 ∉ s ++ 9#u8 :: (p ++ 9#u8 :: o) := by
+ intro hm
+ rcases List.mem_append.mp hm with hx | hx
+ · exact hs10 hx
+ · rcases List.mem_cons.mp hx with hy | hy
+ · exact absurd hy (by decide)
+ · rcases List.mem_append.mp hy with hz | hz
+ · exact hp10 hz
+ · rcases List.mem_cons.mp hz with hw | hw
+ · exact absurd hw (by decide)
+ · exact ho10 hw
+ rw [hshape, splitOnByte_append_cons, splitOnByte_of_not_mem _ _ hno]
+ simp [splitOnByte]
+ · rw [splitOnByte_append_cons, splitOnByte_of_not_mem _ _ hs9,
+ splitOnByte_append_cons, splitOnByte_of_not_mem _ _ hp9,
+ splitOnByte_of_not_mem _ _ ho9]
+ simp
+
+/-- TCB-2 and TCB-3, unbounded and stated the way they are used: a line already
+carrying `n` tab-separated fields carries exactly `n + 3` after the writer
+appends a triple, WHATEVER the prefix is. The prefix is unconstrained, so this
+covers a rule name, a rule index, a binding list of any length, and the
+conclusion and premises of a step already written.
+
+The Kani version proves the same shape with the prefix fixed at one byte and each
+term at four bytes or fewer. -/
+theorem triple_fields_adds_exactly_three_fields (pre s p o : List U8)
+ (hs : termFits s = true) (hp : termFits p = true) (ho : termFits o = true) :
+ (splitOnByte 9#u8 (pre ++ tripleFields s p o)).length
+ = (splitOnByte 9#u8 pre).length + 3 := by
+ obtain ⟨hs9, _, _⟩ := no_separator_of_termFits hs
+ obtain ⟨hp9, _, _⟩ := no_separator_of_termFits hp
+ obtain ⟨ho9, _, _⟩ := no_separator_of_termFits ho
+ have hshape : pre ++ tripleFields s p o
+ = pre ++ 9#u8 :: (s ++ 9#u8 :: (p ++ 9#u8 :: o)) := by
+ simp [tripleFields]
+ rw [hshape, splitOnByte_length_append_cons, splitOnByte_length_append_cons,
+ splitOnByte_of_not_mem _ _ hs9, splitOnByte_length_append_cons,
+ splitOnByte_of_not_mem _ _ hp9, splitOnByte_of_not_mem _ _ ho9]
+ simp
+
+/-- And which fields, not only how many: the three appended fields are the three
+terms, in order, after whatever the prefix contributed. -/
+theorem triple_fields_are_the_three_terms (pre s p o : List U8)
+ (hs : termFits s = true) (hp : termFits p = true) (ho : termFits o = true) :
+ splitOnByte 9#u8 (pre ++ tripleFields s p o)
+ = splitOnByte 9#u8 pre ++ [s, p, o] := by
+ obtain ⟨hs9, _, _⟩ := no_separator_of_termFits hs
+ obtain ⟨hp9, _, _⟩ := no_separator_of_termFits hp
+ obtain ⟨ho9, _, _⟩ := no_separator_of_termFits ho
+ have hshape : pre ++ tripleFields s p o
+ = pre ++ 9#u8 :: (s ++ 9#u8 :: (p ++ 9#u8 :: o)) := by
+ simp [tripleFields]
+ rw [hshape, splitOnByte_append_cons, splitOnByte_append_cons,
+ splitOnByte_of_not_mem _ _ hs9, splitOnByte_append_cons,
+ splitOnByte_of_not_mem _ _ hp9, splitOnByte_of_not_mem _ _ ho9]
+ simp
+
+end OOBoundary
diff --git a/aeneas/lean/OOBoundary/Spec.lean b/aeneas/lean/OOBoundary/Spec.lean
new file mode 100644
index 00000000..2b3d27b3
--- /dev/null
+++ b/aeneas/lean/OOBoundary/Spec.lean
@@ -0,0 +1,138 @@
+import OOBoundary.Generated
+
+/-!
+# What the boundary functions are supposed to do
+
+Written in plain Lean over `List UInt8`, with no reference to the generated
+model. That separation is the point: a specification written by reading the
+translation back is a restatement, and a restatement proves nothing. These
+definitions say what `asserted.tsv` and `axioms.tsv` need in order to be
+readable, and `OOBoundary/Proofs.lean` is where they meet the model Aeneas
+produced from `src/boundary_core.rs`.
+
+The bytes, once, so that no theorem below has to spell them:
+
+* `9` is TAB, the field separator of every certificate file;
+* `10` is LINE FEED, the record separator;
+* `13` is CARRIAGE RETURN, which is not a separator here but would make one
+ half of a CRLF file and is refused for that reason;
+* `32` is SPACE, the separator INSIDE a concept in `axioms.tsv` and
+ `model.tsv` (`concept_string` in `src/tableaux.rs`), which is why the DL
+ path refuses one more byte than the rest;
+* `60` is `<`, `34` is `"`, `95` is `_` and `58` is `:`, the leading bytes of
+ the three N-Triples term spellings.
+-/
+
+namespace OOBoundary.Spec
+
+open Aeneas.Std
+
+/-- A byte no tab-separated, one-record-per-line file can carry. -/
+def isTsvSeparator (b : U8) : Bool := b = 9#u8 || b = 10#u8 || b = 13#u8
+
+/-- A byte the DL model certificate cannot carry: the three above and SPACE,
+because the concept grammar inside a field is space separated. -/
+def isDlSeparator (b : U8) : Bool := b = 32#u8 || isTsvSeparator b
+
+/-- TCB-4, as a property of a list of bytes: a field is non-empty and carries
+no separator. This is the half that is about the FORMAT. -/
+def fieldFits (l : List U8) : Bool :=
+ !l.isEmpty && l.all (fun b => !isTsvSeparator b)
+
+/-- TCB-5, the half that is about N-TRIPLES: a term begins with `<` (an IRI),
+`"` (a literal) or `_:` (a blank node), so no two spellings collide when the
+checker compares terms as opaque strings. -/
+def ntriplesLeadingByte (l : List U8) : Bool :=
+ l[0]! = 60#u8 || l[0]! = 34#u8 || (l[0]! = 95#u8 && 1 < l.length && l[1]! = 58#u8)
+
+/-- TCB-4 and TCB-5 together: what a term must satisfy to be written. -/
+def termFits (l : List U8) : Bool := fieldFits l && ntriplesLeadingByte l
+
+/-- TCB-25: a name that survives the round trip through `axioms.tsv` and
+`model.tsv`. -/
+def nameIsSafe (l : List U8) : Bool :=
+ !l.isEmpty && l.all (fun b => !isDlSeparator b)
+
+/-- The guard that closed the unwritable-conclusion defect: a literal cannot be
+a subject and only an IRI can be a predicate. -/
+def writableTriple (subject predicate : List U8) : Bool :=
+ !(subject[0]? = some 34#u8) && predicate[0]? = some 60#u8
+
+/-- One line of `asserted.tsv`, as bytes. -/
+def assertedLine (s p o : List U8) : List U8 :=
+ s ++ [9#u8] ++ p ++ [9#u8] ++ o ++ [10#u8]
+
+/-- Three further fields of a line already begun. -/
+def tripleFields (s p o : List U8) : List U8 :=
+ [9#u8] ++ s ++ [9#u8] ++ p ++ [9#u8] ++ o
+
+/-!
+## Splitting, so that "exactly three fields" is a statement and not a picture
+
+`OOCert.Parse.parseTriples` reads a line by splitting it on TAB. The theorem
+worth proving about the writer is the one about what the READER gets back, so
+the split has to exist here. This is `List.splitOn` specialised to one byte and
+written out rather than imported, because the whole file has to be readable by
+someone checking whether the statement says what they think it says.
+-/
+
+/-- Split a byte list on a separator byte. Always returns at least one field,
+and `n` occurrences of the separator give `n + 1` fields. -/
+def splitOnByte (sep : U8) : List U8 → List (List U8)
+ | [] => [[]]
+ | b :: bs =>
+ if b = sep then [] :: splitOnByte sep bs
+ else match splitOnByte sep bs with
+ | [] => [[b]] -- unreachable: `splitOnByte` is never empty
+ | f :: fs => (b :: f) :: fs
+
+/-- Splitting never returns nothing: there is always at least one field, even
+in the empty list. -/
+theorem splitOnByte_ne_nil (sep : U8) (l : List U8) : splitOnByte sep l ≠ [] := by
+ induction l with
+ | nil => simp [splitOnByte]
+ | cons b bs ih =>
+ by_cases hb : b = sep
+ · simp [splitOnByte, hb]
+ · cases h : splitOnByte sep bs with
+ | nil => exact absurd h ih
+ | cons f fs => simp [splitOnByte, hb, h]
+
+/-- A list carrying no occurrence of `sep` is exactly one field. -/
+theorem splitOnByte_of_not_mem (sep : U8) (l : List U8) (h : sep ∉ l) :
+ splitOnByte sep l = [l] := by
+ induction l with
+ | nil => simp [splitOnByte]
+ | cons b bs ih =>
+ have hb : ¬ (b = sep) := by grind
+ have hbs : sep ∉ bs := by grind
+ simp [splitOnByte, hb, ih hbs]
+
+/-- The one lemma the field-count theorems are built from: a separator between
+two pieces closes the left piece's last field and opens the right piece's
+first, so the fields of the whole are the fields of the parts, concatenated.
+
+Note what it does NOT assume. `l` may itself carry separators, which is why
+this is the lemma that lets a theorem about APPENDING fields to a line already
+begun be stated for every prefix rather than for a separator-free one. -/
+theorem splitOnByte_append_cons (sep : U8) (l r : List U8) :
+ splitOnByte sep (l ++ sep :: r) = splitOnByte sep l ++ splitOnByte sep r := by
+ induction l with
+ | nil => simp [splitOnByte]
+ | cons b bs ih =>
+ by_cases hb : b = sep
+ · simp [splitOnByte, hb, ih]
+ · cases h : splitOnByte sep bs with
+ | nil => exact absurd h (splitOnByte_ne_nil sep bs)
+ | cons f fs =>
+ have hcat : splitOnByte sep (bs ++ sep :: r) = (f :: fs) ++ splitOnByte sep r := by
+ rw [ih, h]
+ simp [splitOnByte, hb, hcat, h]
+
+/-- Appending a separator and a piece adds exactly that piece's field count. -/
+theorem splitOnByte_length_append_cons (sep : U8) (l r : List U8) :
+ (splitOnByte sep (l ++ sep :: r)).length
+ = (splitOnByte sep l).length + (splitOnByte sep r).length := by
+ rw [splitOnByte_append_cons]; simp
+
+end OOBoundary.Spec
diff --git a/aeneas/lean/lake-manifest.json b/aeneas/lean/lake-manifest.json
new file mode 100644
index 00000000..593ac5f8
--- /dev/null
+++ b/aeneas/lean/lake-manifest.json
@@ -0,0 +1,106 @@
+{"version": "1.2.0",
+ "packagesDir": ".lake/packages",
+ "packages":
+ [{"url": "https://github.com/AeneasVerif/aeneas",
+ "type": "git",
+ "subDir": "backends/lean",
+ "scope": "",
+ "rev": "505b6ca35217e7be5c96c3e2f8045edfbdf47291",
+ "name": "aeneas",
+ "manifestFile": "lake-manifest.json",
+ "inputRev": "505b6ca35217e7be5c96c3e2f8045edfbdf47291",
+ "inherited": false,
+ "configFile": "lakefile.lean"},
+ {"url": "https://github.com/leanprover-community/mathlib4.git",
+ "type": "git",
+ "subDir": null,
+ "scope": "",
+ "rev": "fabf563a7c95a166b8d7b6efca11c8b4dc9d911f",
+ "name": "mathlib",
+ "manifestFile": "lake-manifest.json",
+ "inputRev": "v4.31.0",
+ "inherited": true,
+ "configFile": "lakefile.lean"},
+ {"url": "https://github.com/leanprover-community/plausible",
+ "type": "git",
+ "subDir": null,
+ "scope": "leanprover-community",
+ "rev": "63045536fe95024e6c18fc7b48e03f506701c5bc",
+ "name": "plausible",
+ "manifestFile": "lake-manifest.json",
+ "inputRev": "main",
+ "inherited": true,
+ "configFile": "lakefile.toml"},
+ {"url": "https://github.com/leanprover-community/LeanSearchClient",
+ "type": "git",
+ "subDir": null,
+ "scope": "leanprover-community",
+ "rev": "c5d5b8fe6e5158def25cd28eb94e4141ad97c843",
+ "name": "LeanSearchClient",
+ "manifestFile": "lake-manifest.json",
+ "inputRev": "main",
+ "inherited": true,
+ "configFile": "lakefile.toml"},
+ {"url": "https://github.com/leanprover-community/import-graph",
+ "type": "git",
+ "subDir": null,
+ "scope": "leanprover-community",
+ "rev": "5c7542ed018c78194f1e2b903eaf6a792b74c03d",
+ "name": "importGraph",
+ "manifestFile": "lake-manifest.json",
+ "inputRev": "main",
+ "inherited": true,
+ "configFile": "lakefile.toml"},
+ {"url": "https://github.com/leanprover-community/ProofWidgets4",
+ "type": "git",
+ "subDir": null,
+ "scope": "leanprover-community",
+ "rev": "24b0d9dc081c5423f8eec7e866c441e5184f29d9",
+ "name": "proofwidgets",
+ "manifestFile": "lake-manifest.json",
+ "inputRev": "main",
+ "inherited": true,
+ "configFile": "lakefile.lean"},
+ {"url": "https://github.com/leanprover-community/aesop",
+ "type": "git",
+ "subDir": null,
+ "scope": "leanprover-community",
+ "rev": "e3cb2f741431ce31bf73549fb52316a57368b06f",
+ "name": "aesop",
+ "manifestFile": "lake-manifest.json",
+ "inputRev": "master",
+ "inherited": true,
+ "configFile": "lakefile.toml"},
+ {"url": "https://github.com/leanprover-community/quote4",
+ "type": "git",
+ "subDir": null,
+ "scope": "leanprover-community",
+ "rev": "f46324995fca5f0483b742e4eb4daec7f4ee50d2",
+ "name": "Qq",
+ "manifestFile": "lake-manifest.json",
+ "inputRev": "master",
+ "inherited": true,
+ "configFile": "lakefile.toml"},
+ {"url": "https://github.com/leanprover-community/batteries",
+ "type": "git",
+ "subDir": null,
+ "scope": "leanprover-community",
+ "rev": "fa08db58b30eb033edcdab331bba000827f9f785",
+ "name": "batteries",
+ "manifestFile": "lake-manifest.json",
+ "inputRev": "main",
+ "inherited": true,
+ "configFile": "lakefile.toml"},
+ {"url": "https://github.com/leanprover/lean4-cli",
+ "type": "git",
+ "subDir": null,
+ "scope": "leanprover",
+ "rev": "92564e5770e4d09f2d86dfbf8ada1e9c715b384c",
+ "name": "Cli",
+ "manifestFile": "lake-manifest.json",
+ "inputRev": "v4.31.0",
+ "inherited": true,
+ "configFile": "lakefile.toml"}],
+ "name": "ooboundary",
+ "lakeDir": ".lake",
+ "fixedToolchain": false}
diff --git a/aeneas/lean/lakefile.toml b/aeneas/lean/lakefile.toml
new file mode 100644
index 00000000..9f28ff25
--- /dev/null
+++ b/aeneas/lean/lakefile.toml
@@ -0,0 +1,27 @@
+# A SEPARATE Lake workspace, on purpose.
+#
+# `lean/` is core Lean only: no Mathlib, no external package, and every theorem
+# pinned to `[propext, Classical.choice, Quot.sound]` by a `#guard_msgs`-checked
+# `#print axioms`. This directory cannot live under that rule and does not
+# pretend to. Aeneas's Lean backend pins `leanprover/lean4:v4.31.0` and its
+# support library `require`s Mathlib, so importing it here would drag nine
+# packages and a different Lean into a build whose value is that it has none.
+#
+# So: its own `lean-toolchain`, its own manifest, its own `lake build`, and NO
+# path from `lean/lakefile.toml` to this one. `docs/aeneas-boundary.md` records
+# the trust regime this workspace runs under and how it differs.
+name = "ooboundary"
+version = "0.1.0"
+defaultTargets = ["OOBoundary"]
+
+# Pinned to the exact Aeneas commit that generated `OOBoundary/Generated.lean`.
+# A different commit is a different translation, and the whole claim here is
+# that the Lean model is the model of the Rust that was translated.
+[[require]]
+name = "aeneas"
+git = "https://github.com/AeneasVerif/aeneas"
+subDir = "backends/lean"
+rev = "505b6ca35217e7be5c96c3e2f8045edfbdf47291"
+
+[[lean_lib]]
+name = "OOBoundary"
diff --git a/aeneas/lean/lean-toolchain b/aeneas/lean/lean-toolchain
new file mode 100644
index 00000000..18640c8b
--- /dev/null
+++ b/aeneas/lean/lean-toolchain
@@ -0,0 +1 @@
+leanprover/lean4:v4.31.0
diff --git a/aeneas/oo-boundary/.gitignore b/aeneas/oo-boundary/.gitignore
new file mode 100644
index 00000000..40d411a7
--- /dev/null
+++ b/aeneas/oo-boundary/.gitignore
@@ -0,0 +1,2 @@
+/target
+*.llbc
diff --git a/aeneas/oo-boundary/Cargo.lock b/aeneas/oo-boundary/Cargo.lock
new file mode 100644
index 00000000..d2a64120
--- /dev/null
+++ b/aeneas/oo-boundary/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "oo-boundary"
+version = "0.0.0"
diff --git a/aeneas/oo-boundary/Cargo.toml b/aeneas/oo-boundary/Cargo.toml
new file mode 100644
index 00000000..4974bea8
--- /dev/null
+++ b/aeneas/oo-boundary/Cargo.toml
@@ -0,0 +1,24 @@
+# NOT a member of anything and NOT a dependency of the shipped crate.
+#
+# `cargo build` at the repository root never sees this file: the root
+# `Cargo.toml` has no `[workspace]` table, so a package in a subdirectory is its
+# own workspace and is built only when someone stands in this directory and asks
+# for it. `aeneas/run.sh` is the only thing that does, and nothing in `make
+# check` calls that. The Kani harnesses are kept out of the normal build the
+# same way and for the same reason.
+[package]
+name = "oo-boundary"
+version = "0.0.0"
+edition = "2024"
+publish = false
+license = "MIT"
+description = "Charon/Aeneas extraction target: the certificate boundary's pure core, verbatim."
+
+[lib]
+path = "src/lib.rs"
+
+# No dependencies, and there must never be one. Aeneas translates a subset of
+# safe Rust and stops at any type it does not model; a dependency here would
+# either fail to translate or translate to an opaque declaration, which is a
+# hole in the model that looks like a model.
+[dependencies]
diff --git a/aeneas/oo-boundary/rust-toolchain b/aeneas/oo-boundary/rust-toolchain
new file mode 100644
index 00000000..2c474db0
--- /dev/null
+++ b/aeneas/oo-boundary/rust-toolchain
@@ -0,0 +1,11 @@
+# Charon is a `rustc` driver: it links against `rustc_private` and therefore
+# pins the exact nightly it was built against. This file is what makes
+# `charon cargo` work in this directory and it is the ONLY place in the
+# repository that names a toolchain. The shipped crate has no `rust-toolchain`
+# and builds on stable, which is the point of keeping this crate separate.
+#
+# Keep in step with the `rust-toolchain` shipped inside the Charon release
+# named in `aeneas/run.sh`.
+[toolchain]
+channel = "nightly-2026-08-18"
+components = [ "rustc-dev", "llvm-tools", "rust-src" ]
diff --git a/aeneas/oo-boundary/src/lib.rs b/aeneas/oo-boundary/src/lib.rs
new file mode 100644
index 00000000..549e975e
--- /dev/null
+++ b/aeneas/oo-boundary/src/lib.rs
@@ -0,0 +1,12 @@
+//! The extraction target for Charon and Aeneas.
+//!
+//! This crate has ONE line of its own. `src/boundary_core.rs` at the repository
+//! root is reached with `#[path]`, so the Lean model that comes out of
+//! `aeneas/run.sh` is a model of the bytes the shipped engine compiles, not of
+//! a transcription of them. Copying the file here would make the whole exercise
+//! worthless the first time the two drifted, and drift is what happens.
+//!
+//! `aeneas/lean/OOBoundary/Generated.lean` is the output. See
+//! `docs/aeneas-boundary.md`.
+#[path = "../../../src/boundary_core.rs"]
+pub mod boundary_core;
diff --git a/aeneas/run.sh b/aeneas/run.sh
new file mode 100755
index 00000000..2a818d22
--- /dev/null
+++ b/aeneas/run.sh
@@ -0,0 +1,87 @@
+#!/usr/bin/env bash
+#
+# Re-translate src/boundary_core.rs into aeneas/lean/OOBoundary/Generated.lean.
+#
+# OPTIONAL AND SEPARATE, the way the Kani harnesses 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. It downloads a
+# hundred and thirty megabytes of release tarball the first time it runs.
+#
+# What it does:
+# 1. fetches the pinned Charon and Aeneas release for this platform;
+# 2. runs Charon over aeneas/oo-boundary, which is src/boundary_core.rs
+# reached with #[path] and nothing else, producing LLBC;
+# 3. runs Aeneas over the LLBC, producing the Lean model;
+# 4. tells you whether the model changed.
+#
+# Step 4 is the one that matters in review. The proofs in
+# aeneas/lean/OOBoundary/Proofs.lean are about the file this writes, so a
+# change to src/boundary_core.rs that changes the model is a change that can
+# break them, and the diff is how you find out.
+#
+# Building the proofs is a separate command and a separate toolchain:
+#
+# cd aeneas/lean && lake exe cache get && lake build
+#
+# See docs/aeneas-boundary.md for what that pulls in and why it is not in
+# lean/.
+set -euo pipefail
+
+# The pinned release. Aeneas publishes a nightly per day; the tag and the
+# commit are both named so that the lakefile's `rev` and this script cannot
+# drift apart silently.
+AENEAS_TAG="${AENEAS_TAG:-nightly-2026.09.15-505b6ca}"
+AENEAS_REV="505b6ca35217e7be5c96c3e2f8045edfbdf47291"
+
+here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+repo="$(cd "$here/.." && pwd)"
+tools="${OO_AENEAS_HOME:-$here/.toolchain}"
+
+case "$(uname -s)-$(uname -m)" in
+ Darwin-arm64) asset="aeneas-macos-aarch64.tar.gz" ;;
+ Linux-x86_64) asset="aeneas-linux-x86_64.tar.gz" ;;
+ Linux-aarch64) asset="aeneas-linux-aarch64.tar.gz" ;;
+ *) echo "no Aeneas release for $(uname -s)-$(uname -m); build from source" >&2; exit 1 ;;
+esac
+
+if [ ! -x "$tools/aeneas/aeneas" ]; then
+ echo "fetching Aeneas $AENEAS_TAG ($asset)"
+ mkdir -p "$tools/aeneas"
+ gh release download "$AENEAS_TAG" --repo AeneasVerif/aeneas \
+ --pattern "$asset" --dir "$tools" --clobber
+ tar xzf "$tools/$asset" -C "$tools/aeneas"
+fi
+
+# The Aeneas bundle ships the Charon binary it was built against, and the
+# `rust-toolchain` that Charon links its `rustc_private` against. Using any
+# other pair is how you get an LLBC that does not match the binary reading it.
+shipped_channel="$(grep -E '^channel' "$tools/aeneas/rust-toolchain" | tr -d ' "')"
+ours_channel="$(grep -E '^channel' "$here/oo-boundary/rust-toolchain" | tr -d ' "')"
+if [ "$shipped_channel" != "$ours_channel" ]; then
+ echo "TOOLCHAIN MISMATCH. Charon is a rustc driver and pins its nightly exactly." >&2
+ echo " release ships: $shipped_channel" >&2
+ echo " this repo has: $ours_channel" >&2
+ echo "Update aeneas/oo-boundary/rust-toolchain, or pin an older AENEAS_TAG." >&2
+ exit 1
+fi
+
+out="$repo/aeneas/lean/OOBoundary/Generated.lean"
+previous="$(mktemp)"
+[ -f "$out" ] && cp "$out" "$previous"
+
+cd "$here/oo-boundary"
+"$tools/aeneas/charon" cargo --preset aeneas
+"$tools/aeneas/aeneas" -backend lean oo_boundary.llbc \
+ -dest "$repo/aeneas/lean/OOBoundary" -namespace OOBoundary
+mv "$repo/aeneas/lean/OOBoundary/OoBoundary.lean" "$out"
+
+if [ -s "$previous" ] && ! diff -q "$previous" "$out" >/dev/null; then
+ echo
+ echo "THE MODEL CHANGED. The proofs in OOBoundary/Proofs.lean are about the"
+ echo "old one. Diff:"
+ diff -u "$previous" "$out" || true
+ rm -f "$previous"
+ exit 2
+fi
+rm -f "$previous"
+echo "model unchanged: $out"
diff --git a/docs/aeneas-boundary.md b/docs/aeneas-boundary.md
new file mode 100644
index 00000000..350b0849
--- /dev/null
+++ b/docs/aeneas-boundary.md
@@ -0,0 +1,290 @@
+# Aeneas at the Rust/Lean boundary
+
+`docs/trusted-computing-base.md` ends on the same sentence every time: `lean/` proves a conditional,
+and everything to the left of its "if" is fifty thousand lines of unverified Rust writing down the
+truth. The functions that decide whether it does are small, pure and total. This page is the record
+of pointing a Rust-to-Lean verification tool at exactly those functions and finding out, honestly,
+what it can and cannot do here.
+
+The tool is [Aeneas](https://github.com/AeneasVerif/aeneas) (Inria and Microsoft Research). Its
+front end, [Charon](https://github.com/AeneasVerif/charon), is a `rustc` driver that extracts LLBC
+(a low-level borrow calculus) from a crate; Aeneas consumes the LLBC and emits a pure functional
+model in Lean 4, F\*, Coq or HOL4. It handles a subset of safe Rust.
+
+Read the gate first. It decides everything else on this page.
+
+## The gate
+
+Three questions had to be answered before a line was written, and two of them have answers that
+constrain the result permanently.
+
+### 1. Does it install and run on this machine?
+
+**Yes.** macOS 26.6.2 (`darwin 25.6.0`), Apple silicon. Aeneas publishes a nightly release per day with
+a `aeneas-macos-aarch64.tar.gz` asset carrying prebuilt `aeneas` (OCaml), `charon` and
+`charon-driver` (Rust) binaries plus the four backends, so no OCaml toolchain was needed. This
+machine has no `opam` and none was installed. The pinned release is
+`nightly-2026.09.15-505b6ca` (`505b6ca35217e7be5c96c3e2f8045edfbdf47291`).
+
+`aeneas/run.sh` fetches it, runs Charon over `aeneas/oo-boundary`, runs Aeneas over the resulting
+LLBC and writes `aeneas/lean/OOBoundary/Generated.lean`. End to end it takes under ten seconds once
+the release is downloaded.
+
+### 2. Which Lean does it target, and what does its support library depend on?
+
+**This is the finding that shapes everything else.** It does not break the three-axiom pin, and
+the measurement further down says so; what it breaks is any hope that the output could live in
+`lean/`.
+
+`lean/` is core Lean only. `lean/lakefile.toml` says so in a comment and the manifest is empty: no
+Mathlib, no Batteries, no external package at all, `leanprover/lean4:v4.33.1`, and every headline
+theorem carries a `#guard_msgs`-checked `#print axioms` pinning it to exactly
+`[propext, Classical.choice, Quot.sound]`.
+
+Aeneas's generated files open with `import Aeneas`. That is not optional and there is no smaller
+target: the model is written in Aeneas's `Result` monad over its `Slice`, `alloc.vec.Vec` and
+`UScalar` types, and every one of those lives in the support library. The support library's
+`backends/lean/lakefile.lean` reads, verbatim:
+
+```lean
+-- Important: mathlib imports std4 and quote4: we mustn't add a `require std4` line
+require mathlib from git
+ "https://github.com/leanprover-community/mathlib4.git" @ "v4.31.0"
+```
+
+and its `backends/lean/lean-toolchain` reads `leanprover/lean4:v4.31.0`.
+
+So, concretely, measured in this repository rather than quoted from a README:
+
+| | `lean/` | `aeneas/lean/` |
+|---|---|---|
+| Lean | `v4.33.1` | `v4.31.0` |
+| Lake packages required | 0 | 10 (`aeneas`, `mathlib`, `batteries`, `aesop`, `Qq`, `plausible`, `proofwidgets`, `importGraph`, `LeanSearchClient`, `Cli`) |
+| `.lake` on disk after a build | 78 MB | 7.6 GB, of which 6.2 GB is Mathlib (8176 `.olean`s, fetched by `lake exe cache get`) |
+| axiom pin | `[propext, Classical.choice, Quot.sound]`, no exceptions | see "the axiom accounting" below |
+
+Some care is owed here, because "depends on Mathlib" is not by itself an indictment:
+
+- **Mathlib does not add axioms.** Mathlib's own policy is the same three, so importing it does not
+ by itself put a fourth axiom behind a theorem. The axiom accounting below is measured, not
+ assumed.
+- **Aeneas's `Std` is `sorry`-free.** `grep -rn sorry backends/lean/Aeneas/Std/` is empty. The nine
+ `sorry`s in the bundle are all inside `#guard_msgs` doc-strings in `Aeneas/Tactic/`, which are the
+ *expected output* of `extract_goal` in the tactic framework's own tests, not sorried declarations.
+ `native_decide` appears only in `example`s, which do not propagate.
+
+What is true is that the *trust surface* is a different object. `lean/`'s is "the Lean kernel plus
+what is written in this directory, small enough to read in an afternoon". `aeneas/lean/`'s is the
+Lean kernel plus Mathlib plus eight more packages plus the Aeneas support library plus the Aeneas
+translation itself. The three-axiom pin is worth having precisely because it has no exceptions, so
+this work does not touch it: `aeneas/lean/` is a separate Lake workspace with its own
+`lean-toolchain`, its own manifest and its own `lake build`, and there is no path from
+`lean/lakefile.toml` to it. Nothing in `make check` or `lake build` under `lean/` reaches this
+directory.
+
+### 3. Does Charon work with this repository's Rust?
+
+**Not with the shipped crate, and it does not need to.** Charon is a `rustc` driver linking
+`rustc_private`, so it pins a nightly exactly: `nightly-2026-08-18` with `rustc-dev`, `llvm-tools`
+and `rust-src`. The shipped crate has no `rust-toolchain` file, is `edition = "2024"` and builds on
+stable (1.96.0 here). It also has around ninety dependencies and fifty thousand lines, most of it
+reaching into `oxrdf`, `oxiri`, `tokio` and `axum`, none of which Aeneas models.
+
+So Charon is pointed at `aeneas/oo-boundary`, a crate with one line of its own:
+
+```rust
+#[path = "../../../src/boundary_core.rs"]
+pub mod boundary_core;
+```
+
+and no dependencies. The `rust-toolchain` pin lives in that directory and nowhere else. This is the
+only place in the repository that names a toolchain, and the shipped crate still builds on stable.
+
+## What was extracted, and what it cost
+
+`src/boundary_core.rs` is new and is the pure core of the certificate boundary: seven functions and
+one three-constructor enum, over `u8`, `&[u8]`, `Vec<u8>`, `usize` and `bool`. `src/reason.rs` and
+`src/tableaux.rs` call it. It is not a copy of them and there is no transcription step: the crate
+Charon reads reaches this same file with `#[path]`, so the Lean model is a model of the bytes the
+shipped engine compiles.
+
+Six shipped functions became one-line wrappers:
+
+| shipped | file | now |
+|---|---|---|
+| `writable_triple` | `src/reason.rs` | `writable_triple_bytes(s.as_bytes(), p.as_bytes())` |
+| `field_fits_the_format` | `src/reason.rs` | `field_fits_the_format(f.as_bytes())` |
+| `term_fits_the_format` | `src/reason.rs` | `term_fits_the_format(t.as_bytes())` |
+| `push_asserted_line` | `src/reason.rs` | `push_asserted_line_bytes(out, …)` |
+| `push_triple_fields` | `src/reason.rs` | `push_triple_fields_bytes(out, …)` |
+| `name_is_safe` | `src/tableaux.rs` | `name_is_safe_bytes(s.as_bytes())` |
+
+The refactor was not free, and neither cost is cosmetic:
+
+1. **The certificate buffers are now `Vec<u8>` rather than `String`.** Aeneas does not model `str`
+ well enough to translate a writer that appends into one, and a wrapper cannot bridge that without
+ `unsafe`. `std::fs::write` takes `AsRef<[u8]>`, so nothing downstream notices, and every byte
+ appended still comes from a `&str`. The two property tests and the two generic Kani harness
+ bodies that assert on the buffer (nine instantiations between them) were changed to match; what
+ they assert is unchanged, and `make verify` still verifies all fifteen.
+2. **`&str` predicates became byte predicates.** `s.contains([' ', '\t', '\n', '\r'])` became a
+ byte scan. These agree on every `&str`, because all four are ASCII and no ASCII byte occurs
+ inside a multi-byte UTF-8 sequence, but that sentence is an argument and arguments are what this
+ repository writes tests for. `tcb_wrappers_agree_with_the_char_level_predicates` in
+ `src/reason.rs` is that test: it runs the original `char`-level bodies and the new byte-level
+ ones over the same adversarial generator and requires them to agree.
+
+## What Aeneas translated
+
+Everything in `src/boundary_core.rs`, with no opaque declarations and no `sorry`:
+`Position` (with its derived `Clone`, `Copy`, `Debug`, `PartialEq`, `Eq` instances),
+`starts_with_byte`, `writable_triple_bytes`, `field_fits_the_format`, `term_fits_the_format`,
+`name_is_safe_bytes`, `push_asserted_line_bytes`, `push_triple_fields_bytes`. 311 lines of Lean.
+
+The parts most likely to have failed did not, and they are worth naming:
+
+- **The `while` loops translated.** Each becomes a `body` returning `ControlFlow` plus a
+ `loop` combinator defined by `partial_fixpoint`, which is a real fixpoint and not an axiom. The
+ induction to reason about it has to be written by hand; it is written in
+ `aeneas/lean/OOBoundary/Proofs.lean`.
+- **`Vec::extend_from_slice` translated to a primitive with a real model**
+ (`alloc.vec.Vec.extend_from_slice`, which is `v.val ++ s.val` under a length side-condition), not
+ to an opaque declaration. That is what let the writers keep `extend_from_slice` instead of a
+ byte-at-a-time push loop, so the refactor costs no memcpy.
+
+## What was proved
+
+See `aeneas/lean/OOBoundary/Proofs.lean`. The decision procedures are stated as equations
+`model x = ok (spec x)` rather than as Hoare triples, because an equation covers more ground than a
+triple: the model never fails, it never diverges, and its result is the specification.
+
+Fourteen theorems, in `OOBoundary`:
+
+| theorem | says | was |
+|---|---|---|
+| `starts_with_byte_eq` | the leading-byte test is the head of the list, every length | not stated |
+| `writable_triple_bytes_eq` | the unwritable-conclusion guard decides both positions, every length | BOUNDED: `writable_triple_decides_both_positions` fixes both terms at four bytes |
+| `field_fits_the_format_eq` / `_iff` | a field is accepted IF AND ONLY IF it is non-empty and carries no tab, line feed or carriage return | SAMPLED |
+| `name_is_safe_bytes_eq` / `_iff` | TCB-25: a name is accepted IF AND ONLY IF it is non-empty and carries no space, tab, line feed or carriage return | SAMPLED: `tcb_25_name_is_safe_refuses_every_separator` |
+| `term_fits_the_format_eq` | TCB-4 and TCB-5: accepted exactly when non-empty, separator-free and in one of the three N-Triples spellings | SAMPLED |
+| `push_asserted_line_bytes_ok` | when the three terms fit, the buffer gains exactly `s TAB p TAB o LF` | BOUNDED: `asserted_line_round_trips_at_0` to `_at_4`, so terms of zero to four bytes |
+| `push_triple_fields_bytes_ok` | the same for `TAB s TAB p TAB o` | BOUNDED: `triple_fields_append_exactly_three_at_0`, `_at_2`, `_at_3`, `_at_4` |
+| `push_asserted_line_bytes_refuses` / `push_triple_fields_bytes_refuses` | all or nothing: a term that does not fit makes the writer refuse AND hand back the buffer it was given, byte for byte | BOUNDED, and only at a one-byte prefix |
+| `asserted_line_reads_back` | TCB-1: an accepted line is one record on line feed, and that record splits on TAB into exactly the three terms that went in | SAMPLED |
+| `triple_fields_adds_exactly_three_fields` | TCB-2, TCB-3: a line carrying `n` tab-separated fields carries exactly `n + 3` afterwards, FOR EVERY PREFIX | BOUNDED: prefix fixed at one byte |
+| `triple_fields_are_the_three_terms` | and which fields they are, in order | SAMPLED |
+
+One hypothesis, said out loud because "no bound" should not be read as "no
+precondition": the two `_ok` theorems assume the buffer plus the line it is about
+to gain fits in a `usize`
+(`out.length + s.length + p.length + o.length + 2 < Usize.max`). That is not a
+length bound on the terms, it is the capacity precondition Aeneas's `Vec` model
+carries and that Rust's `Vec` enforces by aborting. The two `_refuses` theorems
+carry no such hypothesis, because refusing allocates nothing.
+
+The entries a bounded checker cannot reach at all are worth reading twice:
+
+- **The prefix in `triple_fields_adds_exactly_three_fields` is unconstrained and
+ may itself carry tabs.** The Kani version fixes it at a single byte.
+ Real prefixes are a rule name, or a rule index and a binding list of any
+ length, and then the conclusion and premises of a step already written. The
+ Lean theorem covers every one of them because it is proved from
+ `splitOnByte_append_cons`, which does not assume the left side is
+ separator-free.
+- **`writable_triple_bytes_eq` covers the EMPTY term** and the Kani harness
+ cannot: it allocates a fixed four-byte array. What the theorem shows is that
+ an empty subject PASSES this guard, which is fine only because
+ `term_fits_the_format` refuses an empty term and the certificate paths run
+ both. That is now written down rather than assumed.
+
+The reader-side theorems are stated against `Spec.splitOnByte`, a one-byte
+splitter written out in `aeneas/lean/OOBoundary/Spec.lean` rather than imported,
+so that anyone checking whether the statement says what they think it says can
+read the splitter in ten lines. It is not `OOCert.Parse`'s splitter, and the
+claim is the one `docs/trusted-computing-base.md` already argues is the right
+one: the theorems are about the BYTE LAYOUT, which is what any correct splitter
+needs and all it needs.
+
+### What Aeneas could not handle, and why
+
+- **`str` and `String`.** Aeneas has a `String` model but not enough of one to
+ translate a writer that appends into a `String`, which is why the certificate
+ buffers moved to `Vec<u8>` and the predicates moved to `&[u8]`. Everything
+ else on this page follows from that one limitation.
+- **The interner (TCB-15, TCB-16, TCB-17).** `Interner` is a
+ `HashMap<String, u32>` plus a `Vec<String>`. Aeneas does not model
+ `std::collections::HashMap`, and the property at issue (that interning is a
+ bijection) is about the map. Nothing here touches it.
+- **`parse_pat` (TCB-20).** Returns `anyhow::Result` and formats a message
+ naming the line and the position, so translating it would mean translating
+ `core::fmt` and `anyhow`. This is the same shape of obstacle that killed its
+ Kani harness, and the same fix would serve both: lift the classification into
+ a pure `Option<Pat>` function and leave the messages where they are.
+- **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 opaque
+ functions during the run; they are `core` library functions it models in
+ `Aeneas.Std` (the `Debug` derive reaches `core::fmt::Formatter::write_str`),
+ they are not emitted into the file, and no theorem here depends on one.
+
+
+## The honest accounting
+
+### This is a trade, not a gain
+
+Trading "fifty thousand lines of unverified Rust" for "Aeneas's translation from Rust to the Lean
+model is faithful" is a large net win at the boundary, and it is still a trade. TCB-30 in
+`docs/trusted-computing-base.md` records it.
+
+### The axiom accounting is separate and it is not the same regime
+
+All fourteen theorems pinned in `aeneas/lean/OOBoundary/Axioms.lean` depend on exactly
+
+```
+[propext, Classical.choice, Quot.sound]
+```
+
+which is the same three `lean/` pins. `aeneas/lean/OOBoundary/Axioms.lean`
+checks every one of them with `#guard_msgs`, so a change breaks `lake build` in
+this directory rather than widening the trust surface quietly. Measured, not
+assumed: the first draft of this page said "Mathlib does not add axioms" as a
+fact about Mathlib's policy, and a policy is not a measurement.
+
+**Do not read that as "so it is the same regime."** It is not, and the
+difference is not in the axiom list:
+
+- the Lean is `v4.31.0` against `lean/`'s `v4.33.1`, so the two can never share
+ a file, a build or a `lake build` invocation;
+- checking any of it needs ten packages on disk and a 7.6 GB `.lake`, 6.2 GB of
+ it Mathlib `.olean`s, against 78 MB for `lean/`, which needs a Lean toolchain
+ and nothing else;
+- the elaborated proofs run through Mathlib tactics (`scalar_tac`, `omega`,
+ `tauto`, `grind`) rather than only through what is written in the directory,
+ so "small enough to read in an afternoon" is false of this workspace and true
+ of `lean/`;
+- and above all, every theorem here is about AENEAS'S OUTPUT. The axiom list
+ measures what the Lean kernel had to assume. It says nothing at all about
+ whether the model is the Rust, which is TCB-30 and is the actual price of this
+ work.
+
+So the three-axiom pin on `lean/` is untouched and still has no exceptions, and
+the useful sentence is the one at the top of this section together with the four
+below it, not either half on its own.
+
+
+### What would close the gaps
+
+- **The translation itself.** Charon and Aeneas are together tens of thousands of lines of Rust and
+ OCaml, unverified, and the model is only as good as the translation. What would close it: nothing
+ available today. Aeneas has no machine-checked soundness proof of its own pipeline. The partial
+ mitigation that IS available is the one `aeneas/run.sh` implements: re-run the translation, diff
+ the model, and fail if it moved, so a change to `src/boundary_core.rs` that changes the model
+ cannot slip past review with the old proofs still in the tree.
+- **Coverage.** Seven functions is seven functions. The interner (TCB-15 to TCB-17) is a `HashMap` and
+ Aeneas does not model `std::collections::HashMap`; `parse_pat` (TCB-20) returns `anyhow::Result`
+ and formats messages, which is the same thing that killed its Kani harness. Both would need the
+ same treatment this work gave the writers: lift the pure decision out, leave the machinery where
+ it is.
+- **The toolchain split.** `aeneas/lean/` is on Lean v4.31.0 and `lean/` is on v4.33.1, so the two
+ can never share a file. That closes when Aeneas's Lean backend catches up, and it will always lag
+ by some amount because Mathlib does.
diff --git a/docs/architecture.md b/docs/architecture.md
index 3d0ee11f..df75743f 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -121,7 +121,7 @@ the built-in table earns. Details in
The theorem is conditional, and what it is conditional on is the Rust writing
down the truth: the asserted graph the certificate names, and the steps it
records. That boundary is small, it is the whole trusted base of this layer, and
-it is enumerated as twenty-nine checkable properties in
+it is enumerated as thirty checkable properties in
[docs/trusted-computing-base.md](docs/trusted-computing-base.md), with what
checks each and what is still trusted. Read it before relying on a certificate.
diff --git a/docs/ci-gates.md b/docs/ci-gates.md
index 1342886f..3a9dbe80 100644
--- a/docs/ci-gates.md
+++ b/docs/ci-gates.md
@@ -133,9 +133,19 @@ The other seven files under `python/tests/` have no skip path.
- **The `features/breadth` job runs no tests** (`test: false`); it is
`cargo check` plus clippy across all features. That is deliberate and is not a
skip, but it does mean an all-features build is type-checked and never run.
-- **Kani.** `make verify` runs three bounded-model-checking harnesses. No job
+- **Kani.** `make verify` runs fifteen bounded-model-checking harnesses. No job
installs Kani, so none of them runs in CI. `docs/trusted-computing-base.md`
- says so where it reports their results.
+ says so where it reports their results. (The count was three until 15
+ September 2026 and this line had not followed it.)
+- **Aeneas.** `aeneas/run.sh` re-translates `src/boundary_core.rs` into
+ `aeneas/lean/OOBoundary/Generated.lean` and fails if the model moved, and
+ `cd aeneas/lean && lake build` checks the theorems about it. NEITHER runs in
+ any job, and neither is reachable from `make check`, `cargo build`,
+ `cargo test` or `lean/`'s `lake build`. The first needs a 130 MB release
+ tarball and a pinned rustc nightly; the second needs Lean v4.31.0 and a 7.6 GB
+ `.lake` including Mathlib. `docs/aeneas-boundary.md` reports what they produced
+ when they were run here, which is the same arrangement Kani is under and for
+ the same reason: a gate nobody can run locally is not a gate.
- **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 whatever
diff --git a/docs/lean-certificates.md b/docs/lean-certificates.md
index 051ec314..3d40dc7e 100644
--- a/docs/lean-certificates.md
+++ b/docs/lean-certificates.md
@@ -590,7 +590,7 @@ distinction this is about. See
The theorem is conditional. It says that IF the asserted graph is `G` and IF these steps check,
THEN the conclusions hold in every model of `G`. Everything to the left of that is the Rust writing
down the truth, and the checker cannot see any of it: it reads files, not the store and not the
-run. `docs/trusted-computing-base.md` enumerates that boundary as twenty-nine checkable properties
+run. `docs/trusted-computing-base.md` enumerates that boundary as thirty checkable properties
and says for each what checks it. Read it before relying on a certificate, because a certificate is
a claim about a file and the file's relationship to the store is the part nobody proved.
## First-order model certificates: `oo-folmodel`
diff --git a/docs/trusted-computing-base.md b/docs/trusted-computing-base.md
index 309f3337..8e8a0de3 100644
--- a/docs/trusted-computing-base.md
+++ b/docs/trusted-computing-base.md
@@ -13,7 +13,7 @@ The point of writing it down is that an unwritten trusted base cannot be reviewe
finishes this page should be able to say how much of the engine is verified (almost none of it) and
which specific, small pieces carry the weight (the ones below).
-**Where this stands on 15 September 2026.** Of the twenty-nine properties, six are PROVED by bounded
+**Where this stands on 15 September 2026.** Of the thirty properties, six are PROVED by bounded
model checking rather than sampled: TCB-1, TCB-2, TCB-3, TCB-4, TCB-5 and TCB-20. Five moved from
something this repository OBSERVED to something it ENFORCES: TCB-4 and TCB-5 are now a refusal at
the certificate writer rather than a fact about `oxrdf` and `oxiri`; TCB-8 across runs was a DEFECT
@@ -634,3 +634,56 @@ the toolchain that runs it, and the axioms the proofs are stated over. A certifi
this page should say so in the same breath as it says what the engine does not prove about itself.
What can be done about that layer, what it would cost, and what was actually run, are in
[docs/independent-rechecking.md](independent-rechecking.md).
+
+<!-- ─────────────────────────────────────────────────────────────────────────
+ Everything below this line was added by the Aeneas work and is deliberately
+ kept as one self-contained section at the end of the file. It adds one
+ property (TCB-30) and does not edit any entry above it.
+ ───────────────────────────────────────────────────────────────────────── -->
+
+## Aeneas: the translation itself is now trusted, and that is a trade
+
+`docs/aeneas-boundary.md` is the full record. The short version belongs here because it adds an
+entry to the list above and takes nothing off it.
+
+The certificate boundary's pure core now lives in `src/boundary_core.rs`: seven functions and one
+enum over `u8`, `&[u8]`, `Vec<u8>`, `usize` and `bool`. `writable_triple`,
+`field_fits_the_format`, `term_fits_the_format`, `push_asserted_line` and `push_triple_fields` in
+`src/reason.rs`, and `name_is_safe` in `src/tableaux.rs`, are one-line wrappers over it.
+[Charon and Aeneas](https://github.com/AeneasVerif/aeneas) translate that file into a pure
+functional model in Lean 4, and `aeneas/lean/OOBoundary/Proofs.lean` proves things about the model
+for EVERY input rather than at a bound.
+
+- **TCB-30 (Aeneas's translation is faithful).** Every theorem in `aeneas/lean/` is a theorem about
+ `OOBoundary.boundary_core.*`, which is Aeneas's output, not about the Rust. If the translation is
+ wrong, the theorem is true of a function the engine does not run. Charon is a `rustc` driver and
+ Aeneas is an OCaml compiler from LLBC to a pure lambda calculus; together they are tens of
+ thousands of unverified lines, and Aeneas has no machine-checked soundness proof of its own
+ pipeline. This is the same shape of assumption as TCB-1's old reliance on `oxrdf`, moved one level
+ up.
+ *To close it:* nothing available today closes it. The partial mitigation in the tree is
+ `aeneas/run.sh`, which re-runs the translation and FAILS if the model moved, so a change to
+ `src/boundary_core.rs` cannot leave stale proofs in place unnoticed. A second mitigation that
+ costs nothing and is not implemented: translate to a second backend (Aeneas emits F\*, Coq and
+ HOL4 as well as Lean) and check that the two models agree, which would catch a backend bug though
+ not a front-end one.
+
+**Why this is worth doing anyway.** The trade is fifty thousand lines of unverified Rust for one
+unverified translator, on six functions that carry the whole serialisation half of this document.
+What it buys is the removal of the length bound. The Kani table above proves its statements for
+every byte pattern at a term length of at most four bytes, because a symbolic length made CBMC
+reach fifteen gigabytes without a verdict. The Lean theorems have no length bound and no
+shape bound.
+
+**What it does not buy, and this is the part to read twice.** `aeneas/lean/` is NOT `lean/`. It is a
+separate Lake workspace on a different Lean (v4.31.0 against v4.33.1) with ten packages including
+Mathlib against zero, and nothing in `make check` or in `lean/`'s `lake build` reaches it. The
+three-axiom pin on `lean/` is unchanged and still has no exceptions; `docs/aeneas-boundary.md`
+carries the axiom accounting for the other workspace separately, because a pin with an exception in
+it is not a pin.
+
+Measured there, and worth saying so that nobody guesses: all fourteen theorems in `aeneas/lean/`
+depend on exactly `[propext, Classical.choice, Quot.sound]` as well, pinned by
+`aeneas/lean/OOBoundary/Axioms.lean`. Mathlib brings packages, not axioms. What the axiom list does
+NOT measure is whether the model is the Rust, which is TCB-30, and that is the whole price of this
+work.
diff --git a/python/src/open_ontologies_lite/horn/reason.py b/python/src/open_ontologies_lite/horn/reason.py
index 15e44d95..e7275a87 100644
--- a/python/src/open_ontologies_lite/horn/reason.py
+++ b/python/src/open_ontologies_lite/horn/reason.py
@@ -246,7 +246,7 @@ def _facts(store, graphs) -> tuple[list[Fact], list[str]]:
The default is the DEFAULT GRAPH ALONE, which is where `OntologyEngine.load()`
puts everything, so this package's own users lose nothing by it. The Rust
engine flattens every named graph here EXCEPT the inferred one
- (`src/reason.rs:2968`, `graph.triples_outside(&[INFERRED_GRAPH])`). Before
+ (`src/reason.rs:2935`, `graph.triples_outside(&[INFERRED_GRAPH])`). Before
15 September 2026 it excepted nothing, which was the defect above: a store
holding a prior materialisation turned derived triples into assertions.
"""
diff --git a/python/tests/test_horn_differential.py b/python/tests/test_horn_differential.py
index 23158cf4..00afa4f8 100644
--- a/python/tests/test_horn_differential.py
+++ b/python/tests/test_horn_differential.py
@@ -26,7 +26,7 @@ WHAT IS COMPARED, AND WHAT IS NOT.
The assertion is SET EQUALITY OF DERIVED TRIPLES against the Rust `run_horn`, over
the same `builtin_rules.tsv`. Byte identity of the two `horn.tsv` files is NOT a
goal and must not be asserted: the Rust emitter sorts interned `u32` triples
-(`src/reason.rs:3038`, `all.sort_unstable()` over `Vec<(u32,u32,u32)>`), so its
+(`src/reason.rs:3005`, `all.sort_unstable()` over `Vec<(u32,u32,u32)>`), so its
line order is first-appearance order in the store, not lexicographic order.
Reproducing it from Python would mean reimplementing the interner and betting on
identical store-iteration order across two bindings, to buy nothing the set
diff --git a/python/tests/test_horn_fixpoint_and_scope.py b/python/tests/test_horn_fixpoint_and_scope.py
index ffbf8948..55850735 100644
--- a/python/tests/test_horn_fixpoint_and_scope.py
+++ b/python/tests/test_horn_fixpoint_and_scope.py
@@ -24,7 +24,7 @@ previous materialisation in the inferred graph turned derived triples into
ASSERTIONS. The checker could not detect it: the soundness theorem is conditional
on the assertions, and it is TOLD what they are, so the result was a green
absolute verdict about a graph nobody asserted. It now reads
-`src/reason.rs:2968`, `graph.triples_outside(&[INFERRED_GRAPH])`, and the
+`src/reason.rs:2935`, `graph.triples_outside(&[INFERRED_GRAPH])`, and the
inferred graph is out of scope.
The two engines still differ in HOW, and the difference is deliberate. Rust
diff --git a/src/boundary_core.rs b/src/boundary_core.rs
new file mode 100644
index 00000000..4fc46ff7
--- /dev/null
+++ b/src/boundary_core.rs
@@ -0,0 +1,173 @@
+//! The pure core of the certificate boundary, over bytes and nothing else.
+//!
+//! `docs/trusted-computing-base.md` says that every Lean theorem in `lean/` is
+//! conditional on the Rust engine writing down the truth, and that the code
+//! deciding whether it does is a handful of small, total, pure functions. This
+//! module is those functions. `src/reason.rs` and `src/tableaux.rs` call them;
+//! they are not a copy.
+//!
+//! Everything here is `u8`, `&[u8]`, `Vec<u8>`, `usize`, `bool` and one
+//! three-constructor enum. No `str`, no `String`, no trait beyond what the
+//! primitives carry, no type from any other crate. That is not a style rule.
+//! `aeneas/oo-boundary` reaches THIS FILE with `#[path]` and Aeneas translates
+//! it into a pure functional model in Lean 4; Aeneas handles a subset of safe
+//! Rust that stops at `str` and at anything reaching into `oxrdf` or `oxiri`.
+//! Widening a signature here to `&str` deletes the Lean model of that function.
+//! See `docs/aeneas-boundary.md`.
+//!
+//! The `&str` wrappers live at the call sites and are `as_bytes()` and nothing
+//! else. Every separator this module tests for is ASCII, and no ASCII byte can
+//! occur inside a multi-byte UTF-8 sequence, so a byte-level test and a
+//! `char`-level test agree on every `&str` and the wrapper costs nothing.
+//! `tcb_wrappers_agree_with_the_char_level_predicates` in `src/reason.rs` is
+//! the property test that pins that sentence.
+
+/// Which position of a certificate line refused to be written.
+///
+/// Deliberately a bare enum and not an `anyhow::Error`. A formatted error
+/// inside a writer is what put CBMC inside the formatting machinery and killed
+/// the first `parse_pat` Kani harness, and it would put Aeneas inside
+/// `core::fmt` too. The message a user reads is built by the caller, from this
+/// and the term.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum Position {
+ Subject,
+ Predicate,
+ Object,
+}
+
+/// Can this triple be written by an RDF serialiser?
+///
+/// A literal cannot be a subject and only an IRI can be a predicate, in every
+/// RDF 1.1 serialisation. Terms arrive in their N-Triples spelling, so a
+/// literal begins with `"` and an IRI with `<`. The history of the defect this
+/// guard closed is on `reason::writable_triple`, which is the `&str` wrapper.
+///
+/// Note what it says about the EMPTY subject: `"".starts_with('"')` is false,
+/// so an empty subject passes this guard. That is not a hole, because
+/// `term_fits_the_format` refuses an empty term outright and every certificate
+/// path runs both, but it is the kind of edge the bounded harness never saw:
+/// `writable_triple_decides_both_positions` fixes the term length at four
+/// bytes. `OOBoundary.writable_triple_bytes_eq` covers every length including
+/// zero.
+pub fn writable_triple_bytes(subject: &[u8], predicate: &[u8]) -> bool {
+ !starts_with_byte(subject, b'"') && starts_with_byte(predicate, b'<')
+}
+
+/// Whether `s` begins with the byte `b`. False on the empty slice.
+pub fn starts_with_byte(s: &[u8], b: u8) -> bool {
+ !s.is_empty() && s[0] == b
+}
+
+/// The half of [`term_fits_the_format`] that is about the FORMAT and not about
+/// N-Triples: a field is non-empty and carries no separator.
+///
+/// `horn.tsv` also writes variable names, which are not terms and have no
+/// N-Triples spelling, and this is what they have to satisfy.
+pub fn field_fits_the_format(f: &[u8]) -> bool {
+ if f.is_empty() {
+ return false;
+ }
+ let mut i = 0;
+ while i < f.len() {
+ if f[i] == b'\t' || f[i] == b'\n' || f[i] == b'\r' {
+ return false;
+ }
+ i += 1;
+ }
+ true
+}
+
+/// Whether a term can be written to a certificate file without forging it.
+///
+/// This is TCB-4 and TCB-5, enforced here rather than observed of `oxrdf`.
+/// The reasoning is on `reason::term_fits_the_format`, the `&str` wrapper.
+pub fn term_fits_the_format(t: &[u8]) -> bool {
+ if !field_fits_the_format(t) {
+ return false;
+ }
+ t[0] == b'<' || t[0] == b'"' || (t[0] == b'_' && t.len() > 1 && t[1] == b':')
+}
+
+/// A name that survives the round trip through `axioms.tsv` and `model.tsv`.
+///
+/// TCB-25. The concept grammar is SPACE separated and the files are TAB
+/// separated, so the DL path is exposed to a space as well as to the three
+/// separators `field_fits_the_format` refuses. The two predicates are
+/// deliberately separate functions rather than one with a flag: the set of
+/// bytes that breaks a format is a property of that format.
+pub fn name_is_safe_bytes(name: &[u8]) -> bool {
+ if name.is_empty() {
+ return false;
+ }
+ let mut i = 0;
+ while i < name.len() {
+ if name[i] == b' ' || name[i] == b'\t' || name[i] == b'\n' || name[i] == b'\r' {
+ return false;
+ }
+ i += 1;
+ }
+ true
+}
+
+/// Append one line of `asserted.tsv`: `s TAB p TAB o NEWLINE`.
+///
+/// This is the whole of that file's grammar, and it is the narrowest point of
+/// the trusted computing base: `OOCert.certificate_sound` is conditional on the
+/// asserted graph and `OOCert.Parse.parseTriples` recovers it by splitting on
+/// those two characters.
+///
+/// Every term is checked BEFORE anything is appended, so a refusal leaves `out`
+/// byte for byte as it was. A writer that appended a subject and then refused
+/// the object would leave a half-line in the buffer, which is the same defect
+/// the non-atomic materialiser had.
+pub fn push_asserted_line_bytes(
+ out: &mut Vec<u8>,
+ s: &[u8],
+ p: &[u8],
+ o: &[u8],
+) -> Result<(), Position> {
+ if !term_fits_the_format(s) {
+ return Err(Position::Subject);
+ }
+ if !term_fits_the_format(p) {
+ return Err(Position::Predicate);
+ }
+ if !term_fits_the_format(o) {
+ return Err(Position::Object);
+ }
+ out.extend_from_slice(s);
+ out.push(b'\t');
+ out.extend_from_slice(p);
+ out.push(b'\t');
+ out.extend_from_slice(o);
+ out.push(b'\n');
+ Ok(())
+}
+
+/// Append a triple as three further fields of a line already begun, the shape
+/// `derivations.tsv` and `horn.tsv` use after their header fields. Same guard
+/// and same all-or-nothing discipline as [`push_asserted_line_bytes`].
+pub fn push_triple_fields_bytes(
+ out: &mut Vec<u8>,
+ s: &[u8],
+ p: &[u8],
+ o: &[u8],
+) -> Result<(), Position> {
+ if !term_fits_the_format(s) {
+ return Err(Position::Subject);
+ }
+ if !term_fits_the_format(p) {
+ return Err(Position::Predicate);
+ }
+ if !term_fits_the_format(o) {
+ return Err(Position::Object);
+ }
+ out.push(b'\t');
+ out.extend_from_slice(s);
+ out.push(b'\t');
+ out.extend_from_slice(p);
+ out.push(b'\t');
+ out.extend_from_slice(o);
+ Ok(())
+}
diff --git a/src/lib.rs b/src/lib.rs
index 3cd79a46..3d9cc358 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,6 +4,11 @@ pub mod batch;
pub mod connect;
pub mod daemon;
pub mod output;
+// The pure core of the certificate boundary. PRIVATE on purpose: these are
+// the definitions `reason` and `tableaux` call, not a public API, and
+// `aeneas/oo-boundary` reaches the file itself with `#[path]` rather than
+// through this crate. See `docs/aeneas-boundary.md`.
+mod boundary_core;
pub mod borderline_loop;
pub mod buffer;
pub mod cache;
diff --git a/src/reason.rs b/src/reason.rs
index 4d039dee..a0d6e5a1 100644
--- a/src/reason.rs
+++ b/src/reason.rs
@@ -603,8 +603,16 @@ fn refutation_prefix(
///
/// Terms arrive in their N-Triples spelling, so a literal begins with `"` and
/// an IRI with `<`.
+///
+/// The body is `crate::boundary_core::writable_triple_bytes`, which is the
+/// function Aeneas translates into Lean. `OOBoundary.writable_triple_bytes_eq`
+/// proves it decides both positions for terms of EVERY length, which is the
+/// unbounded form of what `writable_triple_decides_both_positions` proves at a
+/// fixed four bytes. `str::starts_with` with an ASCII `char` and a leading-byte
+/// test agree on every `&str`, because no ASCII byte occurs inside a multi-byte
+/// UTF-8 sequence; `tcb_wrappers_agree_with_the_char_level_predicates` pins it.
fn writable_triple(subject: &str, predicate: &str) -> bool {
- !subject.starts_with('"') && predicate.starts_with('<')
+ crate::boundary_core::writable_triple_bytes(subject.as_bytes(), predicate.as_bytes())
}
/// Which position of a certificate line refused to be written.
@@ -614,12 +622,11 @@ fn writable_triple(subject: &str, predicate: &str) -> bool {
/// about, and a formatted error inside a function is what put CBMC inside the
/// formatting machinery and killed the first `parse_pat` harness. The message a
/// user reads is built by the caller, from this and the term.
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum Position {
- Subject,
- Predicate,
- Object,
-}
+///
+/// Defined in `crate::boundary_core` so that Aeneas translates it with the
+/// writers that return it, and re-exported here so `reason::Position` is still
+/// the path it always was.
+pub use crate::boundary_core::Position;
impl Position {
fn name(self) -> &'static str {
@@ -655,11 +662,7 @@ impl Position {
/// `_:` and quotes a `Literal`), and so does every constant `parse_pat` accepts,
/// so this refuses nothing the engine has any business writing.
fn term_fits_the_format(t: &str) -> bool {
- if !field_fits_the_format(t) {
- return false;
- }
- let b = t.as_bytes();
- b[0] == b'<' || b[0] == b'"' || (b[0] == b'_' && b.len() > 1 && b[1] == b':')
+ crate::boundary_core::term_fits_the_format(t.as_bytes())
}
/// The half of [`term_fits_the_format`] that is about the FORMAT and not about
@@ -668,18 +671,7 @@ fn term_fits_the_format(t: &str) -> bool {
/// `horn.tsv` also writes variable names, which are not terms and have no
/// N-Triples spelling, and this is what they have to satisfy.
fn field_fits_the_format(f: &str) -> bool {
- let b = f.as_bytes();
- if b.is_empty() {
- return false;
- }
- let mut i = 0;
- while i < b.len() {
- if b[i] == b'\t' || b[i] == b'\n' || b[i] == b'\r' {
- return false;
- }
- i += 1;
- }
- true
+ crate::boundary_core::field_fits_the_format(f.as_bytes())
}
/// Append one line of `asserted.tsv`: `s TAB p TAB o NEWLINE`.
@@ -696,45 +688,20 @@ fn field_fits_the_format(f: &str) -> bool {
/// byte for byte as it was. A writer that appended a subject and then refused
/// the object would leave a half-line in the buffer, which is the same defect
/// the non-atomic materialiser had.
-fn push_asserted_line(out: &mut String, s: &str, p: &str, o: &str) -> Result<(), Position> {
- if !term_fits_the_format(s) {
- return Err(Position::Subject);
- }
- if !term_fits_the_format(p) {
- return Err(Position::Predicate);
- }
- if !term_fits_the_format(o) {
- return Err(Position::Object);
- }
- out.push_str(s);
- out.push('\t');
- out.push_str(p);
- out.push('\t');
- out.push_str(o);
- out.push('\n');
- Ok(())
+///
+/// The buffer is a `Vec<u8>` and not a `String` because the body is
+/// `crate::boundary_core::push_asserted_line_bytes`, the function Aeneas
+/// translates. Nothing downstream notices: `std::fs::write` takes
+/// `AsRef<[u8]>`, and every byte appended here comes from a `&str`.
+fn push_asserted_line(out: &mut Vec<u8>, s: &str, p: &str, o: &str) -> Result<(), Position> {
+ crate::boundary_core::push_asserted_line_bytes(out, s.as_bytes(), p.as_bytes(), o.as_bytes())
}
/// Append a triple as three further fields of a line already begun, the shape
/// `derivations.tsv` and `horn.tsv` use after their header fields. Same guard
/// and same all-or-nothing discipline as [`push_asserted_line`].
-fn push_triple_fields(out: &mut String, s: &str, p: &str, o: &str) -> Result<(), Position> {
- if !term_fits_the_format(s) {
- return Err(Position::Subject);
- }
- if !term_fits_the_format(p) {
- return Err(Position::Predicate);
- }
- if !term_fits_the_format(o) {
- return Err(Position::Object);
- }
- out.push('\t');
- out.push_str(s);
- out.push('\t');
- out.push_str(p);
- out.push('\t');
- out.push_str(o);
- Ok(())
+fn push_triple_fields(out: &mut Vec<u8>, s: &str, p: &str, o: &str) -> Result<(), Position> {
+ crate::boundary_core::push_triple_fields_bytes(out, s.as_bytes(), p.as_bytes(), o.as_bytes())
}
// ─────────────────────────────────────────────────────────────────────────────
@@ -2236,7 +2203,7 @@ impl Reasoner {
if let Some(dir) = certificate_dir {
std::fs::create_dir_all(dir)?;
- let mut asserted = String::with_capacity(facts.len() * 96);
+ let mut asserted: Vec<u8> = Vec::with_capacity(facts.len() * 96);
for &(s, p, o) in &facts {
push_asserted_line(
&mut asserted,
@@ -2253,10 +2220,10 @@ impl Reasoner {
std::fs::write(dir.join("asserted.tsv"), asserted)?;
let mut by_rule: std::collections::BTreeMap<&str, usize> = std::collections::BTreeMap::new();
- let mut lines = String::with_capacity(derivations.len() * 256);
+ let mut lines: Vec<u8> = Vec::with_capacity(derivations.len() * 256);
for d in &derivations {
*by_rule.entry(d.rule).or_default() += 1;
- lines.push_str(d.rule);
+ lines.extend_from_slice(d.rule.as_bytes());
for &(s, p, o) in std::iter::once(&d.conclusion).chain(d.premises.iter()) {
push_triple_fields(
&mut lines,
@@ -2270,7 +2237,7 @@ impl Reasoner {
Position::Object => o,
})))?;
}
- lines.push('\n');
+ lines.push(b'\n');
}
std::fs::write(dir.join("derivations.tsv"), lines)?;
@@ -3116,7 +3083,7 @@ impl Reasoner {
}
std::fs::write(certificate_dir.join("rules.tsv"), &canonical_rules)?;
- let mut asserted = String::with_capacity(facts.len() * 96);
+ let mut asserted: Vec<u8> = Vec::with_capacity(facts.len() * 96);
for &(s, p, o) in &facts {
push_asserted_line(
&mut asserted,
@@ -3132,13 +3099,13 @@ impl Reasoner {
}
std::fs::write(certificate_dir.join("asserted.tsv"), asserted)?;
- let mut horn = String::with_capacity(steps.len() * 256);
+ let mut horn: Vec<u8> = Vec::with_capacity(steps.len() * 256);
let mut by_rule: Vec<usize> = vec![0; rules.len()];
for st in &steps {
by_rule[st.rule] += 1;
- horn.push_str(&st.rule.to_string());
- horn.push('\t');
- horn.push_str(&st.binds.len().to_string());
+ horn.extend_from_slice(st.rule.to_string().as_bytes());
+ horn.push(b'\t');
+ horn.extend_from_slice(st.binds.len().to_string().as_bytes());
for (v, term) in &st.binds {
// A variable name is not a term and has no N-Triples spelling,
// so it gets the format half of the guard. `parse_rules` cannot
@@ -3154,10 +3121,10 @@ impl Reasoner {
if !term_fits_the_format(bound) {
return Err(unwritable_term("horn.tsv", Position::Object, bound));
}
- horn.push('\t');
- horn.push_str(v);
- horn.push('\t');
- horn.push_str(bound);
+ horn.push(b'\t');
+ horn.extend_from_slice(v.as_bytes());
+ horn.push(b'\t');
+ horn.extend_from_slice(bound.as_bytes());
}
for &(s, p, o) in std::iter::once(&st.conclusion).chain(st.premises.iter()) {
push_triple_fields(
@@ -3172,7 +3139,7 @@ impl Reasoner {
Position::Object => o,
})))?;
}
- horn.push('\n');
+ horn.push(b'\n');
}
std::fs::write(certificate_dir.join("horn.tsv"), horn)?;
@@ -3392,7 +3359,7 @@ mod boundary_tests {
fn tcb_1_an_asserted_line_splits_back_into_its_three_terms(
s in term(), p in term(), o in term(),
) {
- let mut out = String::from("<a>\t<b>\t<c>\n");
+ let mut out: Vec<u8> = "<a>\t<b>\t<c>\n".as_bytes().to_vec();
let before = out.clone();
let r = push_asserted_line(&mut out, &s, &p, &o);
let fits = term_fits_the_format(&s)
@@ -3403,6 +3370,8 @@ mod boundary_tests {
prop_assert_eq!(out, before, "a refused line left a fragment behind");
return Ok(());
}
+ let out = String::from_utf8(out).expect("every byte came from a &str");
+ let before = String::from_utf8(before).expect("every byte came from a &str");
prop_assert!(out.ends_with('\n'));
let line = out.strip_prefix(&before).expect("the line was appended");
let body = &line[..line.len() - 1];
@@ -3417,8 +3386,8 @@ mod boundary_tests {
head in "[a-z0-9-]{1,8}",
ts in prop::collection::vec((term(), term(), term()), 1..4),
) {
- let mut out = String::new();
- out.push_str(&head);
+ let mut out: Vec<u8> = Vec::new();
+ out.extend_from_slice(head.as_bytes());
let mut written = 0usize;
for (s, p, o) in &ts {
let fits = term_fits_the_format(s)
@@ -3433,6 +3402,7 @@ mod boundary_tests {
written += 1;
}
}
+ let out = String::from_utf8(out).expect("every byte came from a &str");
let f: Vec<&str> = out.split('\t').collect();
prop_assert_eq!(f.len(), 1 + 3 * written);
prop_assert_eq!(f[0], head.as_str());
@@ -3473,6 +3443,46 @@ mod boundary_tests {
}
}
+ /// The `&str` wrappers agree with the `char`-level predicates they
+ /// replaced.
+ ///
+ /// `writable_triple`, `field_fits_the_format`, `term_fits_the_format`
+ /// and `name_is_safe` are now one line each, delegating to
+ /// `crate::boundary_core`, which is the file Aeneas translates into the
+ /// Lean model under `aeneas/`. The delegation is `as_bytes()` and the
+ /// argument that it changes nothing is that every byte those functions
+ /// look for is ASCII and no ASCII byte occurs inside a multi-byte UTF-8
+ /// sequence. That is an argument. This is the test: the ORIGINAL bodies
+ /// are written out here and required to agree with the shipped
+ /// wrappers on the same adversarial generator, including a combining
+ /// character, a NUL and a lexical form spelled like an IRI.
+ #[test]
+ fn tcb_wrappers_agree_with_the_char_level_predicates(t in term(), u in term()) {
+ for s in [&t, &u] {
+ // As `field_fits_the_format` was written before the extraction.
+ let field_before = !s.is_empty() && !s.contains(['\t', '\n', '\r']);
+ prop_assert_eq!(field_fits_the_format(s), field_before, "{:?}", s);
+
+ // As `term_fits_the_format` was written before the extraction.
+ let term_before = field_before && {
+ let b = s.as_bytes();
+ b[0] == b'<' || b[0] == b'"' || (b[0] == b'_' && b.len() > 1 && b[1] == b':')
+ };
+ prop_assert_eq!(term_fits_the_format(s), term_before, "{:?}", s);
+
+ // As `tableaux::name_is_safe` was written before the extraction.
+ let name_before = !s.is_empty() && !s.contains([' ', '\t', '\n', '\r']);
+ prop_assert_eq!(
+ crate::boundary_core::name_is_safe_bytes(s.as_bytes()),
+ name_before,
+ "{:?}", s
+ );
+ }
+ // As `writable_triple` was written before the extraction.
+ let writable_before = !t.starts_with('"') && u.starts_with('<');
+ prop_assert_eq!(writable_triple(&t, &u), writable_before, "{:?} {:?}", t, u);
+ }
+
/// TCB-20 at one rule position. `parse_pat` and `Pat::render` are
/// inverse, so a constant never renders to something that reads back as
/// a variable. `run_horn`'s re-parse guard rests on this.
@@ -3585,8 +3595,8 @@ mod kani_harnesses {
// A non-empty buffer, so "nothing was appended" is a real claim and not
// "the buffer is still empty".
- let mut out = String::with_capacity(4 * N + 8);
- out.push('x');
+ let mut out: Vec<u8> = Vec::with_capacity(4 * N + 8);
+ out.push(b'x');
let r = push_asserted_line(&mut out, s, p, o);
let fits =
@@ -3594,11 +3604,11 @@ mod kani_harnesses {
assert!(r.is_ok() == fits);
if !fits {
assert!(out.len() == 1);
- assert!(out.as_bytes()[0] == b'x');
+ assert!(out[0] == b'x');
return;
}
- let w = &out.as_bytes()[1..];
+ let w = &out[1..];
// Nothing added and nothing lost: three terms, two tabs, one newline.
assert!(w.len() == 3 * N + 3);
@@ -3681,8 +3691,8 @@ mod kani_harnesses {
let p = any_ascii(&mut b);
let o = any_ascii(&mut c);
- let mut out = String::with_capacity(4 * N + 8);
- out.push('r');
+ let mut out: Vec<u8> = Vec::with_capacity(4 * N + 8);
+ out.push(b'r');
let r = push_triple_fields(&mut out, s, p, o);
let fits =
@@ -3690,11 +3700,11 @@ mod kani_harnesses {
assert!(r.is_ok() == fits);
if !fits {
assert!(out.len() == 1);
- assert!(out.as_bytes()[0] == b'r');
+ assert!(out[0] == b'r');
return;
}
- let w = out.as_bytes();
+ let w = out.as_slice();
assert!(w.len() == 1 + 3 * N + 3);
assert!(w[0] == b'r');
assert!(w[1] == b'\t');
diff --git a/src/tableaux.rs b/src/tableaux.rs
index 6091c03d..751949e8 100644
--- a/src/tableaux.rs
+++ b/src/tableaux.rs
@@ -3766,8 +3766,16 @@ impl ModelOutcome {
/// and blank node labels never do. A literal can, and `owl:hasValue` is
/// approximated here by an atomic concept named after the individual, which may
/// be a literal. Refusing is the only honest answer for one of those.
+///
+/// The body is `crate::boundary_core::name_is_safe_bytes`, which is the
+/// function Aeneas translates into Lean. `OOBoundary.name_is_safe_bytes_iff`
+/// proves it accepts a name IF AND ONLY IF the name is non-empty and carries
+/// none of those four bytes, for names of every length, which is what the
+/// proptest below can only sample. All four are ASCII and no ASCII byte occurs
+/// inside a multi-byte UTF-8 sequence, so the byte-level test and
+/// `str::contains` over a `char` array agree on every `&str`.
fn name_is_safe(s: &str) -> bool {
- !s.is_empty() && !s.contains([' ', '\t', '\n', '\r'])
+ crate::boundary_core::name_is_safe_bytes(s.as_bytes())
}
// ── Serialisation ───────────────────────────────────────────────────────