Skip to content

Commit

Permalink
Reformat using newer versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
CI User committed Jun 13, 2024
1 parent 0e226bf commit 78dcc00
Show file tree
Hide file tree
Showing 129 changed files with 274 additions and 119 deletions.
3 changes: 3 additions & 0 deletions slither/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""
.. include:: ../README.md
"""

from .slither import Slither

__all__ = ["Slither"]
8 changes: 4 additions & 4 deletions slither/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ def _process(
###################################################################################


def get_detectors_and_printers() -> Tuple[
List[Type[AbstractDetector]], List[Type[AbstractPrinter]]
]:
def get_detectors_and_printers() -> (
Tuple[List[Type[AbstractDetector]], List[Type[AbstractPrinter]]]
):
detectors_ = [getattr(all_detectors, name) for name in dir(all_detectors)]
detectors = [d for d in detectors_ if inspect.isclass(d) and issubclass(d, AbstractDetector)]

Expand Down Expand Up @@ -825,7 +825,7 @@ def main_impl(

default_log = logging.INFO if not args.debug else logging.DEBUG

for (l_name, l_level) in [
for l_name, l_level in [
("Slither", default_log),
("Contract", default_log),
("Function", default_log),
Expand Down
1 change: 1 addition & 0 deletions slither/all_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module import all slither exceptions
"""

# pylint: disable=unused-import
from slither.slithir.exceptions import SlithIRError
from slither.solc_parsing.exceptions import ParsingError, VariableNotFound
Expand Down
5 changes: 3 additions & 2 deletions slither/analyses/data_dependency/data_dependency.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Compute the data depenency between all the SSA variables
"""

from collections import defaultdict
from typing import Union, Set, Dict, TYPE_CHECKING, List

Expand Down Expand Up @@ -380,7 +381,7 @@ def propagate_function(
transitive_close_dependencies(function, context_key, context_key_non_ssa)
# Propage data dependency
data_depencencies = function.context[context_key]
for (key, values) in data_depencencies.items():
for key, values in data_depencencies.items():
if key not in contract.context[context_key]:
contract.context[context_key][key] = set(values)
else:
Expand Down Expand Up @@ -493,7 +494,7 @@ def convert_to_non_ssa(
) -> Dict[SUPPORTED_TYPES, Set[SUPPORTED_TYPES]]:
# Need to create new set() as its changed during iteration
ret: Dict[SUPPORTED_TYPES, Set[SUPPORTED_TYPES]] = {}
for (k, values) in data_depencies.items():
for k, values in data_depencies.items():
var = convert_variable_to_non_ssa(k)
if var not in ret:
ret[var] = set()
Expand Down
1 change: 1 addition & 0 deletions slither/analyses/write/are_variables_written.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Detect if all the given variables are written in all the paths of the function
"""

from collections import defaultdict
from typing import Dict, Set, List, Any, Optional

Expand Down
2 changes: 2 additions & 0 deletions slither/core/cfg/node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Node module
"""

from enum import Enum
from typing import Optional, List, Set, Dict, Tuple, Union, TYPE_CHECKING

Expand Down Expand Up @@ -106,6 +107,7 @@ class NodeType(Enum):

# endregion


# I am not sure why, but pylint reports a lot of "no-member" issue that are not real (Josselin)
# pylint: disable=no-member
class Node(SourceMapping): # pylint: disable=too-many-public-methods
Expand Down
11 changes: 6 additions & 5 deletions slither/core/declarations/contract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""""
Contract module
"""

import logging
from collections import defaultdict
from pathlib import Path
Expand Down Expand Up @@ -528,9 +529,9 @@ def state_variables_used_in_reentrant_targets(

if self._state_variables_used_in_reentrant_targets is None:
reentrant_functions = [f for f in self.functions_entry_points if f.is_reentrant]
variables_used: Dict[
StateVariable, Set[Union[StateVariable, "Function"]]
] = defaultdict(set)
variables_used: Dict[StateVariable, Set[Union[StateVariable, "Function"]]] = (
defaultdict(set)
)
for function in reentrant_functions:
for ir in function.all_slithir_operations():
state_variables = [v for v in ir.used if isinstance(v, StateVariable)]
Expand Down Expand Up @@ -1455,7 +1456,7 @@ def add_constructor_variables(self) -> None:
from slither.core.declarations.function_contract import FunctionContract

if self.state_variables:
for (idx, variable_candidate) in enumerate(self.state_variables):
for idx, variable_candidate in enumerate(self.state_variables):
if variable_candidate.expression and not variable_candidate.is_constant:

constructor_variable = FunctionContract(self.compilation_unit)
Expand Down Expand Up @@ -1485,7 +1486,7 @@ def add_constructor_variables(self) -> None:
counter += 1
break

for (idx, variable_candidate) in enumerate(self.state_variables):
for idx, variable_candidate in enumerate(self.state_variables):
if variable_candidate.expression and variable_candidate.is_constant:

constructor_variable = FunctionContract(self.compilation_unit)
Expand Down
1 change: 1 addition & 0 deletions slither/core/declarations/function.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Function module
"""

