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 end_processes(self, test): """ End processes for the given test, slurp up the output and compare the traces returns the length of the canon-trace emitted (or -1) """ # Handle the old processes if test is None: return None tracelen = 0 canon_steps = None canon_trace = [] first = True stats = VMUtils.Stats() for (proc_info, client_name) in test.procs: t1 = time.time() test.storeTrace(client_name, proc_info['cmd']) canonicalizer = self.canonicalizers[client_name] canon_steps = [] with open(test.tempTraceLocation(client_name)) as output: canon_step_generator = canonicalizer(output) stat_generator = stats.traceStats(canon_step_generator) canon_trace = [VMUtils.toText(step) for step in stat_generator] stats.stop() test.canon_traces.append(canon_trace) tracelen = len(canon_trace) t2 = time.time() logger.info( "Processed %s steps for %s on test %s, pTime:%.02f ms" % (tracelen, client_name, test.identifier, 1000 * (t2 - t1))) # print(stats) # print(canon_steps) # print("\n".join(canon_trace)) return (tracelen, stats.result())
def end_processes(self, test): """ End processes for the given test, slurp up the output and compare the traces returns the length of the canon-trace emitted (or -1) """ # Handle the old processes if test is None: return None tracelen = 0 canon_steps = None canon_trace = [] first = True stats = VMUtils.Stats() for (proc_info, client_name) in test.procs: t1 = time.time() if len(test.socketData) > 0: # If there was any output, it indicates an error, see #102. # The only possible output, since we wrap the execution and pipe everything to file, # are docker container exec errors if it could not instantiate the executable. # In that case, which happens about once a million execs, just ignore this test and move on. logger.warning("Got spurious docker failure: %s", str(test.socketData)) return (0, stats.result()) test.storeTrace(client_name, proc_info['cmd']) canonicalizer = self.canonicalizers[client_name] canon_steps = [] filename = test.tempTraceLocation(client_name) try: with open(filename) as output: canon_step_generator = canonicalizer(output) stat_generator = stats.traceStats(canon_step_generator) canon_trace = [ VMUtils.toText(step) for step in stat_generator ] except FileNotFoundError: # We hit these sometimes, maybe twice every million execs or so logger.warning("The file %s could not be found!" % filename) logger.warning("Socket event %s" % test.socketEvent) logger.warning("Socket data %s" % str(test.socketData)) #TODO, try to find out what happened -- if there's any output from the process stats.stop() test.canon_traces.append(canon_trace) tracelen = len(canon_trace) self._num_traces_processed += 1 self._total_trace_len += tracelen self._max_trace_len = max(self._max_trace_len, tracelen) if tracelen == 0: self._num_zero_traces += 1 t2 = time.time() logger.info( "Processed %s steps for %s on test %s, pTime:%.02f ms (depth: %s, ConstantinopleOps: %s)" % (tracelen, client_name, test.identifier, 1000 * (t2 - t1), stats.result().get("maxDepth", "nA"), stats.result().get("constatinopleOps", "nA"))) # print(stats) # print(canon_steps) # print("\n".join(canon_trace)) return (tracelen, stats.result())
def end_processes(self, test): """ End processes for the given test, slurp up the output and compare the traces returns the length of the canon-trace emitted (or -1) """ # Handle the old processes if test is None: return None tracelen = 0 canon_steps = None canon_trace = [] first = True stats = VMUtils.Stats() for (proc_info, client_name) in test.procs: t1 = time.time() test.storeTrace(client_name, proc_info['cmd']) canonicalizer = self.canonicalizers[client_name] canon_steps = [] filename = test.tempTraceLocation(client_name) try: with open(filename) as output: canon_step_generator = canonicalizer(output) stat_generator = stats.traceStats(canon_step_generator) canon_trace = [ VMUtils.toText(step) for step in stat_generator ] except FileNotFoundError: # We hit these sometimes, maybe twice every million execs or so logger.warning("The file %s could not be found!" % filename) logger.warning("Socket event %s" % test.socketEvent) logger.warning("Socket data %s" % str(test.socketData)) #TODO, try to find out what happened -- if there's any output from the process stats.stop() test.canon_traces.append(canon_trace) tracelen = len(canon_trace) self._num_traces_processed += 1 self._total_trace_len += tracelen self._max_trace_len = max(self._max_trace_len, tracelen) if tracelen == 0: self._num_zero_traces += 1 t2 = time.time() logger.info( "Processed %s steps for %s on test %s, pTime:%.02f ms " % (tracelen, client_name, test.identifier, 1000 * (t2 - t1))) # print(stats) # print(canon_steps) # print("\n".join(canon_trace)) return (tracelen, stats.result())
def finishProc(name, processInfo, canonicalizer, fulltrace_filename=None): """ Ends the process, returns the canonical trace and also writes the full process output to a file, along with the command used to start the process""" outp = "" for chunk in processInfo['output']: outp = outp + chunk.decode() outp = outp.split("\n") if fulltrace_filename is not None: #logging.info("Writing %s full trace to %s" % (name, fulltrace_filename)) with open(fulltrace_filename, "w+") as f: f.write("# command\n") f.write("# %s\n\n" % processInfo['cmd']) f.write("\n".join(outp)) canon_text = [VMUtils.toText(step) for step in canonicalizer(outp)] return canon_text
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 finishProc(name, processInfo, canonicalizer, fulltrace_filename=None): """ Ends the process, returns the canonical trace and also writes the full process output to a file, along with the command used to start the process""" process = processInfo['proc'] extraTime = False if name == "py": extraTime = True outp = VMUtils.finishProc(processInfo['proc'], extraTime, processInfo['output']) if fulltrace_filename is not None: #logging.info("Writing %s full trace to %s" % (name, fulltrace_filename)) with open(fulltrace_filename, "w+") as f: f.write("# command\n") f.write("# %s\n\n" % processInfo['cmd']) f.write("\n".join(outp)) canon_text = [VMUtils.toText(step) for step in canonicalizer(outp)] return canon_text
def end_processes(test): """ End processes for the given test, slurp up the output and compare the traces returns the length of the canon-trace emitted (or -1) """ # Handle the old processes if test is None: return None tracelen = 0 canon_steps = None canon_trace = [] for (proc_info, client_name) in test.procs: t0 = time.time() full_trace = proc_info["output"]() t1 = time.time() #logger.info("Wait for %s took in %.02f milliseconds" % (client_name, 1000 * (t1 - t0))) #test.storeTrace(client_name, full_trace,proc_info['cmd']) canonicalizer = canonicalizers[client_name] canon_steps = [] with open(test.tempTraceLocation(client_name)) as output: canon_step_generator = canonicalizer(output) canon_trace = [ VMUtils.toText(step) for step in canon_step_generator ] test.canon_traces.append(canon_trace) tracelen = len(canon_trace) t2 = time.time() logger.info( "Processed %s steps for %s on test %s, wtime: %.02f ms, pTime:%.02f ms" % (tracelen, client_name, test.identifier, 1000 * (t1 - t0), 1000 * (t2 - t1))) stats = VMUtils.traceStats(canon_steps) #print(stats) #print(canon_steps) #print("\n".join(canon_trace)) return (tracelen, stats)
def toText(op): return VMUtils.toText(op)