Skip to content

--verdict: the kernel runs out of fuel on a closed Nat comparison of literals around 3 000 000 that bend2 checks at once (2.0.34) #1322

Open

Description

@jeromelaurens

What you did

bend fuel.bend             # bend2 only
bend fuel.bend --verdict   # bend2, then the BendTT kernel

Bend 2.0.34 (release v2.0.34, 7d8a3eb0), Bun 1.3.14, kernel built from bend2/bendtt.lean (digest of the file: 61e0d2d9f4ddd7dd) with Lean 4.34.0.

What happened

bend2 checks the file at once; the kernel runs out of fuel, and --verdict reports it as a mismatch:

$ bend fuel.bend
ALL PROOFS CHECK
Use --verdict for mathematical validity.

$ bend fuel.bend --verdict
SOME PROOFS FAIL
Sorry - this is a mismatch between the TypeScript implementation, and the formalized BendTT kernel. Your proofs may or may not be correct, and we cannot validate them yet. This will be addressed in a future update. Meanwhile, feel free to open an issue to report this bug.

$ bend fuel.bend -o fuel.bendtt && ~/.bend/bendtt/<hash>/bendtt fuel.bendtt
SOME PROOFS FAIL
In bigLe:
out of fuel

A Nat literal past 256n is U32.to_nat(n); bend2 evaluates it natively, the kernel evaluates it in unary and compares step by step, so one conversion on literals of a few million exhausts FUEL (400 000 000 in bendtt.lean). Measurements, one law per file, same machine (--verdict takes about 8 s to give up):

Law (proven by {==}) bend2 --verdict
{Nat.is_le(2500000n, 2500001n) == True{} : Bool} pass pass (7 s)
{Nat.is_le(3000000n, 3000001n) == True{} : Bool} pass out of fuel
{Nat.is_le(4200000n, 4200001n) == True{} : Bool} pass out of fuel
{Bool.and(Nat.is_le(1600000n, 1600001n), Nat.is_le(1600000n, 1600001n)) == True{} : Bool} pass out of fuel
{Nat.is_le(1600000n, 1600001n) == True{} : Bool} & {Nat.is_le(1600000n, 1600001n) == True{} : Bool}, proven by ({==}, {==}) pass pass

The last two rows show the budget is per conversion (Term.check's Rfl case calls Term.conv … FUEL afresh, bendtt.lean:1102): two comparisons that pass as two separate equalities fail inside one Boolean conversion. The practical case that led here: a closed Bool computation over a list of 18 inclusive intervals of code points up to 1114111n (Unicode's noncharacters), checked by bend2 in 13 s and rejected by the kernel with the same notice.

This is not #1193 (the kernel running out of fuel where bend2 shares a graph): no sharing is involved here, only the unary evaluation of literals. WONTFIX.txt covers bend2's own exponential or overflowing conversions and asks for large constants to stay abstract; it says nothing about the kernel's fuel, and the 2.0.34 changelog mentions it only for shared graphs. If the kernel's unary literals are a known limit, a line there and a verdict message that says "out of fuel" (what the kernel prints) instead of the generic mismatch notice would save the next person the diagnosis.

Expected: either a native path for Nat literals in the kernel's evaluator (a normal form for U32.to_nat of a literal that converts without unfolding), or the limit documented with its order of magnitude and surfaced by --verdict.

Workaround used: keep every large literal comparison in its own equality obligation (one {==} each) and derive the closed Bool form from a generic law, so that no single conversion evaluates more than one such comparison.

The file

import Base

law bigLe:
  {Nat.is_le(3000000n, 3000001n) == True{} : Bool}

def bigLe():
  {==}

The paired control (passes both checkers):

import Base

law paired:
  {Nat.is_le(1600000n, 1600001n) == True{} : Bool} &
  {Nat.is_le(1600000n, 1600001n) == True{} : Bool}

def paired():
  ({==}, {==})

and the same two comparisons inside one conversion (bend2 passes, the kernel runs out of fuel):

import Base

law combined:
  {Bool.and(Nat.is_le(1600000n, 1600001n),
    Nat.is_le(1600000n, 1600001n)) == True{} : Bool}

def combined():
  {==}

bend --version

bend 2.0.34 (bend --version is not an option in this release; the version is the release tag v2.0.34, 7d8a3eb0)

uname -sm

Darwin arm64

clang --version (the first line)

Apple clang version 21.0.0 (clang-2100.3.34.2)

