Cairo 1.0 / Henri Lieutaud

EthereumZuri.ch 2023 · April 2023 · 24:36

Henri Lieutaud gives an overview of Cairo 1.0, the programming language for writing provable programs and smart contracts on Starknet, the Ethereum layer-2 rollup built on STARK proofs. At EthereumZuri.ch 2023 he sets out to answer the common questions developers have about Cairo 1 and how it is used to build on Starknet.

Speakers

Topics

From EthereumZuri.ch 2023, hosted by EthereumZuri.ch.

Transcript

foreign [Music] can you hear me ah this is better hello everyone my name is Henry I'll present for you today um and I'm going to talk about how Starks and Cairo will allow ethereum to scale in a mind-blowing way I'm going to try to make my presentation in various steps for those of you who are not familiar I'm going to start by explaining really quickly what ZK Roll-Ups are and how they work I'm going to explain to you a few basic concepts

and then we're going to build on top of that to see where we go can we first do a quick show of hand who here con considers themselves a Dev very nice who here has already written a solidity smart contract who here has heard about Cairo very nice who here has written Cairo not so bad so can you raise your hand again all right so all these peoples you see them raising their hand if you have questions about Cairo don't take my words for it ask them no of the truly you'll have the best feedback all right so uh my name is angry I'm based in Paris I'm uh the lead developer advocate for starknet so my job is to explain to people what Stark net is and

how they can build cool stuff on top of it so if you're wondering how you can build stuff on starknet or how you can extend your L1 application and do more stuff on Layer Two you should reach out I'm happy to answer either on Twitter telegram or here happy to talk whenever don't hesitate all right so I'm going to start with first what it is we're building and let's talk first about the blockchain paradox don't you think it's kind of weird that the Technologies we're using in the blockchain space are all relatively new right 15 10 years old for ethereum and yet they don't scale right there has been massive Payment Systems emerging in the past 10 years

you can name alipay Visa venmo there's a bunch of them well who are managing to handle thousands of transactions how come Bitcoin and ethereum who are newer Technologies why can't they do the same thing right and when you really look at it it boils down to the trust model that blockchain use compared to traditional institutions in the traditional world you have one entity say your bank or your payment processor who is in charge of keeping tabs of who owns what everything goes through their computer everything goes through their Data Center now this has a bunch of disadvantages

I'm not going to tell you why blockchain is cool but it also has pretty cool advantages right there's only one place where all the transactions go through and if at some point you need more capacity you just throw more data centers at it right pretty easy to scale we know how to do that with a cloud now compare this with the blockchain in the blockchain world we don't trust we verify this means that we don't trust somebody else to do the accounting for you for us we take every transaction and we re-execute them and here first you have a first notion as to why blockchains don't scale because every and why blockchains are expensive

because every time a transaction is done in the system it is not done by one actor it is done by all the actors in the system implicitly a work that is done by thousands of people is going to be more expensive that they work that is owned by just a handful right and another question to that is like who here thinks that on their laptop they're able to handle the load of Visa while you might have a very big computer then but other than that I think it's really hard for you with a retail computer to handle the loader Visa right so blockchains give us really cool stuff but we sacrifice things for that we sacrifice scalability we don't we can't do a lot of transactions and we sacrifice privacy right so that's why

blockchain don't scale today we talk about them as distributed ledgers they're not distributed they're replicated right everybody is doing the same work now I want to introduce a concept you may be familiar with and it's a concept you can put in the same box as digital signatures or Ash functions right they're tools you can use in your application they're backed by mathematics you don't have necessarily to understand how they work but you can know how you can use them right and the way they work is they following a validity proof allows Alice to execute a program and to send the output of such program

to Bob along with a proof now Bob is able to take this proof analyze it and make sure that the program was executed correctly without having to execute the program simple enough well that basically here is a fundamental paradigm shift in how Computing works because there is no other Paradigm where you can give to somebody the assurance that the program ran correctly without him or her running it themselves so this has deep implication for computing in general but mostly for the blockchain world today right so ZK proof or validity proofs guarantee

computational integrity in our case we don't use them for privacy we use them for scaling why do we use them for scaling well for a very neat property that these proofs have which is that there is an asymmetry between how much work it takes for Alice to execute the program and how much work it takes to Bob to verify the program the more work Alice executes the less time it takes for Bob to verify it say it differently Bob can execute a program on a supercomputer and Alice can verify the proof and use the output of the super computer in our application on her

retail laptop without having to trust Bob at any step which is kind of mind-blowing when you think about it it really introduces an asymmetry between these two players so validity proofs are to computation what zipping is to a file size this analogy is actually it's good but is that is its limit in the sense that with recursion you can actually compress further a validity proof and you can't with compressing a file but let's not get into it right now all right so far so good now let's talk about how we apply this in the blockchain context let's talk about starknet so starknet is a general purpose smart contract platform that is based on that is that

lives on top of ethereum it is secured by ethereum and the way it works is the following you have a bunch of actors that are able to run a blockchain with transactions with block which is darknet and this blockchain uses a lot of resources it is able to process a lot of transaction like a lot lot and you can scale this machine as much as you want because every time a block is processed a proof is generated this proof then gets sent to ethereum and is verified there meaning that ethereum can take for granted that the output of that blockchain is correct without having to trust any human and this is here

