Skip to content

Commit

Permalink
Fixed issue which disallowed using operator[] with TopLevelVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiko7454 committed Jun 20, 2023
1 parent ccad542 commit 4735769
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
7 changes: 5 additions & 2 deletions slither/slithir/operations/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from slither.core.declarations import SolidityVariableComposed
from slither.core.source_mapping.source_mapping import SourceMapping
from slither.core.variables.variable import Variable
from slither.core.variables.top_level_variable import TopLevelVariable
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue, RVALUE, LVALUE
from slither.slithir.variables.reference import ReferenceVariable
Expand All @@ -13,8 +14,10 @@ def __init__(
self, result: ReferenceVariable, left_variable: Variable, right_variable: RVALUE
) -> None:
super().__init__()
assert is_valid_lvalue(left_variable) or left_variable == SolidityVariableComposed(
"msg.data"
assert (
is_valid_lvalue(left_variable)
or left_variable == SolidityVariableComposed("msg.data")
or isinstance(left_variable, TopLevelVariable)
)
assert is_valid_rvalue(right_variable)
assert isinstance(result, ReferenceVariable)
Expand Down
3 changes: 2 additions & 1 deletion slither/slithir/variables/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from slither.core.declarations import Contract, Enum, SolidityVariable, Function
from slither.core.variables.variable import Variable
from slither.core.variables.top_level_variable import TopLevelVariable

if TYPE_CHECKING:
from slither.core.cfg.node import Node
Expand Down Expand Up @@ -46,7 +47,7 @@ def points_to(self, points_to):
from slither.slithir.utils.utils import is_valid_lvalue

assert is_valid_lvalue(points_to) or isinstance(
points_to, (SolidityVariable, Contract, Enum)
points_to, (SolidityVariable, Contract, Enum, TopLevelVariable)
)

self._points_to = points_to
Expand Down
18 changes: 18 additions & 0 deletions slither/solc_parsing/variables/local_variable_init_from_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@ def underlying_variable(self) -> LocalVariableInitFromTuple:
# Todo: Not sure how to overcome this with mypy
assert isinstance(self._variable, LocalVariableInitFromTuple)
return self._variable

def _analyze_variable_attributes(self, attributes: Dict) -> None:
"""'
Variable Location
Can be storage/memory or default
"""
if "storageLocation" in attributes:
location = attributes["storageLocation"]
self.underlying_variable.set_location(location)
else:
if "memory" in attributes["type"]:
self.underlying_variable.set_location("memory")
elif "storage" in attributes["type"]:
self.underlying_variable.set_location("storage")
else:
self.underlying_variable.set_location("default")

super()._analyze_variable_attributes(attributes)

0 comments on commit 4735769

Please sign in to comment.