Skip to content

Commit

Permalink
Merge branch 'run-black' into halstead
Browse files Browse the repository at this point in the history
  • Loading branch information
devtooligan committed May 2, 2023
2 parents 0decd00 + fd5a17f commit acec488
Show file tree
Hide file tree
Showing 126 changed files with 81 additions and 224 deletions.
1 change: 0 additions & 1 deletion examples/scripts/possible_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def __find_target_paths(target_function, current_path=None):
# Look through all functions
for contract in slither.contracts:
for function in contract.functions_and_modifiers_declared:

# If the function is already in our path, skip it.
if function in current_path:
continue
Expand Down
5 changes: 0 additions & 5 deletions examples/scripts/slithIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@

# Iterate over all the contracts
for contract in slither.contracts:

# Iterate over all the functions
for function in contract.functions:

# Dont explore inherited functions
if function.contract_declarer == contract:

print(f"Function: {function.name}")

# Iterate over the nodes of the function
for node in function.nodes:

# Print the Solidity expression of the nodes
# And the SlithIR operations
if node.expression:

print(f"\tSolidity expression: {node.expression}")
print("\tSlithIR:")
for ir in node.irs:
Expand Down
1 change: 0 additions & 1 deletion plugin_example/slither_my_plugin/detectors/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Example(AbstractDetector): # pylint: disable=too-few-public-methods
WIKI_RECOMMENDATION = ""

def _detect(self):

info = "This is an example!"

json = self.generate_result(info)
Expand Down
8 changes: 4 additions & 4 deletions slither/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,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 @@ -747,7 +747,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
4 changes: 2 additions & 2 deletions slither/analyses/data_dependency/data_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,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 not key in contract.context[context_key]:
contract.context[context_key][key] = set(values)
else:
Expand Down Expand Up @@ -492,7 +492,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 not var in ret:
ret[var] = set()
Expand Down
1 change: 0 additions & 1 deletion slither/analyses/evm/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def get_evm_instructions(obj):
assert isinstance(obj, (Function, Contract, Node))

if KEY_EVM_INS not in obj.context:

CFG = load_evm_cfg_builder()

slither = obj.slither
Expand Down
3 changes: 1 addition & 2 deletions slither/core/cfg/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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 Expand Up @@ -847,9 +848,7 @@ def add_phi_origin_state_variable(self, variable: StateVariable, node: "Node") -
###################################################################################

def _find_read_write_call(self) -> None: # pylint: disable=too-many-statements

for ir in self.irs:

self._slithir_vars |= {v for v in ir.read if self._is_valid_slithir_var(v)}

