Skip to content

BendTT mismatch for opaque higher-order template with dependent equality result #1182

Open

Description

@leo-guinan

Bug description

Bend 2.0.32's ordinary checker accepts a closed definition containing an opaque higher-order template parameter whose result type contains dependent equality, but --verdict cannot validate the same definition and reports a TypeScript/BendTT mismatch.

This is not being claimed as a soundness exploit or bounty submission. The kernel rejects it; the report is for the reproducible checker/formalization synchronization failure.

Environment

  • Bend: 2.0.32
  • Source revision tested: v2.0.32, commit 573002f01ec6c52416d44489543f69a9625facf8
  • macOS arm64

Minimal reproducer

import Base

type N is Data:
  Z{}
  S{p: N}

def pred(n: N) -> N:
  match n:
    case Z{}: Z{}
    case S{p}: p

def inj(a: N, b: N, e: {S{a} == S{b} : N}) -> {a == b : N}:
  %x@e : {pred(S{a}) == pred(_) : N}
  {==}

def use(~F: @a: N -> @b: N -> {S{a} == S{b} : N} -> {a == b : N}, a: N, b: N, e: {S{a} == S{b} : N}) -> {a == b : N}:
  F(a, b, e)

def main() -> N:
  Z{}

Save as higher_evidence_base.bend and run:

bend higher_evidence_base.bend --check-only
bend higher_evidence_base.bend --verdict

Observed behavior

--check-only:

ALL PROOFS CHECK
Use --verdict for mathematical validity.

--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.

Minimization results

The mismatch disappears when any of these changes are made:

  • Remove the ~ from F and make it an ordinary affine function parameter.
  • Remove dependent equality from the result type while retaining equality as an input.
  • Use the standalone inj proof without the higher-order opaque template parameter.

Equality only as an input passes both checker and verdict. Equality in the result of an opaque ~F reproduces the mismatch.

I also tested direct, curried, let-bound, eta-expanded, and explicitly annotated applications. They all preserve the same mismatch. Making the result family reduce to an Empty branch does not produce an accepted proof: --verdict still rejects the definition.

Expected behavior

Either:

  1. the ordinary checker rejects this unsupported form before reporting ALL PROOFS CHECK, or
  2. BendTT accepts and validates the emitted term.

The current result is an explicit synchronization failure between the ordinary TypeScript checker and the formalized kernel.

