Skip to content

--verdict: the kernel runs out of fuel on conversion_shared_cells_once.bend, which bend2 checks by sharing (2.0.34) #1193

Open

Description

@nicolas-abril

What you did

cd tests/check
bun ../../bend2/main.ts conversion_shared_cells_once.bend --verdict

On main (eb8f58b1, Bend 2.0.34).

What happened

bend2 checks the file, but the kernel rejects it:

$ bun ../../bend2/main.ts conversion_shared_cells_once.bend --check-only
ALL PROOFS CHECK
Use --verdict for mathematical validity.

$ bun ../../bend2/main.ts conversion_shared_cells_once.bend --verdict
SOME PROOFS FAIL
Sorry - this is a mismatch between the TypeScript implementation, and the formalized BendTT kernel. ...

Running the kernel directly on the emitted book (9.8 KB) shows why:

$ bun ../../bend2/main.ts conversion_shared_cells_once.bend -o csc.bendtt
$ ~/.bend/bendtt/<hash>/bendtt csc.bendtt
SOME PROOFS FAIL
In agree_32:
out of fuel

It takes about 7 s to give up.

The test came in with 2.0.34 (#1071, PR #1151, 7d8a3eb0), which made bend2's conversion compare a shared graph once. As the test's own comment says, each of the 32 levels of both roots uses the level below twice, so comparing them as a tree takes about 2^32 steps. bend2 now avoids that blowup; the kernel in bend2/bendtt.lean doesn't, so it runs out of fuel on agree_32.

This wasn't caught because the normal gates don't run --verdict: gates/test.ts checks each test with --checkup, and gates/_run.ts runs repo, test, perf and ping. Only gates/safe.ts tests runs the kernel over the corpus. In a local --verdict sweep of all 1,522 files in tests/, this is the only kernel mismatch.

Expected

Either the kernel's conversion shares equal subterms the way bend2's now does (so agree_32 checks within its fuel), or the mismatch is recorded as a known limit of the kernel. Sharing in the kernel means bendtt.lean's proofs have to cover it.

The file

tests/check/conversion_shared_cells_once.bend:

import Base

def mix(a: U32, b: U32) -> U32:
  (a * 31 + b : U32)

def root_loop(d: Nat, +h: U32) -> U32:
  match d:
    case 0n: h
    case 1n+p: root_loop(p, mix(h, h))

def sq(+h: U32) -> U32:
  mix(h, h)

def root_rec(d: Nat, +x: U32) -> U32:
  match d:
    case 0n: x
    case 1n+p: sq(root_rec(p, x))

def agree_32(+x: U32) -> {root_loop(32n, x) == root_rec(32n, x) : U32}:
  {==}

bend --version

bend 2.0.34 (main at eb8f58b1)

uname -sm

Darwin arm64

clang --version (the first line)

Apple clang version 17.0.0 (clang-1700.6.4.2)

Activity

  1. added
    bug
    on Sep 29, 2026
  2. Lorenzobattistela commented on Oct 14, 2026

    @Lorenzobattistela
    Collaborator

    Timings on main (e78dc9c), with the kernel built from bend2/bendtt.lean:

    • agree_16: ALL PROOFS CHECK in 0.6 s
    • agree_20, agree_24, agree_32: out of fuel after about 7 s, reported as a mismatch

    This was the only ! (false reject) that gates/safe.ts found in tests (1635 files). Since #1556 makes the safe gate exit 1 on !, it cut conversion_shared_cells_once.bend from 32 levels to 16. The test can go back to 32 once the kernel compares shared cells once. (#1555 was a duplicate of this issue and is now closed.)

  3. Lorenzobattistela commented on Oct 16, 2026

    @Lorenzobattistela
    Collaborator

    #1593 by @GunnarZarncke has the same cause and has been closed as a duplicate of this issue. Here's what it adds:

    • A smaller repro (kernel_copy_shared.bend). Each step of run and dbl uses the previous value twice. bend shares that value, so its check time stays flat as n grows. The kernel copies it at every use, so its cost doubles with each level:

      n bend --check-only --verdict
      16 0.06 s 0.34 s, checks
      20 0.07 s 4.2 s, checks
      22 0.06 s 8.8 s, out of fuel
      60 0.06 s —
    • A regression test on main...GunnarZarncke:bend:kernel-copies-unshared. It passes gates/test.ts (it prints its #| line on every lane), and gates/safe.ts should classify it as a false reject.

    • A real-world case. He hit this while proving an ARM64 trap handler correct by running its machine code symbolically, where each state reads the previous one. Written the obvious way, the kernel got 5 steps in before it used 13 GB. The 80-step paths had to be cut into 154 segments of at most 8 steps, joined by a composition lemma, and the full kernel check took about 7 minutes (demos/hypervisor/SPEC.md §14, on the hypervisor branch of his fork).

    • Two possible fixes:

      1. the kernel evaluates a copied argument once and reuses it, or
      2. bend warns when a definition's unshared size would go over the kernel's fuel. Today nothing warns until --verdict runs.
    • Since --verdict reports a kernel "out of fuel" as a TypeScript/kernel mismatch, without the def or the reason (2.0.36) #1535, the "out of fuel" reason is shown, but the "Sorry - this is a mismatch…" text is still printed after it.

    For reference, #1556 cut agree_32 to 16 levels as a workaround, and #1555 tracks restoring it.

  4. wi001 commented on Oct 24, 2026

    @wi001

    Another case, still on 2.0.39: the kernel runs out of fuel when a lemma's type
    contains a large computation, which bend accepts.

    Reproduce: in busy_beaver/bb2.bend of https://github.com/wi001/bend2-trials,
    change check2 to A.check(TM.machine2(a0, a1, b0, b1), 6n, 1n, 100n) (drop
    the match u) and run bend PROOF.bend --verdict. It fails in
    bb2_elim.elim_a0.w.

    Workaround: start check2 with a match on a variable u, so the checks in
    lemma types stay unevaluated.

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