This provides an overview of a custom zero-knowledge circuit implemented using the Circom language. The circuit, named customCircuit
, demonstrates the creation of logic gates and their connections to create a custom computation. The resulting circuit can be used to generate zero-knowledge proofs for certain computations while keeping the input values private.
The customCircuit
demonstrates the use of logic gates to compute an output signal based on input signals. The circuit involves the following components:
- Inputs: The circuit takes two input signals,
A
andB
, which serve as operands for the computation. - Gates: The circuit uses three logic gates:
AND
,NOT
, andOR
. These gates are defined as separate templates. - Intermediate Signals: The circuit has two intermediate signals,
X
andY
, which are the outputs of theAND
andNOT
gates, respectively. - Output: The final output signal,
Q
, is computed using theOR
gate with inputs from the intermediate signals.
The customCircuit
template represents the main circuit. It defines input signals A
and B
, intermediate signals X
and Y
, and the final output signal Q
. The circuit involves the following steps:
- An
AND
gate (andG
) computes the logical AND of inputsA
andB
, and its output is stored in the intermediate signalX
. - A
NOT
gate (notG
) computes the logical NOT of inputB
, and its output is stored in the intermediate signalY
. - An
OR
gate (orG
) computes the logical OR of the intermediate signalsX
andY
, resulting in the final output signalQ
.
These templates define the logic for the AND
, NOT
, and OR
gates, respectively. Each gate takes input signals and produces an output signal based on the defined logic.
-
Install the required dependencies by running the command:
npm install
-
Compile the circuit using the command:
npx hardhat circom
This will generate circuit intermediaries and the necessary Solidity verifier contracts.
-
Generate a proof and deploy a verifier contract using the provided script:
npx hardhat run scripts/deploy.ts
This script performs the following tasks:
- Deploys the verifier contract.
- Generates a proof using circuit intermediaries.
- Generates calldata for verification.
- Calls
verifyProof()
on the verifier contract with calldata for proof verification.
circuits
├── CustomLogicCircuit
│ ├── circuit.circom
│ ├── input.json
│ └── out
│ ├── circuit.wasm
│ ├── CustomLogicCircuit.r1cs
│ ├── CustomLogicCircuit.vkey
│ └── CustomLogicCircuit.zkey
├── new-circuit
└── powersOfTau28_hez_final_12.ptau
contracts
contracts
└── CustomLogicCircuitVerifier.sol
The customCircuit
demonstrates the construction of a zero-knowledge circuit using logic gates. By following the provided steps, you can compile the circuit, generate proofs, deploy verifier contracts, and perform zero-knowledge proof verification.
This project is licensed under the MIT License - see the LICENSE.md file for details