* Create EVMInstructionException, properly emit did_evm_execute_instruction for insns that trap to the platform * Emit event before execution of platform handlers. This is because many of the platform handles actually destroy the cpu (platform.current) via pop_vm. Clients that receive the event may want to access the cpu though, for example to see the current PC. so we emit the event right before, so they can do this * simplify * move closure below result decl * Add comment to explain * Fix typo * Revert back to pythonic style It was this way to test emitting the did execute signal here, rather than in the evm cpu * Remove inline function definition from critical path * Add test for events for exception instructions
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
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)
|