Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions triton_viz/clients/sanitizer/sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
And,
Or,
Not,
Xor,
sat,
simplify,
)
Expand Down Expand Up @@ -1085,6 +1086,9 @@ def eval(self) -> tuple[Union[ArithRef, list[ArithRef]], list[BoolRef]]:
return expr, constraints

def _to_z3(self) -> tuple[ArithRef, list]:
def _to_bool(x):
return x if isinstance(x, BoolRef) else (x != 0)

if self._z3 is not None:
return self._z3, self._constraints

Expand Down Expand Up @@ -1159,8 +1163,15 @@ def _to_z3(self) -> tuple[ArithRef, list]:
self._z3 = If(lhs >= rhs, lhs, rhs)
if self.op == "minimum":
self._z3 = If(lhs <= rhs, lhs, rhs)
if self.op == "bitwise_and":
self._z3 = And(lhs, rhs)
if "bitwise" in self.op:
lhs = _to_bool(lhs)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the logic of to_bool.

You should probably look into BitVec in Z3

rhs = _to_bool(rhs)
if self.op == "bitwise_and":
self._z3 = And(lhs, rhs)
if self.op == "bitwise_or":
self._z3 = Or(lhs, rhs)
if self.op == "bitwise_xor":
self._z3 = Xor(lhs, rhs)
if self.op == "ashr":
raise NotImplementedError(
"Arithmetic shift right is not implemented in Z3"
Expand Down