예제 #1
0
    def sym_exec(self, main_address=None, creation_code=None, contract_name=None, code_extension=None):
        logging.debug("Starting LASER execution")
        self.time = datetime.now()

        if main_address:
            logging.info("Starting message call transaction to {}".format(main_address))
            execute_message_call(self, main_address)
        elif creation_code:
            logging.info("Starting contract creation transaction")
            created_account = execute_contract_creation(self, creation_code, contract_name=contract_name, code_extension=code_extension)
            logging.info("Finished contract creation, found {} open states".format(len(self.open_states)))
            if len(self.open_states) == 0:
                print("No contract was created during the execution of contract creation "
                      "Try to increase the resources for creation exection (max-depth or create_timeout)")
            printd("Finished outer creation")

            # Reset code coverage
            self.coverage = {}

            self.time = datetime.now()
            logging.info("Starting message call transaction")
            execute_message_call(self, created_account.address)

            #self.time = datetime.now()
            #execute_message_call(self, created_account.address)

        logging.info("Finished symbolic execution")
        logging.info("%d nodes, %d edges, %d total states", len(self.nodes), len(self.edges), self.total_states)
        for code, coverage in self.coverage.items():
            cov = reduce(lambda sum_, val: sum_ + 1 if val else sum_, coverage[1]) / float(coverage[0]) * 100
            logging.info("Achieved {} coverage for code: {}".format(cov, code))
예제 #2
0
    def _execute_transactions(self, address):
        """This function executes multiple transactions on the address based on
        the coverage.

        :param address: Address of the contract
        :return:
        """
        self.coverage = {}
        for i in range(self.transaction_count):
            initial_coverage = self._get_covered_instructions()

            self.time = datetime.now()
            log.info(
                "Starting message call transaction, iteration: {}, {} initial states".format(
                    i, len(self.open_states)
                )
            )

            execute_message_call(self, address)

            end_coverage = self._get_covered_instructions()

            log.info(
                "Number of new instructions covered in tx %d: %d"
                % (i, end_coverage - initial_coverage)
            )
예제 #3
0
파일: svm.py 프로젝트: nbanmp/mythril
    def sym_exec(self,
                 main_address=None,
                 creation_code=None,
                 contract_name=None):
        logging.debug("Starting LASER execution")
        self.time = datetime.now()

        if main_address:
            logging.info(
                "Starting message call transaction to {}".format(main_address))
            execute_message_call(self, main_address)
        elif creation_code:
            logging.info("Starting contract creation transaction")
            created_account = execute_contract_creation(
                self, creation_code, contract_name)
            logging.info(
                "Finished contract creation, found {} open states".format(
                    len(self.open_states)))
            if len(self.open_states) == 0:
                logging.warning(
                    "No contract was created during the execution of contract creation "
                    "Increase the resources for creation execution (--max-depth or --create-timeout)"
                )

            # Reset code coverage
            self.coverage = {}
            for i in range(self.max_transaction_count):
                initial_coverage = self._get_covered_instructions()

                self.time = datetime.now()
                logging.info(
                    "Starting message call transaction, iteration: {}".format(
                        i))
                execute_message_call(self, created_account.address)

                end_coverage = self._get_covered_instructions()
                if end_coverage == initial_coverage:
                    break

        logging.info("Finished symbolic execution")
        logging.info(
            "%d nodes, %d edges, %d total states",
            len(self.nodes),
            len(self.edges),
            self.total_states,
        )
        for code, coverage in self.coverage.items():
            cov = (reduce(lambda sum_, val: sum_ + 1 if val else sum_,
                          coverage[1]) / float(coverage[0]) * 100)
            logging.info("Achieved {} coverage for code: {}".format(cov, code))
예제 #4
0
    def _execute_transactions(self, address):
        """
        This function executes multiple transactions on the address based on the coverage
        :param address: Address of the contract
        :return:
        """
        self.coverage = {}
        for i in range(self.max_transaction_count):
            initial_coverage = self._get_covered_instructions()

            self.time = datetime.now()
            logging.info(
                "Starting message call transaction, iteration: {}".format(i))
            execute_message_call(self, address)

            end_coverage = self._get_covered_instructions()
            if end_coverage == initial_coverage:
                break
예제 #5
0
    def _execute_transactions(self, address):
        """This function executes multiple transactions on the address

        :param address: Address of the contract
        :return:
        """
        for i in range(self.transaction_count):
            self.time = datetime.now()
            log.info(
                "Starting message call transaction, iteration: {}, {} initial states"
                .format(i, len(self.open_states)))
            for hook in self._start_sym_trans_hooks:
                hook()

            execute_message_call(self, address)

            for hook in self._stop_sym_trans_hooks:
                hook()
예제 #6
0
    def _execute_transactions(self, address, priority=None):
        """
        This function executes multiple transactions on the address based on the coverage
        :param address: Address of the contract
        :return:
        """
        self.coverage = {}
        for i in range(self.transaction_count):
            initial_coverage = self._get_covered_instructions()

            self.time = datetime.now()
            logging.info(
                "Starting message call transaction, iteration: {}".format(i))

            if priority is None:
                execute_message_call(self, address, priority)
            else:
                heuristic_message_call(self, address, priority)

            end_coverage = self._get_covered_instructions()

            logging.info("Number of new instructions covered in tx %d: %d" %
                         (i, end_coverage - initial_coverage))