import logging
from abc import abstractmethod, ABCMeta
from collections import namedtuple
Expand Down
1 change: 1 addition & 0 deletions slither/core/declarations/function_contract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Function module
"""

from typing import Dict, TYPE_CHECKING, List, Tuple, Optional

from slither.core.declarations.contract_level import ContractLevel
Expand Down
1 change: 1 addition & 0 deletions slither/core/declarations/function_top_level.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Function module
"""

from typing import Dict, List, Tuple, TYPE_CHECKING, Optional

from slither.core.declarations import Function
Expand Down
1 change: 1 addition & 0 deletions slither/core/declarations/modifier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Modifier module
"""

from .function_contract import FunctionContract


Expand Down
1 change: 1 addition & 0 deletions slither/core/declarations/solidity_import_placeholder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Special variable to model import with renaming
"""

from typing import Union

from slither.core.declarations import Import
Expand Down
1 change: 1 addition & 0 deletions slither/core/dominators/node_dominator_tree.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Nodes of the dominator tree
"""

from typing import TYPE_CHECKING, Set, List

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This expression does nothing, if a contract used it, its probably a bug
"""

from slither.core.expressions.expression import Expression
from slither.core.solidity_types.type import Type
from slither.core.solidity_types.elementary_type import ElementaryType
Expand Down
1 change: 1 addition & 0 deletions slither/core/slither_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Main module
"""

import json
import logging
import os
Expand Down
1 change: 1 addition & 0 deletions slither/core/solidity_types/user_defined_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from slither.core.declarations.enum import Enum
from slither.core.declarations.contract import Contract


# pylint: disable=import-outside-toplevel
class UserDefinedType(Type):
def __init__(self, t: Union["Enum", "Contract", "Structure"]) -> None:
Expand Down
1 change: 1 addition & 0 deletions slither/core/source_mapping/source_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# All an object needs to do is to inherits from SourceMapping
# And call set_offset at some point


# pylint: disable=too-many-instance-attributes
class Source:
def __init__(self, compilation_unit: "SlitherCompilationUnit") -> None:
Expand Down
2 changes: 2 additions & 0 deletions slither/core/variables/variable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Variable module
"""

from typing import Optional, TYPE_CHECKING, List, Union, Tuple

from slither.core.source_mapping.source_mapping import SourceMapping
Expand All @@ -10,6 +11,7 @@
if TYPE_CHECKING:
from slither.core.expressions.expression import Expression


