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

Cannot verify a constant function if crate has effect feature enabled #3258

Closed
celinval opened this issue Jun 11, 2024 · 1 comment · Fixed by #3259
Closed

Cannot verify a constant function if crate has effect feature enabled #3258

celinval opened this issue Jun 11, 2024 · 1 comment · Fixed by #3259
Labels
[C] Bug This is a bug. Something isn't working.

Comments

@celinval
Copy link
Contributor

I tried this code:

#![feature(effects)]

#[kani::requires(kani::mem::can_dereference(arg))]
const unsafe fn dummy<T>(arg: *const T) -> T {
    std::ptr::read(arg)
}

#[kani::proof_for_contract(dummy)]
fn check() {
    unsafe { dummy(&kani::any::<u8>()) };
}

using the following command line invocation:

kani -Z function-contracts -Z mem-predicates contract.rs

with Kani version:

I expected to see this happen: Verification should pass;

Instead, this happened: Compilation fails

error: mismatch in the number of generic parameters: original function/method `dummy` takes 2 generic parameters(s), stub `dummy_recursion_wrapper_8b0f77` takes 1
  --> constant.rs:15:1
   |
15 | #[kani::proof_for_contract(dummy)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the attribute macro `kani::proof_for_contract` (in Nightly builds, run with -Z macro-backtrace for more info)
@celinval celinval added the [C] Bug This is a bug. Something isn't working. label Jun 11, 2024
@celinval
Copy link
Contributor Author

Note: For effects feature, the compiler inserts an extra constant parameter named "host". More implementation details here:

rust-lang/rust#113210
rust-lang/rust#118605

celinval added a commit that referenced this issue Jun 12, 2024
We now check if the host effect index is present. If so, remove it
before performing stub operation.

Resolves #3258
github-merge-queue bot pushed a commit that referenced this issue Oct 25, 2024
Culprit PR: rust-lang/rust#131985

The automatic PR failed because the culprit PR removed the
`host_param_index` field that we used in the `contract_host_param`
function. We needed the `contract_host_param` function in the first
place because previously, Rust would add a `<const HOST: bool>`
parameter to a function's `GenericArgs` to handle trait constness (c.f.
#3258). The culprit PR [removed that
argument](https://github.com/rust-lang/rust/pull/131985/files#diff-0a61b538a3cec072c76fecae4635af6a12ec3256860029ac70549c2aa53ab394L1527),
so our logic to find and remove this parameter during stubbing is no
longer necessary.

Resolves #3645

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Bug This is a bug. Something isn't working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant