Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Filosofía Código EN profile imageAhmed Castro
Ahmed Castro forFilosofía Código EN

Posted on • Edited on

     

Noir on Scroll

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
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode

Generate a proof

Generate a new noir project and prepare it to receive the prover inputs.

nargo new hello_worldcdhello_worldnargo check
Enter fullscreen modeExit fullscreen mode

Now put the inputs inProver.toml and generate the proof.

Prover.toml

x="1"y="2"
Enter fullscreen modeExit fullscreen mode
nargo prove
Enter fullscreen modeExit fullscreen mode

The proof is now located atproofs/hello_world.proof.

Verify the proof

Generate the solidity verifier.

nargo codegen-verifier
Enter fullscreen modeExit fullscreen mode

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]);}}
Enter fullscreen modeExit fullscreen mode

Nullifier

Circuit

usedep::std;fnmain(x:Field,y:pubField)->pubField{assert(x!=y);lethash=std::hash::pedersen_hash([x,y]);hash}
Enter fullscreen modeExit fullscreen mode
nargo provenargo codegen-verifier
Enter fullscreen modeExit fullscreen mode

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;}}
Enter fullscreen modeExit fullscreen mode

Advanced zkDapp Demo

  • Metamask compatibility
  • Anonimity set merkle tree
  • Node.js relayer
  • Prover in browser

Github repohere.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

More fromFilosofía Código EN

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp