-
Notifications
You must be signed in to change notification settings - Fork 236
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
feat: Add 'bv_div_unsafe' to support 'bv / bv' expressions. #3030
Conversation
This is useful when encoding LLVM IR semantics into FStar, where we are only concerned about partial correctness in the cases where the denominator is nonzero. Thus, we introduce a new 'bv_div_unsafe' operations, with both operands as bitvectors, along with a soundness axiom which asserts that 'bv_div_unsafe' behaves as 'bv_div' when the denominator is nonzero. We add a 'bv_div_unsafe' lowering in the smt2 encoding that mimics 'bv_div'.
ed145ba
to
e99194f
Compare
Hi @bollu, wondering if this really a useful model to represent UB. For instance, at the F* level, |
ulib/FStar.BV.fsti
Outdated
|
||
(** An unsafe version of 'bvdiv' that does not impose the precondition that the | ||
denominator is nonzero. The behaviour of the solver when the denominator | ||
is zero is implementation-defined. *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more accurate to say that bvdiv_unsafe is an uninterpreted function on bv_t n, modeling the corresponding operator from SMT-LIB. When its second argument is zero, the lemma below says that it is equivalent to bvdiv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated comment.
ulib/FStar.BV.fst
Outdated
@@ -90,6 +90,11 @@ let bvdiv #n a b = | |||
let int2bv_div #n #x #y #z pf = | |||
inverse_vec_lemma #n (bvdiv #n (int2bv #n x) y) | |||
|
|||
let bvdiv_unsafe #n a b = admit () | |||
|
|||
let bvdiv_unsafe_sound #n #a #b b_nonzero_pf = admit () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under that revised implementation above, this lemma should be provable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proved.
This convention is used by most proof assistants. https://xenaproject.wordpress.com/2020/07/05/division-by-zero-in-type-theory-a-faq/
Thanks Sid! |
This is useful when encoding LLVM IR semantics into FStar, where we are only concerned about partial correctness in the cases where the denominator is nonzero. Thus, we introduce a new 'bv_div_unsafe' operations, with both operands as bitvectors, along with a soundness axiom which asserts that 'bv_div_unsafe' behaves as 'bv_div' when the denominator is nonzero.
We add a 'bv_div_unsafe' lowering in the smt2 encoding that mimics 'bv_div'.