if isinstance(ir, OperationWithLValue):
Expand Down
6 changes: 2 additions & 4 deletions slither/core/declarations/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,9 +1379,8 @@ 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)
constructor_variable.set_function_type(FunctionType.CONSTRUCTOR_VARIABLES)
constructor_variable.set_contract(self) # type: ignore
Expand Down Expand Up @@ -1409,9 +1408,8 @@ 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)
constructor_variable.set_function_type(
FunctionType.CONSTRUCTOR_CONSTANT_VARIABLES
Expand Down
1 change: 0 additions & 1 deletion slither/core/expressions/new_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class NewArray(Expression):

# note: dont conserve the size of the array if provided
def __init__(
self, depth: int, array_type: Union["TypeAliasTopLevel", "ElementaryType"]
Expand Down
1 change: 0 additions & 1 deletion slither/core/scope/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def _generic_source_unit_getter(
name: str,
getter: Callable[[SourceUnit], Dict[str, AbstractReturnType]],
) -> Optional[AbstractReturnType]:

assert self.filename in crytic_compile_compilation_unit.source_units

source_unit = crytic_compile_compilation_unit.source_unit(self.filename)
Expand Down
4 changes: 0 additions & 4 deletions slither/core/slither_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ def _compute_offsets_from_thing(self, thing: SourceMapping):
implementation = get_implementation(thing)

for offset in range(definition.start, definition.end + 1):

if (
isinstance(thing, TopLevel)
or (
Expand All @@ -216,7 +215,6 @@ def _compute_offsets_from_thing(self, thing: SourceMapping):

for ref in references:
for offset in range(ref.start, ref.end + 1):

if (
isinstance(thing, TopLevel)
or (
Expand Down Expand Up @@ -300,7 +298,6 @@ def parse_ignore_comments(self, file: str) -> None:
# The first time we check a file, find all start/end ignore comments and memoize them.
line_number = 1
while True:

line_text = self.crytic_compile.get_code_from_line(file, line_number)
if line_text is None:
break
Expand Down Expand Up @@ -358,7 +355,6 @@ def has_ignore_comment(self, r: Dict) -> bool:
)

for file, lines in mapping_elements_with_lines:

# Check if result is within an ignored range.
ignore_ranges = self._ignore_ranges[file][r["check"]] + self._ignore_ranges[file]["all"]
for start, end in ignore_ranges:
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
2 changes: 1 addition & 1 deletion 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 Expand Up @@ -57,7 +58,6 @@ def to_detailed_str(self) -> str:
return f"{filename_short}{lines} ({self.starting_column} - {self.ending_column})"

def _get_lines_str(self, line_descr: str = "") -> str:

line_prefix = self.compilation_unit.core.line_prefix

lines = self.lines
Expand Down
1 change: 1 addition & 0 deletions slither/core/variables/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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
3 changes: 1 addition & 2 deletions slither/detectors/attributes/incorrect_solc.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,14 @@ def _detect(self) -> List[Output]:

# If we found any disallowed pragmas, we output our findings.
if disallowed_pragmas:
for (reason, p) in disallowed_pragmas:
for reason, p in disallowed_pragmas:
info: DETECTOR_INFO = ["Pragma version", p, f" {reason}\n"]

json = self.generate_result(info)

results.append(json)

if self.compilation_unit.solc_version not in self.ALLOWED_VERSIONS:

if self.compilation_unit.solc_version in self.BUGGY_VERSIONS:
info = [
"solc-",
Expand Down
1 change: 0 additions & 1 deletion slither/detectors/attributes/locked_ether.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class LockedEther(AbstractDetector): # pylint: disable=too-many-nested-blocks

ARGUMENT = "locked-ether"
HELP = "Contracts that lock ether"
IMPACT = DetectorClassification.MEDIUM
Expand Down
2 changes: 0 additions & 2 deletions slither/detectors/compiler_bugs/array_by_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def get_funcs_modifying_array_params(contracts: List[Contract]) -> Set[FunctionC
# Loop through all functions in all contracts.
for contract in contracts:
for function in contract.functions_declared:

# Skip any constructor functions.
if function.is_constructor:
continue
Expand Down Expand Up @@ -118,7 +117,6 @@ def detect_calls_passing_ref_to_function(
for contract in contracts:
for function in contract.functions_and_modifiers_declared:
for node in function.nodes:

# If this node has no expression, skip it.
if not node.expression:
continue
Expand Down
4 changes: 1 addition & 3 deletions slither/detectors/compiler_bugs/reused_base_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def _detect_explicitly_called_base_constructors(

# Loop until there are no queued contracts left.
while len(queued_contracts) > 0:

# Pop a contract off the front of the queue, if it has already been processed, we stop.
current_contract = queued_contracts.pop(0)
if current_contract in processed_contracts:
Expand Down Expand Up @@ -143,7 +142,6 @@ def _detect(self) -> List[Output]:

# Loop for each contract
for contract in self.contracts:

# Detect all locations which all underlying base constructors with arguments were called from.
called_base_constructors = self._detect_explicitly_called_base_constructors(contract)
for base_constructor, call_list in called_base_constructors.items():
Expand All @@ -159,7 +157,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
4 changes: 1 addition & 3 deletions slither/detectors/erc/unindexed_event_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def detect_erc20_unindexed_event_params(

# Loop through all events to look for poor form.
for event in contract.events_declared:

# If this is transfer/approval events, expect the first two parameters to be indexed.
if event.full_name in [
"Transfer(address,address,uint256)",
Expand All @@ -84,8 +83,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 ",
event,
Expand Down
3 changes: 1 addition & 2 deletions slither/detectors/functions/arbitrary_send_eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,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: 0 additions & 1 deletion slither/detectors/functions/dead_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class DeadCode(AbstractDetector):
WIKI_RECOMMENDATION = "Remove unused functions."

def _detect(self) -> List[Output]:

results = []

functions_used = set()
Expand Down
4 changes: 0 additions & 4 deletions slither/detectors/functions/external_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ def get_base_most_function(function: FunctionContract) -> FunctionContract:
# Loop through the list of inherited contracts and this contract, to find the first function instance which
# matches this function's signature. Note here that `inheritance` is in order from most basic to most extended.
for contract in function.contract.inheritance + [function.contract]:

# Loop through the functions not inherited (explicitly defined in this contract).
for f in contract.functions_declared:

# If it matches names, this is the base most function.
if f.full_name == function.full_name:
return f
Expand Down Expand Up @@ -159,14 +157,12 @@ def _detect(self) -> List[Output]: # pylint: disable=too-many-locals,too-many-b

# Loop through all contracts
for contract in self.contracts:

# Filter false-positives: Immediately filter this contract if it's in blacklist
if contract in dynamic_call_contracts:
continue

# Next we'll want to loop through all functions defined directly in this contract.
for function in contract.functions_declared:

# If all of the function arguments are non-reference type or calldata, we skip it.
reference_args = []
for arg in function.parameters:
Expand Down
1 change: 0 additions & 1 deletion slither/detectors/functions/protected_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


class ProtectedVariables(AbstractDetector):

ARGUMENT = "protected-vars"
HELP = "Detected unprotected variables"
IMPACT = DetectorClassification.HIGH
Expand Down
1 change: 0 additions & 1 deletion slither/detectors/functions/suicidal.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def _detect(self) -> List[Output]:
for c in self.contracts:
functions = self.detect_suicidal(c)
for func in functions:

info: DETECTOR_INFO = [func, " allows anyone to destruct the contract\n"]

res = self.generate_result(info)
Expand Down
2 changes: 0 additions & 2 deletions slither/detectors/naming_convention/naming_convention.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ def should_avoid_name(name: str) -> bool:

# pylint: disable=too-many-branches,too-many-statements
def _detect(self) -> List[Output]:

results = []
info: DETECTOR_INFO
for contract in self.contracts:

if not self.is_cap_words(contract.name):
info = ["Contract ", contract, " is not in CapWords\n"]

Expand Down
1 change: 0 additions & 1 deletion slither/detectors/operations/bad_prng.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def _detect(self) -> List[Output]:
for c in self.compilation_unit.contracts_derived:
values = detect_bad_PRNG(c)
for func, nodes in values:

for node in nodes:
info: List[AllSupportedOutput] = [func, ' uses a weak PRNG: "', node, '" \n']
res = self.generate_result(info)
Expand Down
4 changes: 1 addition & 3 deletions slither/detectors/operations/block_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def _detect_dangerous_timestamp(


class Timestamp(AbstractDetector):

ARGUMENT = "timestamp"
HELP = "Dangerous usage of `block.timestamp`"
IMPACT = DetectorClassification.LOW
Expand All @@ -81,8 +80,7 @@ def _detect(self) -> List[Output]:

for c in self.contracts:
dangerous_timestamp = _detect_dangerous_timestamp(c)
for (func, nodes) in dangerous_timestamp:

for func, nodes in dangerous_timestamp:
info: DETECTOR_INFO = [func, " uses timestamp for comparisons\n"]

info += ["\tDangerous comparisons:\n"]
Expand Down
Loading

0 comments on commit acec488

Please sign in to comment.