StarkWare 🛠️ Explore the world of provable programming through Cairo 1.0 - Gnana Lakshmi
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Speaker
Join Gnana Lakshmi from StarkWare for a workshop titled "Explore the world of provable programming through Cairo 1.0 ". Hearing a lot about zero knowledge proofs? Intrigued as to what a high performing provable programming language might look like? Come and learn all about Cairo in this workshop, how to write smart contracts that are eventually used to create STARK Proofs for Starknet. Thank you to everyone who joined us for ETHGlobal Paris 2023! Paris is the city of light and birthplace of many revolutions. Therefore we were thrilled to be back in one of the most buzzing and free-spirited cities in Europe for ETHGlobal Paris 2023. A lot has changed in the European ecosystem since the last time we hosted a hackathon in 2019. ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com
Transcript
foreign [Music] and I have my colleague Omar together will be exploring the world of travel programming through Cairo it's a bit of a long title but I have bolded things that are basically important that is proven programming and Cairo the agenda for today is why Cairo before learning any new programming language especially in the web 3 space I feel like everybody should ask this question to themselves why why should you learn another new programming language and what does it bring to the table we look at what are validity proofs and how are they solving the scalability problem and then all about Cairo with Omar thank you so why Cairo I just have one slide for it and try and explain this in a scenario that's best understood by Developers when when you write a program in any programming language you execute the program and you try to get a result for that program right most of the times this is how you are trying this is how you have been seeing systems running so far however if you want to make sure that you want to prove that something was done correctly then you want to create a proof out of that program right and most of the programming languages that exist as of today do not allow you to generate that proof however when you write a programming a program in a programming language like Cairo when you execute this program in any supercomputer for example in this context or any computer for that matter in the world it will not just execute that program it will also generate a result and a proof for you now this slide is actually has a little bit more context but because of the shorter Workshop today imagine if this supercomputer exists in a rival country and you have given them a piece of code to execute right you want them to give you the result and you want to make sure that the result is accurate if the Rival country tries to manipulate the result uh whether it was intentional or unintentional you will come to know because along with the result a proof is generated so the idea of web3 or the idea of blockchains is to be able to create trustless cooperations right you want to be able to trust any Source or any machine that runs a piece of code and the best way to do that is for that machine to be able to prove that I have run the exact same algorithm that you have given me this is exactly what proof systems do proof systems help not only generate a result for your algorithm from your algorithm but they also generate a proof that I ran the same algorithm that you gave me and you might have heard of zero knowledge proofs you might have heard of provers and verifiers which is what is used in zero knowledge proofs and this this is what exactly the provers do they generate a proof that a certain computation was done authentically so in case the computation was tampered whether intentionally or intentionally the proof generated for that computation will be invalid and this is how in a zero knowledge proof or in a validity proof scenario a regular computer is able to keep a super computer honest the Crux of all of this is that in order to generate a proof you need to learn a provable programming language which is what Cairo is Cairo is a powerful and a highly performant programming language which is not just used in stock net but can also be used as a standalone provable programming language that's why we chose to freeze the talk today as explore the world of provable programming through Cairo how a validity roll ups solving the scalability problem and why should you build on stop net that's the next question right when you think of the L1 scaling problem you have ethereum where say for example when you're producing a block it just says that hey like you remember the uh the problem where we are seeing like okay here is an algorithm we are executing this algorithm the new state of the system is 42 right and a lot of books also see that the answer to all worlds problems is funny too well we can only look um and what happens in the system is the validators actually validate whether this new state is correct and how do the value rate is validate they are going to rerun the entire computation that this particular block producer actually ran in the first place and I'm sure all of you already know that ethereum has gotten congested more often than not in the past couple of years especially when there's been huge launches etc etc and that's a huge opportunity in advance whereas when you think of proof systems if you remember in a programming language like Cairo you can not just generate a result saying hey the state of the new system is 42 but you can also generate a proof that how the seed of the system became 42. and what happens at ethereum level right so you can see there are two distinctions here one is the sequencer and one is the validator now sequencer is what is sitting at the layer 2 at stocknet which is producing this new block and it is also able to create a proof now the validators instead of having to rerun the entire computation we'll just have to verify the proof that is generated by the sequencer and the time taken as you can see is pretty pretty less than what it takes to actually rerun the entire computation not just start net but almost all of the zero knowledge proof mechanisms that you're looking at or validity roll up mechanisms that you're looking at use this exact mechanism to achieve scalability for ethereum and that's why you should learn about stocknet that is validity proofs a variety proofs are an implementation of zeroise proofs to see that they are zero knowledge proofs is actually a misnomer it's not correct because starknet is a decentralized layer 2 which is a public network so it's not entirely a zero knowledge proof system but it adapts from the mathematics of zero knowledge proof systems it takes from the arithmetics of that and is built on top of that and because it validates in a way that is based on the prover verifier system that's why we call them validity proofs they use ZK proofs to guarantee computational Integrity that means you can always say that a particular computation was correct or not just by being able to validate or invalidate the proof what this means is doing the right thing even when no one is looking which is the ethos with which web3 was created right uh we placed our trust into code and non-metalmen because we want everybody to be able to do the right thing even when no one is looking um there's a lot of um um there's a lot of misunderstanding when it comes to what you can build on things which are built on top of principles of zero knowledge proofs because zero knowledge proofs are generally considered to have more privacy use cases but that's not the truth in this case Stark net itself it's all about scaling right so you can just about build anything on stocknet a lot of people came to our booth asking if we are leaning towards a particular domain and my answer is surprise us if you're building one stop net build anything cool and we are more than happy to you know see what you're building like I said roll up is a misnomer and starknet is a Verity roll up it uses a particular algorithm called Starks not star snacks are two advantages of stocks I want to quickly run through before passing it over to Umar uh the first one is that stocks are post Quantum secure because they don't rely on elliptical cryptography they rely on collision resistant hashes and the second is uh stocks do not require a trusted setup whereas snarks do so they are decentralized from the get-go Cairo is the programming language that we are using right now to be able to write contracts to deploy on stock net and the next session is all about Cairo thank you so thank you very much now we know the relevance of Cairo what I started this for and not now let's look from atson Cairo is who is here considering building something on a star net for this hackathon okay awesome most of you okay so today who of you have already written Cairo who has written Cairo before okay so okay okay what is your name sir Danilo you know who the nilo is he's building this is which is using Cairo forbidden as your Norwich VM so what Gian was saying was very relevant you can build a Serial GBM on top of Cairo and style me so this is very very interesting you can do a lot of different stuffs and to be honest we won't be able to be to to learn how to write Cairo right now in this 20 minutes we have left but there's our boots and feel free to come and we will see more details about it we'll go like with an overview right now but feel free to come to our boats downstairs and we can guide you we can help you and you can build some very cool projects for example uh some guys which I I don't know they they are not here but they came out and asked us if there's something like auto payments they can Implement on on starnet with Kyle and auto payment is for example when you subscribe to Netflix and Netflix made you makes you a charge every month without you even you don't authorize it go towards it once and then you have you don't have to keep signing the transaction each month it's automatic and that's thanks to a camera structure that is something that we have natively installments and it's something that we can be working on a lot of time with open set billion Bravos Aryan members from the team foundation so we have been working hard on a construction and that is something that I don't know if you can build it without quality another place that it is not Starbucks and you can do all that with Cairo so Cairo basically is a smart contract it's a language that is very similar to Ross who knows Rost here Rost perfect but for you is going to be very very simple but don't worry we don't know roles it is very doable who knows solidity here okay if you know solidity and you know how a smart contract works it is very simple so I will go and see a small smart contract here and also point you to a place where you can learn more I love learning in a written way so if you want to install everything you need your setup in order to build on top of current started if you scan this QR code you will go to the start netbook as with the rose book you will have everything you need to start coding in the syntax of Cairo the setup the CLI in order to interact with the with the network some tooling you can write your contracts using started JS which is an SDK that will be similar to whatever you use in in JavaScript to interact with ethereum you can do it with python you can do it with roast so we have different sdks everything you can find in the Theon ecosystem you can find it here and this is the guide for you this is the guide for you to install everything and then start writing Cairo contracts you will be able to go for this hackathon again you can you can ask anything you want downstairs actually one of the creators of Cairo is down there with us so whoever thank him to to answer your questions and let's look how as Mark contracts in Cairo looks do the stock Netbook this is the started book the one you already scanned your code and you will go to chapter number two inside here you will have the fundamentals of Cairo Cairo applied for Starlet because it's different right and here he says small smart contract that will allow you to vote it's a boating contract just an example but this example will get you going so let's start okay I will import is the library that contains everything related to starnet and gonna import the contract advice okay not very similar to solidity and then as as in roast we're gonna Define a droids this trade is going to contain all the functions that are going to be external functions what I mean with external functions the external functions are those that interact with this with the memory or the state of the smart contract okay those that can read or write from the state for example this is the trade both trades T here makes reference in this case to the state of the smart contract okay so we are receiving here the state of the smart contract and then we're going to be interacting with T so again T in this case is the state of the smart contract then we have this function called get both status yeah I want a function that is a getter function for for those original solidity is going to be reading from the storage and it's going to get me the status of about how many yes how many know it will make a reference pointing towards the storage okay why because I don't need to write on storage for the for those of you who knows Rost or memory management this is very familiar to you so here we're referencing the storage because we need to read from it we don't need to write on it so it is basically a read function or I get and it will be returning four different new Aids on sign integers 8 Bits okay this is also another getter function it will be written from them on the storage and it will tell me if a motor can bolt it will receive again the storage of the contract and we'll receive the contact address of the user that I'm asking for can this user vote I will give it the address and it will returns it will return a Boolean true or false and we have the same with Isa both the register yes or no in this case one or zero because it's a Boolean it looks like that and finally we have an external function but it is a right function okay this write function which is both it references the storage but it can it is not only like a reference to reads from the storage but it can write it it can alterate the storage I that's what I'm telling with this notice the difference between this and this okay these are getter functions on your reading from the storage this is right into the storage and it will also receive the boat an onsite integer 8 Bits yes or no in this case it would be zero or one okay then we'll be implementing destroy it so what if I hear the storage the the functions are going to be interacting with the storage either by writing or by reading and then finally we go into the standard contracts this this via this is going to be a module mod called bolts that is the name of the smartcom then we will import a couple and we will import the contract address from the started and we're going to import the function called get color address I don't need to explain those those are very similar for you we have two constants one that represents a GS and a no those are u8 and they are one you ate this looks a lot like roast for those of you that have already seen it but it is very simple if you don't know Rose no problem then we're gonna go to the storage this storage is very simple if you can you can read for a moment and you will understand it we have guest boats no boats cambods which is going to be a Boolean it's gonna be my pink this is a mapping like in solidity a contract address to a Boolean oyster boater is going to map a contract address with the Boolean again and yes and no boats are simply on sign in tears until now is there a question we have seen how to create the trade for the functions that are going to be interact in with the storage we have created we have started our own smart contract and we have defined the storage the next going to be easier so is there any phone any question here yes yes you won't even notice it behind it it's building everything you need in order to to interact with Cairo Ali no no on the control it's very very cheap so the goal here is that we are having a network that is going to be very cheap to use and also very fast we have we had a recent update to the network last week actually which increased a lot the TPS from the network like I think right now is the fastest serial knowledge and network there is it's it's it's to be honest this is going to increase in a lot in the next month so congratulations for being here because to be honest we are on a very good spot right now with starnet and this is going to be even even better okay so I will proceed again there might be more questions what we can meet downstairs no problem then I have the Constructor this for you is very similar if you know python Ross I don't know JavaScript if they have a Consulting like a Constructor or simply what we're doing is initializing the smart contract so the Constructor when we deploy it we are asking for four things first we're asking for the contract State again this we can modify so I can I asking for the state and I'm gonna be able to modify it and I'm gonna ask for three contract addresses for the voter number one voter number two and Boulder number three we only have a smart contract for three different addresses to both this can be infinite four or five whatever in this case in this example we only have three then we are doing some stuff in the initialization we are calling functions inside our smart contract using save self and calling internal function like register voters in here I will show it in a minute but to me this is very important here I am altering the state of the smart contracts I am writing to it okay so what I'm doing here is self on this smart contract that is cell go to the gist boats which is on the storage here this is the guest volts variable in the storage and then write the number zero but 0 in a format of a of unsigned interior of 8 Bits so I'm making some Zoom here do the same with no bolts what I'm doing here is basically saying hey the the voting corner is going to start with zero votes with no zero with this okay so right to the storage that we don't have any boats with no and no bolts with yes that's basically it and we are also registering the voters like motor 1 motor 2 and motor 3 can bolt that's all we're saying these guys can vote and we're initializing the the boat count with zero and zero then we we create an event this is how events look like in starnet and Cairo I won't go into details right now but again you can go to the boot or you can read this in the book starnet.io I will give you the URL in case you want to review it but this is how an event looks like okay then I want to show you how to implement the functions that we actually defined before in the trades okay so we create an implementation of that is going to be called both this name can be changed they can have any name no problem this is an implementation of super which means is an implementation of something that is in this file which is called both trades and it's going to be receiving the contract state if you go to what is both trades both trade is the trade that we Define at the beginning that contains all the functions that are going to be external functions okay so we are now implementing all these functions here I am defining a gateboard status look like this and receive this and returns this why not telling you how to implement it okay so now we are going to implement it and yes that's all here's a function you can see it here it is get both status we will show we've mentioned it before it is not going to be right into the storage it's simply going to be reading from the storage and it will be returning me 4 on sign in there so 8 Bits then I start writing the function as you can see it's nothing sorry it is nothing out of this world let's calling this function with self the self because simply it is referencing to something that is inside this smart contract they were defining the yes storage and no percentage it looks like for those in Python it looks like a topple it's actually a top ball and then it we call a function and that's it I think you can understand this is very very simple then we Implement another reads another get their function which only reads from Storage we do the same here and this is very interesting to me this is the external function that actually writes which is the boat so it Alters the storage it says this number of bolts work with yes and this with no that basically it receives a boat then it helps an assertion which is very useful in Cairo for for fighting errors in your code so we assert that the boat should either be no or guess otherwise it will return this error both zero or one this is an error that would return if I can if I bought with two or three or four it won't understand it and it will return the server and it will stop then we start calling some functions but again this looks to you very similar to solidity okay or any other Brahmin language it's it's very simple and basically then I do the same with another set of functions and that's it that's basically it this is the kairosmart contract right now is to be honest very simple you know python or you know you know rust or or solid this to you is very simple so sorry we couldn't go through a lot of details but again we will be downstairs and tomorrow today and the day after tomorrow will be there answering any question that you can have and please go to the book started dot IO let me give it to you then is the QR code to the book where we have most of the content units to do this you will have the voting contract plus other examples you are willing to implement a gun instruction you also have a construction examples we have all the tooling you need if you were at python JavaScript roast whatever you will find it there if not please let us know all the tools are there the the future for us is going to be scalable and and we we really believe we're building the stuff for the next 20 years and started we think is is a great solution to me it is the way to go and yes let us know what you think and and yes thank you very much thank you to Jan and thank you for coming we have a couple minutes cool swag so we have a telegram Group which is uh of high quality where we have a lot of builders in a standard so you can feel free to ask stuff go go write some Cairo let us know that we're writing Cairo and and we can we can help you in different ways right so go explore it feel it if you like it let us know if you don't like it also let us know and and we can we can support you we are here to help you our goal is to make to to get as many developers as possible we're not interested right now in investors or in that many users Financial users per se we are more interested in building right now so if you're a builder let us know and we can help each other oh foreign and you will find everything you need here in the star Netbook in this QR code he will you you will find in the introduction to starnets your first smart contract first started contract and then you will find everything you need here to deploy you have to create a signer because we're using a class fraction somebody that signs for a transaction you have to declare it with this a different concept or you will find it here then deploy it and not yes you here you will find anything unique sorry yeah so I'm trying to figure out uh in practice what use case could run on starknet that I couldn't run let's say on on a regular evm chain if I understand correctly this is one of the fastest of the serial knowledge chains but doesn't mean there are some some things I can do in this chain that I cannot do on the others or is it just faster than what yes imagine you have a bigger computer and so whatever you think requires more computation power computational power I think this is a use case for example right now we are building a lot of autonomous walls for gaming on chain gaming where all the regulation is made on chain all the operations are made on chain also because it's cheap and it is fast you can do AI on chain this is something that I have not seen in done on chain it's something that is weird I don't know if somebody knows about on chain AI build all the calculations on the chain that is something that's something hard to implement because of the cost of the Velocity so I think that if you can think in something that requires a lot of computation this could be a use case of course I'm not saying that this is good for everything you don't want to kill a fly without Asuka right so you have to think about it but yes yeah so we actually want to use it for AI but um as far as we understand if we use zero knowledge for AI it increases computational cost by like a hundred even a thousand sometimes so um is that something that would happen in starnet as well sorry Daniel is working on that right then can you also you want to do some AI I recommend you you check out Orion from the GSAT tech company it's they are building they're using starnet and Cairo to build some AI so they're actually in this hackathon right now and you can meet These Guys these are these guys are genius and they are making own chain ML and actually we have a lot of different tutorials on how to use their models and this is something that I think is going to be the future in the next year we're talking about this and I think this is a great opportunity to win a hackathon right it sounds very impressive AI on chain okay thank you very much we'll be downstairs Slim
Automatic transcript — names and jargon may be misspelled.