Example #1
0
//Refer to apps_sfdl_gen/insertion_sort_q_cons.h for constants to use in this exogenous
//check.
bool insertion_sort_qProverExo::exogenous_check(const mpz_t* input, const mpq_t* input_q,
    int num_inputs, const mpz_t* output, const mpq_t* output_q, int num_outputs, mpz_t prime) {
  bool lists_equal = true;

#ifdef ENABLE_EXOGENOUS_CHECKING
  mpq_t *output_q_recomputed;
  alloc_init_vec(&output_q_recomputed, num_inputs);

  // call baseline to compute output
  baseline(input_q, num_inputs, output_q_recomputed, num_outputs);

  mpz_t *output_recomputed;
  alloc_init_vec(&output_recomputed, num_outputs);

  convert_to_z(num_outputs, output_recomputed, output_q_recomputed, prime);

  for(int j = 0; j < num_outputs; j++) {
    if (mpz_cmp(output[j], output_recomputed[j]) == 0)
      continue;
    else
      lists_equal = false;
  }
  clear_vec(num_outputs, output_recomputed);
  clear_vec(num_outputs, output_q_recomputed);

#else
  gmp_printf("Exogeneous checking disabled\n");
  lists_equal = true;
#endif
  return lists_equal;
};
Example #2
0
void ZComputationVerifier::create_input() {
    // as many computations as inputs
    for (int k=0; k<batch_size; k++) {
        int input_size = size_input;
        //v->get_random_vec(size_input, input, num_bits_in_input);
        //v->add_sign(size_input, input);

        input_creator->create_input(input_q, input_size);

        snprintf(scratch_str, BUFLEN-1, "input1_q_b_%d", k);
        dump_vector(input_size, input_q, scratch_str);
        send_file(scratch_str);

        convert_to_z(input_size, input, input_q, prime);

        snprintf(scratch_str, BUFLEN-1, "input1_b_%d", k);
        dump_vector(size_input, input, scratch_str);
        send_file(scratch_str);
    }
}
Example #3
0
void convert_to_z(const int size, mpz_t *z, const mpq_t *q, const mpz_t prime) {
  for (int i = 0; i < size; i++)
    convert_to_z(z[i], q[i], prime);
}
void verify (string verification_key_fn, string inputs_fn, string outputs_fn,
             string proof_fn, int num_inputs, int num_outputs, mpz_t prime) {

    libsnark::default_r1cs_gg_ppzksnark_pp::init_public_params();

    libsnark::r1cs_variable_assignment<FieldT> inputvec;
    libsnark::r1cs_gg_ppzksnark_proof<libsnark::default_r1cs_gg_ppzksnark_pp> proof;

    std::cout << "loading proof from file: " << proof_fn << std::endl;
    std::ifstream proof_file(proof_fn);
    if (!proof_file.good()) {
        std::cerr << "ERROR: " << proof_fn << " not found. " << std::endl;
        exit(1);
    }
    proof_file >> proof;
    proof_file.close();

    std::cout << "loading inputs from file: " << inputs_fn << std::endl;
    std::ifstream inputs_file(inputs_fn);

    std::cout << "loading outputs from file: " << outputs_fn << std::endl;
    std::ifstream outputs_file(outputs_fn);

    mpq_t tmp; mpq_init(tmp);
    mpz_t tmp_z; mpz_init(tmp_z);

    for (int i = 0; i < num_inputs; i++) {
        inputs_file >> tmp;
        convert_to_z(tmp_z, tmp, prime);
        FieldT currentVar(tmp_z);
        inputvec.push_back(currentVar);
    }

    for (int i = 0; i < num_outputs; i++) {
        outputs_file >> tmp;
        convert_to_z(tmp_z, tmp, prime);
        FieldT currentVar(tmp_z);
        inputvec.push_back(currentVar);
    }

    mpq_clear(tmp); mpz_clear(tmp_z);

    inputs_file.close();
    outputs_file.close();

    cout << "loading vk from file: " << verification_key_fn << std::endl;
    std::ifstream vkey(verification_key_fn);
    libsnark::r1cs_gg_ppzksnark_processed_verification_key<libsnark::default_r1cs_gg_ppzksnark_pp> pvk;
    vkey >> pvk;
    vkey.close();

    cout << "verifying..." << std::endl;
    libff::start_profiling();
    bool result = libsnark::r1cs_gg_ppzksnark_online_verifier_strong_IC<libsnark::default_r1cs_gg_ppzksnark_pp>(pvk, inputvec, proof);

    if (result) {
        cout << "VERIFICATION SUCCESSFUL" << std::endl;
    }
    else {
        cout << "VERIFICATION FAILED" << std::endl;
    }

}