예제 #1
0
    def processTraces(self, test, forceSave=False):
        if test is None:
            return None

        # Process previous traces

        (equivalent,
         trace_output) = VMUtils.compare_traces(test.canon_traces,
                                                self._config.clientNames)

        if equivalent and not forceSave:
            test.removeFiles()
            return None

        if not equivalent:
            logger.warning("CONSENSUS BUG!!!")

        trace_summary = self.get_summary(trace_output)
        # save the state-test
        test.saveArtefacts()
        # save combined trace and abbreviated trace
        test.addArtefact("combined_trace.log", "\n".join(trace_output))
        test.addArtefact("shortened_trace.log", "\n".join(trace_summary))

        return test
예제 #2
0
파일: evmfuzz.py 프로젝트: wtf/evmlab
def execute(code, gas=0xFFFF, verbose=False):

    from evmlab import vm
    from evmlab.genesis import Genesis

    gvm = VMUtils.GethVM("holiman/std-gethvm", docker=True)
    pvm = VMUtils.ParityVM("holiman/std-parityvm", docker=True)

    intrinsic_geth_gas = VMUtils.getIntrinsicGas(code)
    print("Intrinsic gas: %s" % str(intrinsic_geth_gas))
    # sys.exit(0)
    g_out = gvm.execute(code=code,
                        gas=gas,
                        json=True,
                        genesis=Genesis().export_geth())
    p_out = pvm.execute(code=code,
                        gas=gas,
                        json=True,
                        genesis=Genesis().export_parity())

    g_canon = VMUtils.GethVM.canonicalized(g_out)
    p_canon = VMUtils.ParityVM.canonicalized(p_out)

    g_txt = [toText(x) for x in g_canon]
    p_txt = [toText(x) for x in p_canon]

    import logging
    logger = logging.getLogger()

    diff_found = vm.compare_traces([g_txt, p_txt], ['Geth', 'Par'])

    return (diff_found, [], gvm.lastCommand, pvm.lastCommand)
예제 #3
0
def processTraces(test):
    if test is None:
        return True

    # Process previous traces
    (equivalent,
     trace_output) = VMUtils.compare_traces(test.canon_traces,
                                            cfg['DO_CLIENTS'])

    if equivalent:
        tmpfile_path = os.path.abspath(test.tmpfile)
        os.remove(tmpfile_path)
        #delete non-failed traces
        for f in test.traceFiles:
            os.remove(f)
    else:
        logger.warning("CONSENSUS BUG!!!")
        # save the state-test
        statetest_filename = "%s/%s-test.json" % (cfg['LOGS_PATH'], test.id())
        os.rename(test.tmpfile, statetest_filename)

        # save combined trace
        passfail_log_filename = "%s/FAIL-%s.log.txt" % (cfg['LOGS_PATH'],
                                                        test.id())

        with open(passfail_log_filename, "w+") as f:
            logger.info("Combined trace: %s", passfail_log_filename)
            f.write("\n".join(trace_output))

        # save a summary of the trace, with up to 20 steps preceding the first diff
        trace_summary = get_summary(trace_output)
        summary_log_filename = "%s/FAIL-%s.summary.txt" % (cfg['LOGS_PATH'],
                                                           test.id())
        with open(summary_log_filename, "w+") as f:
            logger.info("Summary trace: %s", summary_log_filename)
            f.write("\n".join(trace_summary))
        sys.exit(1)

    return equivalent
예제 #4
0
def perform_test(testfile, test_name, test_number=0):

    logger.info("file: %s, test name %s " % (testfile, test_name))

    pass_count = 0
    failures = []
    fork_name = cfg['FORK_CONFIG']
    clients = cfg['DO_CLIENTS']
    test_tmpfile = cfg['SINGLE_TEST_TMP_FILE']
    prestate_tmpfile = cfg['PRESTATE_TMP_FILE']

    try:
        prestate, txs_dgv = convertGeneralTest(testfile, fork_name)
    except Exception as e:
        logger.warn("problem with test file, skipping.")
        return (test_number, fail_count, pass_count, failures)


