Instalation
On Linux
mkdir-p$HOME/.nargo/bin&&\curl-o$HOME/.nargo/bin/nargo-x86_64-unknown-linux-gnu.tar.gz-L https://github.com/noir-lang/noir/releases/download/v0.22.0/nargo-x86_64-unknown-linux-gnu.tar.gz&&\tar-xvf$HOME/.nargo/bin/nargo-x86_64-unknown-linux-gnu.tar.gz-C$HOME/.nargo/bin/&&\echo-e'\nexport PATH=$PATH:$HOME/.nargo/bin'>> ~/.bashrc&&\source ~/.bashrc
On MacOs Apple Silicon
mkdir-p$HOME/.nargo/bin&&\curl-o$HOME/.nargo/bin/nargo-aarch64-apple-darwin.tar.gz-L https://github.com/noir-lang/noir/releases/download/v0.22.0/nargo-aarch64-apple-darwin.tar.gz&&\tar-xvf$HOME/.nargo/bin/nargo-aarch64-apple-darwin.tar.gz-C$HOME/.nargo/bin/&&\echo'\nexport PATH=$PATH:$HOME/.nargo/bin'>> ~/.zshrc&&\source ~/.zshrc
On MacOs Intel
mkdir-p$HOME/.nargo/bin&&\curl-o$HOME/.nargo/bin/nargo-x86_64-apple-darwin.tar.gz-L https://github.com/noir-lang/noir/releases/download/v0.22.0/nargo-x86_64-apple-darwin.tar.gz&&\tar-xvf$HOME/.nargo/bin/nargo-x86_64-apple-darwin.tar.gz-C$HOME/.nargo/bin/&&\echo'\nexport PATH=$PATH:$HOME/.nargo/bin'>> ~/.zshrc&&\source ~/.zshrc
Generate a proof
Generate a new noir project and prepare it to receive the prover inputs.
nargo new hello_worldcdhello_worldnargo check
Now put the inputs inProver.toml
and generate the proof.
Prover.toml
x="1"y="2"
nargo prove
The proof is now located atproofs/hello_world.proof
.
Verify the proof
Generate the solidity verifier.
nargo codegen-verifier
The verifier contract is now located atcontract/hello_world/plonk_vk.sol
. Deploy it and send it's address as param to the following contract with custom logic.
// SPDX-License-Identifier: MITpragmasolidity>=0.7.0<0.9.0;interfaceINoirVerifier{functionverify(bytescalldata_proof,bytes32[]calldata_publicInputs)externalviewreturns(bool);}contractNoirCustomLogic{INoirVerifierpublicnoirVerifier;uintpublicpublicInput;constructor(addressnoirVeriferAddress){noirVerifier=INoirVerifier(noirVeriferAddress);}functionsendProof(bytescalldata_proof,bytes32[]calldata_publicInputs)public{// ZK verificationnoirVerifier.verify(_proof,_publicInputs);// Your custom logicpublicInput=uint(_publicInputs[0]);}}
Nullifier
Circuit
usedep::std;fnmain(x:Field,y:pubField)->pubField{assert(x!=y);lethash=std::hash::pedersen_hash([x,y]);hash}
nargo provenargo codegen-verifier
Solidity
// SPDX-License-Identifier: MITpragmasolidity>=0.7.0<0.9.0;interfaceINoirVerifier{functionverify(bytescalldata_proof,bytes32[]calldata_publicInputs)externalviewreturns(bool);}contractNoirCustomLogic{INoirVerifierpublicnoirVerifier;uintpublicpublicInput;mapping(bytes32=>bool)publicnullifiers;constructor(addressnoirVeriferAddress){noirVerifier=INoirVerifier(noirVeriferAddress);}functionsendProof(bytescalldata_proof,bytes32[]calldata_publicInputs)public{// ZK verificationnoirVerifier.verify(_proof,_publicInputs);// Your custom logicrequire(!nullifiers[_publicInputs[1]],"Proof already nullified");publicInput=uint(_publicInputs[0]);nullifiers[_publicInputs[1]]=true;}}
Advanced zkDapp Demo
- Metamask compatibility
- Anonimity set merkle tree
- Node.js relayer
- Prover in browser
Github repohere.
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse