Skip to content

Commit

Permalink
Make entry_point return an Optional[Node] and update the detectors
Browse files Browse the repository at this point in the history
Related to #1280
Fix #1279
  • Loading branch information
montyly committed Jul 27, 2022
1 parent 26ad3c6 commit 38511dd
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
3 changes: 3 additions & 0 deletions examples/scripts/taint_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@


def visit_node(node, visited):
if node is None:
return

if node in visited:
return

Expand Down
2 changes: 1 addition & 1 deletion slither/core/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
8 changes: 6 additions & 2 deletions slither/detectors/statements/calls_in_loop.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions slither/detectors/statements/costly_operations_in_loop.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions slither/detectors/statements/delegatecall_in_loop.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions slither/detectors/statements/msg_value_in_loop.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion slither/detectors/variables/uninitialized_local_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down

0 comments on commit 38511dd

Please sign in to comment.