zkREPL, Applied ZK - Day 2
Ethereum DEV NL·Sun, Oct 9, 2022, 12:00 AM
zkREPL is a fully in-browser development environment for zk-SNARKs written in Circom Speaker(s): Kevin Kwok Hosted at Devconnect Amsterdam, 2022 Visit the website: https://devconnect.org/ Or follow @EFDevconnect on Twitter
Transcript
[Music] i'm here to talk about zk ruffle which is like an online uh like playground for writing sircom circuits uh does this work or okay um and uh i feel like a fun way to frame this would be to talk about what is a rebel and like go back a little bit to some like computer history uh and talk about like the original like uh like uh rebel discovered in sort of the 1950s uh so um uh so back then in the 1950s we had these large computers that cost millions and millions of dollars that cost millions of dollars to operate and could uh produce a sort of whopping dozens of transactions or like executions per second and occasionally they would have bugs and these bugs would uh cause errors these bugs were lit often literally insects that would chew into the wires uh like create short circuits and burn entire systems to the ground and so uh at the it was on these computers that at some point uh people developed this language lisp which was powerful enough that it could represent uh its own execution as a first class like operation uh and they called this uh operation eval uh that is like your program could run it could uh like programs could be written that could invoke their own execution uh and a lot of researchers uh at the time or like at the time the way people wrote software that was they would punch out physical cards uh with little holes and then uh like feed them into these large computers uh sometimes you would have to flip switches back and forth in order to like uh encode like a single like bite at a time uh i i believe with uh the alt hair that like bill gates used to develop the first version of like dos uh it had no keyboard so you had to like flip switches back and forth in order to program things so oh no um with this eval construct in lisp people discovered a useful pattern which was you could write a program which would read something from the keyboard feed it into the interpreter with eval uh print it and then loop back to accept further input and in this like repel construct was ultimately what like led to like a cambrian explosion of like software because uh rather than like punching cards you could just type stuff iterate and develop really quickly and so that's kind of uh the homage that z zk ruppel exists uh uh too uh and uh so with that uh i'll just get started with the demo uh you can follow along by just going to zkrebel.dev uh it loads in your browser and you can see that the main part of it is this text editor it's using monaco which is the same text rendering engine as a visual studio code and what's sort of shown inside is the circom language the circom 2.0 version uh in particular uh we've got like a few little extensions so for instance uh you surcom lib is built in and you can click you can mouse over any uh like include statement to view the source code for any linked thing the other thing you can do is you can import directly from external like github repository so in this case we have some of the stuff from the zkzx zkzk project here and we can just like include it directly as a url and it will handle loading as well um the uh we've also sort of extended it with this little syntax on the bottom where you can specify in line the inputs that you want for trial execution so over here in the sidebar you can see the trace of running circom you can see the statistics about the number of constraints the number of wires the log output from the trial execution with the specified input and the output but beyond just showing the like inputs and outputs that get logged since a witness file gets generated with ultimately every single wire and signal inside the program we can actually integrate that into the ide so we can like mouse over any variable and see its value and this works not just for like inputs and outputs but even these more complicated like uh templates so in this case i can mouse over hash and see like all of the various recursive inputs here so i'm going to at this point take a little break to talk about how this works so this works totally in the browser and the first part we had to do in order to get this to run because the circom2 language is written in rust is we had to basically get circom to come like cross compile into webassembly uh and beyond just having this uh a browser system we've also published a npm module uh for the circom2 uh version uh so if uh so if you have uh some circumfile uh on your computer rather than having to install the entire rust tool chain uh if you have nodejs installed you can just run npx or com2 and then like whatever circum file and it'll run from your computer like fetch and sort of automatically install one because uh we're running it in web assembly and a lot of the multi-threading stuff is very like primitive and mostly doesn't work uh it runs the sircom compiler as a like single threaded execution which uh in my sort of experience it means like a performance uh hit of about like like 30 um at least on my computer uh which i think is like relatively modest uh probably it'll get worse uh if you're trying to compile large things i know with the like particularly in early circuits uh with like millions of constraints like uh zk ruppel and uh correspondingly the node.js thing is more likely to choke um so uh with that um uh it's pretty simple you can just hit control enter it'll run uh sort of invoke the like circum compiler and generate a list of these artifacts so this web assembly and the javascript file is there so you can just download directly the witness generator and and other things um uh for collaboration uh you can just hit control s and what it'll do is it will sync up to your github save this uh url as a github gist and you can just copy the url uh share it a lot of the like xerox park uh uh like primitives have been developed on zkrebel basically by passing these links along in the discord and in addition you can take this and embed it in a iframe and then you can publish it as part of learning resources in different websites uh just as an embedded module um and the last part is i i want to show a preview of something that um uh basically takes this uh zk ruppel thing end to end so in this bottom part we have this like experimental bit where we can generate these proving and verifying keys so here i'm just going to click this graph 16 button it's going to at this point automatically fetch from ipfs some list of the appropriately sized power of tau and then it's going to take that do a like testing insecure um uh set of uh like uh a number of rounds of the like uh contribution to the z keys it's gonna generate this trial z key uh and it's gonna generate generate this html file which embeds snark js and like the z keys and verification keys so that you have like a starting point for whatever circuit you're working on so in this case it generated i can click main.html to download this and i can just uh click on this to open this sample application so in this uh the sample application you could just tweak it for whatever particular application you want you can fiddle around with the inputs hit generate proof and after a second or so it will like show the proof the public outputs you can click verify proof and see that in this case this proof is valid if i presumably change a random number here the proof becomes invalid but of course like all of this stuff isn't really useful unless you can get some sort of reasonable credible belief that this application is in fact running some code that you you or someone else could audit so in this case we can hit download z key and get the z key out of this application and we can feed it and we can open uh zkrebel again hit click verify open this z key and you can see that what it does is it will just verify that this circuit matches the z key uh for this application so here we we've like gone from building this circuit sharing it among ourselves uh sort of developing it uh we've generated uh some we've tested it with certain uh in-line witnesses uh and inputs we've uh generated some testing keys uh testing application and then gone from that application to extract out the z key and verify that that matches the circuit um so i think that gives like a pretty clean story for how like people can like get their toes wet uh playing around with uh like zero knowledge stuff in general um and just to sort of conclude i think that uh there's a lot of interesting like i think in many ways uh like zero knowledge and crypto in general is like the the 1950s our our tools our processes are extremely like primitive uh but i i i think uh focus on developer tooling and like uh shortening the process for iteration and being able to explore things we can have it really uh like spawn a new cambrian explosion in zero knowledge stuff so [Applause] cool any questions for kevin well i find a really great great tool in fact i teach from time to time tilken and i have i think this tool is really nice to teach students and then to you know as you said to to make your uh your shoes wet uh one question is there any way to connect to the real the compiler the ras compiler maybe i mean you cross compile to web assembly so you can run it on the browser yeah but there is a way to just if you have an installed version of the ras compiler to use it there is some kind of configuration or um there isn't currently a way and uh in order to do that maybe it's a good uh a nice feature to have i mean yeah that might be especially for developing with these really really massive uh circuits yeah that's an interesting idea um you can uh it as of a few hours ago uh uh it's now open source so if you go to github.
com you can see the source code uh and uh i'd be happy to accept any of these contributions okay really nice talk any other questions okay thank you kevin [Applause] [Music] you
Automatic transcript — names and jargon may be misspelled.