Repository navigation
Description
Update: the same rule also splits the proven program from the one that runs, with LAWS.bend and PROOF.bend both canonical. See the comment below.
What I did
Put three files in one directory.
LAWS.bend (the human's file, unchanged throughout):
import Base
law two_plus_two:
{Nat.add(2n, 2n) == 5n : Nat}
LAWS.Nat.bend:
import Base
def add(a: Nat, b: Nat) -> Nat:
5n
PROOF.bend:
import Base
import ./LAWS.Nat.bend as H
import ./LAWS.bend as Laws
def Laws.two_plus_two():
{==}
Then run:
bun bend2/main.ts PROOF.bend
What happened
All terms check.
Exit code 0. There is no @unsafe, FFI, hole or open law. Without the import ./LAWS.Nat.bend as H line, the same PROOF.bend is rejected with expected : 4n / observed : 5n at LAWS.two_plus_two, as it should be.
Why it happens
parse_reso resolves a name k written in a module with namespace ns to ns + "." + k whenever that key is already in book.tlds or book.ctrs, and falls back to the global k otherwise (parse_reso). When PROOF.bend imports ./LAWS.bend, LAWS.bend is parsed with namespace LAWS, so its Nat.add is first looked up as LAWS.Nat.add.
A file named LAWS.Nat.bend gets namespace LAWS.Nat, and its def add is stored under the key LAWS.Nat.add. If that file is loaded before LAWS.bend, the lookup succeeds and the law's Nat.add becomes a Ref("LAWS.Nat.add") to the attacker's definition. The two keys never meet parse_fresh: LAWS.Nat.add and Base's Nat.add are different keys, so nothing is a duplicate.
The same rule applies to every call site of parse_reso: references, constructors, D<..> families, patterns, operator sugar and dotted field access.
It does not need PROOF.bend to look suspicious
The injected file can also be imported by application code that the AI owns. In demos/app_win_is_bug_2d, add one line to main.bend and one file:
# main.bend, after `import Base`
import ./LAWS.U32.bend as Q
# LAWS.U32.bend
import Base
def is_eq(a: U32, b: U32) -> Bool:
False{}
LAWS.bend is unchanged, and PROOF.bend keeps its canonical import Base / import ./main.bend as Game / import ./LAWS.bend as Laws header. Loading main.bend first registers LAWS.U32.is_eq, so the U32.is_eq(code, k) in LAWS.bend's ch now always returns False{}, and never_on_flag no longer looks at the board the page draws. This proof, which never mentions the map, then replaces the demo's certificate:
def row_no(s: String, x: Nat) -> {Laws.flag_in_row(s, x) == False{} : Bool}:
match s:
case SNil{}:
{==}
case SCon{c, rest}:
match c:
case Chr{code}:
match x:
case 0n:
{==}
case 1n+p:
row_no(rest, p)
def at_no(y: Nat, x: Nat, s: String) -> {Laws.flag_at(y, x, s) == False{} : Bool}:
match y:
case 0n:
row_no(s, x)
case 1n+q:
at_no(q, x, Laws.next_row(s))
def g_no(g: Game.Game) -> {Laws.at_flag(g) == False{} : Bool}:
match g:
case Game.Game{x, y, won}:
at_no(y, x, Laws.drawn())
def Laws.never_on_flag(moves):
g_no(Game.replay(Game.start(), moves))
bun bend2/main.ts PROOF.bend prints All terms check. and exits 0. Without the extra import in main.bend, the same proof fails with expected : Cmp.is_eq(U32.cmp(code, 70)) / observed : False{}.
Checking bend LAWS.bend on its own does not reveal anything, because as the root file LAWS.bend has namespace "" and resolves everything to Base.
Relation to #1001
This is related to #1001 in that a file PROOF.bend imports defeats the gate, but the mechanism is different and a fix for #1001 does not close it. There is no @unsafe to disclose here: every definition is safe and every law is filled. The problem is that the law being proven is not the law the human wrote.
Expected behavior
What a name in LAWS.bend refers to should not depend on which other files were loaded before it. The resolution of a name written in a module should depend only on that module's own declarations, its own imports and Base. A key that a different file registered under the module's namespace prefix should not count. Alternatively, the checker could reject any declaration whose key lands in another file's namespace, like LAWS.Nat.add from LAWS.Nat.bend, or a file namespace that is a dotted extension of another loaded file's namespace.
Version
bend 2.0.25
commit 26659268
Bun 1.4.2
Darwin arm64
Activity
jasisz commentedon Sep 23, 2026
The same resolution rule also splits the checked program from the program that runs, with LAWS.bend and PROOF.bend both completely ordinary. The app file is checked as a module, but
bend main.bendand the Bun/Node loader compile it as the root file, so its names resolve differently in the two places.main.bend:main.Nat.bend:LAWS.bend:PROOF.bend:A page that imports
./main.bendthrough the loader (asdemos/app_win_is_bug_2d/webdoes) gets the sameApp.next(5n) === 6n.Under PROOF.bend, main.bend has namespace
main, so itsNat.addresolves tomain.Nat.add, which is the keymain.Nat.bendregisters. Run as the root, main.bend has namespace"", whereparse_qualleavesNat.addalone, so it is Base's addition. The law is proven about one function and the other one ships. Nothing in LAWS.bend or PROOF.bend differs from the canonical layout; the only change is on the app side, which is the side the gate is meant to police.A fix for the original report should therefore make resolution independent of the importer as well: a file should mean the same thing whether it is the root or a module.
Checked on 6a77e12 (bend 2.0.26), Bun 1.4.2, Darwin arm64.
[-]A module named `LAWS.<X>.bend` changes what an unmodified LAWS.bend says: PROOF.bend proves `{Nat.add(2n, 2n) == 5n : Nat}`[/-][+]Names resolve to keys other files register under the importer's namespace: an app file can rewrite what LAWS.bend says, or make PROOF.bend check different code than `bend main.bend` runs[/+]A name is words joined by dots, a namespace is the file's real path, …