Skip to content

Commit

Permalink
issue crytic#2085 fix: return UnaryType instead of UnaryOperationType…
Browse files Browse the repository at this point in the history
… for Unary IR operation
  • Loading branch information
dokzai committed Sep 4, 2023
1 parent 0de7a25 commit 4486a65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions slither/slithir/operations/unary.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
self,
result: Union[TemporaryVariableSSA, TemporaryVariable],
variable: Union[Constant, LocalIRVariable, LocalVariable],
operation_type: UnaryOperationType,
operation_type: UnaryType,
) -> None:
assert is_valid_rvalue(variable)
assert is_valid_lvalue(result)
Expand All @@ -53,7 +53,7 @@ def rvalue(self) -> Union[Constant, LocalVariable]:
return self._variable

@property
def type(self) -> UnaryOperationType:
def type(self) -> UnaryType:
return self._type

@property
Expand Down
10 changes: 9 additions & 1 deletion slither/visitors/slithir/expression_to_slithir.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
Member,
TypeConversion,
Unary,
UnaryType,
Unpack,
Return,
SolidityCall,
Expand Down Expand Up @@ -109,6 +110,13 @@ def set_val(expression: Expression, val: Any) -> None:
BinaryOperationType.OROR: BinaryType.OROR,
}


_unary_to_unary = {
UnaryOperationType.BANG: UnaryType.BANG,
UnaryOperationType.TILD: UnaryType.TILD,
}


_signed_to_unsigned = {
BinaryOperationType.DIVISION_SIGNED: BinaryType.DIVISION,
BinaryOperationType.MODULO_SIGNED: BinaryType.MODULO,
Expand Down Expand Up @@ -585,7 +593,7 @@ def _post_unary_operation(self, expression: UnaryOperation) -> None:
operation: Operation
if expression.type in [UnaryOperationType.BANG, UnaryOperationType.TILD]:
lvalue = TemporaryVariable(self._node)
operation = Unary(lvalue, value, expression.type)
operation = Unary(lvalue, value, _unary_to_unary[expression.type])
operation.set_expression(expression)
self._result.append(operation)
set_val(expression, lvalue)
Expand Down

0 comments on commit 4486a65

Please sign in to comment.