Graceful exit when no states to run (#815)

* rm unnecessary return, change assert to graceful handle

* Add regression test

* Add regression test

* Correct logic

* Rm unnecessary check

This branch is unnecessary, if this condition is true, then ultimately
the executor will do nothing, and we'll simply return anyway.

* Raise NoAliveStates if no alive states to execute

* docstr update

* Update mult_tx_analysis to handle NoAliveStates

* Fancy

* Update test

* Codeclimate fmt

* fmt

* better readability

* add docstr
This commit is contained in:
Mark Mossberg
2018-03-16 17:48:36 -04:00
committed by GitHub
parent a21c8b6012
commit fb79127bc2
5 changed files with 63 additions and 8 deletions
+7
View File
@@ -0,0 +1,7 @@
contract Simple {
function f(uint a) payable public {
if (a == 65) {
revert();
}
}
}
+1 -1
View File
@@ -128,7 +128,7 @@ class IntegrationTest(unittest.TestCase):
self.assertTrue(len(actual) > 100 )
def test_eth_regressions(self):
contracts = [676, 678, 701, 714, 735, 760, 780]
contracts = [676, 678, 701, 714, 735, 760, 780, 795]
for contract in contracts:
self._simple_cli_run('{}.sol'.format(contract))
+26 -1
View File
@@ -4,7 +4,7 @@ import os
from manticore.core.smtlib import ConstraintSet, operators
from manticore.core.smtlib.expression import BitVec
from manticore.core.state import State
from manticore.ethereum import ManticoreEVM, IntegerOverflow, Detector
from manticore.ethereum import ManticoreEVM, IntegerOverflow, Detector, NoAliveStates
from manticore.platforms.evm import EVMWorld, ConcretizeStack, concretized_args
@@ -92,6 +92,31 @@ class EthTests(unittest.TestCase):
self.assertIn('STOP', context)
self.assertIn('REVERT', context)
def test_graceful_handle_no_alive_states(self):
"""
If there are no alive states, or no initial states, we should not crash. issue #795
"""
# initiate the blockchain
m = ManticoreEVM()
source_code = '''
contract Simple {
function f(uint a) payable public {
if (a == 65) {
revert();
}
}
}
'''
# Initiate the accounts
user_account = m.create_account(balance=1000)
contract_account = m.solidity_create_contract(source_code, owner=user_account, balance=0)
contract_account.f(1) # it works
contract_account.f(65) # it works
with self.assertRaises(NoAliveStates):
contract_account.f(m.SValue) # no alive states, but try to run a tx anyway
def test_can_create(self):
mevm = ManticoreEVM()
source_code = """