Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Roostock, Tron and other EVM-compatible blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
mythril/ether/evm.py

40 lines
1.0 KiB

from ethereum import vm, messages, transactions
from ethereum.state import State
from ethereum.slogging import get_logger
from logging import StreamHandler
from io import StringIO
import codecs
from .util import safe_decode
def trace(code, address = "", calldata = ""):
logHandlers = ['eth.vm.op', 'eth.vm.op.stack', 'eth.vm.op.memory', 'eth.vm.op.storage']
output = StringIO()
streamHandler = StreamHandler(output)
for handler in logHandlers:
log_vm_op = get_logger(handler)
log_vm_op.setLevel("TRACE")
log_vm_op.addHandler(streamHandler)
addr_from = codecs.decode('0123456789ABCDEF0123456789ABCDEF01234567', 'hex_codec')
addr_to = safe_decode(address)
data = safe_decode(calldata)
state = State()
ext = messages.VMExt(state, transactions.Transaction(0, 0, 21000, addr_from, 0, addr_to))
message = vm.Message(addr_from, addr_to, 0, 21000, data, code_address=addr_to)
res, gas, dat = vm.vm_execute(ext, message, code)
streamHandler.flush()
# print(output.getvalue())
ret = output.getvalue()
return ret