import unittest import os from manticore.ethereum import ManticoreEVM, IntegerOverflow, Detector THIS_DIR = os.path.dirname(os.path.abspath(__file__)) # FIXME(mark): Remove these two lines when logging works for ManticoreEVM from manticore.utils.log import init_logging init_logging() class EthDetectors(unittest.TestCase): def test_int_ovf(self): mevm = ManticoreEVM() mevm.register_detector(IntegerOverflow()) filename = os.path.join(THIS_DIR, 'binaries/int_overflow.sol') mevm.multi_tx_analysis(filename) 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) class EthTests(unittest.TestCase): def test_emit_did_execute_end_instructions(self): class TestDetector(Detector): def did_evm_execute_instruction_callback(self, state, instruction, arguments, result): if instruction.semantics in ('REVERT', 'STOP'): with self.locked_context('insns', dict) as d: d[instruction.semantics] = True mevm = ManticoreEVM() p = TestDetector() mevm.register_detector(p) filename = os.path.join(THIS_DIR, 'binaries/int_overflow.sol') mevm.multi_tx_analysis(filename, tx_limit=1) self.assertIn('insns', p.context) context = p.context['insns'] self.assertIn('STOP', context) self.assertIn('REVERT', context)