From 38511dd5d57e4eb7f9f90dfa9257e74f224cec2a Mon Sep 17 00:00:00 2001 From: Josselin Feist Date: Wed, 27 Jul 2022 11:23:39 +0200 Subject: [PATCH] Make entry_point return an Optional[Node] and update the detectors Related to #1280 Fix #1279 --- examples/scripts/taint_mapping.py | 3 +++ slither/core/declarations/function.py | 2 +- slither/detectors/statements/calls_in_loop.py | 8 ++++++-- slither/detectors/statements/costly_operations_in_loop.py | 8 ++++++-- slither/detectors/statements/delegatecall_in_loop.py | 8 ++++++-- slither/detectors/statements/msg_value_in_loop.py | 8 ++++++-- .../detectors/variables/uninitialized_local_variables.py | 6 +++++- .../variables/uninitialized_storage_variables.py | 2 +- 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/examples/scripts/taint_mapping.py b/examples/scripts/taint_mapping.py index feb843b203..75ed3d8df3 100644 --- a/examples/scripts/taint_mapping.py +++ b/examples/scripts/taint_mapping.py @@ -10,6 +10,9 @@ def visit_node(node, visited): + if node is None: + return + if node in visited: return diff --git a/slither/core/declarations/function.py b/slither/core/declarations/function.py index 8983769cc8..8ec5a00aea 100644 --- a/slither/core/declarations/function.py +++ b/slither/core/declarations/function.py @@ -538,7 +538,7 @@ def nodes(self, nodes: List["Node"]): self._nodes = nodes @property - def entry_point(self) -> "Node": + def entry_point(self) -> Optional["Node"]: """ Node: Entry point of the function """ diff --git a/slither/detectors/statements/calls_in_loop.py b/slither/detectors/statements/calls_in_loop.py index 7ea83f8fd9..fdd0c67329 100644 --- a/slither/detectors/statements/calls_in_loop.py +++ b/slither/detectors/statements/calls_in_loop.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Optional from slither.core.cfg.node import NodeType, Node from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification from slither.core.declarations import Contract @@ -22,7 +22,11 @@ def detect_call_in_loop(contract: Contract) -> List[Node]: return ret -def call_in_loop(node: Node, in_loop_counter: int, visited: List[Node], ret: List[Node]) -> None: +def call_in_loop( + node: Optional[Node], in_loop_counter: int, visited: List[Node], ret: List[Node] +) -> None: + if node is None: + return if node in visited: return # shared visited diff --git a/slither/detectors/statements/costly_operations_in_loop.py b/slither/detectors/statements/costly_operations_in_loop.py index d10cfaaf03..930085cc61 100644 --- a/slither/detectors/statements/costly_operations_in_loop.py +++ b/slither/detectors/statements/costly_operations_in_loop.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Optional from slither.core.cfg.node import NodeType, Node from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification from slither.core.declarations import Contract @@ -17,8 +17,12 @@ def detect_costly_operations_in_loop(contract: Contract) -> List[Node]: def costly_operations_in_loop( - node: Node, in_loop_counter: int, visited: List[Node], ret: List[Node] + node: Optional[Node], in_loop_counter: int, visited: List[Node], ret: List[Node] ) -> None: + + if node is None: + return + if node in visited: return # shared visited diff --git a/slither/detectors/statements/delegatecall_in_loop.py b/slither/detectors/statements/delegatecall_in_loop.py index 58de0359b6..b7bf70cbc7 100644 --- a/slither/detectors/statements/delegatecall_in_loop.py +++ b/slither/detectors/statements/delegatecall_in_loop.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Optional from slither.core.cfg.node import NodeType, Node from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification from slither.slithir.operations import LowLevelCall, InternalCall @@ -15,8 +15,12 @@ def detect_delegatecall_in_loop(contract: Contract) -> List[Node]: def delegatecall_in_loop( - node: Node, in_loop_counter: int, visited: List[Node], results: List[Node] + node: Optional[Node], in_loop_counter: int, visited: List[Node], results: List[Node] ) -> None: + + if node is None: + return + if node in visited: return # shared visited diff --git a/slither/detectors/statements/msg_value_in_loop.py b/slither/detectors/statements/msg_value_in_loop.py index 5bd5c398ca..bfd541201c 100644 --- a/slither/detectors/statements/msg_value_in_loop.py +++ b/slither/detectors/statements/msg_value_in_loop.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Optional from slither.core.cfg.node import NodeType, Node from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification from slither.slithir.operations import InternalCall @@ -15,8 +15,12 @@ def detect_msg_value_in_loop(contract: Contract) -> List[Node]: def msg_value_in_loop( - node: Node, in_loop_counter: int, visited: List[Node], results: List[Node] + node: Optional[Node], in_loop_counter: int, visited: List[Node], results: List[Node] ) -> None: + + if node is None: + return + if node in visited: return # shared visited diff --git a/slither/detectors/variables/uninitialized_local_variables.py b/slither/detectors/variables/uninitialized_local_variables.py index 45c86c22d0..7f7cb76e04 100644 --- a/slither/detectors/variables/uninitialized_local_variables.py +++ b/slither/detectors/variables/uninitialized_local_variables.py @@ -88,7 +88,11 @@ def _detect(self): for contract in self.compilation_unit.contracts: for function in contract.functions: - if function.is_implemented and function.contract_declarer == contract: + if ( + function.is_implemented + and function.contract_declarer == contract + and function.entry_point + ): if function.contains_assembly: continue # dont consider storage variable, as they are detected by another detector diff --git a/slither/detectors/variables/uninitialized_storage_variables.py b/slither/detectors/variables/uninitialized_storage_variables.py index a84462f38f..a0c35d80df 100644 --- a/slither/detectors/variables/uninitialized_storage_variables.py +++ b/slither/detectors/variables/uninitialized_storage_variables.py @@ -96,7 +96,7 @@ def _detect(self): for contract in self.compilation_unit.contracts: for function in contract.functions: - if function.is_implemented: + if function.is_implemented and function.entry_point: uninitialized_storage_variables = [ v for v in function.local_variables if v.is_storage and v.uninitialized ]