zkSessions: Jordi Baylina on Circom
20 May 2021 · 11:25
Jordi Baylina of Hermez and Iden3 discusses Circom, the circuit description language used to build zero-knowledge proof systems. Recorded for the zkSessions series on ZK languages, the conversation covers how Circom compiles arithmetic circuits for zk-SNARK proving and its place in the broader zero-knowledge tooling landscape.
Speakers
Topics
Transcript
so first off i want to welcome jordy to the stage to tell us all about sircom please take it away jordy okay thank you anna well first of all congratulate alex because i think he did a very good job just explaining all this ecosystem of of languages i'm gonna talk about circum you know um circum well like any other like any language i like to start like a kind of hello world here we don't have a real hello world so hello world would be just a multiplication now it's a very simple circuit as you know a simple circuit is just a deterministic circuit you have uh inputs outputs and you get almost the same result and here is where you construct the proof that you have you know the inputs and uh
that you know that that you know the inputs that builds these outputs without revealing the inputs this is mainly what zero knowledge about so here is a hello world you know you see here we define two inputs a and b we define an output c and then we just assign c to a b and then we just instantiate these templates multiplier as a main and that's it we have the circuit so this is the first property of circumstances it's very easy [Music] as you can see well this this program is uh not good you know it's uh because uh we are working with fields and you know it's just if we what we really want is to for example now if we are able to do a factorization
uh this circuit is quite obvious because uh you know you cannot you can factorize very easily it's not like a normal uh uh you know it's not like a normal integra in that's much easier it's much more difficult if you want to get some more complex maybe what one thing that you can do is for example check that a and b have a number of bits okay so here is like let me say a more complex this would be a more complex uh circuit uh that mainly has uh two blocks okay two objects as alex explained it circum is an hdl so you build like hardware so you have like microchips and then you just connect them all together and with microchip you get another bigger and bigger
so in this example we have uh checkbits actually is you get an input and then you check that this input has exactly exactly 60 bits i'm going to step a little forward just to move forward but you can write it easily in you can write it easily in circle but at the end we just instantiate two of them and then assign the a and b to these inputs and then just build output so here we have a circle with a very simple circuit but actually for um proves that you know the fact writes uh 128 bits uh number into 64 bits okay so this is just a an example because um just to to to explain clear is once when you are building a zero knowledge what's the
what's the flow you know what what what are you building okay and this is very important because this is i think this is very different in in in in many languages in libraries okay but they all put so the input of the circuit of course is a circle is the language but what's the output what's the what's the executable okay so in circum the output are two things one is the constraint system this is the circuit r1cs actually all the intermediary hold this all this intermediary so the silk with all these intermediary signals uh how they relate to one each other so this is one output which is you know an array if you want a matrix of uh constraints okay and the other thing that's important is a witness calculation this whole do you at
the end it's a program and this is very important to understand circle is a language that one of the outputs is a program this program it can be a wasm and will be a cpp and in the future can be other language but right now we are able to build the what's in the cpp and this program that generated by circle actually what it does it takes an input and it computes all intermediary signals on the opera so it computes all the the weakness okay so the output of the circuit is this input and f1cs and here is when the one cs is what we block when we block in the in uh in growth16 or we plug in plonk and and we just create a setup through set or not trusted depending on the on the on the primitive that the cryptography primitive that you want to
use generates a proper key generate a verification key and then the process the normal process goes from left to right you get an input you calculate the weakness within windows you calculate the proof and this proof is verified and of course this proof you verify according to the it's these two matches these public uh public inputs and outputs much as this situation so this is the main flow but it's very important to understand that silicon actually generates c plus plus and was i mean it generates it very efficiently especially in the c plus plus the code that generates uh it runs in parallel it's using a finite field that's very optimistic it's optimal um and it's uh uh actually we are generating circuits of
128 million constraints to the 27 constraints uh and a code we're generating a code that's building that and it's computing all these weakness in in very few in very few seconds you know two three four seconds because it does it in in parallel okay um just properties silicon is very it's very useful it's very used in the academic because it's very easy to you know it's very the entry level and the learning curve is very fast so here are a lot of uh courses online courses and universities and people that it's very useful for for explaining and now you can do the tutorial in circum and will take you less than one hour and it's absolutely worth
because you understand uh how this works and this is very easy for the academic but actually the circle of the important thing is that's running in production all these projects some way or the other are doing that in uh some production uh environment i'm going to highlight uh tornado for tornado cache is using that this was one of the first uh uh projects that actually was using and is using circle it's been training for a while of course hermes harvest roll up is built fully uh on silicon all the big all the circuits that are running in hermes and in circum and then there is a uh well an important set of projects that are using the forest as a game
bognoni for voting uh another role ups optimistic roll-ups optimistic zika roll-ups even three from identity so there are many different projects that are using this and this is important that circo means if you've seen the list you know it's quite circum was the first version was in 2017 i think or something like that so in in this world has been very mature on that silicon goes together with a library it's like a special celebrity that's written in circum itself so there is not special library writing in something else it's a set of circles that already implemented that implements uh that already have some uh primitive cryptographical non-cryptographic but
here for example we can do an sha 256 we can do a positive hash we can do a mincy we can do merkel trees we can do uh ddsa signatures we can do all sort of uh baby jab jobs or electric curve operations inside the core we have also boolean operations so we have a conversion to binary to not binary so we have all the basic functions are in circumlive it's a library that's it's growing and i hope that the next month even will be much uh it will grow uh much more that's an important part of well it's not go together because it's just a library anybody can write a library but um well it's a good starting point and it's a set of tools that you would need
when you're building a circuit okay and i also want to mention that um there are some pieces outside circum that uh blocks very good this is a these are the engines of uh the engines here though so i want to highlight the snare js it's an arcgis it's a javascript uh javascript library of uh snarks actually implements growth 16 and well i have not mentioned yet but in a few days it will be available it will be available also in plonk basic blog so you just write the circuits and you can run that for example in in in in the browser
okay and another important another important project is rapid snark that's mainly a fast prover at this point is for growth 16 but it's a proverb that runs in in parallel in a very efficient way and as a reference for example we in hermes we are computing proofs uh of 128 million constraints in in a minute or less than a minute okay uh two words about licensing licensing circo means uh gpl three for the circumvent together i think that if you are doing anything in cryptography you should do open source if you are not doing that but maybe you have other problems and for the runtime it's about so if you are
building some special projects and you don't feel comfortable with cpl you can still use circle because the one thing is silicon the language other thing is the the code that so the result that language generates so the runtime pipe or the root and part of the circle you can run it in uh whatever license you want so you are not tied to the gpl restrictions okay a little bit about the future we are uh finishing very close we are reviewing uh the fully rewrite of silco maxwell leader brighton in in rust this is uh has a lot of advantages first because this rust is much faster than javascript as you can imagine
uh it's much more better brighton it's secondary right and the and the most important thing on my site is that this is for example audi kingdom these language is quite complex but so writing the language two times for independent people even in different independent uh approach and just comparing the results and comparing how it works together this is a very very very very good way of testing that the language actually do what it has to to do okay another things that we are thinking and i hope that we can implement very soon is personal custom gates for plonk and this is something that we will start to work very soon on that and also for example things about typing and and especially just you don't mess up
it's like it's very much like a signal so like in hardware when you connect uh different voltage signals so you do a shortcut this is very much a kind of thing that you can do with this hd hdl language you know it's just checking that the signals are quite good or not okay um for accessing circum i would just put here two links one is circum itself is the github repository you can go there you can find the tutorials on the one and the other thing is the community there's a telegram channel there is a very nice community there many people that's using circum there so if you are you start using silicon when you want to you just connect there and there is some very nice people there just
will can ask questions on their common