Skip to content

Kani misses pow overflow panics #4970

Closed

Description

@zhouxt1

The problem is x.pow(e) don't panics on overflow.

I tried this code (as pow.rs:

pub fn pow(x: u32, e: u32) -> u32 { x.pow(e) }
pub fn mul(x: u32, y: u32) -> u32 { x * y }

#[cfg(kani)] #[kani::proof] #[kani::unwind(40)]
fn pow_overflow_panics() { let _ = pow(2, 32); }

#[cfg(kani)] #[kani::proof] #[kani::unwind(40)]
fn pow_value_is_zero() { assert!(pow(2, 32) == 0); }     

using the following command line invocation:

kani pow.rs

with Kani version:

Kani Rust Verifier 0.68.0 (standalone)
CBMC 6.11.0

I expected to see this happen:
both should fail with an overflow panic.

Instead, this happened:

SUMMARY:
 ** 0 of 23 failed (6 unreachable)

VERIFICATION:- SUCCESSFUL
Verification Time: 0.01692504s

Manual Harness Summary:
Complete - 2 successfully verified harnesses, 0 failures, 2 total.

I also found the older version of Kani (0.65.0) correctly catches the overflow.

The cause of the issue is that Kani routes the compiler intrinsic overflow_checks() to false at kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs#L64, even though Kani compiles with overflow checks on. And rust changed their implementation of pow into if overflow_checks() { strict_pow } else { wrapping_pow }. Under Kani, pow therefore always takes the wrapping_pow branch, which has no overflow check. So now, real Rust panics, but Kani misses the panic.

(found with help of Opus 5.5)

Activity

  1. added
    [C] Bug
    on Oct 5, 2026
  2. added
    T-High Priority
    on Nov 6, 2026
  3. added this to the Soundness milestone on Nov 6, 2026
  4. added
    Z-Kani Compiler
    on Nov 6, 2026
  5. added theissue type on Nov 6, 2026
  6. self-assigned this
    on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

T-High PriorityZ-Kani Compiler[C] Bug

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions