Skip to content

Commit

Permalink
add recursive check for base constructors | strange setter
Browse files Browse the repository at this point in the history
  • Loading branch information
olegggatttor committed Apr 12, 2024
1 parent 1d10755 commit d9a684c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion slitherin/detectors/strange_setter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification
from slither.core.declarations import Function
import slither.core.expressions.new_array as na
from slither.analyses.data_dependency.data_dependency import is_dependent


class StrangeSetter(AbstractDetector):
Expand Down Expand Up @@ -54,11 +55,18 @@ def _is_strange_setter(self, fun: Function) -> bool:
for arg in [*external.arguments, external._called._expression]:
if str(arg) == str(param):
used_params.add(param)
if fun.name == "constructor":
for base_call in fun.explicit_base_constructor_calls:
if not self._is_strange_constructor(base_call):
for param_cur in fun.parameters:
for param_base in base_call.parameters:
if is_dependent(param_base, param_cur, base_call):
used_params.add(param_cur)
intersection_len = len(set(fun.parameters) & used_params)
return intersection_len != len(fun.parameters)

def _is_strange_constructor(self, fun: Function) -> bool:
"""Checks if constructor sets nothing"""
"""Checks if constructor setqs nothing"""
return self._is_strange_setter(fun)

def _detect(self) -> List[Output]:
Expand Down
4 changes: 4 additions & 0 deletions tests/strange_setter_test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ contract OkConstructor {
init = true;
}
}

contract TestInheritance is StrangeSetter{
constructor(uint256 _toSet) StrangeSetter(_toSet) {}
}

0 comments on commit d9a684c

Please sign in to comment.