StarkNet:Cairo1.0
StarkNet:Cairo 1.0 · 21 Sept 2022 · 35:58
Lucas Levy introduces the planned Cairo 1.0 language and compiler redesign. He explains developer-tooling improvements and Sierra, an intermediate representation designed to make failed transactions provable and account for gas.
Speakers
Topics
From StarkNet:Cairo 1.0.
Transcript
and welcome to today's english seminar of dive learning and stock wire today this event is called organized by the stock knight chinese community and dev learning community we will have two sharing sessions yeah today is about uh the topic is about the career 1.1 1.0 and we invite lucas as our presenter to tell us some knowledge or technologies you need to know about this cardio 1.0 and tomorrow we will have another seminar and knowledge sharing not a share is the topic is that it's a recursion proof at the presenter hungry yeah if the stock
wire developer i'm best about uh a cannot show up today's and uh so before we start uh let me give you a brief introduction about the stock wire stock knights and the deb learning the community so let me i mean we start from the stock night so stock nineties and open programmable it's their ethernet and layer 2 scatting solution developed by the stock wire that used stark validity proof to enable all chain coupled computation and on-chain verification and stock velocity proof is secure
reliable and efficient ensuring that stock night is an infrastructure built for future mass adoptions now let's move to our own community yeah that's an adapt learning yeah the dev learning i mean um we have a lot of members from the chinese communities and we are designed for developers to step into blockchain dev development uh covering uh defy ft dao crypto projects and we hope we could not only give junior developers a feasible and easy to use blockchain dev learning roadmap but also presents advanced developers with a platform for
communication and cooperation by the way our type learning is a non-profits organization and you may notice that uh bitcoin has a new wave yeah bitcoin 15. if you have to if you like to support our community please donate us on the bitcoin okay i think i have finished this introduction parts um and i'm alex yeah you can just call me alex from the dev learning community and uh yeah uh lucas can you hear me yes um so thank you for uh inviting me and organizing this event
i'm lucas i'm a star star queer developer advocates i work with seabook and henry and today i'm gonna speak about cairo one so first let me share my presentation here yeah uh one more thing yeah sorry to interrupt uh so during this presentation uh feel free to uh ask any questions in the comment area uh or you can uh send your questions in the wechat group or our discord channel okay yeah back to you lucas okay thanks
so uh let's speak about cairo one and the next evolution of cairo so cairo today uh is a programming language kind of hard to use but it has been used in production for about two years now it started with the star kicks which is our layer two application specific roll up and a year after with start net which is the layer two that you all know and it has processed around 200 million transactions and 600 billion dollars of cumulative trading there are around for 15 000 cargo files on github and it's way easier to write than polynomials
so this code is cairo 001 which is the first minor release of cairo it had already some abstraction but it was way harder to write than now because now cairo looks like that we have open zeppelin libraries which are really convenient we had some syntax updates so it looks more like rust or solidity so it's really easier to onboard and cairo for the record cairo is an assembly language efficient for stark it has been created by starkware for starkex because at the time they had they had to write the polynomials manually which was
really cumbersome and to update anything it was really hard and it's really hard to edit um polynomials so they wanted to create something that would enable to generate stark securely and easily so they came up with cairo which was not meant for external use so it misses a lot of tools and it's not really extensible for the tools that are missing we lack a package manager for now there is pip but it's not that convenient we don't have that much standard libraries we have the uint library but it's not really
easy to use and we miss some basic syntax things like loops or error management so that's the state of cairo now it's a bit like hell but it will change with cairo one uh you'll see it will like really improve the the life of developers and that's the goal of cairo one it's to make developer happy so if you want to learn and build on stark nets you'll love the the new update of cairo which will be the first major release to create that we have a dedicated team that fully works on the compiler and the
compiler is rewritten in rust which will enable to have a better base because right now the code is really messy i don't know if someone has tried to read the compiler but it's really hard to understand what's happening uh with the rewrite it will be like way easier and the good thing is that all the code that you right now will be easily portable to cairo one so you don't have to wait for cairo one to start learning cairo and in a sense you'll you'll be like you'll have an advantage to learn now as it's lower level you'll understand how things work and it's always good to know how everything works
so the goal of cairo is to improve the syntax and to add some features so first right now if you want to create a variable you have to know if you want to create a let a ten bar or a local this is hard to know and this will disappear in cairo one the compiler will take care of everything which means that you will only declare a let for example let x equals one and the compiler will know if it's a templar or a local or just a let this will enable to deal with revoked preferences more easily um
the compiler will handle almost everything i think so i think that's that's a good improvement we'll have more data types for example we'll have ins as a standard library which means that you'll simply have to type your variable as an hint and it will act like an end so for now if you want to have a lint you'll have to use the untwi 256 library which is not really convenient um you can't use like the regular operators for the division multiplication and everything with the native in type you will be able to perform this so for example if you
divide nine by three if it's type as a felt it will act like a felt so it will be a modular division which will output a weird result if you type it as an int it will just output three which is way better than the current behavior uh we'll also be able to manage errors so for now there's no error management basically if you want to check that someone has i don't know if you want to check that your user has exactly one token you assert that his balance is one if it's not one then it fails now you'll have something like rust or golden
which means that the function will return a value and an error and you can check if the error is null of the or if the error is populated and then you can either choose to propagate the error or to just handle it so it creates a try catch and we'll have native safety uh for uh mathematical operations which is always good um as i said the compiler will be better the base of it will be like way cleaner uh it will be written in rust so it will be really efficient that means that now when you want to compile a big file that
imports some libraries it won't take uh an hour like now python is good but it's really slow um that's why we're turning to rust and we will be able to add more features um more frequently because the base will be easier so uh you could also contribute to the compiler uh we'll add a packet package manager uh either it would be cargo the rus package manager or a specific one that we'll create we don't know yet and we'll also add language server which is like
a small a small extension on vs code that will help you detect errors when you write carol i will show you at the end how it works and the ripple will be public so you'll be able to contribute and follow what what's happening carol one will also introduce sierra which i will talk more about later so right now in the state of starknet is that transactions are executed in native cairo it means that we don't sandbox anything so it's more efficient and it's kind of safe because our cairo
memory is immutable so you can a transaction can't miss with the os memory but the good analogy would be if ethereum executed the transactions on plane x86 it would be a disaster so for now we do that to have more efficient to be more efficient but we can't prove a transaction that fails and that's a big problem because uh if we can't prove in the transaction we can't include it in a block so we can't charge for fees so if someone wants to spam us with the transaction that fails
we can't do anything right now we try to mitigate it with the validate entry point in an account contract which will basically allow us to take fees for a transaction that fails but it's not perfect so we want something um to be fully provable whatever happens in it so for example now when you will want to assert that someone has exactly one token you will be it will be transformed to an if and uh the if if it's false it will return an error and then you will choose how you install it either you propagate it in the transaction and you revert it but
it won't be a revert like a real reverse it will be provable so we will be able to take fees and it will allow gas counting easier for us and the solution is called sierra which which stands for a safe intermediate representation and yes the result is always probable by construction so the new flow would be that you will write your code in high level cairo swinkar1 and then it will be compiled to sierra which is the safe intermediate representation and then it will be compiled to cairo by
bytecode um this the compilation from sierra to cairo bytecode had nearly zero overheads so it's really convenient because it solves many problems for us and it doesn't uh mess with the code or introducing like really unoptimized contracts so zero is really a great thing for the development process the first steps has been taken we have a poc that works um it can compile some code but not really complex one uh i will show you right after uh small example of the compiler
it's expected to be released in three months a bit before regenesis and the cairo one repo will be public soon i guess so you'll be able to track what happens there to submit prs and to try it before it's released um so let me show you how it works so this is a small snippet of cairo one it's basically a fibonacci function that will compute the fibonacci sequence so you just enter the number you want to go to compute the first two elements
and then it will match on the number of elements so uh match works like in all the other languages like rust imagine n either it's zero and then you return a either it's uh everything else than zero and it returns a fibonacci uh a recursive function uh and so this compiles um i can show it will appear red but don't worry it's expected so this is uh this i'm gonna zoom in i think this is the sierra representation of this
snippet of code you don't have to know how to code in sierra don't worry it's just so that you know how it works and here is uh chasm which is cairo assembly which uh is the low level cairo that they used to write at the further at the first version of cairo and this code will be compiled to carrier bytecode so you see that everything works and that's uh the matching like the match keyword will enable a lot of things so for example for error management it will be really convenient because you can have something that
returns an error and then you can match on your error if it's now then great there will be no error if there is an error you can do uh something you can either propagate the error and revert the transaction or you can just do whatever you want which will be somehow like a try catch i hope that was clear and if you have any question please ask them i know that there were some questions that were already asked i'll get them and answer them in a second
yeah yeah yeah okay yeah thanks for sharing lucas uh yeah i can see uh carville is more efficient and safer here in these uh released versions and here we prepared some questions for you about the career point 1.0 and some relative uh specs so the first one is that um i mean for you uh a developer and advocates um there any i mean favorite parts in carrier 1.0 you united yes so the error handling is for me like a huge thing because right now we
don't have a choice if we want to handle errors we'd have to have a multiple if else which is not convenient at all and now with the error handling and pattern matching it will be really easy to deal with errors and also the native hint type is huge well basically all the native types that we'll introduce it's super helpful and also the for loops because i know that everyone dislikes recursion so the full loop will be like a huge improvement for everyone and it will it will be so much simpler okay okay see uh
one more thing from my side in just now you mentioned the arrow handling um edit um this arrow handling similar with the rust rust here yes it's really similar uh it in the syntax and in the the way it works it will be really similar okay okay i see because i mean previously i i don't have too much i mean idea about how to handle arrow in the blockchain like solidity or some other language yeah no it will be like really the carol one is supposed to look a lot like rust
so it will be similar in a lot of points yeah okay got it okay thanks for your answers uh let me check the next okay i know uh car will um i mean it's written in rust so how is the cargo 1.1 1.0 compared with the rust in terms of the use um as for the syntax it will be really similar but for everything else like the way it works underneath it's really different well uh basically what will change is only the
syntax the byte code stays the same so it doesn't change how caro works it will just be a matter of compiler and syntax and for the performance we'll integrate the rust vm uh cleopatra i think um which is developed by a lambda class so cairo will be more much more efficient with the new vm also okay okay yeah uh i think the third question is raised by some members who are interested
in the transpiler yeah it's ripe so is the wrap going to become more efficient to transpire from solidity to cario from my side i'm i'm not quite familiar with the ripe or how write works yeah um yeah so basically warp uh it compiles the solidity to yule which is an intermediate representation of solidity and then from the yule code it reconstructs a cairo contract i don't really know how it will handle cairo 1
i guess it will maybe just compile solidity to chasm uh but i don't really maybe to sierra but they will have to rework on warp so i don't really know how neither mine wants to handle this okay so the nethermind is responsible for this part yes okay okay yeah okay and a member mastering at tyson asks is there any suggestions for him or her to learn cario i mean with the basic knowledge about python i know it's totally
different or maybe we can change this question to another one if the only suggestion uh you want to give us i mean to the new career developers or learners maybe eras or yeah i subject yeah yeah basically if you're coming from python you can use like there are a lot of python tools for now so you you can use them uh as for the cairo syntax you won't have any choice than to learn a new one which is different from python um and for newcomers uh you can do all the tutorials uh that we have under the starting edu repo you
can also check the only dust uh starklings which is an equivalent an equivalent of the rust length which holds you by the hand to teach you how cairo worked in every concepts but if you if you do that you'll have no trouble understanding cairo you can also come on discord and ask questions people will answer you or i will answer you so yeah okay okay uh so now i'm a rust baby developer and i think it's it could be easy to i mean
to use carrier right for the rust developers yes with cairo one basically it will be really similar to rust so you'll have no trouble uh getting into cairo okay okay gotcha yeah i'll fight after today's meeting yeah and uh another question is about the layer 2 native apps i mean in your size and what do you think how car will help the layer 2 native depths in stock stock.net
you can narrow down [Music] any aspect like security or efficiency yeah um so yeah as i said with the rust vm it will be much more efficient and on start net computation is really cheap so we will see a lot of games i guess of course we'll see d5 we already have d5 but we'll see much more games or ai or computational heavy dabs than on other chains for example we we have an app which is on mainnet which is an ai for trading that basically is an ai on l2 that sends messages on l1 uh
to trade uh i think that's super cool and that will see a lot of these things in the near future okay okay see um yeah next and i think it's a question about comparisons and uh yeah any difference between the carrier and uh i leo did you know i mean the l2 privacy blockchain isn't it an ll1 ah i mean kario and alio i mean alio blockchain
um our blockchain basically relies on stark uh ilo or whatever i can't say the name it whatever is uh relying on snarks uh which is a pretty big difference for example uh snarks need to have a circuit so you need to generate your circuits uh when you start your blockchain and you need to generate a random number once you have generated your uh circuit you can't modify it or it's really complicated um so you have to think of every possible thing you need to have a suitable circuit and
for the random number generation if anyone knows this number uh he can create every every snark he wants with starx we don't have this problem because we don't have a circuit and we don't have a trusted setup so i would say it's safer and it's really easier to use okay good and uh how about the polygon maiden it's the layer 2 solution from polygon um you mean her hair that conversation is not
correct no i just oh polygon maiden yeah uh i i don't know i didn't really look into it uh it's okay yeah okay okay yeah okay and uh the last one yeah now you have answered six questions but yeah last one and uh yeah it's um i mean uh forward to the future and then your man's uh what will it look like uh in the stark knights because system in two or three years i mean uh cardio like we will have cardio
points 2.0 or 3.0 and many versions um that's a really good question i don't know how long will cairo one last but i don't think that we'll see a major release uh that often so i guess we'll still be to cairo one but we'll have way more tooling way more libraries um everything will be way faster and easier to to do okay okay see yeah definitely i think he's uh um a right direction for any language and the ecosystem and yeah another small
questions like sub questions so what kind of depths uh in the snack next you expect like defy or nft or gamify or some new stuff um i guess we'll see a lot of games uh because of the computation and a lot of ai uh which will be really cool to see and probably something that we can't imagine uh obviously yeah there will be a lot of defy we already have a lot of a bams a lot of nft projects yeah so of course we'll have them but we'll also have some use
cases that weren't possible on blockchains before that will emerge from starkness okay okay yeah totally agree especially for the game final i mean currently uh game 5 cannot do too much computations in the layer one or other blockchains and uh yeah as you said maybe in the future when we have like three a style gamepl uh let me check the comment area or discord wechat please wait for a while okay
uh it seems like we don't have any questions or problems raised by our members or yeah someone okay uh i think it's done yeah thanks for um telling knowledge about the kario 1.0 to the chinese communities and uh yeah also thanks to the snark night cooperating with these um events and our last um it's a dive learning uh thanks for them to uh giving us a chance to uh i mean talk with the carrier 1.1 and meet
the advocate uh face-to-face okay uh i think uh yeah actually i think we have some questions for the community as well like what's a good language for you guys to pick up obviously cairo is the very new language so uh what ideally is a good language for you to pick up and what kind of tutorials examples you guys need um i didn't hear you quite well can you speak a bit louder please maybe can you guys help me yeah yeah yeah very clear yeah just um actually i want to ask
community what can we do to help the community to learn the language like maybe more real uh examples real application examples so like how how to help the community you learn the cairo is the question you hear me lucas yeah um yeah so what can you do to help the community learn cairo well uh explain how everything works
um display tutorials uh yeah even getting feedback from the community is really valuable because yeah so yeah i would like to get some feedback from the community from that learning point of view anything we can do to help community to learn viral maybe i can repeat the question yeah actually this is the question for the depth learning community now for luca ah okay okay i think
i mean the depth learning i mean we are knowledge sharing communities and i think the easiest way is to translate or provide some some help when our members learn the clario tutorial or the stock nets and if we find any questions or issues in their tutorial or their codes and we can give them feedback and try to contribute i think that's uh easy way for me and uh yeah and for the advanced one uh
i'm not sure about um like like look outside they have their own ripple yeah with a lot of tutorials or codes you can review them or try to make some contributions that could be like uh i mean in depth and jumping to the stark stock night and carrier yeah any question from the all of the participants okay okay i think
[Music] it's done and yeah thanks for everyone attending and showing up this event and uh yeah please remember uh tomorrow we will have another session our uh knowledge here share events from lucas sorry from hungary another developer ambassador yeah the topic is the recursion proof and the time is the same it's uh 1 pm utc and if you like it or yeah learn more about this topic please
set up your schedule and attend our meeting tomorrow okay guys and uh yeah i will hop off and uh thanks for attending and enjoy the rest of your day and uh yeah we will see you in the metaverse thanks lucas thanks alex everyone bye thanks bye bye guys