Merge pull request #423 from crytic/dev-fix-name-reused

Improve support of codebase with contract's name reused
pull/425/head
Feist Josselin 5 years ago committed by GitHub
commit d77ad1c8d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      slither/core/declarations/function.py
  2. 6
      slither/detectors/slither/name_reused.py
  3. 33
      slither/solc_parsing/declarations/contract.py
  4. 2
      slither/solc_parsing/slitherSolc.py

@ -1383,6 +1383,7 @@ class Function(ChildContract, ChildInheritance, SourceMapping):
compute_dominators(self.nodes) compute_dominators(self.nodes)
compute_dominance_frontier(self.nodes) compute_dominance_frontier(self.nodes)
transform_slithir_vars_to_ssa(self) transform_slithir_vars_to_ssa(self)
if not self.contract.is_incorrectly_constructed:
add_ssa_ir(self, all_ssa_state_variables_instances) add_ssa_ir(self, all_ssa_state_variables_instances)
def update_read_write_using_ssa(self): def update_read_write_using_ssa(self):

@ -79,10 +79,12 @@ As a result, the second contract cannot be analyzed.
for b in most_base_with_missing_inheritance: for b in most_base_with_missing_inheritance:
info = [b, ' inherits from a contract for which the name is reused.\n'] info = [b, ' inherits from a contract for which the name is reused.\n']
if b.inheritance: if b.inheritance:
info += ['\t- Slither could not determine which contract has a duplicate name, but it is NOT:\n'] info += ['\t- Slither could not determine which contract has a duplicate name:\n']
for inheritance in b.inheritance: for inheritance in b.inheritance:
info += ['\t\t-', inheritance, '\n'] info += ['\t\t-', inheritance, '\n']
info += ['\t- Check the inheritance tree to find which contract is missing from this list.\n'] info += ['\t- Check if:\n']
info += ['\t\t- A inherited contract is missing from this list,\n']
info += ['\t\t- The contract are imported from the correct files.\n']
if b.derived_contracts: if b.derived_contracts:
info += [f'\t- This issue impacts the contracts inheriting from {b.name}:\n'] info += [f'\t- This issue impacts the contracts inheriting from {b.name}:\n']
for derived in b.derived_contracts: for derived in b.derived_contracts:

