HarryR / ethsnarks

A toolkit for viable zk-SNARKS on Ethereum, Web, Mobile and Desktop
GNU Lesser General Public License v3.0
240 stars 57 forks source link

Pinocchio compiler and libsnark support #47

Closed HarryR closed 5 years ago

HarryR commented 5 years ago

Fixes #43

This imports the Pinocchio C to Circuit compiler and adds support for parsing the output format.

However, the Pinocchio code is currently in a 'very academic' state, and I need to make sure that there are some end-to-end automated tests for this before it can be merged.

It also adds some new common stubs to stubs.cpp to remove some code duplication.

The pinocchio python module isn't compatible with Python3, and is quite messy. The automated code checks are showing lots of general style problems with the code, and from a cursory glance I think the quality of the code is has a lot that could be improved. However, I'll leave that for another day - what's most important now is getting end-to-end tests between the Python pinocchio module and the C++ libsnark backend.

I don't have any examples of arithmetic files generated from jsnark / xjsnark at the moment, but I was told that it was compatible with a persons project when they tested it.

HarryR commented 5 years ago

After cleaning up the Python imports for Pinocchio there are a few bits missing:

pinocchio/ArithBusReq.py:200: undefined name 'neg1'
pinocchio/build-test-matrix.py:138: local variable 'random_header_cpparg' is assigned to but never used
pinocchio/vercomp.py:363: undefined name 'ArrayVal'
pinocchio/vercomp.py:833: local variable 'cond_val' is assigned to but never used
pinocchio/vercomp.py:1016: local variable 'outsource_func' is assigned to but never used
pinocchio/BusReq.py:232: undefined name 'BooleanCastBus'
pinocchio/BooleanBusReq.py:56: undefined name 'BooleanMultiplyBus'
pinocchio/BooleanBusReq.py:88: undefined name 'BooleanConditionalBus'
pinocchio/BooleanBusReq.py:115: undefined name 'TODO'
pinocchio/BooleanFactory.py:41: undefined name 'SubtractReq'
HarryR commented 5 years ago

So, my aim for this branch is to get the test suite for Pinocchio running, and being verified by the libsnark plugin, with Python code coverage for the compiler.

This will give me an accurate reading of which code is unused, and where test cases need to be made.

However, I don't want to block merging this code into master, as I could spend months in the guts of the C compiler quite easily geeking out, and I really don't want to do that.

So, instead the aim is getting some examples running, having at least one or two non-trivial end-to-end tests working etc.

HarryR commented 5 years ago

Interestingly the compiler and pinocchio executable are working well now, as is the trace mode which traces execution of the circuit.

However, it currently requires you to provide example inputs when generating the proving key, otherwise the proving key will not be compatible - I'm looking into this and putting together more test cases.

With the eval mode, it displays all output wires and their values, this can be used to run test cases with known inputs, and to verify native versus in-circuit - and also to detect regressions.

HarryR commented 5 years ago

In https://github.com/HarryR/ethsnarks/blob/76ffd4119a90f390709ab4661c9bc26fab79d616/src/pinocchio/circuit_reader.cpp#L629

1 - Y requires a variable with value 1 to be verified.

Need to create a list of opcodes and their descriptions.

HarryR commented 5 years ago

All that's remaining on this branch, IMO, is to get the 3bit lookup table working for the Pinocchio circuit arithmetic reader.