示例#1
0
/*
 * Load an entire array of scalars. Useful when there are multiple functions in
 * the prover.
 *
 * Vectors will be stored with the following name:
 *      f<num_func>_<suffix>
 * num_func is an integer in [0, n).
 */
void load_scalar_array(int n, mpz_t *scalars, const char *suffix, char *folder_name) {
  char vec_name[BUFLEN];

  for (int i = 0; i < n; i++) {
    snprintf(vec_name, sizeof(vec_name), "f%d_%s", i, suffix);
    load_scalar(scalars[i], vec_name, folder_name);
  }
}
bool MatrixCubicVerifier::run_correction_and_circuit_tests(uint32_t beta) {
  bool result = true;
  bool lin;

  for (int rho=0; rho<num_repetitions; rho++) {

    for (int i=0; i<NUM_REPS_LIN; i++) {
      int base = i*NUM_LIN_QUERIES;
      lin = v->lin_test(f_answers[rho*num_lin_pcp_queries + base + Q1],
                        f_answers[rho*num_lin_pcp_queries + base + Q2],
                        f_answers[rho*num_lin_pcp_queries + base + Q3],
                        prime);

#if VERBOSE == 1
      if (false == lin)
        cout<<"LOG: F failed the linearity test"<<endl;
      else
        cout<<"LOG: F passed the linearity test"<<endl;
#endif
      result = result & lin;
    }

    // Quad Correction test and Circuit test
    mpz_set_ui(temp, 1);
    mpz_t ans;
    mpz_init_set_ui(ans, 0);
    snprintf(scratch_str, BUFLEN-1, "corr_answer_b_%d_r_%d", beta, rho);
    load_scalar(ans, scratch_str);
    bool cor1 = v->corr_test(ans /*f2_answers[rho*NUM_LIN_PCP_QUERIES + Q1]*/, temp,
                             f_answers[rho*num_lin_pcp_queries + Q6],
                             f_answers[rho*num_lin_pcp_queries + Q1], prime);

#if VERBOSE == 1
    if (false == cor1)
      cout<<"LOG: F1, F2 failed the correction test"<<endl;
    else
      cout<<"LOG: F1, F2 passed correction test"<<endl;
#endif

    result &= cor1;

    mpz_set(ckt_answers[0], f_answers[rho*num_lin_pcp_queries + Q7]);
    mpz_set(ckt_answers[1], f_answers[rho*num_lin_pcp_queries + Q1]);
    bool ckt2 = v->ckt_test(2, ckt_answers,
                            c_values[beta * num_repetitions + rho], prime);

#if VERBOSE == 1
    if (false == ckt2)
      cout <<"LOG: F1 failed the circuit test"<<endl;
    else
      cout <<"LOG: F1 passed the circuit test"<<endl;
#endif

    result &= ckt2;
  }
  return result;
}
示例#3
0
/*
 * This is the main function for dumping any node.
 */
SV *
load_node(perl_yaml_loader_t *loader)
{
    /* Get the next parser event */
    if (!yaml_parser_parse(&loader->parser, &loader->event))
        goto load_error;

    /* Return NULL when we hit the end of a scope */
    if (loader->event.type == YAML_DOCUMENT_END_EVENT ||
        loader->event.type == YAML_MAPPING_END_EVENT ||
        loader->event.type == YAML_SEQUENCE_END_EVENT) return NULL;

    /* Handle loading a mapping */
    if (loader->event.type == YAML_MAPPING_START_EVENT) {
        SV *hash_ref;
        char *tag = (char *)loader->event.data.mapping_start.tag;

        /* Handle mapping tagged as a Perl hard reference */
        if (tag && strEQ(tag, TAG_PERL_REF))
            return load_scalar_ref(loader);
        
        /* Handle mapping tagged as a Perl typeglob */
        if (tag && strEQ(tag, TAG_PERL_GLOB))
            return load_glob(loader);

        /* Load the mapping into a hash ref and return it */
        return load_mapping(loader, NULL);
    }

    /* Handle loading a sequence into an array */
    if (loader->event.type == YAML_SEQUENCE_START_EVENT)
        return load_sequence(loader);

    /* Handle loading a scalar */
    if (loader->event.type == YAML_SCALAR_EVENT)
        return load_scalar(loader);

    /* Handle loading an alias node */
    if (loader->event.type == YAML_ALIAS_EVENT)
        return load_alias(loader);

    /* Some kind of error occurred */
    if (loader->event.type == YAML_NO_EVENT)
        croak(loader_error_msg(loader, NULL));

    croak(ERRMSG "Invalid event '%d' at top level", (int) loader->event.type);

load_error:
    croak(loader_error_msg(loader, NULL));
}
/*
 * This is the main function for dumping any node.
 */