@ -273,7 +273,8 @@ class ContractSolc04(Contract):
################################################################################### ###################################################################################
################################################################################### ###################################################################################
def log_incorrect_parsing(self): def log_incorrect_parsing(self, error):
logger.error(error)
self._is_incorrectly_parsed = True self._is_incorrectly_parsed = True
def analyze_content_modifiers(self): def analyze_content_modifiers(self):
@ -281,8 +282,7 @@ class ContractSolc04(Contract):
for modifier in self.modifiers: for modifier in self.modifiers:
modifier.analyze_content() modifier.analyze_content()
except (VariableNotFound, KeyError) as e: except (VariableNotFound, KeyError) as e:
logger.error(e) self.log_incorrect_parsing(f'Missing modifier {e}')
self.log_incorrect_parsing()
return return
def analyze_content_functions(self): def analyze_content_functions(self):
@ -290,8 +290,7 @@ class ContractSolc04(Contract):
for function in self.functions: for function in self.functions:
function.analyze_content() function.analyze_content()
except (VariableNotFound, KeyError) as e: except (VariableNotFound, KeyError) as e:
logger.error(e) self.log_incorrect_parsing(f'Missing function {e}')
self.log_incorrect_parsing()
return return
def analyze_params_modifiers(self): def analyze_params_modifiers(self):
@ -303,8 +302,7 @@ class ContractSolc04(Contract):
Cls = ModifierSolc Cls = ModifierSolc
self._modifiers = self._analyze_params_elements(elements_no_params, getter, getter_available, Cls) self._modifiers = self._analyze_params_elements(elements_no_params, getter, getter_available, Cls)
except (VariableNotFound, KeyError) as e: except (VariableNotFound, KeyError) as e:
logger.error(e) self.log_incorrect_parsing(f'Missing params {e}')
self.log_incorrect_parsing()
self._modifiers_no_params = [] self._modifiers_no_params = []
return return
@ -317,8 +315,7 @@ class ContractSolc04(Contract):
Cls = FunctionSolc Cls = FunctionSolc
self._functions = self._analyze_params_elements(elements_no_params, getter, getter_available, Cls) self._functions = self._analyze_params_elements(elements_no_params, getter, getter_available, Cls)
except (VariableNotFound, KeyError) as e: except (VariableNotFound, KeyError) as e:
logger.error(e) self.log_incorrect_parsing(f'Missing params {e}')
self.log_incorrect_parsing()
self._functions_no_params = [] self._functions_no_params = []
return return
@ -369,8 +366,7 @@ class ContractSolc04(Contract):
element.is_shadowed = True element.is_shadowed = True
accessible_elements[element.full_name].shadows = True accessible_elements[element.full_name].shadows = True
except (VariableNotFound, KeyError) as e: except (VariableNotFound, KeyError) as e:
logger.error(e) self.log_incorrect_parsing(f'Missing params {e}')
self.log_incorrect_parsing()
return all_elements return all_elements
def analyze_constant_state_variables(self): def analyze_constant_state_variables(self):
@ -458,8 +454,7 @@ class ContractSolc04(Contract):
var.analyze(self) var.analyze(self)
return return
except (VariableNotFound, KeyError) as e: except (VariableNotFound, KeyError) as e:
logger.error(e) self.log_incorrect_parsing(f'Missing state variable {e}')
self.log_incorrect_parsing()
def analyze_using_for(self): def analyze_using_for(self):
try: try:
@ -491,8 +486,7 @@ class ContractSolc04(Contract):
self._using_for[old].append(new) self._using_for[old].append(new)
self._usingForNotParsed = [] self._usingForNotParsed = []
except (VariableNotFound, KeyError) as e: except (VariableNotFound, KeyError) as e:
logger.error(e) self.log_incorrect_parsing(f'Missing using for {e}')
self.log_incorrect_parsing()
def analyze_enums(self): def analyze_enums(self):
try: try:
@ -505,8 +499,7 @@ class ContractSolc04(Contract):
self._analyze_enum(enum) self._analyze_enum(enum)
self._enumsNotParsed = None self._enumsNotParsed = None
except (VariableNotFound, KeyError) as e: except (VariableNotFound, KeyError) as e:
logger.error(e) self.log_incorrect_parsing(f'Missing enum {e}')
self.log_incorrect_parsing()
def _analyze_enum(self, enum): def _analyze_enum(self, enum):
# Enum can be parsed in one pass # Enum can be parsed in one pass
@ -540,8 +533,7 @@ class ContractSolc04(Contract):
for struct in self.structures: for struct in self.structures:
self._analyze_struct(struct) self._analyze_struct(struct)
except (VariableNotFound, KeyError) as e: except (VariableNotFound, KeyError) as e:
logger.error(e) self.log_incorrect_parsing(f'Missing struct {e}')
self.log_incorrect_parsing()
def analyze_events(self): def analyze_events(self):
try: try:
@ -555,8 +547,7 @@ class ContractSolc04(Contract):
event.set_offset(event_to_parse['src'], self.slither) event.set_offset(event_to_parse['src'], self.slither)
self._events[event.full_name] = event self._events[event.full_name] = event
except (VariableNotFound, KeyError) as e: except (VariableNotFound, KeyError) as e:
logger.error(e) self.log_incorrect_parsing(f'Missing event {e}')
self.log_incorrect_parsing()
self._eventsNotParsed = None self._eventsNotParsed = None

@ -227,7 +227,7 @@ class SlitherSolc(Slither):
if missing_inheritance: if missing_inheritance:
self._contract_with_missing_inheritance.add(contract) self._contract_with_missing_inheritance.add(contract)
contract.log_incorrect_parsing() contract.log_incorrect_parsing(f'Missing inheritance {contract}')
contract.set_is_analyzed(True) contract.set_is_analyzed(True)
contract.delete_content() contract.delete_content()

Loading…
Cancel
Save