Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for powf operations #2966

Closed
nickgarfield opened this issue Jan 3, 2024 · 6 comments · Fixed by #2996
Closed

Support for powf operations #2966

nickgarfield opened this issue Jan 3, 2024 · 6 comments · Fixed by #2996
Assignees
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] Unsupported Construct Add support to an unsupported construct T-User Tag user issues / requests

Comments

@nickgarfield
Copy link

Requested feature: powf
Use case: I want to verify a function that uses powf
Link to relevant documentation (Rust reference, Nomicon, RFC): https://doc.rust-lang.org/std/primitive.f64.html#method.powf

Test case:

pub fn f(a: u64) -> u64 {
    const C: f64 = 0.618;
    (a as f64).powf(C) as u64
}

#[cfg(kani)]
mod verification {
    use super::*;

    #[kani::proof]
    fn verify_f() {
        const LIMIT: u64 = 10;
        let x: u64 = kani::any();
        let y: u64 = kani::any();
        kani::assume(x < LIMIT || x > u64::MAX - LIMIT);
        kani::assume(y < LIMIT || y > u64::MAX - LIMIT);
        kani::assume(x > y);
        let x_ = f(x);
        let y_ = f(y);
        assert!(x_ >= y_);
    }
}
@nickgarfield nickgarfield added the [C] Feature / Enhancement A new feature request or enhancement to an existing feature. label Jan 3, 2024
@nickgarfield
Copy link
Author

The docs suggest Numerics are fully supported. Without floats, I think "partial" would be more appropriate.

Screenshot 2024-01-03 at 15 12 06 Screenshot 2024-01-03 at 15 12 56

@zhassan-aws
Copy link
Contributor

Thanks for creating this issue, @nickgarfield.

This is related to #2763. Now that support has been added in CBMC (diffblue/cbmc#7906), this should be doable.

@zhassan-aws zhassan-aws added T-User Tag user issues / requests [E] Unsupported Construct Add support to an unsupported construct labels Jan 4, 2024
@adpaco-aws
Copy link
Contributor

Hi @nickgarfield , do you mind explaining the test case you attached? Does it test a well-known numerical property or why do you think it should pass?

The reason I'm asking is that I have a development version with the powf64 intrinsic, but the result I'm getting is not the one you're expecting:

SUMMARY:
 ** 1 of 89 failed
Failed Checks: assertion failed: x_ >= y_
 File: "powf_example.rs", line 20, in verification::verify_f

VERIFICATION:- FAILED
Verification Time: 0.59359556s

Concrete playback returns these inputs:

#[test]
fn kani_concrete_playback_verify_f_9913905681601751135() {
    let concrete_vals: Vec<Vec<u8>> = vec![
        // 18446744073709551608ul
        vec![248, 255, 255, 255, 255, 255, 255, 255],
        // 18446744073709551606ul
        vec![246, 255, 255, 255, 255, 255, 255, 255],
    ];
    kani::concrete_playback_run(concrete_vals, verify_f);
}

Running the test case with those inputs doesn't cause it to panic. It's possible that the intrinsic is over-approximating too much, but first I'd like to know more about your test case.

@adpaco-aws
Copy link
Contributor

The docs suggest Numerics are fully supported. Without floats, I think "partial" would be more appropriate.

I don't agree with this assessment. What we're missing support for are the pow* intrinsics which appear as "Not supported" in the table summarizing support for intrinsics.

Screenshot 2024-01-05 at 3 46 08 PM

@nickgarfield
Copy link
Author

Does it test a well-known numerical property or why do you think it should pass?

I drafted this example rather quickly. It might have some bugs. I was trying to write a proof to show f(x) > f(y) if x > y.

@adpaco-aws
Copy link
Contributor

We were discussing this issue now. We suspect it's a spurious failure due to over-approximation, but haven't determined it yet.

@celinval notes that, for the intrinsics that over-approximate, we should find a way to alert the user about such behaviors. This isn't the first time users are confused, see #1342 for another example.

tautschnig added a commit to tautschnig/kani that referenced this issue Feb 6, 2024
CBMC provides approximating implementations of these.

Resolves: model-checking#2763, model-checking#2966
adpaco-aws pushed a commit that referenced this issue Feb 7, 2024
CBMC provides approximating implementations of these.

Resolves: #2966
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] Unsupported Construct Add support to an unsupported construct T-User Tag user issues / requests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants