def _find_test_cases(self):
        print('Finding test cases ...')
        self._main_evm = ManticoreEVM(workspace_url=self._args.workspace)

        if self._args.quick_mode:
            self._args.avoid_constant = True
            self._args.exclude_all = True
            self._args.only_alive_testcases = True
            consts_evm = config.get_group("evm")
            consts_evm.oog = "ignore"
            consts.skip_reverts = True

        if consts.skip_reverts:
            self._main_evm.register_plugin(SkipRevertBasicBlocks())

        if consts.explore_balance:
            self._main_evm.register_plugin(KeepOnlyIfStorageChanges())

        if self._args.limit_loops:
            self._main_evm.register_plugin(LoopDepthLimiter())

        with self._main_evm.kill_timeout():
            self._main_evm.multi_tx_analysis(
                self._args.argv[0],
                contract_name=self._args.contract,
                tx_limit=self._args.txlimit,
                tx_use_coverage=not self._args.txnocoverage,
                tx_send_ether=not self._args.txnoether,
                tx_account=self._args.txaccount,
                tx_preconstrain=self._args.txpreconstrain,
                compile_args=vars(self._args),
            )

        self._test_cases = list(self._main_evm.all_states)
Beispiel #2
0
    def test_ignore_states(self):
        m = self.mevm
        m.register_plugin(KeepOnlyIfStorageChanges())
        filename = os.path.join(THIS_DIR, "contracts", "absurdrepetition.sol")

        with m.kill_timeout():
            m.multi_tx_analysis(filename)

        for st in m.all_states:
            if st.platform.logs:
                return
        self.fail("We did not reach any state with logs")
Beispiel #3
0
    def test_essence3(self):
        source_code = """contract Sha3_Multiple_tx{
            event Log(string);
            bytes32 val;
            function foo(uint x) public {
                if (x == 12345){
                    val = keccak256(keccak256(uint(6789)));
                }
                else{
                    if (keccak256(val) == keccak256(keccak256(keccak256(x)))){
                        emit Log("bug");
                    }
                }
            }
        }

        """

        m = self.ManticoreEVM()
        m.register_plugin(KeepOnlyIfStorageChanges())
        owner = m.create_account(balance=1000, name="owner")
        attacker = m.create_account(balance=1000, name="attacker")
        contract = m.solidity_create_contract(source_code,
                                              owner=owner,
                                              name="contract")

        x1 = m.make_symbolic_value()
        contract.foo(x1)
        x2 = m.make_symbolic_value()
        contract.foo(x2)

        for st in m.all_states:
            if not m.fix_unsound_symbolication(st):
                m.kill_state(st)
                continue

        self.assertTrue(
            m.count_all_states() >= 4)  # Some fake results may appear

        found = 0
        for st in m.all_states:
            m.generate_testcase(st)
            found += len(st.platform.logs)
        self.assertTrue(found >= 1)  # log is reachable
Beispiel #4
0
 def setUp(self):
     self.mevm = ManticoreEVM()
     self.mevm.register_plugin(KeepOnlyIfStorageChanges())
     self.mevm.verbosity(0)
     self.worksp = self.mevm.workspace