zkInterface is a standard tool for zero-knowledge interoperability.
- In a frontend, implement a feature to export the circuits or gadgets to ZkInterface format.
- In a proving system, support loading circuits from ZkInterface buffers or files.
See the implementation guide section in the spec above for more details, and check out the existing implementations below.
Proving System | Export Circuits | Import Circuits | |
---|---|---|---|
Bellman (Groth16) | Yes | No | Yes |
Dalek (Bulletproofs) | Yes | No | No |
ZoKrates | - | Yes | No |
Libsnark | PGHR | Yes | No |
See also the WebAssembly modules and the live demo.
zkInterface.pdf |
The interface specification |
zkinterface.fbs |
The gadget interface definition using FlatBuffers |
rust/src/zkinterface_generated.rs |
Generated Rust code |
rust/src/reading.rs |
Rust helpers to read messages |
rust/src/writing.rs |
Rust helpers to write messages |
rust/src/cpp_gadget.rs |
Rust helpers to interact with C++ |
rust/src/examples.rs |
Example messages for a simple test circuit |
cpp/zkinterface_generated.h |
Generated C++ code |
cpp/gadget_example.cpp |
Example gadget in C++ |
build.rs |
Generate Rust and C++ code from zkinterface.fbs, and compile the C++ example |
cpp/libsnark_integration.hpp |
Libsnark support |
cpp/libsnark_example.cpp |
Libsnark gadget example |
In the rust
directory:
cargo test
This will generate and compile Rust and C++ code, and run a test of both sides communicating through the standard interface.
cargo run --bin example > example.zkif
cargo run --bin print < example.zkif
This will generate and print a file containing the messages Circuit, R1CSConstraints, and Witness for a toy circuit.
Generated C++ and Rust code is included.
For other languages, install the FlatBuffers code generator (flatc
).
One way is to compile it with the following:
git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
make
Then run:
flatc --LANGUAGE zkinterface.fbs