def main(): g = genesis.Genesis() g.setConfigMetropolis() (geth_g, parity_g) = g.export() print(parity_g) geth = vm.GethVM( "/home/martin/go/src/github.com/ethereum/go-ethereum/build/bin/evm") par = vm.ParityVM(executable="holiman/std-parityvm", docker=True) print("Bytecode: ") print(generateCall()) g_out = geth.execute(code=generateCall(), genesis=geth_g, json=True, gas=0xFFFF, memory=True) p_out = par.execute(code=generateCall(), genesis=parity_g, json=True, gas=0xFFFF, memory=True) l = len(g_out) if len(p_out) < l: l = len(p_out) for i in range(0, l): print(g_out[i]) print("g:" + vm.toText(json.loads(g_out[i]))) print("p:" + vm.toText(json.loads(p_out[i])))
def main(): cloneaddr = 0x123456789A123456789A123456789A123456789A g = genesis.Genesis() g.setConfigMetropolis() g.add({ 'address': hex(cloneaddr), 'nonce': 0, 'code': "0x1337", 'balance': 0 }) (geth_g, parity_g) = g.export() initcode = generateInitcode(cloneaddr) #geth = vm.GethVM("/home/martin/go/src/github.com/ethereum/go-ethereum/build/bin/evm") geth = vm.GethVM("holiman/gethvm", docker=True) print("Bytecode: ", initcode) g_out = geth.execute(code=initcode, genesis=geth_g, json=True, gas=0xFFFF, memory=True) for i in g_out: obj = json.loads(i) if 'stack' in obj.keys(): print("{} {}".format(obj['opName'], obj['stack'])) else: print(i)
def reproduceTx(txhash, evmbin, api): from evmlab import gethvm vm = gethvm.VM(evmbin) genesis = gen.Genesis() tx = api.getTransaction(txhash) s = tx['from'] r = tx['to'] tx['input'] = tx['input'][2:] #s = tx['sender'] #r = tx['recipient'] debugdump(tx) blnum = int(tx['blockNumber']) bootstrap = generateCall(r, incode=tx['input']) toAdd = [s, r] done = False while not done: done = True # Add accounts that we know of for x in toAdd: if not genesis.has(x): acc = api.getAccountInfo(x, blnum) debugdump(acc) genesis.add(acc) done = False if not done: #genesis.prettyprint() g_path = genesis.export_geth() print("Executing tx...") output = vm.execute(code=bootstrap, genesis=g_path, json=True, sender=s, input=tx['input']) externalAccounts = findExternalCalls(output) print("Externals: %s " % externalAccounts) toAdd = externalAccounts fd, temp_path = tempfile.mkstemp(dir='.', prefix=txhash + '_', suffix=".txt") with open(temp_path, 'w') as f: f.write("\n".join(output)) os.close(fd) print("Saved trace to %s" % temp_path) print("Genesis complete: %s" % g_path)
def main(): g = genesis.Genesis() g.setConfigMetropolis() (geth_g, parity_g) = g.export() geth = vm.GethVM( "/home/martin/go/src/github.com/ethereum/go-ethereum/build/bin/evm") outp = geth.execute(code=generateCall(), genesis=geth_g, json=True) prev = 0 for l in outp: obj = json.loads(l) if 'gas' in obj.keys(): g = int(obj['gas'], 16) print(l) print("Gas: %d (delta: %d)" % (g, (g - prev))) prev = g
def main(): g = genesis.Genesis() g.setConfigConstantinople() bytecode = generateCall() #print("code:", bytecode) # g.addPrestateAccount({'address':'0x0000000000000000000000000000000000000000', 'code': '0x'+bytecode, 'balance':"0x00",'nonce':"0x01"}) (geth_g, parity_g) = g.export() print(parity_g) print(geth_g) geth = vm.GethVM("/home/martin/go/src/github.com/ethereum/go-ethereum/build/bin/evm") g_out = geth.execute(code = bytecode, receiver="0x0000000000000000000000000000000000000000", genesis = geth_g, json=True, gas=100000, memory=False) #print(geth.lastCommand) print("") l = len(g_out) for i in range(0,l): print(vm.toText(json.loads(g_out[i])))
def startGeth(test_case, test_tx): logger.info("running state test in geth.") genesis = gen.Genesis() for account_key in test_case['pre']: account = test_case['pre'][account_key] account['address'] = account_key genesis.addPrestateAccount(account) genesis.setCoinbase(test_case['env']['currentCoinbase']) genesis.setTimestamp(test_case['env']['currentTimestamp']) genesis.setGasLimit(test_case['env']['currentGasLimit']) genesis.setDifficulty(test_case['env']['currentDifficulty']) genesis.setBlockNumber(test_case['env']['currentNumber']) if cfg['FORK_CONFIG'] == 'Metropolis' or cfg['FORK_CONFIG'] == 'Byzantium': genesis.setConfigMetropolis() if cfg['FORK_CONFIG'] == 'Homestead': genesis.setConfigHomestead() geth_genesis = genesis.geth() g_path = genesis.export_geth() if sys.platform == "darwin": # OS X workaround for https://github.com/docker/for-mac/issues/1298 "The path /var/folders/wb/d8qys65575g8m2691vvglpmm0000gn/T/tmpctxz3buh.json is not shared from OS X and is not known to Docker." g_path = "/private" + g_path input_data = test_tx['data'] if input_data[0:2] == "0x": input_data = input_data[2:] tx_to = test_tx['to'] tx_value = parse_int_or_hex(test_tx['value']) gas_limit = parse_int_or_hex(test_tx['gasLimit']) gas_price = parse_int_or_hex(test_tx['gasPrice']) block_gaslimit = parse_int_or_hex(test_case['env']['currentGasLimit']) if gas_limit > block_gaslimit: logger.info("Tx gas limit exceeds block gas limit. not calling geth") return [] sender = '0x' + getTxSender(test_tx) sender_balance = parse_int_or_hex(test_case['pre'][sender]['balance']) balance_required = (gas_price * gas_limit) + tx_value if balance_required > sender_balance: logger.info("Insufficient balance. not calling geth") return [] intrinsic_gas = getIntrinsicGas(test_tx) if tx_to == "": # create contract cost not included in getIntrinsicGas intrinsic_gas += 32000 if gas_limit < intrinsic_gas: logger.info("Insufficient startgas. not calling geth") return [] if tx_to == "" and input_data == "": logger.info("no init code. not calling geth") return [] if tx_to in test_case['pre']: if 'code' in test_case['pre'][tx_to]: if test_case['pre'][tx_to]['code'] == '': logger.info( "To account in prestate has no code. not calling geth") return [] vm = VMUtils.GethVM(executable=cfg['GETH_DOCKER_NAME'], docker=True) return vm.start(genesis=g_path, gas=gas_limit, price=gas_price, json=True, sender=sender, receiver=tx_to, input=input_data, value=tx_value)