also an interesting artifact this is the only concept Zeke Roll-Ups are the only contexts where two blockchains are able to understand each other when you think about it when you have wbtc on ethereum what ethereum knows is that some humans say yes yes we have BTC stored and we'll give them to you but we have them stores trust us right they rely on signatures well with proofs you can have guarantee that these funds are there and you can have guarantee that would happen on this other network is valid so let's talk a little bit about the lingual of starknet right so you have a bunch of new actors that the fact that these validity proof allow you to do that to delegate

execution to specialized actors changes a little bit the topology of the network it changes what it means to be a node it changes what it means to be a validator right so in general in zq overlaps we have these actors the sequencer the sequencer is the entity that receive transaction and Aggregates them in a block it doesn't prove them it just Aggregates them in a block and calculate what is the latest state the prover then takes this block and processes them to generate a proof that these blocks are correct right and this proof is then sent to ethereum in a verifier smart contract that's the beautiful thing also about proofs it is a program right and you can write one in

a smart contract how crazy is that so there is a smart contract on ethereum that verifies Stark proof and is able to say yes all of these blocks were processed correctly now what is a full node in starknet a full node is not necessarily a node that will store all the transactions because it doesn't need to it just needs the proof that the latest state is valid so the full node will just store the state and give access to the data to sorry to the application using it then you have startnet core starknet core is another smart contract on ethereum that manages the state of starknet right don't hesitate if you

have more if you have questions on that so one thing I want to mention about starknet is that if you followed so far you understand that validity proofs are a fundamental new building block in the way we design blockchain networks they have deep implication of what it means to be a node what it means to run a validator what it means to verify and not trust right they fundamentally affect the topology of your network but also the way they're designed they're based on mathematics fundamentally impacts the programming Paradigm in which your smart contract is used so when faced with building a new

Solution on top of that we thought what should we do should we try to emulate what is happening on the blockchain right now or should we try to leverage all these new advantages that these new paradigm gives us and we chose the latter we chose to build this network from first principle we chose to optimize for speed for performances for security so stocknet first of all uses Stark proofs Stark proofs don't need any trusted setup they're Quantum resistant they scale very nicely and they gave you they they're faster to prove and they're better to prove big workloads so they allow layer twos to scale to amazing quantities

the second thing is starknet uses a ZK VM it does not emulate ethereum it has its own VM this comes with a general purpose language which is Cairo I'm going to talk about it in a second it is not a smart contract language it's a general purpose programming language that is provable and stagnet also comes with no backwards compatibility with ethereum so it allows it to leverage new innovations that come with ZK relapse such as the ability to choose where you store your data also known as what how do you deal with data availability it also Builds on the shoulder of giants

like ethereum and takes good Innovations like account attraction and use them at the network level and it also allows things like off-chain proving it actually allows for distributed blockchains to exist where work is done by certain entities and verified on main chain all right so summarizing what is darknet is a general purpose layer 2 on ethereum it allows heavy machines to process the network and smaller machine to have mathematical certainty that they were not cheated without having to incur a big cost stocknet is about scaling it is not about privacy and starknet was built from first principles it's optimized for

this new paradigm that are validity proofs because it's worth it all right so now let's talk about Cairo right because at the end of the day my presentation is about Cairo what why where do where am I going with that so what is Cairo the first thing you have to know without getting too much into the mathematics validity proofs are a mathematical concept right and validity proofs are based on designing specific polynomials that represent specific programming specific programs who here has already used cercom for example a few so if you use circum you know that you have to Define your program and then it will

Define a circuit and it will Define a verifier right um we went down that route in the beginning we tried to write programs using specific polynomials and then eventually we quickly realized that this doesn't scale it's too hard it's too long and it's a bit less safe also um so we decided instead of trying to craft a polynomial for each program to create a program that can run programs AKA a CPU this is the basis so this is the basic of what you have in your computer right a CPU is a chip that allows you to run to run any program

well Cairo is a virtual CPU that allows you to execute instructions that you can compile from a high level programming language and these instructions are in turn provable okay so Cairo is a virtual CPU it stands for CPU air Cairo we also use Cairo to designate the programming language meaning it's a high level programming language that boils down to these instructions that in turn are provable you can use Cairo just like you would use Python it does not need to exist in the context of a blockchain it's a general purpose programming language it allows you to write any program and prove it

which is extremely powerful now if you've heard about Cairo then you might think okay what kind of program can I do with Cairo well you can write starknet the network I told you about before it is all written in Cairo when we say that starknet the network is verified by ethereum it's because the whole execution of starknet the aggregation of transactions the fact that the transactions are valid that the blocks are valid what is the state the state diff at the end and what what is the output all of this gets proven to ethereum think about it how much work would it take for you to write a circumcircuit that manages a full blockchain with State and smart

