def fire_lasers( self, modules: Optional[List[str]] = None, transaction_count: Optional[int] = None, ) -> Report: """ :param modules: The analysis modules which should be executed :param transaction_count: The amount of transactions to be executed :return: The Report class which contains the all the issues/vulnerabilities """ all_issues = [] # type: List[Issue] SolverStatistics().enabled = True exceptions = [] for contract in self.contracts: StartTime() # Reinitialize start time for new contracts try: sym = SymExecWrapper( contract, self.address, self.strategy, dynloader=DynLoader( self.eth, storage_loading=self.onchain_storage_access, contract_loading=self.dynld, ), max_depth=self.max_depth, execution_timeout=self.execution_timeout, loop_bound=self.loop_bound, create_timeout=self.create_timeout, transaction_count=transaction_count, modules=modules, compulsory_statespace=False, enable_iprof=self.enable_iprof, disable_dependency_pruning=self.disable_dependency_pruning, ) issues = fire_lasers(sym, modules) except KeyboardInterrupt: log.critical("Keyboard Interrupt") issues = retrieve_callback_issues(modules) except Exception: log.critical( "Exception occurred, aborting analysis. Please report this issue to the Mythril GitHub page.\n" + traceback.format_exc()) issues = retrieve_callback_issues(modules) exceptions.append(traceback.format_exc()) for issue in issues: issue.add_code_info(contract) all_issues += issues log.info("Solver statistics: \n{}".format(str(SolverStatistics()))) source_data = Source() source_data.get_source_from_contracts_list(self.contracts) # Finally, output the results report = Report(contracts=self.contracts, exceptions=exceptions) for issue in all_issues: report.append_issue(issue) return report
def __init__( self, contract, function_name, address, swc_id, title, bytecode, gas_used=(None, None), severity=None, description_head="", description_tail="", debug="", ): """ :param contract: The contract :param function_name: Function name where the issue is detected :param address: The address of the issue :param swc_id: Issue's corresponding swc-id :param title: Title :param bytecode: bytecode of the issue :param gas_used: amount of gas used :param severity: The severity of the issue :param description_head: The top part of description :param description_tail: The bottom part of the description :param debug: The transaction sequence """ self.title = title self.contract = contract self.function = function_name self.address = address self.description_head = description_head self.description_tail = description_tail self.description = "%s\n%s" % (description_head, description_tail) self.severity = severity self.debug = debug self.swc_id = swc_id self.min_gas_used, self.max_gas_used = gas_used self.filename = None self.code = None self.lineno = None self.source_mapping = None self.discovery_time = time() - StartTime().global_start_time try: keccak = sha3.keccak_256() keccak.update( bytes.fromhex(bytecode[2:]) if bytecode[:2] == "0x" else bytes.fromhex(bytecode)) self.bytecode_hash = "0x" + keccak.hexdigest() except ValueError: log.debug( "Unable to change the bytecode to bytes. Bytecode: {}".format( bytecode)) self.bytecode_hash = ""
def __init__( self, contract, function_name, address, swc_id, title, bytecode, gas_used=(None, None), severity=None, description_head="", description_tail="", transaction_sequence=None, ): """ :param contract: The contract :param function_name: Function name where the issue is detected :param address: The address of the issue :param swc_id: Issue's corresponding swc-id :param title: Title :param bytecode: bytecode of the issue :param gas_used: amount of gas used :param severity: The severity of the issue :param description_head: The top part of description :param description_tail: The bottom part of the description :param debug: The transaction sequence """ self.title = title self.contract = contract self.function = function_name self.address = address self.description_head = description_head self.description_tail = description_tail self.description = "%s\n%s" % (description_head, description_tail) self.severity = severity self.swc_id = swc_id self.min_gas_used, self.max_gas_used = gas_used self.filename = None self.code = None self.lineno = None self.source_mapping = None self.discovery_time = time() - StartTime().global_start_time self.bytecode_hash = get_code_hash(bytecode) self.transaction_sequence = transaction_sequence
def fire_lasers( self, strategy, contracts=None, address=None, modules=None, verbose_report=False, max_depth=None, execution_timeout=None, create_timeout=None, transaction_count=None, enable_iprof=False, ): """ :param strategy: :param contracts: :param address: :param modules: :param verbose_report: :param max_depth: :param execution_timeout: :param create_timeout: :param transaction_count: :return: """ all_issues = [] SolverStatistics().enabled = True exceptions = [] for contract in contracts or self.contracts: StartTime() # Reinitialize start time for new contracts try: sym = SymExecWrapper( contract, address, strategy, dynloader=DynLoader( self.eth, storage_loading=self.onchain_storage_access, contract_loading=self.dynld, ), max_depth=max_depth, execution_timeout=execution_timeout, create_timeout=create_timeout, transaction_count=transaction_count, modules=modules, compulsory_statespace=False, enable_iprof=enable_iprof, ) issues = fire_lasers(sym, modules) except KeyboardInterrupt: log.critical("Keyboard Interrupt") issues = retrieve_callback_issues(modules) except Exception: log.critical( "Exception occurred, aborting analysis. Please report this issue to the Mythril GitHub page.\n" + traceback.format_exc()) issues = retrieve_callback_issues(modules) exceptions.append(traceback.format_exc()) for issue in issues: issue.add_code_info(contract) all_issues += issues log.info("Solver statistics: \n{}".format(str(SolverStatistics()))) source_data = Source() source_data.get_source_from_contracts_list(self.contracts) # Finally, output the results report = Report(verbose_report, source_data, exceptions=exceptions) for issue in all_issues: report.append_issue(issue) return report