Activity

  1. leo-guinan commented on Sep 29, 2026

    @leo-guinan
    Author

    Follow-up: we packaged the full investigation and reproducible receipts in a public repository:

    https://github.com/leo-guinan/bend-verdict-investigation

    Pinned environment:

    • Bend 2.0.32
    • commit 573002f01ec6c52416d44489543f69a9625facf8

    The repository documents the negative result: no bounty-grade live Empty inhabitant was found. It includes the 1,508-file scan receipts, targeted probe harnesses, minimized Bend files, and the higher-order dependent-equality mismatch from this issue.

    For the minimized reproducer in the repository:

    • --check-only returns ALL PROOFS CHECK
    • --verdict rejects with the TypeScript/formalized BendTT mismatch

    So this remains a synchronization bug report, not a false-proof or bounty claim.

  2. MuhDur commented on Sep 29, 2026

    @MuhDur

    Same mismatch, still present on 2.0.34 (commit 7d8a3eb), with a smaller reproducer: the trigger is calling a higher-order ~ parameter whose result is an equation with a non-variable side.

    import Base
    
    law v_n:
      for ~A: Data
      for ~le: A -> A -> Bool
      for ~step: @x: A -> @y: A -> {x == x : A} -> {le(x, y) == True{} : Bool}
      for +a: A
      for +b: A
      for h: {a == a : A}
      {le(a, b) == True{} : Bool}
    
    def v_n(A, le, step, a, b, h):
      step(a, b, h)
    

    --check-only → ALL PROOFS CHECK; --verdict → SOME PROOFS FAIL + the mismatch message.
    Bisection: declaring ~step without calling it passes, and so does calling it when it returns {le(x, y) == le(x, y) : Bool} or {x == x : A}.

    Impact: this is the usual shape of abstract order/algebra theorems (transitivity chains over a ~le with its laws passed as ~ proofs). In the published hub package bend-mathlib, 7 of 10 modules pass --verdict on 2.0.34, and the other three (algebra, order, sort) fail only on this. Happy to test a fix.

  3. MuhDur commented on Oct 1, 2026

    @MuhDur

    Root cause and a proposed fix in #1263: --verdict never reached the kernel here. safe.ts picks a model for each ~ constant one at a time, so le got λx y. False{} and then step had none (bend f.bend -o f.bendtt prints no model for v_n~step). The PR backtracks over the root's constants until their models hold together; contradictory ~ laws still stay out of scope.

    A correction to my comment above: with the fix, bend-mathlib's algebra and order pass --verdict, but sort still does not, for a second reason unrelated to this issue (20 defs report a kind that depends on a run-time value).

  4. nohzafk commented on Oct 10, 2026

    @nohzafk

    Another shape of the same mismatch, still present on 2.0.36. Here the ~ function has a model only together with the other ~ constant: it is the step hypothesis of a generic invariant ~P.

    import Base
    
    def lift(~P: @+n: Nat -> Bool, ~H: @+n: Nat -> @_: {P(n) == True{} : Bool} -> {P(1n+n) == True{} : Bool}, +n: Nat, h: {P(n) == True{} : Bool}) -> {P(1n+n) == True{} : Bool}:
      H(n, h)
    
    def twice(~P: @+n: Nat -> Bool, ~H: @+n: Nat -> @_: {P(n) == True{} : Bool} -> {P(1n+n) == True{} : Bool}, +n: Nat, h: {P(n) == True{} : Bool}) -> {P(2n+n) == True{} : Bool}:
      H(1n+n, H(n, h))
    
    $ bend h.bend --check-only
    ALL PROOFS CHECK
    $ bend h.bend --verdict
    SOME PROOFS FAIL
    Sorry - this is a mismatch between the TypeScript implementation, and the formalized BendTT kernel. ...
    $ bend h.bend -o h.bendtt
    BendTT: out of scope, so not in h.bendtt:
    - lift: no model for lift~H
    - twice: no model for lift~H
    

    What I found while narrowing it down:

    Impact: this is the usual shape of a preservation proof. You state an invariant once as ~P, take one ~H per operation saying the operation keeps P, and then induct over a run, applying each H once per step. In a scheduler core I am verifying, about 30 such lemmas sit under two top-level laws. Both pass --check-only and fail --verdict only because of this. The workaround is to instantiate every lemma for each concrete invariant, which multiplies the proof by the number of invariants.

    Environment: bend 2.0.36, macOS arm64.

  5. nohzafk commented on Oct 11, 2026

    @nohzafk

    Still reproduces on 2.0.36 (also 2.0.34 and 2.0.35). A smaller reproducer, and what -o says about it:

    import Base
    
    def k(~P: Nat, ~f: Nat -> {P == 1n : Nat}, x: Nat) -> {P == 1n : Nat}:
      f(x)
    
    $ bend t1.bend --check-only
    ALL PROOFS CHECK
    $ bend t1.bend --verdict
    SOME PROOFS FAIL
    Sorry - this is a mismatch between the TypeScript implementation, and the formalized BendTT kernel. ...
    $ bend t1.bend -o t1.bendtt
    BendTT: out of scope, so not in t1.bendtt:
    - k: no model for k~f
    

    The .bendtt file gives ~P the model opaque k_7e_P : Nat = (.Zero, ()). With that model, the type of ~f, Nat -> {0 == 1 : Nat}, has no inhabitant, so the translation has no model for ~f and leaves k out. Changing only the literal agrees with that reading:

    result type of ~f --verdict
    {P == 0n : Nat} ALL PROOFS CHECK
    {P == 1n : Nat} SOME PROOFS FAIL
    {1n == P : Nat} SOME PROOFS FAIL
    {P == P : Nat} ALL PROOFS CHECK
    {1n == 1n : Nat} (no ~P) ALL PROOFS CHECK
    {P == 1n : Nat}, f not a template ALL PROOFS CHECK
    {P == 1n : Nat}, ~f never applied ALL PROOFS CHECK

    The Bool version, ~P: Bool with ~f: Nat -> {P == True{} : Bool}, fails the same way.

    Impact: bend-mathlib's sort.bend (0.6.0.0 to 0.7.2.0) passes --check-only and fails --verdict. bend sort.bend -o sort.bendtt reports no model for internal_cons_ins_step~le_total for insert_by_sorted, isort_by_sorted and their helpers, because ~le_total: @x: A -> @y: A -> {le(x, y) == False{} : Bool} -> {le(y, x) == True{} : Bool} is this shape. Any project that proves under --verdict cannot import it.

  6. MuhDur commented on Oct 12, 2026

    @MuhDur

    A data point on how much of the "constants that only fit together" case is left, measured on a real library.

    bend-mathlib 0.7.3.0 (0xf8a2f05bbfb67041ce3d1eaece892a1a, published today) dropped the one #1483 shape it used, following bendlib/bendlib#25. On 2.0.36, everything it still leaves out of BendTT is no model for an abstract hypothesis that has a model only together with the other ~ constants of its def:

    module out of scope on 2.0.36 reason
    algebra 3 defs no model for internal_foldl_foldr~id (~id: @x: B -> {op(z, x) == x : B})
    order 6 defs no model for ~le_total (3), ~le_trans (2), ~le_antisymm (1)
    sort 13 defs no model for ~le_trans (8), ~le_total (5)

    nat, bool, list, string, maybe, equal and perm already pass --verdict. With the backtracking model search from #1263 (its branch, based on 2.0.35), algebra, order, sort and all print ALL PROOFS CHECK too, so every module of the package reaches the kernel and passes.

    Like nohzafk's ~H case, these hypotheses are abstract, so the book has no closed def of their types to use as a model. A model exists in each case (le := λx y. True{} with reflexivity proofs for the order hypotheses, B := Unit for ~id), but only if the constants are chosen together.

    Because --verdict rejects a file when any def of an imported module is out of scope, a project that gates on --verdict can't import sort, order, algebra or all today, even to use only the Nat instances, which do translate.

  7. aaaxn commented on Oct 14, 2026

    @aaaxn
    Contributor

    The v_n reproducer in the comment above fails because of the model that --verdict picks for ~le. model_at in bend2/safe.ts builds a model for each ~ parameter. It fills a datatype with the first constructor whose fields all get a model, and it fills each field with the first model it finds. Bool's first constructor is False, so ~le gets the model λx λy. False, and {le(x, y) == True{} : Bool} then has no model. With == False{} in both places, the same file passes --verdict, and its export shows the models: opaque v_n_7e_le ... = λx0 => λx1 => (.False, ()) and opaque v_n_7e_step ... = λx0 => λx1 => λx2 => {==}.

    The same choice rejects an inhabited type when the equation sits in a datatype field:

    import Base
    
    type Pos is Data:
      Pos{n: Nat, positive: {Nat.is_lt(0n, n) == True{} : Bool}}
    
    def pick(~make: Nat -> Pos, +p: Nat) -> Pos:
      make(p)
    

    At 32d23b43, --check-only passes and --verdict fails with no model for pick~make. The 2.0.37 release fails the same way; its --verdict prints only the mismatch banner, and -o names the same cause. The search sets n = 0 and never tries Pos{1n, {==}}. With Nat.is_le in place of Nat.is_lt, both pass. A type whose first constructor fails and whose second succeeds also passes, so the search does try other constructors, but not other field values. Calling pick with a valid instance does not help.

    The first reproducer in this issue is a different gap: an equation gets the model {==} only when its two sides convert, so {a == b} under {S{a} == S{b}} has no model, even though inj proves it.

  8. oxura commented on Oct 29, 2026

    @oxura
    Contributor

    The inj example in the issue body already passes on main 4f99f4c (use~F gets inj as its model). The original law_higher_evidence_probe.bend, without that helper, still fails.

    Working branch derives a total constructor-field projection and uses ordinary rewrite/reflexivity as the model. The real kernel now accepts that law, both fields of a mixed Bool/N record, and an equation-hypothesis identity. Ten existing model/proof cases keep the same verdicts. The unrelated-field and Empty-result probes still stay out of scope; erased evidence keeps its existing exclusion.

    No kernel changes or root-constant backtracking. Still holding the PR: safe.ts is 24599/24000, so this needs actual headroom from #1930. I haven't copied that unmerged patch or changed the cap. Checks were local --verdict runs, not the cluster gate.

  9. MuhDur commented on Oct 29, 2026

    @MuhDur

    Results for the working branch at 99b5554, run locally with --verdict (Lean v4.34.0, Linux x64):

    reproducer in this thread 2.0.39 main 4f99f4c 99b5554
    lift / twice (~P with the step hypothesis ~H) SOME PROOFS FAIL SOME PROOFS FAIL ALL PROOFS CHECK
    k(~P: Nat, ~f: Nat -> {P == 1n : Nat}, x) SOME PROOFS FAIL SOME PROOFS FAIL SOME PROOFS FAIL (no model for k~f)
    pick(~make: Nat -> Pos, +p) SOME PROOFS FAIL SOME PROOFS FAIL SOME PROOFS FAIL (no model for pick~make)

    So the branch also covers the preservation-proof shape (lift/twice), which is not among the cases listed above.

    As a regression check on a larger book: every module of bend-mathlib 0.8.0.0 (0x78e347bf8d0582a322c01b02c727566f: algebra, all, bool, equal, list, maybe, nat, order, perm, sort, string, u32) prints ALL PROOFS CHECK with --verdict on 99b5554, as it does on 2.0.39.

    That also settles my data point from 2026-10-12: since 2.0.38 the package leaves nothing out of BendTT, so algebra, order, sort and all no longer depend on this issue (-o reports no out-of-scope defs on 2.0.39). Of the reproducers in this thread, k and pick still fail on the branch, besides the original probe you mention.

  10. oxura commented on Oct 29, 2026

    @oxura
    Contributor

    Thanks for checking the whole book. I'll keep the distinction clear: the branch covers lift/twice, but it is not a general model-search fix; k and pick still fail on it. Publication is still held on the safe.ts budget.

  11. oxura commented on Oct 29, 2026

    @oxura
    Contributor

    Published as #1943 now that #1930 has merged. Same scope as the working branch: constructor-field projections and available equation hypotheses, not general model search (k/pick are not addressed). Requalified on 4982c105: 17 real CLI/kernel cases kept the expected verdicts, and the repo gate is 54/54 with unchanged caps.

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