contracts right so Cairo is extremely powerful it allows you to write blockchain software now if you've heard about Cairo you might have heard about Cairo 1 which has which was released recently who here has heard about Cairo one maybe just a tweet or something like that all right so Cairo one so spoiler in a few months you won't have to worry about Cairo or cairo1 because referring to Cairo will refer to Cairo one but Cairo One is the next version of Cairo it's a more resilient easier to use Smart contract language it has a rust-like syntax it comes with years of hindsight from running from running Cairo in production it has gas metering and error ending

this is fundamentally a new change a big change for stocknet because it will allow stock net to be more resilient to those attack it will allow it to decentralize it will allow it to be sensorship resistant but for most of you you don't have to necessarily think about it it's just a programming language and you can write your smart contact in it I want to leave you with one last thought about Cairo and Cairo One and it's the following who here has heard about L freeze and fractal scaling enticing right you have URL one you have URL two and then you have your L3 okay you and it kind of makes sense you think about it there's a blockchain on top of a blockchain on top

of a blockchain well here's the truth the space between L2 and L3 is much more continuous than it is discrete I'll give you an example I was last week with one person who did a POC for a yearn right and yearn they have a they have a smart contract to update their yield strategy currently what happens is the governance will sign a message to say yes this is the new strategy and it is good but ethereum the smart contract has no way to verify that this strategy is indeed better right so what he did is he wrote a Cairo program not a Cairo smart contract a Cairo program

that takes input from ethereum verifies that the new strategy is better and then enforces it on chain so that it updates and this right here is an example as to why l3s are a continuous thing it's not a L2 L3 there's a lot of things in between some people will choose to run some of the computation of their app off chain and verify it on chain some people we choose to just aggregate transactions and then settle in on chin settle them on chain some people will build weird constructions that are not blockchain but can still be used on chain you will have for the first time the ability to run code outside the chain and use trustlessly the output inside of

the chain that is a big big paradigm shift in how blockchains works and this is why it's worth it to have this construction to have something that is not just meant to be executed in in a blockchain context all right so summing up why Cairo Cairo allows you to create provable programs proof Pro verification allows you to it allows a retail computer to monitor a herd of super computers and keep them honest without having their computing power um and Cairo allows you to to execute any kind of logic on off chain in the same language that you would write your

smart contracts in and use the results on chain okay well this is the end of the Mario presentation can you raise your hand if you learn something nice who thought it was too easy who thought it was too difficult all right I think I'm spot on so if you have questions I don't know if you have a few more minutes but don't edit it in and ask them if you want to see what car one looks like check out this QR code it will take you for a small ride you don't have to write any code just read it and solve puzzles so that you understand how chiral one works if you want to learn more about starknet and receive educational material check out the second QR code it's our edu newsletter

we send it once every two weeks no just cool stuff for nerds all right thank you and uh then come down to me [Applause] [Music] [Applause] [Music] all right yeah we have a few more minutes for questions so if you have any questions now um our colleagues will show up with the microphone first here you're also able to scale the complexity of the kinds of programs that you execute and

and I I just wanted to ask if I'm getting the order of magnitude right so for example for distributed decentralized video hosting you need re-encoding that needs to be uh provable so you want to re-encode an uploaded video file and you want to prove that you run this exact algorithm to re-encode it in a different resolution and so on so is start not powerful enough to handle these kinds of volumes pointing to a really cool Direction which is zika roll up allow you to do more of the same and to have cheaper transactions or to have more complex transactions now is darknet able to handle encoding right

now probably not also you will have to rewrite all of this stuff in Cairo but there's nothing like eventually the prover will be open source not too far away from now so you'll be able to encode your video on your computer and then verify the proof on the network it doesn't have to be executed on starknet just verified that makes sense cool right we have time for one more question and I assume Henry will be around afterwards for you if you have more questions just hit him up uh thanks for the talk I've been using the previous version of cardiro for a while and I haven't been checked recently but I remember a Cairo approver so the chiroprover were a proprietary

backend service yeah and it wasn't open source like what about Cairo one will the Cairo One Brewer be an open source something that so we can generate the proofs on our machines locally that's a great question so first of all Cairo zero and Cairo One compiled down to the same CPU in the same set of instructions so the prover will be the same for both the approver is currently still closed Source but we announced a few weeks back that we will open source it we committed to it so it will be open sourced and you will be able to run your own instance of it or run a proving a service if you like okay that's great news thanks all right we have actually one time for one more

question or what you think one more question the last one um so I was wondering like when you have something like starknet what do you see as the source of Truth for the transactions is it the L2 or the L1 or then even if you have maybe an L3 on top like where is the real source of Truth at the end of the source of Truth is ethereum definitely we delegate the security to ethereum that's the cool stuff about zikiro Labs right they can leave on top of another Network and be

secured by it so there are different layers of finality to your transactions first it is accepted on L2 right so there's consensus on L2 then eventually a proof is generated and sent on L1 this at this point is when your transaction is the most solid so the source of Truth is on L1 interestingly enough this is also why it's hard to connect the zqr lab to various chains but it's probably not unsolvable and sometime in the future we could have cool applications with that and do you think that also works if the data availability is not on ethereum I think this is an open question and I think that I don't have an answer but I'm really looking forward to what each application is going to decide their

security model should be