# Circom Getting Started ## Metadata **Status**:: #x **Zettel**:: #zettel/fleeting **Created**:: [[2024-03-17]] **Topic**:: [[♯ Zero-Knowledge Proof]] ## Synopsis Install Circom ``` git clone https://github.com/iden3/circom.git cargo build --release && cargo install --path circom ``` Compile ``` circom multiplier2.circom --r1cs --wasm --sym --c ``` Generate Witness (JavaScript) ``` node generate_witness.js multiplier2.wasm input.json witness.wtns ``` Generate Witness (C++) ``` sudo apt install nlohmann-json3-dev libgmp-dev nasm make ./multiplier2 input.json witness.wtns ``` Inspect Witness ``` snarkjs wtns export json witness.wtns witness.json cat witness.json ``` Verification <https://docs.circom.io/getting-started/proving-circuits/> ``` npm install -g snarkjs # 2**12 is the max power of the polynomial to support snarkjs powersoftau new bn128 12 pot12_0000.ptau -v snarkjs powersoftau contribute pot12_0000.ptau pot12_0001.ptau --name="First contribution" -v snarkjs powersoftau prepare phase2 pot12_0001.ptau pot12_final.ptau -v snarkjs groth16 setup multiplier2.r1cs pot12_final.ptau multiplier2_0000.zkey snarkjs zkey contribute multiplier2_0000.zkey multiplier2_0001.zkey --name="1st Contributor Name" -v snarkjs zkey export verificationkey multiplier2_0001.zkey verification_key.json snarkjs groth16 prove multiplier2_0001.zkey witness.wtns proof.json public.json snarkjs groth16 verify verification_key.json public.json proof.json ``` > [!caution] The example above does not add random beacon to powersoftau and keys. ## Inspectation ``` snarkjs r1cs print multiply2.r1cs ``` ## Questions Q. What is powersoftau? A process to setup the parameters. [[Koh Wei Jie - Announcing the Perpetual Powers of Tau Ceremony to benefit all zk-SNARK projects (Highlights)]] Q. When to generate powersoftau? The powers of tau, which is independent of the circuit. Q. When to generate keys? The phase 2, which depends on the circuit. Q. How to choose public signatures? <https://docs.circom.io/circom-language/signals/#public-and-private-signals> ``` component main {public [in1,in2]} = Multiplier2(); ``` > In circom, all output signals of the main component are public (and cannot be made private), the input signals of the main component are private if not stated otherwise using the keyword public as above. The rest of signals are all private and cannot be made public. Q. How to prove Schnorr? - <https://github.com/0xPARC/circom-ecdsa/tree/master> - <https://github.com/nixkitax/circom-schnorr-verify/blob/js-signature-schnorr/circuits/verifyKeySchnorrGroup.circom> Q. How to prove hash? <https://github.com/iden3/circomlib/tree/master/circuits/sha256>