You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using #[kani::stub(target, replacement)] where target has a #[kani::ensures] contract produces a compilation error: Failed to find contract closure __kani_recursion_check_<fn_name>.
Minimal reproducer
#[kani::ensures(|result:&i32| *result >= 0)]fnabs_val(x:i32) -> i32{if x < 0{ -x }else{ x }}fnstub_abs_val(_x:i32) -> i32{let r:i32 = kani::any();
kani::assume(r >= 0);
r
}fncaller(x:i32) -> i32{abs_val(x) + 1}#[kani::proof]#[kani::stub(abs_val, stub_abs_val)]fncheck_caller(){let x:i32 = kani::any();let result = caller(x);assert!(result >= 1);}
$ cargo kani -Z function-contracts -Z stubbing
error: Failed to find contract closure `__kani_recursion_check_abs_val` in function `abs_val`
Expected behavior
#[kani::stub] should work on functions that have contracts. The stub replaces the function body entirely, so the contract instrumentation should be irrelevant.
Impact
This prevents compositional verification where a function has been proved correct via proof_for_contract and callers want to use a standard stub (not stub_verified) to abstract it away. The workaround is to remove the ensures contract from the target function, but this breaks the proof_for_contract harness.
It would help to clarify whether stubbing a contracted target is intended to bypass the target contract entirely or require the replacement to satisfy it. A regression matrix should cover ensures, requires, and recursion contracts independently, because the missing __kani_recursion_check_* closure may be generated only for one contract-lowering path.
Thanks, @hiSandog! I think this currently reflects a tooling limitation rather than intended semantics. With #[kani::stub(abs_val, stub_abs_val)], the abs_val body should be fully abstracted away for that harness, so requiring contract-generated closure symbols from abs_val (e.g. __kani_recursion_check_abs_val) appears inconsistent.
In other words, stubbing and contract instrumentation are not composed correctly yet: the pipeline still resolves contract artifacts for the original target even when the call is redirected. I believe expected behavior is that plain stub works regardless of whether the target has #[kani::ensures] (unless we explicitly document otherwise).
[Note to self] Proposed fix direction: adjust ordering/resolution so contract closure lookup is skipped or redirected when a stub replacement is active, and add this reproducer as a regression test.
Activity
hiSandog commentedon Jul 11, 2026
It would help to clarify whether stubbing a contracted target is intended to bypass the target contract entirely or require the replacement to satisfy it. A regression matrix should cover
ensures,requires, and recursion contracts independently, because the missing__kani_recursion_check_*closure may be generated only for one contract-lowering path.feliperodri commentedon Jul 11, 2026
Thanks, @hiSandog! I think this currently reflects a tooling limitation rather than intended semantics. With
#[kani::stub(abs_val, stub_abs_val)], theabs_valbody should be fully abstracted away for that harness, so requiring contract-generated closure symbols fromabs_val(e.g.__kani_recursion_check_abs_val) appears inconsistent.In other words, stubbing and contract instrumentation are not composed correctly yet: the pipeline still resolves contract artifacts for the original target even when the call is redirected. I believe expected behavior is that plain stub works regardless of whether the target has
#[kani::ensures](unless we explicitly document otherwise).[Note to self] Proposed fix direction: adjust ordering/resolution so contract closure lookup is skipped or redirected when a stub replacement is active, and add this reproducer as a regression test.
Support ordinary stubs of functions with contracts (model-checking#5204)