Skip to content

Is there a same object check in Kani? #110

Answered by celinval
QinyuanWu asked this question in Q&A
Discussion options

You must be logged in to vote

@xsxszab Have you tried casting a pointer with valid memory allocation to unit using as *mut ()? For example, trait_object as *const dyn SampleTrait as *mut ()

I've tried it using the following code and it produced the same failed check:

#[kani::proof]
fn test_unit_type() {
  let unit_obj = ();
  let ptr1: *const () = &unit_obj;
  let ptr2: *const () = &unit_obj;
  assert!(kani::mem::same_allocation(ptr1, ptr2));
}

The main problem with this example is that an zero sized type (ZST) object is not allocated. That's why you are getting this error. Your contract has to account to that, i.e.:, check if the type is not a ZST first.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@xsxszab
Comment options

@zhassan-aws
Comment options

@xsxszab
Comment options

@celinval
Comment options

Answer selected by celinval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants