pepper-project / pequin

A system for verifying outsourced computations, and applying SNARKs. Simplified release of the main Pepper codebase.
Other
122 stars 46 forks source link

Simple code fragment does not compile #70

Open jsalzbergedu opened 2 years ago

jsalzbergedu commented 2 years ago

Hello Pequin Maintainers,

I'm writing this to report a simple code fragment that does not compile :-)

Replace mem_naive_micro.c with the following:

void compute(struct In *input, struct Out *output) {
    int zeroth = input->in[0];
    int first = input->in[1];
    int second = input->in[2];
    int third = input->in[3];
    output->out[0] = zeroth;
    output->out[1] = first;
    output->out[2] = second;
    output->out[3] = third;
}

compile and prove:

./pepper_compile_and_setup_V.sh mem_naive_micro mem_naive_micro.vkey mem_naive_micro.pkey
./pepper_compile_and_setup_P.sh mem_naive_micro
bin/pepper_verifier_mem_naive_micro gen_input mem_naive_micro.inputs
bin/pepper_prover_mem_naive_micro prove mem_naive_micro.pkey mem_naive_micro.inputs mem_naive_micro.outputs mem_naive_micro.proof

it will fail with the following:

pepper_prover_mem_naive_micro: ../thirdparty/libsnark/libsnark/zk_proof_systems/ppzksnark/r1cs_gg_ppzksnark/r1cs_gg_ppzksnark.tcc:406: libsnark::r1cs_gg_ppzksnark_proof<ppT> libsnark::r1cs_gg_ppzksnark_prover(const libsnark::r1cs_gg_ppzksnark_proving_key<ppT>&, libsnark::r1cs_gg_ppzksnark_primary_input<ppT>&, libsnark::r1cs_gg_ppzksnark_auxiliary_input<ppT>&) [with ppT = libff::bn128_pp; libsnark::r1cs_gg_ppzksnark_primary_input<ppT> = std::vector<libff::Fp_model<4, ((const libff::bigint<4>&)(& libff::bn128_modulus_r))>, std::allocator<libff::Fp_model<4, ((const libff::bigint<4>&)(& libff::bn128_modulus_r))> > >; libsnark::r1cs_gg_ppzksnark_auxiliary_input<ppT> = std::vector<libff::Fp_model<4, ((const libff::bigint<4>&)(& libff::bn128_modulus_r))>, std::allocator<libff::Fp_model<4, ((const libff::bigint<4>&)(& libff::bn128_modulus_r))> > >]: Assertion `!qap_wit.coefficients_for_H[qap_wit.degree()-2].is_zero()' failed.

The following, however, does not error on proving:

/*
  Microbenchmark to measure the cost of naive RAM
*/
void compute(struct In *input, struct Out *output) {
    int i;
    for (i = 0; i < NUMACC; i++) {
        output->out[i] = input->in[i] * input->addr[i];
    }
}

And this fragment does error on proving:


```cpp
/*
  Microbenchmark to measure the cost of naive RAM
*/
void compute(struct In *input, struct Out *output) {
    int i;
    for (i = 0; i < NUMACC; i++) {
        output->out[i] = input->in[i] * input->addr[i];
    }
}

So, I believe that the reason the above does not compile is (probably) because there are no multiplications, and therefore no constraints.

I think this could potentially be dealt with by giving a better error message when there are no constraints that come from the code.

Thank you :-)