Implement initial evm workspace, fix small bugs (#638)

* print on every

* save the bytecode to look at later

* update tuple

* wip workspace files

* wip

* generate tx files

* rm unused event handler

* clean up solving for tx.data

* Revert "print on every"

0caaae3658a169c9763c51544aa3c79a4e3940ca
This commit is contained in:
Mark Mossberg 2017-12-11 16:14:06 -05:00 committed by GitHub
parent 7ea30192a1
commit df9af1fd12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -2,7 +2,8 @@
import random, copy
from ..utils.helpers import issymbolic, memoized
from ..platforms.platform import *
from ..core.smtlib import solver, TooManySolutions, Expression, Bool, BitVec, Array, Operators, Constant, BitVecConstant, ConstraintSet
from ..core.smtlib import solver, TooManySolutions, Expression, Bool, BitVec, Array, Operators, Constant, BitVecConstant, ConstraintSet, \
SolverException
from ..core.state import ForkState, TerminateState
from ..utils.event import Eventful
from ..core.smtlib.visitors import pretty_print, arithmetic_simplifier, translate_to_smtlib
@ -2381,3 +2382,18 @@ class EVMWorld(Platform):
self.current._push(value)
self.current.pc += self.current.instruction.size
def generate_workspace_files(self):
ret = {}
for i, tx in enumerate(self.transactions):
name = 'tx.{}'.format(i)
data = {
'to': tx.address,
'from': tx.caller,
'data': solver.get_value(self.constraints, tx.data).encode('hex'),
'value': tx.value if not issymbolic(tx.value) else '{symbolic!}'
}
import json
ret[name] = json.dumps(data, indent=4)
return ret

View File

@ -347,7 +347,7 @@ class ManticoreEVM(Manticore):
@staticmethod
def compile(source_code):
''' Get initialization bytecode from a solidity source code '''
name, source_code, bytecode, srcmap, srcmap_runtime, hashes = ManticoreEVM._compile(source_code)
name, source_code, bytecode, srcmap, srcmap_runtime, hashes, abi = ManticoreEVM._compile(source_code)
return bytecode
@staticmethod
@ -499,6 +499,7 @@ class ManticoreEVM(Manticore):
'''
name, source_code, init_bytecode, metadata, metadata_runtime, hashes, abi = self._compile(source_code)
self._output.store.save_value('contract.bytecode', init_bytecode)
address = self.create_contract(owner=owner, address=address, balance=balance, init=tuple(init_bytecode)+tuple(ABI.make_function_arguments(*args)))
self.metadata[address] = SolidityMetadata(name, source_code, init_bytecode, metadata, metadata_runtime, hashes, abi)
return EVMAccount(address, self, default_caller=owner)
@ -1000,4 +1001,3 @@ class ManticoreEVM(Manticore):
output += "Total assembler lines visited: %d\n"% count
output += "Coverage: %2.2f%%\n"% (count*100.0/total)
return output