Skip to content

--verdict: safe.ts's group_of picks a group by a def's first later-filled name, not by membership — a dead forward reference to a law crashes -o/--verdict, emits a non-member selector, or (with a name_tt collision) PASSes a book computing a different value #1212

Closed

Description

@Vacrin

What you did

bend fb3.bend; bend fb3.bend --verdict; then kernel oracles on bend fb3.bend -o fb3.bendtt (and --verdict on g4.bend, g2.bend)

What happened

fb3.bend (with a-b.bend beside it):
$ bend fb3.bend --check-only      ALL PROOFS CHECK
$ bend fb3.bend                   False{}
$ bend fb3.bend -o fb3.bendtt     exit 0, no out-of-scope lines
$ bend fb3.bend --verdict         ALL PROOFS CHECK
Kernel oracles appended to fb3.bendtt:
  ora : {main == (.True,  ()) : Bool} = {==}   -> ALL PROOFS CHECK
  ora : {main == (.False, ()) : Bool} = {==}   -> In ora: expected: main / observed: (.False, ())

g4.bend:
$ bend g4.bend --check-only       ALL PROOFS CHECK
$ bend g4.bend --verdict          TypeError: null is not an object (evaluating 'g.k')   (exit 1, no FAIL header)
$ bend g4.bend -o g4.bendtt       the same TypeError; no file written

g2.bend:
$ bend g2.bend --verdict          SOME PROOFS FAIL (MISMATCH)
  -o emits  use : ∀x0 : Nat -> Nat = λx0 => {(L.group x0 (.d, (.L, ()))) : Nat}
  kernel:   In use: a label of <L, h>

The file

# ---- a-b.bend ----
def ign(-b: Bool, r: Bool) -> Bool:
  r

law L:
  for n: Nat
  Bool

def M(n: Nat) -> Bool:
  ign(L(n), True{})

# ---- fb3.bend ----
import Base
import ./a-b.bend as AB

def a_2d_b.M(n: Nat) -> Bool:
  AB.ign(AB.L(n), False{})

def AB.L(n):
  match n:
    case Zero{}:
      True{}
    case Succ{p}:
      AB.M(p)

def main() -> Bool:
  a_2d_b.M(Zero{})

# ---- g4.bend ----
import Base
def keep(-p: Nat, x: Nat) -> Nat:
  x
law L:
  for n: Nat
  Nat
law L2:
  for n: Nat
  Nat
def h(n: Nat) -> Nat:
  keep(L(n), n)
def L(n):
  match n:
    case Zero{}:
      keep(L2(0n), 0n)
    case Succ{m}:
      h(m)
def L2(n):
  0n