#    logger.info("prestate: %s", prestate)
    logger.debug("txs: %s", txs_dgv)

    with open(prestate_tmpfile, 'w') as outfile:
        json.dump(prestate, outfile)

    test_subfolder = testfile.split(os.sep)[-2]

    for tx_i, tx_and_dgv in enumerate(txs_dgv):
        test_number += 1
        if test_number < START_I and not TEST_WHITELIST:
            continue

        test_id = "{:0>4}-{}-{}-{}".format(test_number, test_subfolder,
                                           test_name, tx_i)
        logger.info("test id: %s" % test_id)

        single_statetest = selectSingleFromGeneral(tx_i, testfile, fork_name)
        with open(test_tmpfile, 'w') as outfile:
            json.dump(single_statetest, outfile)

        tx = tx_and_dgv[0]
        tx_dgv = tx_and_dgv[1]

        clients_canon_traces = []
        procs = []

        canonicalizers = {
            "geth": VMUtils.GethVM.canonicalized,
            "cpp": VMUtils.CppVM.canonicalized,
            "py": VMUtils.PyVM.canonicalized,
            "parity": VMUtils.ParityVM.canonicalized,
            "js": VMUtils.JsVM.canonicalized,
        }
        logger.info("Starting processes for %s" % clients)

        #Start the processes
        for client_name in clients:

            if client_name == 'geth':
                procinfo = startGeth(test_tmpfile)
            elif client_name == 'cpp':
                procinfo = startCpp(test_subfolder, test_name, tx_dgv)
            elif client_name == 'py':
                procinfo = startPython(prestate_tmpfile, tx)
            elif client_name == 'parity':
                procinfo = startParity(test_tmpfile)
            elif client_name == 'js':
                procinfo = startJs(test_tmpfile)
            else:
                logger.warning("Undefined client %s", client_name)
                continue
            procs.append((procinfo, client_name))

        traceFiles = []
        # Read the outputs
        for (procinfo, client_name) in procs:
            if procinfo['proc'] is None:
                continue

            canonicalizer = canonicalizers[client_name]
            full_trace_filename = os.path.abspath(
                "%s/%s-%s.trace.log" %
                (cfg['LOGS_PATH'], test_id, client_name))
            traceFiles.append(full_trace_filename)
            canon_trace = finishProc(client_name, procinfo, canonicalizer,
                                     full_trace_filename)
            clients_canon_traces.append(canon_trace)

        (equivalent,
         trace_output) = VMUtils.compare_traces(clients_canon_traces, clients)

        if equivalent:
            #delete non-failed traces
            for f in traceFiles:
                os.remove(f)

            pass_count += 1
            passfail = 'PASS'
        else:
            logger.warning("CONSENSUS BUG!!!")
            failures.append(test_name)

            # save the state-test
            statetest_filename = "%s/%s-test.json" % (cfg['LOGS_PATH'],
                                                      test_id)
            os.rename(test_tmpfile, statetest_filename)

            # save combined trace
            passfail = 'FAIL'
            passfail_log_filename = "%s/%s-%s.log.txt" % (cfg['LOGS_PATH'],
                                                          passfail, test_id)
            with open(passfail_log_filename, "w+") as f:
                logger.info("Combined trace: %s", passfail_log_filename)
                f.write("\n".join(trace_output))

            # save a summary of the trace, with up to 20 steps preceding the first diff
            trace_summary = get_summary(trace_output)
            summary_log_filename = "%s/%s-%s.summary.txt" % (cfg['LOGS_PATH'],
                                                             passfail, test_id)
            with open(summary_log_filename, "w+") as f:
                logger.info("Summary trace: %s", summary_log_filename)
                f.write("\n".join(trace_summary))

    return (test_number, len(failures), pass_count, failures)
예제 #5
0
def perform_test(f, test_name, test_number=0):

    logger.info("file: %s, test name %s " % (f, test_name))

    pass_count = 0
    failures = []

    try:
        prestate, txs_dgv = convertGeneralTest(f)
    except Exception as e:
        logger.warn("problem with test file, skipping.")
        return (test_number, fail_count, pass_count, failures)

    clients = cfg['DO_CLIENTS']
    test_tmpfile = cfg['SINGLE_TEST_TMP_FILE']
    prestate_tmpfile = cfg['PRESTATE_TMP_FILE']

    logger.info("prestate: %s", prestate)
    logger.debug("txs: %s", txs_dgv)

    with open(prestate_tmpfile, 'w') as outfile:
        json.dump(prestate, outfile)

    test_case = prestate
    test_subfolder = f.split(os.sep)[-2]

    for tx_i, tx_and_dgv in enumerate(txs_dgv):
        test_number += 1
        if test_number < START_I and not TEST_WHITELIST:
            continue

        # set up logging to file
        log_filename = os.path.abspath(cfg['LOGS_PATH'] + '/' + test_name +
                                       '.log')
        file_log = setupLogToFile(log_filename)

        tx = tx_and_dgv[0]
        tx_dgv = tx_and_dgv[1]
        logger.info("file: %s", f)
        logger.info("test_name: %s. tx_i: %s", test_name, tx_i)
        single_statetest = selectSingleFromGeneral(tx_i, f)
        with open(test_tmpfile, 'w') as outfile:
            json.dump(single_statetest, outfile)

        clients_canon_traces = []
        procs = []

        #Start the processes
        for client_name in clients:
            procs.append(
                startClient(client_name, test_tmpfile, prestate_tmpfile, tx,
                            test_subfolder, test_name, tx_dgv, test_case))

        # Read the outputs
        for (proc, end_fn) in procs:
            canon_trace = end_fn(proc)
            clients_canon_traces.append(canon_trace)

        if VMUtils.compare_traces(clients_canon_traces, clients):
            logger.info("equivalent.")
            pass_count += 1
            passfail = 'PASS'
        else:
            logger.info("CONSENSUS BUG!!!\a")
            passfail = 'FAIL'
            failures.append(test_name)

        file_log.close()
        logger.removeHandler(file_log)
        # Rename file if it passed or not
        trace_file = os.path.abspath(log_filename)
        passfail_log_filename = cfg['LOGS_PATH'] + '/' + str(test_number).zfill(
            4
        ) + '-' + passfail + '-' + test_subfolder + '-' + test_name + '-' + str(
            tx_i) + '.log.txt'
        renamed_trace = os.path.abspath(passfail_log_filename)
        os.rename(trace_file, renamed_trace)

    return (test_number, len(failures), pass_count, failures)