# pylint: disable=too-many-instance-attributes
class Variable(SourceMapping):
def __init__(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions slither/detectors/attributes/const_functions_asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Module detecting constant functions
Recursively check the called functions
"""

from typing import List, Dict

from slither.core.compilation_unit import SlitherCompilationUnit
Expand Down
1 change: 1 addition & 0 deletions slither/detectors/attributes/const_functions_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Module detecting constant functions
Recursively check the called functions
"""

from typing import List, Dict

from slither.core.compilation_unit import SlitherCompilationUnit
Expand Down
1 change: 1 addition & 0 deletions slither/detectors/attributes/constant_pragma.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Check that the same pragma is used in all the files
"""

from collections import OrderedDict
from typing import List, Dict

Expand Down
1 change: 1 addition & 0 deletions slither/detectors/attributes/locked_ether.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Check if ethers are locked in the contract
"""

from typing import List

from slither.core.declarations import Contract, SolidityFunction
Expand Down
1 change: 1 addition & 0 deletions slither/detectors/attributes/unimplemented_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Collect all the interfaces
Check for contracts which implement all interface functions but do not explicitly derive from those interfaces.
"""

from typing import List
from slither.detectors.abstract_detector import (
AbstractDetector,
Expand Down
3 changes: 2 additions & 1 deletion slither/detectors/compiler_bugs/array_by_reference.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Detects the passing of arrays located in memory to functions which expect to modify arrays via storage reference.
"""

from typing import List, Set, Tuple, Union

from slither.core.declarations import Function
Expand Down Expand Up @@ -133,7 +134,7 @@ def detect_calls_passing_ref_to_function(
continue

# Verify one of these parameters is an array in storage.
for (param, arg) in zip(ir.function.parameters, ir.arguments):
for param, arg in zip(ir.function.parameters, ir.arguments):
# Verify this argument is a variable that is an array type.
if not isinstance(arg, (StateVariable, LocalVariable)):
continue
Expand Down
1 change: 1 addition & 0 deletions slither/detectors/compiler_bugs/enum_conversion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module detecting dangerous conversion to enum
"""

from typing import List, Tuple

from slither.core.cfg.node import Node
Expand Down
1 change: 1 addition & 0 deletions slither/detectors/compiler_bugs/public_mapping_nested.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module detecting public mappings with nested variables (returns incorrect values prior to 0.5.x)
"""

from typing import Any, List, Union
from slither.detectors.abstract_detector import (
AbstractDetector,
Expand Down
3 changes: 2 additions & 1 deletion slither/detectors/compiler_bugs/reused_base_constructor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module detecting re-used base constructors in inheritance hierarchy.
"""

from typing import Any, Dict, List, Tuple, Union
from slither.detectors.abstract_detector import (
AbstractDetector,
Expand Down Expand Up @@ -159,7 +160,7 @@ def _detect(self) -> List[Output]:
" arguments more than once in inheritance hierarchy:\n",
]

for (calling_contract, called_by_constructor) in call_list:
for calling_contract, called_by_constructor in call_list:
info += [
"\t- From ",
calling_contract,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module detecting ABIEncoderV2 array bug
"""

from typing import List, Set, Tuple
from slither.detectors.abstract_detector import (
AbstractDetector,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module detecting storage signed integer array bug
"""

from typing import List, Tuple, Set

from slither.core.declarations import Function, Contract
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module detecting uninitialized function pointer calls in constructors
"""

from typing import Any, List, Union
from slither.detectors.abstract_detector import (
AbstractDetector,
Expand Down
1 change: 1 addition & 0 deletions slither/detectors/erc/erc20/incorrect_erc20_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Detect incorrect erc20 interface.
Some contracts do not return a bool on transfer/transferFrom/approve, which may lead to preventing the contract to be used with contracts compiled with recent solc (>0.4.22)
"""

from typing import List, Tuple

from slither.core.declarations.contract import Contract
Expand Down
1 change: 1 addition & 0 deletions slither/detectors/erc/incorrect_erc721_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Detect incorrect erc721 interface.
"""

from typing import Any, List, Tuple, Union
from slither.detectors.abstract_detector import (
AbstractDetector,
Expand Down
3 changes: 2 additions & 1 deletion slither/detectors/erc/unindexed_event_parameters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Detect mistakenly un-indexed ERC20 event parameters
"""

from typing import Any, List, Tuple, Union
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification
from slither.core.declarations.contract import Contract
Expand Down Expand Up @@ -84,7 +85,7 @@ def _detect(self) -> List[Output]:
unindexed_params = self.detect_erc20_unindexed_event_params(c)
if unindexed_params:
# Add each problematic event definition to our result list
for (event, parameter) in unindexed_params:
for event, parameter in unindexed_params:

info = [
"ERC20 event ",
Expand Down
3 changes: 2 additions & 1 deletion slither/detectors/functions/arbitrary_send_eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
TODO: dont report if the value is tainted by msg.value
"""

from typing import Any, Tuple, Union, List

from slither.analyses.data_dependency.data_dependency import is_tainted, is_dependent
Expand Down Expand Up @@ -135,7 +136,7 @@ def _detect(self) -> List[Output]:

for c in self.contracts:
arbitrary_send_result = detect_arbitrary_send(c)
for (func, nodes) in arbitrary_send_result:
for func, nodes in arbitrary_send_result:

info = [func, " sends eth to arbitrary user\n"]
info += ["\tDangerous calls:\n"]
Expand Down
1 change: 1 addition & 0 deletions slither/detectors/functions/dead_code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module detecting dead code
"""

from typing import List, Tuple

from slither.core.declarations import Function, FunctionContract, Contract
Expand Down
Loading

0 comments on commit 78dcc00

Please sign in to comment.