Zero knowledge proof circom circuit to determine whether given input is a factor of 9 or not

piash.tanjin
3 min readApr 19, 2023

--

Prerequisite

Install Node.js https://nodejs.org/en/download (v18.14.2)
Install circom https://docs.circom.io/getting-started/installation/ (vcircom compiler 2.1.5)
Install circomlib https://www.npmjs.com/package/circomlib (v2.0.5)
Install snarkjs https://www.npmjs.com/package/snarkjs (v0.6.10)

Brief Overview

Zero-Knowledge-Proof (ZKP) is a type of mathematical proof that allows data to be verified without revealing the data itself or any other information about it. One popular type of ZKP is zkSNARK, which is a short, succinct, and non-interactive proof that requires only one interaction between the prover and verifier.

Circom is a programming language used to write circuits that describe constraints on a set of inputs, with one or many outputs. These constraints can then be used to generate proofs that the inputs satisfy the constraints, and to verify those proofs. This allows for secure and private verification of data, without the need to reveal any sensitive information.

zkSNARK is a specific type of Zero-Knowledge Proof that enables the verification of data without revealing any sensitive information. It accomplishes this by requiring only one interaction between the prover and verifier, making it highly efficient. Additionally, zkSNARK is designed to be succinct, meaning that it can convey a large amount of information in a very compact form. This makes zkSNARK an ideal tool for applications where privacy and efficiency are key concerns.

Install Process

Clone github repositroy https://github.com/TanjinAlam/Circom-Circuit-Zero-Knowledge-Proof

C
ompile circom circuit

  • Open circuit.circom
  • Modify include
  • "/usr/local/lib/node_modules/circomlib/circuits/comparators.circom" with the your local computer circomlib directory
  • chmod +x compile.sh
  • ./compile.sh

It will generate two folder circuit_cpp & circuit_js

G
enerate witness & Proving circuits with ZK

  • Move start.sh into circuit_js directory
  • Move circuit.r1cs into circuit_js directory
  • Move input.json into circuit_js directory
  • chmod +x start.sh
  • ./start.sh

S
tart interacting with the ZKP-System

  • Move circuit.wasm to root directory where snarkjs.js file exis
  • Move circuit.zkey to root directory where snarkjs.js file exist
  • Move verification_key.json to root directory where snarkjs.js file exist
  • Start frontend.html a web browser.

Output

Since 1 is factor of 9 it shows the result true.

Since 6 is not a factor of 9 it shows the result false.

Deploy Solidity Smart Contract

you can do this using remix

  • Just add input[0] = 1;
  • Now compile the file and deploy the smart contract.

Output

Copy the proof from the fronted and past it into the deployed smart contract verifyProof function parameter as following

Since i have pasted the proof of 6 which is not a factor of 9 its showing false.

--

--