Compile a Circuit
Last updated
Was this helpful?
Last updated
Was this helpful?
There are many ZK libraries and languages that can be used with Sign Protocol, each with its pros and cons. We do not aim to cover these similarities and differences and it is up to you to decide which to use. However, we recommend using a library that can generate a Solidity verifier using your compiled circuit. We will use .
First, follow Circom's docs for . If you have never used Circom before, we recommend reading through their . For this tutorial, we will use a non-trivial example circuit, which you can find . The circom file should contain the following:
This sha256 circuit will take in two signals as input: the first is an array of size 64 and the second is an array of size 32. The first array will be hashed using the sha256 algorithm, requiring that the output (hash) signal equals the provided hash. Next, we will compile our circuit.
Your local Circom installation comes with the circom
command. To compile your circuit, run:
In your output directory (likely named sha256_js
), create a file named input.json
. Paste the following in this file:
Next, navigate to your build directory and run the following command to generate a witness:
Now that you have generated all required files, you can generate a smart contract verifier using the following command:
This will generate a file named verifier.sol
in your root project directory. To facilitate a function call for verifyProof()
, you can run the following command:
When you are ready, proceed to the next page to integrate verifier.sol
with a schema hook.
This command will compile your source code into the required files, including the r1cs constraint system file, and wasm files for generating a witness. You can read more about the command flags . From here, you will generate your witness. Note that you do not need a witness to generate a smart contract verifier. Witnesses are used for creating proofs, which will be verified using your schema hook.
This section follows the documentation located . For more information about each step, please refer to Circom's documentation. Run the following commands to complete the Powers of Tau and Phase 2 requirements: