') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - barnjamin/zk-experiments · GitHub
Skip to content

Repository files navigation

ZK Experimentation

Hackathon Presentation

  • circuits - Holds circuit definitions (except for those used by Groth16 dApp)

  • groth16/

    • contracts - Holds Algorand app definition for verification of Groth16 snarks
    • gnark - experimental
    • zokrates - circuits and scripts used in Zokrates-Algorand workflow (see figure below)
  • host - Definition for controller of RISC0 ZKVM

  • methods - Definition of logic to be run in RISC0 ZKVM

  • python - Implementation of some things with more familiar tooling to help understand the process

  • random - contains a Jupyter notebook with links that was used to generate some examples

  • sanitycheck - For reading in and verifying output of RISC0 compute

Zokrates-Algorand Workflow

Zokrates-Algorand

Installing and Running the Zokrates Demo App

  1. Run Sandbox off a branch that contains elliptic curve math op codes. At the time of this writing this branch works: https://github.com/jannotti/go-algorand/tree/ec-math
  2. Install Zokrates via: curl -LSfs get.zokrat.es | sh
  3. Clone this repo via git clone https://github.com/barnjamin/zk-experiments.git
  4. cd zk-experiments
  5. Install python dependecies via make python-setup
  6. Run the demo with make

Example Run-Log for Alice and Eve:

❯ make zk-snarks-and-beaker-it
cd groth16/zokrates && ./clean.sh ||exit 0
deleting a bunch of zocrates outputs
rm: verifier.sol: No such file or directory
cd"groth16/zokrates"&& ./alice.sh "bls12_381""root"################## HELLO FROM ALICE!!!!!!! ######################################### HELLO FROM ALICE!!!!!!! ######################################### HELLO FROM ALICE!!!!!!! #######################
build zk-SNARK verifier using CURVE=bls12_381 ϵ {bls12_377, bls12_381, bn128, bw6_761} for COMPILATION=root
zokrates compile -i root.zok -c bls12_381
Compiling root.zok
Compiled code written to 'out'
Number of constraints: 1
zokrates setup
Performing setup...
WARNING: You are using the G16 scheme which is subject to malleability. See zokrates.github.io/toolbox/proving_schemes.html#g16-malleability for implications.
Verification key written to 'verification.key'
Proving key written to 'proving.key'
Setup completed
zokrates export-verifier
Could not export verifier with given parameters (curve: bls12_381, scheme: g16): not supported
couldn't export solidity; CONTINUEalice.sh: COMPLETE. Look out for the following artifacts: 1A) abi.json1B) out1C) out.r1cs2A) proving.key2B) root_verification.key3) verifier.solcd "groth16/zokrates" && ./eve.sh "root" "337 113569"################## HELLO FROM EVE!!!!!!! ######################################### HELLO FROM EVE!!!!!!! ######################################### HELLO FROM EVE!!!!!!! #######################build zk-SNARK proof for WITNESSES=337 113569 and PROOF_PREFIX=rootzokrates compute-witness -a 337 113569Computing witness...Witness file written to 'witness'zokrates generate-proofGenerating proof...WARNING: You are using the G16 scheme which is subject to malleability. See zokrates.github.io/toolbox/proving_schemes.html#g16-malleability for implications.Proof written to 'proof.json'proof.json PUBLIC inputs:113569zokrates verify -v root_verification.key --verbosePerforming verification...PASSEDeve.sh: COMPLETE. Look out for the following artifacts: 4A) out.wtns4B) witness5) root_proof.jsonmake alice CURVE="bls12_381" ZOK="secret_factor"cd groth16/zokrates && ./clean.sh || exit 0deleting a bunch of zocrates outputsrm: verifier.sol: No such file or directorycd "groth16/zokrates" && ./alice.sh bls12_381 secret_factor################## HELLO FROM ALICE!!!!!!! ######################################### HELLO FROM ALICE!!!!!!! ######################################### HELLO FROM ALICE!!!!!!! #######################build zk-SNARK verifier using CURVE=bls12_381 ϵ {bls12_377, bls12_381, bn128, bw6_761} for COMPILATION=secret_factorzokrates compile -i secret_factor.zok -c bls12_381Compiling secret_factor.zokCompiled code written to 'out'Number of constraints: 1670zokrates setupPerforming setup...WARNING: You are using the G16 scheme which is subject to malleability. See zokrates.github.io/toolbox/proving_schemes.html#g16-malleability for implications.Verification key written to 'verification.key'Proving key written to 'proving.key'Setup completedzokrates export-verifierCould not export verifier with given parameters (curve: bls12_381, scheme: g16): not supportedcouldn't export solidity; CONTINUE
alice.sh: COMPLETE. Look out for the following artifacts: 1A) abi.json
1B) out
1C) out.r1cs
2A) proving.key
2B) secret_factor_verification.key
3) verifier.sol
make eve WIT="15825923429238183706" ZOK="secret_factor"cd"groth16/zokrates"&& ./eve.sh secret_factor 15825923429238183706
################## HELLO FROM EVE!!!!!!! ######################################### HELLO FROM EVE!!!!!!! ######################################### HELLO FROM EVE!!!!!!! #######################
build zk-SNARK proof for WITNESSES=15825923429238183706 and PROOF_PREFIX=secret_factor
zokrates compute-witness -a 15825923429238183706
Computing witness...
Witness file written to 'witness'
zokrates generate-proof
Generating proof...
WARNING: You are using the G16 scheme which is subject to malleability. See zokrates.github.io/toolbox/proving_schemes.html#g16-malleability for implications.
Proof written to 'proof.json'
proof.json PUBLIC inputs:15825923429238183706
zokrates verify -v secret_factor_verification.key --verbosePerforming verification...
PASSED
eve.sh: COMPLETE. Look out for the following artifacts: 4A) out.wtns
4B) witness
5) secret_factor_proof.json
cd"groth16/contracts"&& python main.py
# ---- --------------------- ---- ## ---- Alice Sets up the App ---- ## ---- --------------------- ---- #
Created app: 3789
And funded with: 1,000,000,000,000 µAlgos
# ---- ------------------------------- ---- ## ---- Now for Eve - the bounty hunter ---- ## ---- ------------------------------- ---- #
Contract verifies root? True
Contract verifies secret_factor? True
Eve claim_bounty? YES!!! Here's the encrypted secret_factor: 15825923429238183706We've sent 1,337,000,000 µAlgos to address=QXMDBBF7OUV3MDK4CX3CMNQHMP6BWCC5D4UNFAU4BFZYNYRG2Y34RT7JJU (eve's address=QXMDBBF7OUV3MDK4CX3CMNQHMP6BWCC5D4UNFAU4BFZYNYRG2Y34RT7JJU)Suppose Eve is evil and tries to claim the same bounty twice:THANKFULLY Eve COULD NOT claim_bounty again:Txn 4WRMNPTKIXCZMB2ZG4HCTWXUGIDJSLBM4CU24SWC42DMX2E6P3XA had error 'assert failed pc=683' at PC 683 and Source Line 381:  load 13 len pushint 32 // 32 > // box <(utf8 bytes: "secret_factor_vk")> is too short to be a verification key. Previously verified? assert <-- Error intc_2 // 13500 intc_3 // 10 + store 15

About

No description, website, or topics provided.

Resources

Stars

11 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages