Merge pull request #1968 from Tiko7454/master

Fixed issue which disallowed using operator[] with TopLevelVariables
pull/1991/head
Feist Josselin 1 year ago committed by GitHub
commit 69bf3bb284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      slither/slithir/operations/index.py
  2. 3
      slither/slithir/variables/reference.py
  3. 18
      slither/solc_parsing/variables/local_variable_init_from_tuple.py

@ -3,6 +3,7 @@ from typing import List, Union
from slither.core.declarations import SolidityVariableComposed from slither.core.declarations import SolidityVariableComposed
from slither.core.source_mapping.source_mapping import SourceMapping from slither.core.source_mapping.source_mapping import SourceMapping
from slither.core.variables.variable import Variable 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.operations.lvalue import OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue, RVALUE, LVALUE from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue, RVALUE, LVALUE
from slither.slithir.variables.reference import ReferenceVariable from slither.slithir.variables.reference import ReferenceVariable
@ -13,8 +14,10 @@ class Index(OperationWithLValue):
self, result: ReferenceVariable, left_variable: Variable, right_variable: RVALUE self, result: ReferenceVariable, left_variable: Variable, right_variable: RVALUE
) -> None: ) -> None:
super().__init__() super().__init__()
assert is_valid_lvalue(left_variable) or left_variable == SolidityVariableComposed( assert (
"msg.data" is_valid_lvalue(left_variable)
or left_variable == SolidityVariableComposed("msg.data")
or isinstance(left_variable, TopLevelVariable)
) )
assert is_valid_rvalue(right_variable) assert is_valid_rvalue(right_variable)
assert isinstance(result, ReferenceVariable) assert isinstance(result, ReferenceVariable)

@ -2,6 +2,7 @@ from typing import Optional, TYPE_CHECKING
from slither.core.declarations import Contract, Enum, SolidityVariable, Function from slither.core.declarations import Contract, Enum, SolidityVariable, Function
from slither.core.variables.variable import Variable from slither.core.variables.variable import Variable
from slither.core.variables.top_level_variable import TopLevelVariable
if TYPE_CHECKING: if TYPE_CHECKING:
from slither.core.cfg.node import Node from slither.core.cfg.node import Node
@ -46,7 +47,7 @@ class ReferenceVariable(Variable):
from slither.slithir.utils.utils import is_valid_lvalue from slither.slithir.utils.utils import is_valid_lvalue
assert is_valid_lvalue(points_to) or isinstance( assert is_valid_lvalue(points_to) or isinstance(
points_to, (SolidityVariable, Contract, Enum) points_to, (SolidityVariable, Contract, Enum, TopLevelVariable)
) )
self._points_to = points_to self._points_to = points_to

@ -16,3 +16,21 @@ class LocalVariableInitFromTupleSolc(VariableDeclarationSolc):
# Todo: Not sure how to overcome this with mypy # Todo: Not sure how to overcome this with mypy
assert isinstance(self._variable, LocalVariableInitFromTuple) assert isinstance(self._variable, LocalVariableInitFromTuple)
return self._variable 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)

Loading…
Cancel
Save