Skip to content

Ordinary stub of a proof_for_contract or stub_verified target fails with an internal error #5206

Closed

Description

@feliperodri

Stubbing a function with an ordinary stub while the same function is also the target of #[kani::proof_for_contract] or #[kani::stub_verified] fails with an internal compiler error instead of a diagnostic.

Reproduce

#[kani::requires(x < 100)]
#[kani::ensures(|r: &u32| *r == x + 1)]
fn f(x: u32) -> u32 { x + 1 }

fn g(x: u32) -> u32 { x.wrapping_add(1) }

fn caller(x: u32) -> u32 { f(x) }

/// Stub the function under verification.
#[kani::proof_for_contract(f)]
#[kani::stub(f, g)]
fn check_target_stubbed() { let x = kani::any(); let _ = f(x); }

/// Stub a function that is also replaced by its contract.
#[kani::proof]
#[kani::stub_verified(f)]
#[kani::stub(f, g)]
fn verified_and_stubbed() { let x: u32 = kani::any_where(|x| *x < 100); let _ = caller(x); }
kani main.rs -Z function-contracts -Z stubbing --harness check_target_stubbed

Both harnesses fail with:

error: Failed to find contract closure `__kani_recursion_check_f` in function `main::f`

The stubbing pass replaces f's body with g's, and the contract pass then looks for f's generated closures in that body. This happens on main and with #5204. That PR fixes the ordinary case (#[kani::stub(f, g)] alone, #4591) but intentionally leaves these two combinations unchanged.

Expected

Both combinations are configuration mistakes: the first stubs the function under verification, the second stubs a function that is replaced by its contract. Kani should reject them with an error that names the conflicting attributes, e.g. "f cannot be both the target of proof_for_contract/stub_verified and replaced by #[kani::stub(f, g)]".

Activity

  1. added this to the Contracts milestone on Nov 19, 2026
  2. added
    [C] Bug
    [F] Crash
    Z-Contracts
    on Nov 19, 2026
  3. added a commit that references this issue on Nov 20, 2026
    70d7da0
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

    Z-Contracts[C] Bug[F] Crash

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions