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

feat: Add 'bv_div_unsafe' to support 'bv / bv' expressions. #3030

Merged
merged 7 commits into from
Aug 25, 2023

Conversation

bollu
Copy link
Contributor

@bollu bollu commented Aug 24, 2023

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'.

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'.
@bollu bollu force-pushed the bvdiv_unsafe branch 2 times, most recently from ed145ba to e99194f Compare August 24, 2023 02:50
@mtzguido
Copy link
Member

Hi @bollu, wondering if this really a useful model to represent UB. For instance, at the F* level, bv_div_unsafe 1 0 is just a value, and equal to itself, so unless there's something I'm not seeing, using bv_div_unsafe for your semantics would mean the semantics guarantees that dividing by 0 is determinisitic, which is likely not what you want?


(** 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. *)
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated comment.

@@ -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 ()
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proved.

@nikswamy nikswamy marked this pull request as ready for review August 25, 2023 21:38
@nikswamy nikswamy enabled auto-merge August 25, 2023 21:38
@nikswamy
Copy link
Collaborator

Thanks Sid!

@nikswamy nikswamy merged commit 03b3086 into FStarLang:master Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants