Example #1
0
    def _test(self, name, should_find, use_ctor_sym_arg=False):
        """
        Tests DetectInvalid over the consensys benchmark suite
        """
        mevm = self.mevm
        mevm.register_detector(DetectInvalid())
        mevm.register_detector(DetectIntegerOverflow())
        mevm.register_detector(DetectReentrancyAdvanced())

        filename = os.path.join(THIS_DIR, "contracts", "consensys_benchmark",
                                f"{name}.sol")

        if use_ctor_sym_arg:
            ctor_arg = (mevm.make_symbolic_value(), )
        else:
            ctor_arg = ()

        mevm.multi_tx_analysis(filename,
                               contract_name="Benchmark",
                               args=ctor_arg)
        mevm.finalize()

        expected_findings = set(((c, d) for b, c, d in should_find))
        actual_findings = set(((c, d) for a, b, c, d in mevm.global_findings))
        self.assertEqual(expected_findings, actual_findings)
Example #2
0
 def test_int_ovf(self):
     mevm = ManticoreEVM()
     mevm.register_detector(DetectIntegerOverflow())
     filename = os.path.join(THIS_DIR, 'binaries/int_overflow.sol')
     mevm.multi_tx_analysis(filename, tx_limit=1)
     self.assertEqual(len(mevm.global_findings), 3)
     all_findings = ''.join(map(lambda x: x[2], mevm.global_findings))
     self.assertIn('underflow at SUB', all_findings)
     self.assertIn('overflow at ADD', all_findings)
     self.assertIn('overflow at MUL', all_findings)
Example #3
0
 def test_int_ovf(self):
     mevm = ManticoreEVM()
     mevm.register_detector(DetectIntegerOverflow())
     filename = os.path.join(THIS_DIR, 'binaries/int_overflow.sol')
     mevm.multi_tx_analysis(filename, tx_limit=1)
     self.assertEqual(len(mevm.global_findings), 3)
     all_findings = ''.join([x[2] for x in mevm.global_findings])
     self.assertIn('Unsigned integer overflow at SUB instruction', all_findings)
     self.assertIn('Unsigned integer overflow at ADD instruction', all_findings)
     self.assertIn('Unsigned integer overflow at MUL instruction', all_findings)
    def _test(self, name, should_find):
        """
        Tests DetectInvalid over the consensys benchmark suit
        """
        mevm = self.mevm

        mevm.register_detector(DetectInvalid())
        mevm.register_detector(DetectIntegerOverflow())

        filename = os.path.join(THIS_DIR, 'binaries', 'benchmark', '{}.sol'.format(name))

        mevm.multi_tx_analysis(filename, tx_limit=3)


        expected_findings = set(( (c, d) for b, c, d in should_find))
        actual_findings = set(( (c, d) for a, b, c, d in mevm.global_findings))
        self.assertEqual(expected_findings, actual_findings)
Example #5
0
    def _test(self, name, should_find):
        """
        Tests DetectInvalid over the consensys benchmark suite
        """
        mevm = self.mevm
        mevm.register_detector(DetectInvalid())
        mevm.register_detector(DetectIntegerOverflow())
        mevm.register_detector(DetectReentrancyAdvanced())

        filename = os.path.join(THIS_DIR, 'binaries', 'benchmark',
                                '{}.sol'.format(name))

        mevm.multi_tx_analysis(filename,
                               contract_name='Benchmark',
                               args=(mevm.make_symbolic_value(), ))

        expected_findings = set(((c, d) for b, c, d in should_find))
        actual_findings = set(((c, d) for a, b, c, d in mevm.global_findings))
        self.assertEqual(expected_findings, actual_findings)
Example #6
0
 def setUp(self):
     self.io = DetectIntegerOverflow()
     self.state = make_mock_evm_state()