Activity

  1. hotschmoe commented on Oct 16, 2026

    @hotschmoe

    Another case of the same fuel limit, with no large literals and no sharing: a long
    closed computation. This is the "proof by reflection" pattern (a decision procedure
    all_ok() -> Bool proven by {==}). bend2 accepts it and --verdict rejects it once
    one conversion needs more than FUEL (400 000 000) steps.

    import Base
    
    def walk(n: Nat) -> Bool:
      match n:
        case 0n:
          True{}
        case 1n+k:
          walk(k)
    
    def walk2(+m: Nat, n: Nat) -> Bool:
      match n:
        case 0n:
          True{}
        case 1n+k:
          walk(m) && walk2(m, k)
    
    def walk3(+m: Nat, +n: Nat, o: Nat) -> Bool:
      match o:
        case 0n:
          True{}
        case 1n+k:
          walk2(m, n) && walk3(m, n, k)
    
    # 2^24 calls of walk; with 128n for the last 256n (2^23 calls) --verdict passes
    law big:
      {walk3(256n, 256n, 256n) == True{} : Bool}
    
    def big():
      {==}
    $ bend repro.bend                # 6.7 s
    ALL PROOFS CHECK
    Use --verdict for mathematical validity.
    
    $ bend repro.bend --verdict      # 19.7 s
    SOME PROOFS FAIL
    Sorry - this is a mismatch between the TypeScript implementation, and the formalized BendTT kernel. ...
    
    $ bend repro.bend -o repro.bendtt && ~/.bend/bendtt/61e0d2d9f4ddd7dd/bendtt repro.bendtt
    SOME PROOFS FAIL
    In big:
    out of fuel
    

    Same result on 2.0.34, on the 2.0.37 linux-arm64 release, and with a kernel built from
    bendtt.lean at main d2aeefc1. The control with 128n passes all three.

    The limit is about 14.1 M recursive calls per {==}. I bisected the call count N
    with {(walk3(256n, 256n, a) && walk2(256n, b)) && walk(c) == True{} : Bool}, where
    N = 65536a + 256b + c:

    N kernel fuel used by the Rfl conversion
    65 536 checks 1 862 581
    1 048 576 checks 29 707 576
    14 121 495 checks 399 999 997
    14 121 496 out of fuel 400 000 017
    16 777 216 out of fuel 475 227 496

    That is about 28.3 fuel per call, linear in N. The fuel column comes from a copy of the
    kernel's Part 1 (the theory, without the proofs) with FUEL raised to 10^12 and a
    dbgTrace of FUEL - r.2 in Term.check's Rfl case. Its pass/fail boundary is the
    same as the stock kernel's.

    On real code this happens early. A GF(256) table-multiply law
    {mul_comm_all() == True{} : Bool}, which enumerates all 65 536 pairs, checks in bend2
    in about 60 s. The kernel fits 16 rows of 256 pairs (4 096 pairs, 398 458 951 fuel) and
    runs out at 17 rows (4 352 pairs, 424 359 031). The full law takes 6 619 901 069 (16.5×
    FUEL), and its sibling div_mul_all takes 8 570 460 762 (21.4×).

    I rebuilt the full bendtt.lean, proofs included, with only FUEL changed:

    • With 4 × 10^9, it accepts repro.bend and the 64-row law. It still rejects a false
      variant of the repro (== False{}) with expected: / observed:.
    • With 10^10, BENDTT=<that kernel> bend PROOF.bend --verdict on the whole 13-law GF(256)
      file prints ALL PROOFS CHECK (12 min).

    So this is a step budget, not a disagreement about what the terms reduce to.

    Two notes on the reporting side:

    • 2.0.37 still prints only the mismatch notice. fix(verdict): show kernel failure details (#1535) #1536 (in main, not in a release yet)
      adds the kernel's In big: / out of fuel above it. The notice still says "mismatch"
      and asks for an issue. fix(verdict): show kernel failure details (#1535) #1536 kept that on purpose, but for this class of failure the
      kernel did not decide anything.
    • Neither WONTFIX.txt nor the guide mentions the per-conversion budget. The guide
      presents {==} over a closed computation as a proof. One sentence giving the order of
      magnitude ("one {==} may take about 4 × 10^8 kernel steps, about 10^7 simple
      recursive calls; split larger closed checks into several laws") would have saved the
      diagnosis. A kernel flag or env var for the budget would also do, since running out
      only ever rejects.

    Environment: Linux aarch64; Lean 4.35.0 for the kernel builds (not the 4.34.0 the CLI
    asks for); bend 2.0.34 and 2.0.37.

    Investigated with the help of Claude Code; the repro and its 128n control were re-run on 2.0.34 just before posting.

  2. ScottMoore0 commented on Oct 17, 2026

    @ScottMoore0
    Contributor

    A variant that may help narrow this down (Bend 2.0.37): the literal only trips --verdict when it is bound to a reusable (+) parameter that is used twice.

    import Base
    
    def twice(+m: Nat) -> Bool:
      Bool.and(Nat.is_le(3n, m), Nat.is_le(4n, m))
    
    law dup_literal:
      {twice(2147483647n) == True{} : Bool}
    
    def dup_literal():
      {==}
    
    • --check-only: ALL PROOFS CHECK.
    • --verdict: SOME PROOFS FAIL, with "this is a mismatch between the TypeScript implementation, and the formalized BendTT kernel".
    • With 1000000n it passes --verdict; with 16777216n or 2147483647n it fails.
    • With m used once, or with the same literal placed in a constructor field, it passes.

    In practice this hits ordinary code. An allocator range defaulting to 0..2^31-1, or a decoder's output limit, ends up as exactly such a parameter. Libraries then switch those fields to U32 to keep --verdict usable.

    Found and tested with Claude Code, running Claude Opus 5.5, during an audit of --verdict.

  3. oxura commented on Oct 23, 2026

    @oxura
    Contributor

    I checked the emitted book rather than the notice: the literals arrive as Nat.add/Nat.mul over Zero/Succ, then Nat.cmp walks them. The unchanged kernel is 62,686/64,000 tokens with the pinned counter.

    For a real fast path, would you prefer compact literals with a proved expansion, or shortcuts for arithmetic definitions whose actual bodies match a proved model? The latter would keep the calculus unchanged; names like Nat.cmp alone wouldn't be trusted. I want to settle that shape before another PR, and won't trim the proof or change the cap.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions