scipr-lab / libsnark

C++ library for zkSNARKs
Other
1.83k stars 585 forks source link

gadgetlib1: add tests #50

Closed benma closed 7 years ago

benma commented 8 years ago

The gadgetlib1 simple example was out of date / broken. This patch fixes it and adds a test, very similar to gadgetlib2.

madars commented 8 years ago

This looks good, thank you!

Previously gen_r1cs_example_from_protoboard was a generic function parametrized by the field type. The PR binds FieldT to equal Fr. This seems a bit too restrictive: gadgetlib1 supports multiple fields and we should be able to test the integration for all field choices. Would you mind re-PR-ing with gen_r1cs_example_from_protoboard templatized again? :)

(There's also a technical issue with the current FieldT=Fr binding: simple_example.hpp header includes simple_example.tcc, which contains the implementation of gen_r1cs_example_from_protoboard. Therefore, if multiple object files have their sources reference simple_example.hpp, all those object files will include a symbol for gen_r1cs_example_from_protoboard, and cause a link-time error.)

benma commented 8 years ago

Thank you.

Previously gen_r1cs_example_from_protoboard was a generic function parametrized by the field type. The PR binds FieldT to equal Fr. This seems a bit too restrictive: gadgetlib1 supports multiple fields and we should be able to test the integration for all field choices. Would you mind re-PR-ing with gen_r1cs_example_from_protoboard templatized again? :)

I removed it to make it consistent with gadgetlib2/examples/simple_example.cpp. I can redo the PR. Should I also templatize the gadgetlib2 example too, then?

(There's also a technical issue with the current FieldT=Fr binding: simple_example.hpp header includes simple_example.tcc, which contains the implementation of gen_r1cs_example_from_protoboard. Therefore, if multiple object files have their sources reference simple_example.hpp, all those object files will include a symbol for gen_r1cs_example_from_protoboard, and cause a link-time error.)

I don't quite understand. Isn't the header guard preventing that?

#ifndef SIMPLE_EXAMPLE_HPP_
#define SIMPLE_EXAMPLE_HPP_
benma commented 8 years ago

@madars Done, I added the template back to the example.

benma commented 8 years ago

@madars Please re-review.