How a group forms. later(k)
(safe.ts#L942-L945)
lists the defs k's body names that are filled after k. It reads refs (L1074-1089), which walks every
field except s, v and T, so a reference in an erased argument counts. group_of(k) (L947-953) is
group_new(later(k)[0] ?? k): the group led by k's first later-filled name, whether or not k is in it.
A live forward call to an unfilled law is rejected by bend2, but a dead one (keep(L(n), n) with
keep(-p: Nat, x: Nat)) is not.

Three faces from that.

  • Crash (g4). A call to the member h queues the item '\t' + L; item_emit (L272-274) rebuilds
    the group with group_of(e, L) — a different computation — and L's own dead reference to L2 gives
    group_new(L2), which is null because nothing names L2 back. group_emit dereferences g.k
    (L1014). A TypeError isn't a Scope_Error, so it escapes to main.ts as a raw trace.
  • Non-member selector (g2). args (L918-921) routes a call through group_call whenever
    group_of(k) is non-null, without checking membership. d has a dead reference to L, so its call
    goes out as L.group with selector .d, which isn't in the enum <L, h>.
  • Wrong program, PASS (fb3). Same misroute, but the non-member's name a_2d_b.M collides under
    name_tt with the module's member a-b.M (BendTT name escaping merges distinct constructor labels across module paths #1131), so the label lands inside the enum
    <a_2d_b.L, a_2d_b.M> and the kernel accepts. main is wired to the module's M (True); the local
    def the source names is emitted as a_2d_b.M_ and nothing references it.

Not a proof of Empty: bend2 checks the source at the source's types and the misroute only rewrites
safe.ts's copy, so whichever side reads a type as Empty rejects. But a --verdict PASS here no longer
attests to the source book.

  1. item_emit (L274): rebuild the group from its lead, group_emit(e, group_new(e, k.slice(1)) as Group, cols, n).
  2. args (L919): if (g !== null && g.ms.includes(k as Name)). With both, g2 and g4 PASS and use
    becomes λx0 => (d x0).
  3. Alternatively, have refs/later count only live positions, so a dead reference never forms a group
    (not tested).

Separately, C3 on #1131 (labels aren't made unique the way def names are) is what turns the misroute
into a silent PASS.

bend --version

bend 2.0.34

uname -sm

Linux x86_64

clang --version (the first line)

No response

Activity

  1. added
    bug
    on Sep 30, 2026
  2. quimmedes commented on Sep 30, 2026

    @quimmedes

    Reproduced the face-3 (value divergence) on HEAD 01875127 (2026-09-29), with a kernel-oracle pin-down. Using your fb3.bend + a-b.bend layout verbatim from the issue.

    This machine (Linux, bun 1.4.2, Lean v4.34.0):

    $ bend fb3.bend --check-only     ALL PROOFS CHECK
    $ bend fb3.bend --verdict         ALL PROOFS CHECK
    $ bend fb3.bend                   False{}          # source reading
    

    Then appending oracle defs to the emitted fb3.bendtt and running the standalone kernel binary directly:

    ora : {main == (.True, ()) : Bool} = {==}    -> ALL PROOFS CHECK
    ora : {main == (.False, ()) : Bool} = {==}   -> In ora: / expected: main / observed: (.False, ())
    

    So the verified book (double-green under --verdict) computes True{}, while the .bend source computes False{} — the a_2d_b.M override in main.bend is silently displaced by the library M through the group-merge (group_of picking the group led by the dead forward reference L), exactly as diagnosed.

    Two notes on exploitability, in case they help scope the fix:

    1. I could not turn the drift into a false claim through either gate: a claim matching the book ({main() == True{}}) is rejected by bend2's checker (expected : False{} / observed : True{} — bend2 checks the source reading), and a claim matching the source ({main() == False{}}) passes bend2 but the verdict self-confesses the TypeScript/kernel mismatch instead of validating. So today the leak is "a wrong book gets certified", not "a false proposition goes double-green" — the Claim.consistent side of the formalization keeps catching it.
    2. The crash face reproduces too, on the same HEAD: g4.bend verbatim gives --check-only green (ALL PROOFS CHECK) and --verdict the raw TypeError: null is not object (evaluating 'g.k') with no FAIL header — exit path identical to the report.
  3. Vacrin commented on Sep 30, 2026

    @Vacrin
    Author

    Appreciate the double check! Agreed, the kernel-oracle is the right way to nail face 3.

    Both directions of your note (1) reproduce on 2.0.32 as well.

    From my findings it isn't Claim.consistent that catches it. That claim is ¬ Conv bk d.T (Enu []) (bendtt.lean:1529 on 2.0.32, :1532 on HEAD) — no def of a checked book has type<> which never runs on this.

    What catches the false claim is the dual-gate structure: bend2 checks the source at the source's reading, safe.ts emits a rewritten book, the kernel checks that book, and the two disagree, so --verdict reports MISMATCH instead of PASS.
    The two independent readings fail to agree. Which is also why face 3 gets through in the first place: when the drift is in a value
    rather than a type, nothing forces the two readings to be compared at all.

    Related: Claim.consistent is narrower than its name suggests. It names Enu [], but safe.ts emits a user Empty as
    Σx0 : <> -> (Empty.arms x0), which the statement doesn't reach. It was filed separately as #1183.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions