Skip to content

Commit

Permalink
Merge pull request #2585 from crytic/dev-storage-location
Browse files Browse the repository at this point in the history
Add StateVariable location
  • Loading branch information
montyly authored Oct 10, 2024
2 parents f680cff + 1f32855 commit 570840d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions slither/core/variables/state_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class StateVariable(ContractLevel, Variable):
def __init__(self) -> None:
super().__init__()
self._node_initialization: Optional["Node"] = None
self._location: Optional[str] = None

def is_declared_by(self, contract: "Contract") -> bool:
"""
Expand All @@ -21,6 +22,19 @@ def is_declared_by(self, contract: "Contract") -> bool:
"""
return self.contract == contract

def set_location(self, loc: str) -> None:
self._location = loc

@property
def location(self) -> Optional[str]:
"""
Variable Location
Can be default or transient
Returns:
(str)
"""
return self._location

# endregion
###################################################################################
###################################################################################
Expand Down
15 changes: 15 additions & 0 deletions slither/solc_parsing/variables/state_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ def underlying_variable(self) -> StateVariable:
# Todo: Not sure how to overcome this with mypy
assert isinstance(self._variable, StateVariable)
return self._variable

def _analyze_variable_attributes(self, attributes: Dict) -> None:
"""
Variable Location
Can be default or transient
"""
if "storageLocation" in attributes:
self.underlying_variable.set_location(attributes["storageLocation"])
else:
# We don't have to support legacy ast
# as transient location was added in 0.8.28
# and we know it must be default
self.underlying_variable.set_location("default")

super()._analyze_variable_attributes(attributes)

0 comments on commit 570840d

Please sign in to comment.