SV *
load_node(perl_yaml_loader_t *loader)
{
    SV* return_sv = NULL;
    /* This uses stack, but avoids (severe!) memory leaks */
    yaml_event_t uplevel_event;

    uplevel_event = loader->event;

    /* Get the next parser event */
    if (!yaml_parser_parse(&loader->parser, &loader->event))
        goto load_error;

    /* These events don't need yaml_event_delete */
    /* Some kind of error occurred */
    if (loader->event.type == YAML_NO_EVENT)
        goto load_error;

    /* Return NULL when we hit the end of a scope */
    if (loader->event.type == YAML_DOCUMENT_END_EVENT ||
        loader->event.type == YAML_MAPPING_END_EVENT ||
        loader->event.type == YAML_SEQUENCE_END_EVENT) {
            /* restore the uplevel event, so it can be properly deleted */
            loader->event = uplevel_event;
            return return_sv;
    }

    /* The rest all need cleanup */
    switch (loader->event.type) {
        char *tag;

        /* Handle loading a mapping */
        case YAML_MAPPING_START_EVENT:
            tag = (char *)loader->event.data.mapping_start.tag;

            /* Handle mapping tagged as a Perl hard reference */
            if (tag && strEQ(tag, TAG_PERL_REF)) {
                return_sv = load_scalar_ref(loader);
                break;
            }

            /* Handle mapping tagged as a Perl typeglob */
            if (tag && strEQ(tag, TAG_PERL_GLOB)) {
                return_sv = load_glob(loader);
                break;
            }

            return_sv = load_mapping(loader, NULL);
            break;

        /* Handle loading a sequence into an array */
        case YAML_SEQUENCE_START_EVENT:
            return_sv = load_sequence(loader);
            break;

        /* Handle loading a scalar */
        case YAML_SCALAR_EVENT:
            return_sv = load_scalar(loader);
            break;

        /* Handle loading an alias node */
        case YAML_ALIAS_EVENT:
            return_sv = load_alias(loader);
            break;

        default:
            croak("%sInvalid event '%d' at top level", ERRMSG, (int) loader->event.type);
    }

    yaml_event_delete(&loader->event);

    /* restore the uplevel event, so it can be properly deleted */
    loader->event = uplevel_event;

    return return_sv;

    load_error:
        croak("%s", loader_error_msg(loader, NULL));
}
示例#5
0
void Verifier::prepare_answers(int beta) {
#if NONINTERACTIVE == 1
  prepare_noninteractive_answers(beta);
#else
#if VERBOSE == 1
  cout << endl << "LOG: Batch " << beta << endl;
#endif

  FILE *fp = NULL;
  if (optimize_answers) {
    char f_name[BUFLEN];
    snprintf(f_name, BUFLEN - 1, "answers_%d", beta + 1);
    snprintf(f_name, BUFLEN - 1, "%s/answers_%d",
             FOLDER_STATE, beta + 1);
    fp = fopen(f_name, "rb");
    if (fp == NULL) {
      printf("Failed to open %s file for reading.", f_name);
      exit(1);
    }
  }

  // only one commitment answer and one consistency answer
  string commitment_answer_str = "f_commitment_answer_b_%d";
  snprintf(scratch_str, BUFLEN - 1, commitment_answer_str.c_str(), beta);
  load_vector(expansion_factor, temp_arr_ptrs[0], scratch_str);

  if (!optimize_answers) {
    string consistency_answer_str = "f_consistency_answer_b_%d";
    snprintf(scratch_str, BUFLEN - 1, consistency_answer_str.c_str(), beta);
    load_scalar(a, scratch_str);
  } else {
    size_t bytes = mpz_inp_raw(a, fp);
    fseek(fp, bytes, SEEK_CUR);
  }

  for (uint32_t j=0; j<num_repetitions*num_lin_pcp_queries; j++)
    mpz_set_ui(f_answers[j], 0);

  std::list<string> files = get_files_in_dir((char *)FOLDER_STATE);
  for (int rho = 0; rho < num_repetitions; rho++) {
    if (!optimize_answers) {
      char *file_exp = (char *)"_qquery_answer_b_%d_r_%d";
      snprintf(scratch_str, BUFLEN-1, file_exp, beta, rho);
      std::list<string>::const_iterator it = files.begin();

      for (; it != files.end(); it++) {
        string file_name = *it;
        size_t b_index = file_name.find(scratch_str);
        if (b_index != string::npos) {
          int q_num = atoi(file_name.substr(file_name.find("q") + 1, b_index).c_str());
          load_scalar(f_answers[rho * num_lin_pcp_queries + Q_list[q_num - 1]],
                      (char*)file_name.c_str());
        }
      }
    } else {
      for (uint32_t q = 0; q < Q_list.size(); q++) {
        size_t bytes =
          mpz_inp_raw(f_answers[rho * num_lin_pcp_queries + Q_list[q]], fp);
        fseek(fp, bytes, SEEK_CUR);
      }
    }
    //populate_answers(f_answers, rho, num_repetitions, beta);
  }

  snprintf(scratch_str, BUFLEN-1, "input_b_%d", beta);
  load_vector(size_input, input, scratch_str);

  snprintf(scratch_str, BUFLEN-1, "output_b_%d", beta);
  load_vector(size_output, output, scratch_str);

  if (output_q != NULL) {
    snprintf(scratch_str, BUFLEN-1, "output_q_b_%d", beta);
    load_vector(size_output, output_q, scratch_str);
    if (verify_conversion_to_z(size_output, output, output_q, prime) == false) {
      cout<<"LOG: Prover presented two different versions of output"<<endl;
      exit(1);
    } 
  }

  if (fp != NULL)
    fclose(fp);
#endif
}