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

Getting java.lang.StackOverflowError for exponent function #51

Open someone235 opened 5 years ago

someone235 commented 5 years ago

When trying to create keys for the below code, I get this error: java.lang.StackOverflowError. Is there a way to fix it? Or is it not possible to make a loop with unknown number of iterations?

#include <stdint.h>

struct In {
        uint8_t number;
        uint8_t exponent;
};

struct Out {
        uint64_t result;
};

void compute(struct In *input, struct Out *output) {
        output->result = input->number;
        uint8_t i = input->exponent;
        for(; i > 0; i--){
                output->result = output->result * input->number;
        }
}
MorelSerge commented 5 years ago

It should be, check out the rle_decode_flat example.

maxhowald commented 5 years ago

All loops must be statically bound at compile time, so that they can be compiled to an arithmetic circuit.

You can use the buffetfsm loop transformer to statically bound your loops without re-writing your code. To do this, just make sure you've built the loop transformer using the install_buffet.sh script, and include the annotation in your computation before your loop: [[buffet::fsm(LOOP_BOUND)]]

(see here for an example use.)

For more information on the static loop bound restriction and the loop transformer, you can check out this paper: https://eprint.iacr.org/2014/674.pdf