Skip to content

Commit

Permalink
Backporting 2.5.1 (#821)
Browse files Browse the repository at this point in the history
* Do not discard `bvnot` applied to uninterpreted terms

In PR #745 we correctly handled the case where uninterpreted terms
appear deep within a bit-vector terms, but we accidentally missed the
case where the whole bit-vector is itself an uninterpreted term, leading
to unsoundness (see the attached test).

This patch fixes the code to properly deal with `bvnot` applied to an
uninterpreted term.

* Update the changes log for v2.5.1

* Review changes

---------

Co-authored-by: Basile Clément <bc@ocamlpro.com>
  • Loading branch information
Halbaroth and bclement-ocp authored Sep 14, 2023
1 parent a5ce941 commit 26298cc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## unreleased

## v2.5.1

### Bug fixes
* fix a critical soundness bug with bvnot primitive (#819)

## v2.5.0

### New features
Expand Down
16 changes: 7 additions & 9 deletions src/lib/reasoners/bitv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,13 @@ module Shostak(X : ALIEN) = struct
let other ~neg t sz ctx =
let r, ctx' = X.make t in
let ctx = List.rev_append ctx' ctx in
match X.extract r with
| Some bv ->
if neg then
try negate_abstract bv, ctx with
| Failure _ ->
[ { bv = Other (X.term_embed (E.BV.bvnot t)); sz } ], ctx
else
bv, ctx
| None -> [ { bv = Other r; sz } ], ctx
let bv = embed r in
if neg then
try negate_abstract bv, ctx with
| Failure _ ->
[ { bv = Other (X.term_embed (E.BV.bvnot t)); sz } ], ctx
else
bv, ctx

let extract_st i j ({ bv; sz } as st) =
match bv with
Expand Down
2 changes: 2 additions & 0 deletions tests/bitv/testfile-bvnot-term.dolmen.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

unknown
7 changes: 7 additions & 0 deletions tests/bitv/testfile-bvnot-term.dolmen.smt2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(set-logic BV)

(declare-const x (_ BitVec 4))
(declare-const y (_ BitVec 4))
(assert (= x (bvnot y)))
(assert (distinct y x))
(check-sat)
22 changes: 22 additions & 0 deletions tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -117948,6 +117948,28 @@
(diff
testfile-bvnot.dolmen.expected
testfile-bvnot.dolmen_dolmen.output)))
(rule
(target testfile-bvnot-term.dolmen_dolmen.output)
(deps (:input testfile-bvnot-term.dolmen.smt2))
(package alt-ergo)
(action
(chdir %{workspace_root}
(with-stdout-to %{target}
(ignore-stderr
(with-accepted-exit-codes 0
(run %{bin:alt-ergo}
--timelimit=2
--enable-assertions
--output=smtlib2
--frontend dolmen
%{input})))))))
(rule
(alias runtest-quick)
(package alt-ergo)
(action
(diff
testfile-bvnot-term.dolmen.expected
testfile-bvnot-term.dolmen_dolmen.output)))
(rule
(target testfile-bitv023_ci_cdcl_no_minimal_bj.output)
(deps (:input testfile-bitv023.ae))
Expand Down

0 comments on commit 26298cc

Please sign in to comment.