ZK HACK - Introduction to StarkNet Smart Contracts - Starkware
10 Nov 2021 · 1:45:38
Starkware's Henri Lieutaud, Ariel Elperin, and Yonatan Iluz lead a ZK HACK workshop introducing StarkNet smart contract development, part of a seven-week zero-knowledge tools series from the Zero Knowledge Podcast and ZKValidator paired with a puzzle competition. The session walks through building and deploying StarkNet contracts, covering zero-knowledge proofs, smart contract tooling, and Layer 2 scaling.
Speakers
Topics
Transcript
be able to see my screen very good all right and to the audience maybe we'll just do a quick thing are you is audio and video coming in good for all of you maybe just let us know in the sessions chat cool okay i'm gonna jump off we're here let us know if you want us to jump back on for anything and take it away wonderful thank you so i'm gonna take my smooth night operative voice and present this starknet voting workshop that we'll have tonight i'm henry lluteau i'm a developer advocate for starknet and i'm joined with my wonderful colleagues arielle who's a product manager for stocknet and jonathan who's working on engineering on starknet
so today we're gonna explain to you a bit what is starknet what is cairo and a few things about writing smart contracts in stargnet that you can use and build your applications on so the first question is obviously what is stark net so stark net is a layer two of ethereum it's a general computation platform which is secured by ethereum layer 1. it allows you to write smart confir smart contracts that are general purpose you can write any kind of logic in these stock net smart contract and they allow you to manipulate ethereum
assets these can be erc20 erc721 or really any kind of assets that you want to have on mainnet it allows you to interact very smoothly with l1 actually you can have logic implemented on l2 that has fx on l1 um in a very short amount of time meaning in a very short amount of execution time and the cool thing about starknet is that contrary to ethereum where the execution of your transaction happens on every node of the network startnet pushes execution of your smart contract to the edge of the network
meaning then that only one node of the network which is called the prover actually execute the payload of your transaction and generates what we call a proof of correctness in turn every node of the network actually verifies the proof of correctness and updates is state so this means intuitively if the computational work is done by only one computer instead of all the computers of the network it lowers the cost of execution because you're not bounded by the smallest machine you want on your network and you still give extremely strong warranties
that your execution was done um correctly you're not trusting the prover to do the work correctly you're trusting mathematics that the the job was on correctly so lowering the cost of execution of your smart contract has two really nice side effects the first one is that you can scale the number of transactions you can do in a given block on l1 so you've you might have heard of the crazy numbers that the ydx is doing with starkx which is a bit different than stock net but i won't get into that right now
but basically um some applications like solar or uidx or imitablex are able to pack a very large number of transaction in a single execution proof and lower the cost of a single execution that's something we see today and everybody needs it right but there's the other side of that which is also very interesting which is that you can do more transaction or you can do more complex one and that's really hard to define i can't really tell you oh you could do this you could do that because it's still very much uncharted territory and it's something that i'm really
curious to see uh you guys explore so um definitely go look for that uh on the revolving arcs around starkness so you may you might have heard about starknet but you also might have heard about cairo so what is cairo exactly so cairo is a language that was designed by starkware it's a programming language that allows you to write provable programs so compared to a classical programming language that compiles to cpu instruction cairo compiles two arithmetic
instructions which have specific properties we and these properties allow a very neat trick which is if i show you a program i show you its inputs and its outputs and a proof of validity you are able to verify the proof and be certain that the output is valid without actually executing the program itself it's and this is a paradigm that you might be use used to uh in the blockchain world um the the the parallel i like to use is with proof of work if i show you a specific blog hash you're
confident that some work has been done without having to actually do the work yourself well in a way what we do is conceptually the same i show you a proof and you're sure the work was done correctly but you don't have to do it yourself now the really cool thing with uh with cairo is that ethereum has opcodes that allow the evm to verify such proof this means that you can execute a cairo program of chain send the proof on chain and have a smart contract actually verify this validity proof so now it's not just you a user that i try to convince that a program was executed correctly i can prove it to
an ethereum smart contract okay i can automate the out of my uh out of my app i can do a lot of things very cool with l1 right so so basically that's it you write a cairo program in outside of l1 and you can prove to l1 that something happened how does that link exactly to startnet right because startnet is a computation network what is the link with skyro well that's a really cool thing starknet is a cairo program startnet is an operating system which has a vm which is called the cairo vm and these vm has storage
and it allows the execution of cairo smart contracts inside this vm right and so this whole vm is written in cairo and you can prove that this vm was executed correctly and that it executed all the sub payloads correctly so you can prove to ethereum layer 1 that your layer to network executed all its smart contract correctly and that's that's really the all there is to it right so so there's cairo which you can write general purpose uh programs with and we have implemented one specific program which is startnet
which allows you to execute sub cairo programs which can be arbitrarily complex inside this vm and have it interact with layer one right so that's a general high level overview of what we're building um and yeah i don't know if i have it on my slide but where is this exactly like how can you use it and when will it hit mainnet well it's been in test nets in july and the alpha will hit mainnet at the end of this month so you can start using it on mainnet at the end of this month all right so that's for the conceptual introduction now about what we're going
to be working on today so today is a hands-on workshop we want to teach you how to use a smart startnet smart contract because everything i've presented is nice and your produced meals you may still still be thinking well but still cairo is not solidity and you're right we do have a transpiler in the work that will allow you to port your solidity contract to start net but that's not what we're covering today today we're covering writing an actual start net smart contract which will give you um more efficiency when running your smart contract and you'll see that it's not that different from solidity uh concepts and uh and the layout and the synthetics of using your contract so you're gonna
learn about the general syntax of stock net smart contracts um you're gonna learn how to import modules which we called built-ins you could you're going to learn how to like declare use variables create functions have them interact and we're going to talk also about composability so how you can write a contract and have it interact with another contract in startnet um while we will be doing all of this and this is nice we won't have time to cover everything we would like you to learn so we won't cover for example l1 to l2 communication meaning how do you send a message and
how do you manage assets on l1 from l2 and vice versa we're not going to cover how to build a front end for your start net app and we're not going to cover we're not going to get into detail about the stock net architecture like for example the network architecture what kind of nodes there is how how do you send the info to the approver and all of this stuff but be sure to if you if this topic interests you this certainly interests me be sure to join our community you can read more about what we're building on our documentation and mostly you can join the party on discord we have a lot of
content there and community calls and things like that so be sure to join and um and you'll learn more about um what it is where uh we're building okay so for the actual topic of the contract you're writing today you're going to be working on a voting system so some of you might be familiar with the first tutorial that is offered by remix when you start working on solidity it's somehow similar you're going to learn how to create a contract that will allow users to create polls to register user for them to vote on polls and then you'll have functions that allow users
to vote on polls all nice and dandy you'll learn how to do functions variables get comfortable with starnet contracts and things like that all right and with that my mission is done i'm gonna stop sharing my screen and i'm gonna ask if ariel can join and take it from there wait just before you do that i just want to point out that in the q a there's actually two questions that were asked maybe we could actually say them out loud for the video viewers later maybe you could just help answer those so the first one i'll ask if that's okay could you briefly explain what would change for the end user can the end user still use metamask so i think um so
the the the first answer to this is that this is very much to be defined right i mean the actual user experience of ethereum was not defined by the people who developed ethereum it was developed it was defined by people who built on top of ethereum so if you want to have a say in that start building on start net that being said it will probably like look like our l2s where you move assets from one network to the other and then you'll have different tools be them what it extension browser extension that will allow you to interact with the network and depending on technical choices you might be able to use metamask or maybe other wallets um
in the first versions i'm not sure it's going to be metamask but we're currently working on an implementation for account abstraction with arjun and open zapin does that answer the question i mean a person can answer this and say it can maybe ask more in the chat if there's anything else the second one is about is anyone building tools to generate zk snark validators in cairo so maybe you want to yeah you're not really doing snarks you're doing starks exactly i see ariel twitching so um yeah we're using a bit of a different primitive we're not using
snarks we're using something that's called stark i'm not gonna get into what is different uh between the two that's an interesting question and you should come ask it but i don't think that's the topic for tonight um and i don't think we can transpire the thing from circum socrates i'm not sure about this specific question um so yeah i don't have much to say about that ariel do you do you have insight on this well i can say that there is some interest in developing uh snark validators in kyle actually as a stock net contract so i think
there's some people who are actively working on it but outside of stockholm so this is still open if you want to be the first one to have uh zika snack verifier uh written as a start with contract then go ahead we'll be happy to uh publicize it of course it goes for uh zk stocks validators in uh kyle which is also something that interests us very cool henry if there's any more questions i see one more in the chat maybe you just want to answer in chat um so that ariel can continue with this presentation sure so ariel will present the workshop and i'll be here answering questions okay cool okay thank you take it away ariel hey so let me just share my screen
okay so i'm guessing you see the presentation okay so first of all before i'll get into uh what we're going to do today i'm real i'm product manager in stockwell and right now we should be sharing a few links in the chat so the first link is to this notion document that you see right here and so as we go through the exercise and different parts of the contract you will have the code in a copy pestable format and for those of you who can't really wait for the answers you have the complete code in the end of the document uh other than that the place you're actually gonna write your code
is the stark net playground which is also you should be seeing the link in chat right now and so you'll have the example contact here so feel free to just remove it write your contact and attempt to compile it um okay so i think that we're all set and let's start talking about uh the actual contact that we're writing so i'm gonna basically walk you through writing a voting contract in starknet okay so let's start with the very basics of a stagnate contact
so every stagnate contact starts with a specification of a contact which is uh as opposed to a native kyle program so kyle programs don't have this line uh the second line that you see right here is a declaration of what buildings we're going to use so henry talked about it briefly i'll just say that you can think of built-ins as pre-compiles these are certain functions who are not implemented in native cairo for optimization purposes so for example you see right here that we're using the peterson built-in which is the harsh uh you use throughout stocknet so you later see how exactly
we're going to use it for now we're just declaring that it will be used somewhere you can see a more built inside here we'll talk about the cdsa built in later after that you have the the modules that were going to use so here we're just importing uh different structs and library functions okay for example the hashtwo function which we're also going to use a bit a bit later the verify ecdsi signature and the few others okay so let's continue with the basics so storage variables just like you would have them in solidity you can define
variables which are part of the contact storage although with a slightly different syntax than perhaps what you use to form solidity okay so here you can see the definition of two storage variables and you can see that the storage variables by the storage valve decorator okay and this is the name of the variable so you can see that the syntax for declaring a storage variable in stock net is actually defining a function so you can see that this function takes one parameter and returns one value so the way to interpret is uh to interpret it is that this is in fact a mapping from a key to a value so it takes the key and it returns the value corresponding to that key and for
example the second storage variable that we see here takes two arguments so you can think of it as a nested mapping mapping of mappings so you need to specify two keys to get the value so simple as that okay something else that you might be seeing here is the type of all keys and values which is felt this is uh the basic type in child it's short for a field element and you can think of it as analogous to you in 256 in solidity and for our purposes it's just a number from zero to a very large point okay so let me just say what those storage variables represent in our
context so public owner public key poll owner public key is actually a mapping between a poll a voting poll id and the public key of the poll owner this owner will will be the only one permissioned to allow voters into this specif a specific poll so you can't vote on a poll unless you have the owner's permission and then you have the mapping of the registered voters so it's a mapping between a poll id and a public key of now some voter and the mapping to a flag which indicates whether or not this particular voter is indeed permissioned to this port okay great so
we're already getting into our first exercise so here we're just asking you to add two more storage variables so the first is a voting state which uh take which is a mapping form a poll id and answer which is the possible answer to the poll in our case simply yes or no represented as a felt and the value is the number of uh number of votes for this particular answer and another variable voter state which indicates whether or not a voter has voted on a given poll so we were going to want to be able to track uh to track the voter state so he won't
be able to vote twice so here again the parameters is our poll id the key consists of poll id and the voters public key okay so please take five minutes and of course let us know if there are any questions and feel free to ask in chat the good luck we'll have a few more of those as we move along a question in the q a what is the
difference between buildings and modules fun control so the modules and functions you saw after the buildings are actually implemented in cairo they are actually written as kyle instructions whereas built-ins are not so the analogy is a pre-compiled code so the these are not cloud instructions that are getting uh for the entire compilation process so ariel i took the liberty of copy pasting some questions that were in the chat um maybe what we can do is uh while people work we can answer a few of these questions
and then um then we'll correct the uh the exercises um so if you want to focus on your work please feel free to mute me so um the second question actually i'd be glad if you can answer it how is it easy to embed cairo into other blockchains what is the critical requirement i'm guessing you need your blockchain to be able to verify starks i'm not sure if something else was done on that i'll just add that okay the critical requirements is being able to verify a verifier in that
in that specific blockchain language the execution of chiral programs so yeah just like we were able to write this verification in solidity i hope i understood your intention quietly okay the next question we saw interesting is what is the status of the solidity to cairo transpiler so the team at never mind is working on it i posted a link to a twitter announcement that was a few days ago basically they have small smart contracts transpiring and they are able to have different smart contract talking with one another how complete will will that be well united mentioned that you're not going to get the best performance out of the
cairo vm using transpiled code but you're still going to be able to do a lot of things and somebody asked also who's going to run starknet nodes and my answer was everyone we're building a decentralized permissionless network so uh that's the end game for us there's not really an interest but to build something else that being said the infrastructure today is fairly centralized um because it's in the process of being built so that's what we're doing so look out for decentralization steps along the deployments and that will have a starkness the following question is what is the
webfree equivalence to interact with cairo smart contracts from a web app or an automation bot we have a few tools that are being built by the community that allow you to connect your program to uh start net contracts um ariel what are the most relevant to you do you think i mean there are some projects for interacting with the probably the permanent and closest one is argent's wallet who's also here we also have our block explorer which allows you to interact with stock methods and transactions there's the cairo land which will uh refer to it in
the end when we give you links to additional resources so there's no uh like a complete web3 analog which is already mature library that allows you to completely interact with it but it's coming along and also uh working on an api for node some web free analog so yeah stay tuned and i think we've passed the five minute mark so maybe we can keep the relevant questions for what next while you correct the exercise yes okay so uh let's go for the solution of the first exercise uh i'll refer to the data
availability question in our next intermission yeah i like this one okay uh so okay you see here that now uh the number of storage variables go a little bit so we have our voting state which is a mapping from paul id and then a possible answer to the number of votes for that answer and we also have the voter state mapping which takes a whole id and the public key of a specific voter and returns a flag that indicates whether or not this particular user has already voted so about that let me present more okay good okay so now we have the storage that's
ready to support our voting logic but now we need to actually implement that logic okay so this is the initial the polish initialization function so you can already see the external decorator right here this means that you can interact with this with this contact by accessing this function okay so this function in it poll it takes under the curly brackets you see three arguments so this syntax is actually called implicit arguments and it takes two regular arguments which are the poll id and the public key of the poll owner so to initialize the poll you need to say to specify the poll id and your
public key to say a word about those implicit arguments we're actually using those under the hood to access storage variables so if you wonder what are they doing here while you don't see an explicit mention of this so that's why they're there okay obviously more information on how exactly implicit arguments work uh work can be found in our child documentation okay so what is the logic of polish initialization so we need to verify that this poll is not already initialized so for this we have our poll on a public key mapping so we're just going to read read from this mapping under the key
which is paul id okay you see the sled syntax which simply defines the reference whose name is is paul id taken and whose value is the return value of the read call right here okay so now at this point i should mention that the default values of all mappings in stock net is zero so unless you've initialized uh the pole with a non-zero public key then this value is going to be zero so here we're asserting that is for id taken equals zero meaning that no user has substituted his public key under this poll id and if we were able to pass this
assertion then we are able to get to the next line which simply writes to this mapping our public key which we've received as a parameter to this to this poll id so note that this variable so leading take is a function that takes one argument the key that you want to inform and the writing takes two arguments which is the key one to read form and the value if this was a nested mapping then the number of arguments for white would be larger okay so now simply returning after we've successfully initialized the poll okay this leads us to the second exercise which you have slightly longer
time for um okay so now we want you to write the declaration of a function which is called register voter okay who takes this parameters paul id the voter public key and two additional values which were calling rns these are going to be the signature of the poll owner of uh this particular poll which signifies that this user in this the poll owner indeed allows this particular voter inside this call okay and uh start uh implementing this function body so i'm not well you shouldn't actually do the signature
verification at this point but you should simply read the current paul owner you we've all we already saw how to read the form storage variable later we're going to do some verification on it um and then update the registered voter storage viable so recall that we had a registered voters variable which indicates which voters are allowed under which polls so it makes sense that the register voter function will eventually update the register voters digital voters storage variable okay so good luck and we'll talk about it in 15 minutes hello again for the
break advertisement how can we call these uh questions okay so you have 15 minutes i put the timer and we can uh answer questions in the meanwhile so there are some questions there's an easy one i mean an easy one there's one i can answer and then there's one i live up to you so the first question is how does data availability work in stark net do we need to keep all that on l1 or is it supported on starknet l2 so the data availability problem is very much an area of research in the l2 space in general the way it works in stark net is that
the way people usually think it works is that you need to push all transactions to layer one for them to be exploitable later on we don't need to do that so for example that's the way optimistic roll-ups work right you push the transaction as call data and if needed you open them this doesn't work like this in stark net because once you have the proof of execution you don't need the transaction to re-execute the payload because you know the execution was done correctly what you need to have on l1 is the state so the way start net works today is that every time we push a new proof of execution we put state diff so that you can recompute the state from the past state and
be sure that um that the transition that led to that this new state is correct this is the first construction of starknet and it's what is called a zq roll-up meaning that you have all the data to reconstruct everything but we're exploring how we can make this more efficient or tailor-made to the user's need by exploring other um constructions so one is the lydium where you basically just post the proof of execution but you don't push the state div to my net so this is obviously cheaper but it has decentralization issue and we're mostly exploring the space between both like how can you publish some data not everything it's very much an area of research and if you
have meaningful contributions you want to do on that topic please join the discussion with us on discord where i mean your ideas are valuable so come and talk with us and uh related to that there was another question in the chat which was basically how our transaction ordered in stark nets so the actual question i think is how does mv extraction work in startnet and for that i would say that this is very much an open question uh we're still designing out designing that there are a few things where we're thinking of and if you have ideas on how we could tackle that please join the discussion and there's this question i want to give to you ariel do starks and snarks do the same thing just differently
so i wouldn't say they do the same thing the eventually if you call the same things they're proving arguments about the program execution then the answer might be yes but one major difference i can think of other than the properties of the construction the cryptographic assumptions and the technical details like this a difference in the statements that were proving uh is that snacks are usually built around the arguments of a specific size so for example circuits of specific size while uh stock the star construction and that while using is actually allows
you to prove the execution of arbitrary programs so my program can take 10 000 steps or a million steps and i can still use the same protocol for proving it obviously the proof will require more resources i'm eventually limited by by my hardware but i'm not limited at the protocol level it's not that if i'm moving to a greater number of steps then i need to change my setup somehow i i don't need to resend any parameters there's actually nothing different going on i just send the program and start executing the portal and regarding the i just want to add emphasize the point
that henry mentioned that availability area that uh it's an important distinction that for for example for optimistic all ups the transactions have to be sent somewhere because otherwise you can't submit a ford proof you must see the transactions themselves while in zika roll up you are you have a guarantee that the execution happened correctly and you just need to keep track of the current state in order to be able to produce new blocks so what we do currently in starnet is publish the state diffs not the transaction it's called data not storage on l1 and we're exploring different possibilities perhaps
different l2s that will hold that will hold the the current state uh so this area is still still under under research but yeah we'll definitely explore the wide spectrum of data availability solutions and our intention is that in the final design you will be able to choose the data availability uh trade-off that is suitable for your needs between for example uh price and security mario so jeff has a question will starknet allow deposits exchange and withdraw of nfts or is it just for fungible tokens
job free your minds from the shackle of the fam and from all the other ziki solutions you've seen so far you can do anything in stark net you can manipulate erc20 you can manipulate erc721 you can create different kind of objects you can create specific custom application connectors on your smart contract on l1 and have it be manipulated by l2 startnet is a general computation platform you can do anything on it and as long as you define the way l2 and l1 communicates together then you can exchange arbitrary messages so you can do anything
and i know it's a it's not a very precise answer but the answer to your question is yes you can manipulate nfts um and you can do um a lot of things with that i'm not sure if you want to to add something real or no i completely agree if you like if you like to move nfts then yeah you can move anything the way uh the bridge works between um because right we're still we're seven minutes in so i hope all of you guys are working well um we still have time so maybe i can talk a bit about the l1 to l2 bridge how does it works exactly so um the the way it works is that the the bridge
of stark nets actually takes as input a proof of execution and a state div and it will also have an inbox and an outbox of messages so your l1 smart contract can go right into this bridge a message which can be arbitrary data that once the block is picked up will be picked up by l2 and sent to l2 in an inbox in l2 and you can have your smart contract on l2 pick that message and execute it right and it works the same the same way the uh the other way around you can have your l2 smart contract send a message to l1 and once a new state is committed on l1
the fact or the message that you're sending will be pickable by your smart contract on l1 so you can implement any kind of of logic right it can just be simple booleans it can be arbitrary data they could you can rlp in code it can be whatever you imagine um so the same question before after that is is it the same with erc777 erc 1151 i'm not sure what these are to be honest but since the bridge of communication between starknet and l1 is general purpose if you designed a way to exchange things you can do so and that being said the bridge is
general purpose um we published code for an erc 20 bridge i'm not sure if it's erc721 but i know some people from the community are working on that so you'll be able to use for standards bridge bridges out of the box but other than that you can um you can execute the you can design them i was gonna say fairly simply maybe i'm not objective but it's doable just mentioned that open zeppelin are working on developing uh standard contacts and you can just view them on github you can see how elc20 is implemented by them 621 yeah
yeah yawning is asking how complex can startnet program be is there starknet gas so these are two questions i'm gonna tackle one and then the other so the first one is how how complex can a startnet program be arbitrarily complex um you might have seen if you're following us on twitter we pushed some content from a guy called guilty gyoza which is down doing like physics simulation and you can see things move on your screen it looks nice there's a free body problem and it looks cool but what is going on exactly so when you have a game um on the blockchain usually what you have is that you will have the transfer of assets that will happen on chain but the actual
calculation for the game will happen off chain or if they happen on chain it will be fairly simple computation the cool thing about startnet is that since you push execution to the edge of the network you're able to have very uh complex calculation be executed and prove that the execution is correct so i want to think about worms too i'm sure i'm not the only one who played that game right you have small worms and you shoot at each other try to imagine writing a smart contract program i mean try to imagine writing a program that calculates the trajectory of a bazooka shoot and then it's hitting a wall and all the shrapnels going around hard but doable now try to imagine
writing this in solidity the first thing you're going to think is like guess why it's not gas wise it's not doable it's not going to work well you can write these things in start net and only one node would execute it and it will prove to you that the shooting of your bazooka added this actual trajectory and this this exact kind of damage so that's the kind of complex simulation uh computation we're talking about and that's what guilty gyoza is actually working on is roy is working on a physics engine with which you'll be able to manipulate objects and have them have trajectory and interact with each other which is a very interesting primitive for gaming because now you have games that you're able to play on chain with the actual gameplay happening
on chain with verifiable contract so that's for the complexity part now the second question is is there start net gas the shortest answer is not yet um of course computing things has a cost so there will be cost associated with your program with execute in your program but this is not really this is not fully defined as of today now in the beginning of the network it's it's not going to be very expensive uh but then it's still an area where we need to uh to define exactly how we're going to
charge users for that um one thing i want to mention regarding that is that in general in stark net computation is cheaper than storage since you're updating storage on l1 this has a higher cost than computation so that's why like calculating calculating a trajectory is cheaper than actually storing the results on chain i don't know if you want to add something to that ariel that's uh that sounds sounds accurate yeah so the following question is if one node can execute a transaction and others are verifying how race conditions are prevented i mean if alice makes a swap on one node and bob makes a swap on
another how the common state is built well you'll have approver which will basically compute the state and push the proof of execution so proving will happen at one entity how this entity is chosen and how the order of the transaction is chosen is still an area of research and if you want to learn more do join the discussion on discord to to to learn more and then we still have a minute and a half so i'm gonna skip on snark this is stark uh somebody asked the question earlier i don't know if you heard the answer if you have more questions uh regarding snap there's a stock please
ask give more details about what you want to learn and um the following question is how does the business model of starkware work how do you guys plan on monitizing your work it's not a technical question but it's a good one um it's still an area of research um we figure that if we build something cool that people use and as usage something will show up um starkware is a company developing uh zk rollaps um but starknet will have a life on its own eventually so um the objective is not to have an enterprise platform permission it's to have a decentralized network so
we'll see what happens uh and we still have 30 seconds to go before correcting so i'm going to let ariel correct the exercise thing and just before i start let me answer the can one hope to understand stock stocks without getting very deep into the muscle it depends what is your motivation if your motivation is to understand stocks and understand our protocol then the short answer is no you're going to have to get into the papers and understand all the definitions they're relying on and so forth but if you want to develop for stock net and write starting adapts then
then you simply don't care you you don't care about it it's just like saying that the that the solidity developer doesn't need to know exactly how from these transistors work so from your point of view it's just an elementary part in the system which works and you can walk around it so an experienced solidity dev knows the evm very good but he doesn't really care about transistors and our stuff actually running so in that it's sort of analogous to starting a developer uh which really knows cairo and really understands the kyo vm but has no idea about starks and how exactly the proof of execution works i mean
those things are pretty much all forgotten okay so i'll move on to the exercise solution i hope you all got it right so about that okay so this is the declaration of the registered voter function so you see our regular implicit parameters are still with us and we take as parameters the poll id the public key of the voter and the rns two additional values which i remind you all represent the signature of the poll owner on this particular voter public key and the poll id so the
signature should should imply that the owner of the poll has uh has given permission to the uh to this particular voter to vote uh okay so you see that the last line in this function will eventually be to add this uh voter to the registered voters storage variable so we're going to update and update this storage variable under the key poll id and the public key of the vote and we're going to write one so one implies that this voter is registered to the small id uh okay so now to the more advanced
verifications uh okay so first of all we are certain uh that this poll is initialized so how we asserting that this poll is already initialized so you can't register voter to an uninitialized poll obviously so we simply read the poll owner from the poll owner public key storage variable so we're reading the public key of the owner and we're asserting that it is different than the voter then the default value reminding you all that the default value is always 0. now so i have the initial part the last part now all that remains is to verify the signature so first of all we need to get the message that
the owner supposedly signed on so again he should sign the poll id and the public key of this particular voter so how it works in ecdsa is that you first hush the message and sign on that hash so this is why we're using the library function which we imported before hash2 which has hashes two arguments to one okay and we feed it the poll id and the public key of the voter again you see this implicit argument here the left side is simply the formal the formal name of the argument hash pointer and we're substituting to it this peterson pointer which represents our harsh building
again so if you want to really understand how implicit arguments work i refer you to the chiral docs okay so now we have a reference to the result of hash two this message is now in reference reference to the result of the hash on the paul id and the voter public key and we're ready now to verify to actually verify the signature so we're just calling another library function verify ecdsa signature on what arguments the message the public key and which public key the public key of the owner because he's the one support who supports the sign and finally the signature values the r and the s so two library two important library
functions here hash two and verify ac dsa signature and we verified everything at this point so we verified the poll is initialized we verified the signature now we can update the storage variable and actually register the voltage okay great okay so we talked about uh okay this is uh we didn't mention this so this is another built-in uh the ecdsa ecdsa built-in which is used uh which is used in this verify cdsa signature function so again these are things that happen behind the scenes okay we're asserting that the value is not zero and
this this we actually talked about uh okay so now we're adding another function to the voting logic uh you can see here a new decorator the view decorator which indicates that this particular function is not allowed to change to change the contact storage so this is a read-only function okay and what does it take as an argument outside our standard implicit arguments that allow accessing storage variables so it takes the poll id as an argument as a key and it returns now two values the number of no votes and the number of yes votes so as as the name suggests
it simply returns the current voting state okay um so right now it's your job to implement the body of this function and you have five minutes for it if you don't want to know exactly if you don't want to get aim for this then stop here and if you do then it simply requires you to read twice from the storage variable which we defined previously and we will keep track of it we will maintain it later so far we haven't really maintained it but assume that this storage variable indeed maintains the current state of the vote okay so uh please take five minutes and
we'll continue with our uh regular habit of answering questions watch the timer for five minutes so um i've seen some questions that were answered in the chat so do look for answers in the chat too um so one question is how big is the overhead for start net programs in comparison to native implementation for the example of worms is it 10x or 100x or something else i don't have an answer for this question i don't know ariel if it's clear to you and you want to answer it otherwise i'll just keep it and then and look for the answer and
give it later talking about the actual size of the program like byte code that okay you do have some overhead because cairo is let's say a lower level than for example python and you don't have libraries that implement all sort of numerical logic yet so there is going to be some overhead in the program size but you don't really care about this in terms of execution if we're talking about an about execution differences i can't i can't really i can't really give you a complete number but again we want you to get the mindset
that computation is cheap and storage is the more expensive part but yeah so computation is cheap because eventually the the only overhead here is submitting the proof of execution which is much smaller so we don't really care uh how long the the computation took so i'm guessing uh 100x is exaggerated but i can't really give you one more concrete estimate at this point cool i'll answer one quickly does the tooling automatically create a zk verifier in solidity for l1 no
what happens is that what you're doing in stark nets is proved in the context of stark net and the execution of starknet so the execution of your old layer 2 is proved to solidity so there's one contract where you prove everything that happens on stocknet and this place where you verify that everything is correct as an inbox and outbox message so that's from a solidity developer perspective all you have to do is handle messages that go to and from l2 you don't have to worry about building a verifier having a circuits having a setup things like that you just need to handle messages which is nice
um i'll answer another one which is what tools are there for you developing um tdding i'm not sure if that's a typo or something but basically for developing cairo contracts hard hat solidity so there's a there's a set of tools that is being developed by uh the community and the other partners uh you'll find plenty of information in the chat we're gonna publish a um a link with community tools and uh do join discord because there are new people joining quite regularly actually and uh sharing their tools and so everything is building built i'm not gonna lie it's a bit more nascent than it's fairly more nascent than solidity but there's a lot
of tooling emerging so there's a lot of things to simplify your life and this will not relate to you ariel are the costs of function arguments in stark net meaningfully greater than say inputs to sharp is that explicit er i'm not sure exactly what you mean because the sharp it actually stands for shelled over and it is a service that we run that one at starkville which allows you which allows us to prove simultaneously the execution of different programs so now sharp is in production with several applications so we have immutable x and soil i believe so these
are both both two apps which are which both require different proofs of completely different programs but using sharp they can share the burden of the proof so this is unrelated to what we're doing here with with the writing a start net contract you could ask eventually the execution the advancing of the state in stock net running this target os which henry mentioned briefly at the beginning of the workshop can be proven in sharp but these are two different type of objects like the contract function and
sharp so i can't uh can't really answer that and just uh about testing driven development so we have our testing framework which is documented in our site and some of the tools that henry mentioned are building on top of our testing framework so so yes you can uh currently you we do have a testing environment and it is uh really dynamic we advan we improve it as we add more features to start it okay i'll answer one last one very quickly before we move on to answer the question by rahul is how often does the the mailman come from l1 to l2 and so how do you think about data availability instead
submission in terms of frequency um so and correct me if i'm wrong ariel right now you have to think there's an estate committed every i think it's like in terms of hours right every eight hours uh but this is pretty much uh something that may evolve with time if we have more volume or more necessity this frequency can probably increase am i saying something stupid is it accurate it's uh right now it's in the order of hours it can be improved with the for example recursion if or when we have it but uh
wonderful so in the orders of hours for now but work in progress and we want to drive it lower okay with that let's go to the answers thank you okay great and just uh also men have fast faster checkpoints than the actually submitting the proof so the proof accepted on ethereum will be the greatest degree of finality but we'll have something uh before that for apps which which need to be uh more more alive and don't really care about waiting for the orphan can settle for all the gear finance okay so let's go to the answer okay so hope you all you were all able
to do it so we're just defining two references simply reading from the voting state again notice the keys that we send so to get the number of no votes we send the poll id and zero and to get the number of yes votes we get we send the poll id and one and we simply return those two values that's it okay let's uh let's move on to now verifying the vote so far we verified uh things that are related to the owner of the poll but now we actually need to verify things that are related to the vote itself and the voter okay so we have the verify and the verify vote function
okay and note that this function has no particular decoy at all this means that it is a helper function which will we will call in one of the either either external or view functions yeah okay so again the implicit arguments that were used to and a few standard explicit arguments the poll id the public key of the voter now again notice the difference between the owner and the voter the vote the value that he is intending to uh to vote and again two values representing the signature now of the voter rather than the owner okay so the first verification is simply that the vote itself
is uh in is binary it's either zero or one and we can verify this by uh asserting that this multiplication equals this to zero this will only be zero if vote is either zero or one uh okay so now we're actually coming to the next exercise and you now have to implement the rest of the verification so first of all you need to verify that this particular voter is allowed in this particular poll this is why we are maintaining the register voters storage variable the next thing you need to know is that this particular voter is not attempting to vote twice this is why we're maintaining the voter state and lastly you need to verify the
signature so you already saw how to uh verify the signature but right now it's the signature of the voter rather than the owner and think about what he's signing on so what he needs to sign on is the poll id and his vote value okay he nobody else should be able to uh to vote in the name of uh this uh of this public key okay so uh you have 15 minutes to implement the rest of the functions you can see the previous code in the notion documents and notion documents and good
luck thank you ariel up putting the timer back so uh i'll take some questions and then uh there's another thing i want to talk quickly about so the first one i'm gonna take is what are your thoughts on zk syncs zk async and their implementation of the zk roll up um well we believe l2s are the future and ck roll ups are the future so we're always happy to see more people interested in the same topic and building toward the same decentralized future we are so we're excited to see what they will release once it's uh once it's visible and usable it's always
interesting to have the perspective of other teams from on the same topic we're trying to solve so very curious to see what they are once they are released and the second question is would writing a gpu shader-like program to manipulate a large memory buffer be possible are you is it something uh i have no idea what exactly is the meaning here me neither okay so let's put this in the back of our head and if we can uh if you need you can give more insight as to what it is you want to build please write it in chat and we'll try to answer it thank you
um and the other thing i wanted to mention really quickly um that i i saw somebody in the chat saying like wow this is interesting you can do more stuff more computation and and yes here's the case computation in stark net is fairly cheap it's very cheap so you can do a lot of stuff and i'll give you one brain teaser about things that you could do all right so imagine you want to do a snapshot to have people vote depending on how how much token they hold right in order to do that snapshot you do you have to do it on shay uh off
chain and then write some tool that will analyze this block and then authorize people to vote or note and not and then you have to collect these signatures of chain and you'll be able to produce a reliable image of who was allowed to vote at a point in time and who actually voted right but there's obvious limitations to that because you can do it off-chain but you can't really have a smart contract actually implement like verify this kind of a thing you can't produ you can't give to a smart contract the state of a block in the past analyze who was allowed to vote or not and who voted what this would be way too computation intensive
well you can do that in in stark net you can give to starknet the content of a block an ethereum block in the past you can have startnet verify the content of that block verify the state of specific smart contracts in that block and then have different mechanism in place you can verify the ethereum signature so you could collect data of chain and have a stockinette smart contract producer proof that somebody did something depending on something that happened on l1 and produce a proof on l2 that can eventually have actions on l1 and that's the basic concept behind something we presented
a few weeks ago which is called stark vote which is a partnership with snapshot which you guys might be uh familiar with and this specific example does give you an idea of how you can exploit l1 data on l2 i don't know really if i've said something you want to correct or if you have something you want to add on this no no perfect so who's going the first two to be the first to write a bitcoin miner on starknet i'm not sure you could mine on stocknet but you can definitely interpret uh the content of bitcoin block on starknet so that's exciting
and yoni gave more information regarding gpu shaders so think running a step of inference for a machine learning model or frame in a 3d game or photoshop like drawing program so i think what you're saying is like how complex can the execution be uh and if you can run logic that is akin to what you would run on a gpu in um [Music] in uh in a computer um [Music] yeah do you want to comment on that i really think the the question basically is like how far can you go with the complexity on uh i mean if your program requires i don't know thousands of dollars one on aws for example then it's probably going to be harder to implement it in a
horrible way so it's you don't have the overhead uh the insane overhead of ethereum but you still do computation so if you're like doing a very heavy model training then you're probably eventually going to get into the same burial barriers that you would if you were to use your own your own very strong computers so there's no magic or not there's magic in the proof aspect but but somebody out there will have to execute this computation just not it won't have to be everyone yeah i'll just say something about uh
privacy by the way there are no syntactical questions so i'm guessing that's because you're all writing it very easily and the your the code is compiling for all of you um so about the privacy question uh in our implementation right here in this voting example then we don't uh do anything related to privacy uh but i i will say a word about uh using for example zk snacks for uh for private voting so you could use zika snacks or stocks for privacy it doesn't really that the technology of the proof does
isn't really important here what is important that when we're talking in in a layer one and layer two context uh information having a zero knowledge proof is far from enough because somebody sends the transaction to a mempool eventually so what point does it have to publicly send my vote to some poll but having the proof exposed no information on it i mean it's a little silly because okay i won't try to read it from the proof i will simply look at the mempool to implement a system which truly exposes no information you need more than the proof to not leak any information this is similar similar to z
cash which on top of uh using zk proofs they also had a complete design in showing privacy so the zk proofs were just one element in a much larger system a crucial element but just just one element um so you could implement something like this on top of stocknet right now our proofs are not technically zk although i believe it's practically uh is it's not a very practical task to extract from it but if you care about privacy you need to do stuff in the business logic of your particular application
because if you simply expect someone to send you the the transaction then obviously you will get you know no privacy regardless of what you're using so there's another question in the usage workflow can i deploy my own start net or shall i use the one provided by starkware well should you use ethereum or run your own chain you can do both it depends on your use case but in most use cases for app developers you want to be on if you're a mainnet right so you probably will find more apps and more content and more infrastructure on um the stark net
the public stark net and when you say the one provided by starkwear once again i want to stress that right now we're developing it and we're maintaining it but this won't stay like this forever it's one eventually it's gonna have legs of its own and it's gonna be outside of our control so we still have some time is there anything to say about accounts on starknet opens up and uses so can you uh talk a bit about account structure abstraction ariel on on startnet let me read the question again carefully okay so uh we are still working on the specific
implement details of uh account abstractions we're also working closely with open zeppelin you can see the account the initial account contact right now you can just go to the repo and see how they implemented it and so yeah they do use a get caller address which returns the which returns the contact otherwise calling you and how does this work with it accounts so if you want to bind your account contact with your youth account one way for example to do it was to just have a field in in your contact account which represents your ethereum address and somehow uh
work your logic around that so uh accounts if we're going down the account contact rules where your account is represented by a contract like any other then you can contain information regarding your ethereum address on it as well and your you might require ethereum signatures uh which correspond to the public key or saving the and this sort of stuff so there are a few programming questions that i will let jonathan maybe answer um there's another question which is interesting is ethereum gas helps preventing getting the smart contract in
an infinite loop what mechanism prevents that on stock net if not using gas um so two aspects the first one is this is still an area of uh discussion and experimentation so there are very interesting discussions regarding this very topic so do join the discussion if you're interested and you have good ideas on that um i'll just say that when you run a cairo program there's a number of steps that you need to execute and you can put a cap on another steps that you'll um that you'll allow in your program um i think ariel do you have something else to add on that topic how do you prevent grieving attack not saying right now yeah
i am okay cool thank you um then there are programming questions which is i guess related to the uh to the [Music] exercise um and i think it's easier if we answer this by uh in writing um so do check the answers yeah the whole question so first of all and notice that yoni is answering questions in the chat so take a look take a look there as well um so our compiler currently doesn't support all i'm guessing that it's not uh conceptually hard to implement it's just
not a top priority so yeah this is why we're using uh this particular assertion here um okay and uh regarding the previous previous question so we will have some some dos prevention mechanism that will that will allow you to charge to charge somehow for for computation for example if somebody in an infinite loop we can limit the number of steps there are some technical obstacles which we are currently dealing with but you can expect some notion of guess definitely in the alpha version we will we won't have it just yet but you can expect something along those lines
one time minutes still minutes to go okay no problem so i'll maybe i'll use those two minutes to uh to refer to the last question about implicit arguments and so essentially we need to have access to them and being able to update those are pointers and every function needs to have a function that accesses the storage needs to be able to cut to track the current location of those pointers so under the it's not particularly sophisticated under the hood what's happening is that those variables the updated value of those arguments is
actually returned so this is a helper function it receives implicit arguments and here it looks like it doesn't return anything but under the hood those parameters actually change changed and return it is just so the user won't have to always return explicitly those uh those arguments which are not directly related to his business logic so yes they do appear here but you can think of it as they only appear once in a sense and from that on they're just implicitly passed to other functions that make use of them so i hope that
shed some luck on it again for more complete explanation see our books and we are at about 15 minutes so we can now with the correction of the exercise okay great so again i hope you all got it right and for those who want to enjoy the show and this is the first verification that the voter is already registered to the poll
so we are maintaining the register voter storage variable so we simply reform it and assert that it is non-zero so it is a flag the equality is a mapping from a call id and the voltage public keyboard flag which indicates if he if the user is registered or not and then we do almost the same thing to verify that the user hasn't already voted so we're going to vote a state and we're reading the flag which uh says whether or not the user is all has already voted and again we're asserting that this value is 0 then we accepted that the value was not 0 now we asserted that the user has imported and now we have
the uh verification of the voter signature so exactly like the previous signature verification only now the message that was signing on is the hush of the poll id and the vote okay because the user is signing on the pair paul id and vote and obviously the public key with respect was with respect to well verifying the signature is the public key of the voter in the previous uh in the previous verification it was the public key of the owner and again while passing those rnps so we'll only pass
this verification if the signature is valid okay now finally we're ready to implement the actual voting logic so we have the vote function uh which takes as the explicit arguments the poll id public key of the voter his vote and this rns representing the ecdsa signature and we first of all call our helper function which does all the all the verification checking that the user is registered to the poll checking that he didn't already vote checking that his signature is valid and if we were able to pass this line this means that
everything everything works and we can simply update the voting state so we're reading what is the current number of votes for the option that this user wants to vote to so we're reading from voting state and the parameters we're sending is the vote of this particular user so we call it's a mapping from the option to the number of votes so while reading this mapping in this particular option and then we're writing to this same storage variable the updated value so the same key the pole id and the volt of this particular user but now the value is the current number of volts plus one
and one thing before we're done is update the voltage state so recall that the storage variable we need to maintain so we need to remember that the user has already voted so we're setting this mapping to one and this is actually now we have our voting logic complete yeah okay great so now we move on to the next part which is uh composability so here we're basically going to show you how to interact with other stagnate contracts okay so this is a dummy contract for the vote recording so think of it as a contract which holds the result of uh all polls
okay it has uh it has one storage variable a mapping between a pole id and the result it has one external function and one view function the external function record takes as arguments the pole id and the result and simply writes records the result and the get result does exactly what you would expect it reads the current uh the current value from the mapping and returns it so i know if you want to yell that there are no verification there is no verification here and anybody can call record even if he's not the poll owner so yes this is just dummy contact to demonstrate composability but you're essentially right
to make the system meaningful if you want uh vote recording then you probably need to verify the signature of the poll owner okay so how can we interact with this new contract uh form our voting our primary voting contract under which we implemented all uh on that logic before uh so we're gonna add three elements uh to our contact basically so the first one is another storage variable which is simply a single felt value a single field element you can see from the fact that this function takes no arguments so
there's no key required it is not a mapping it is just a single variable and this storage variable represents the address of the recorder contract okay we will also add a constructor to our uh to our voting contact which will take as an argument the address of uh of the recording contract and save it to the storage variable so now as opposed to the previous situation to deploy this contact we're going to have to send an argument this argument will be the address of the of the voter recorder contract
okay and the constructor simply takes this address and stores it in storage variable very similar to how you do this sort of things in solidity and then we also have to define the interface of the contract that we're going to use so here you see the contact interface decorator and special syntax namespace and the name that we're going to use to to actually call the contact and here we define the function that we're going to call so we're going to call the record function which we've seen before it takes a poll id and the result okay so now having those three parts incorporated in our contract were ready
to interact with the with this uh recording contact okay so let's see how this is actually done so now we're adding a new function to our voting contact it is called finalize poll again the implicit arguments which were used to it takes only the poll id as an argument okay and what it does is simply read it it first accesses the address of the recorder contact we call it this storage storage variable keeps the others of the contact that we want to interact with
then from the voting state we take the number of no votes and the number of yes votes and then bear with me i'm gonna jump a few lines well checking which is bigger using the is this equal library function the number of no votes or the number of yes votes so this returns one if the number of yes votes is bigger or equal and now we can compute the result of this particular vote and we're not representing it as a boolean value as to not create a mix-up between a zero result for poll and the zero default value for storage variables
so we use you are going to use the short string syntax in stock net so when you write the constant string yes under those uh under those buckets uh what it does is represent the string as a field so this is the way it encodes it it takes the ascii encoding and presents it in a big endian encoding uh so notice that the result is simply the multiplication of yes by result and no by one minus result so if the result of the pole is one okay it means that the number of yes votes is bigger then this is going to be zero and the result is going to be the field element representing yes if on
the other hand this is going to be zero this means that the number of no votes is greater this is going to be zero and this is going to be one so the result will be the field element which represents the string no and now once we have uh the string representation uh of the result we want to record was simply calling the record function so recall we defined the namespace under the name result recorder this is what we defined here so we can simply write result recorder and access the function that we have here record and while accessing it as if you would access a function inside the contact so
with a simple distinction that the first argument is always the address of the contract you want to interact with so the record function takes two arguments and here we send three arguments the first being the others of the contact which we take which we take from form storage so this is how we were able to interact with other contracts and now uh we leave it to you to add another external call to verify that the poll wasn't already finalized so in the finalized poll before we actually record the result we want to verify that this wasn't already
finalized and let me just show you again the code for the recorder recorder contact so we already used record the record function in our voting contract but note that we also have this view function which we didn't use which takes the poll result so think how you would use the contra this function to verify that the vote is not already settled and call it from the voting contract we've implemented so far so again what you need to incorporate is these new definitions um and good luck
so you have five minutes for it and i leave it under this slide so we'll see what you need to add in order to be able to access it access the new uh the new contract and obviously again you have all the code in the notion document so if you need if you need to you can also look there okay so uh we're gonna give you five minutes and i'll take a look at the questions in the meantime okay leave it to henry who led our intermissions hello again so there are two questions there there are less questions in in the beginning so it's
going to be easy how does carry roll and the longer strings example for example strings cannot be in one felt i don't think we have a native support for strings or for longer strings we still don't have any library supporting it you could you feel free to implement it and post it on a discord people will be very glad to hear it but uh yeah you we do and there needs to be some handling of this but all the tools are out out there just waiting for us or somebody else to implement it yeah but he's asking how can i improve myself on coding about starks
so to be honest i think starknet is more of an application running on top of starks you don't really need to and deeply understand starks to write um starkness smart contracts so i'm not sure stocknet would be the place for you to learn how to reason and write about stars that being said our documentation and our code which is open source is a good place to learn how we implemented stuff how would you go about about it ariel so there are our documentation definitely also join our disco to
interact with other developers and see what kind of problems they're taking and the advice they're giving and there's also the tooling around stocknet um start with our documentation and uh just start writing a writing dummy contracts until you slowly get better yeah so that's why for example we're doing this we're doing this workshop yeah so this is the kind of thing you would want to improve it if you're going to develop dubs on stocknet this is completely unrelated to improving your understanding of stocks again i can't stress this enough
you don't need to get into this type uh to the to the mathic papers to be an a very uh to be an excellent top-of-the-line starting developer the analogy between a very sharp solidity dev to a very sharp stagnative would be understanding the ins and outs of cairo and this is unrelated to starks i wouldn't say unrelated because sky was built to support uh stark moving of execution but you don't have to know anything about starts to understand very deeply how chiro works and how starting it contacts
utilizing kyle and i think that's most of the questions we had if you have others feel free to answer them other than that we'll set have two minutes to go so let's wait a bit so yeah well so moving to the solution i see i see just uh another question regarding the guy who's finishing this master then yeah join our discord and see what projects are available i mean there are tons of projects going on if you have any cool idea then be sure to let us
know and uh yeah go go nuts and again feel free to ask our help audi on this code we're very interested in in any startup ideas oh you were the one who asked about getting deep into stocks so yeah if it interests you the papers are out there go nuts with that as well okay okay so i'm gonna move on to the solution so i'm reminding you we want to verify that the poll wasn't already finalized and to do that we simply want to call this view function on the contract we want to see the poll result recall that
when recording we substituted the the field representations of yes and no so if the poll result is zero this means it is still set to the default value so the poll is still ongoing so all we need to do is read the poll result from the recorder and verify that it is uh still zero okay uh so these are the two parts that you need to add to the contract and you need to add to the namespace the other function that you're going to use so this is the getpaul result you wouldn't be able to call it inside the votingcontract unless you explicitly defined its signature here and
and now the all the logic that you need to implement uh to verify that the poll was not already settled is calling get call result and asserting that the value is deal which means it is not yes or no yet and if it was new then we were able to continue to the next line which was recording the result okay so we're actually done with our voting contract i hope you all enjoyed the exercises and the questions and so i'm gonna briefly uh interact with it before uh before going ahead with telling you what else you can do to improve
to improve your starting experience uh okay so let me just share my browser one second i need to only shell here okay so you guys should be able to see my screen now and this is our block explorer voyager so start net is currently deployed on the coily test net and it will be deployed on the main in its alpha version by the end of the month
so right now you see this exact voting contract which i uh pre-deployed and so if you don't believe me you can later check out that the byte code here corresponds to the voting contact and and as you can see i pre-submitted two transactions to it so i deployed it this was a transaction deploying the contract and i submitted two additional transactions those were initializing some poll and the next one was uh giving some voter permissions to that poll so stuff we implemented like uh an hour ago in case you forgot so you see on the right contract you can
see external functions under read contact you can see view functions so these were all our external quantum external functions that we implemented and this is the view function that we implemented so you can see that uh trust me when i say i initialized the poll with the id 2022 and as you can see uh nobody has voted on it yet so the number of votes uh is zero for both uh both no and yes so what i'm gonna do now is in a senate transaction through voyager it is not the only way to interact with starcnet so to interact with starnet using our cairo length package and the
cli view our documentation but right now i'll just for the purposes of uh demonstration will interact uh using using voyager so what i'm going to do is i'm going to vote so i've prepared the signature that i want to put here so this is the poll id that i want to use and now let's see hopefully these are going to be the correct parameters otherwise i won't be permitted this is my public key now i'm going to attach my signature okay so i'm going to vote yes don't ask me to vote no because i
didn't prepare a signature for the no answer so i'm going to vote yes if you don't mind let's imagine this is a question well the answer is obviously yes okay so hopefully these are all the valid arguments for voting so i'm gonna send this transaction okay so this transaction is uh is now sent and we're waiting for it to be included in a stack net block so the life cycle of a transaction is first being captured by our system or by any other
sequencer when startnet will be decentralized and after it is accepted on l2 and this is the term we use at least in a voyager we're waiting for a final confirmation that a proof attesting to the validity of this transaction was also accepted on ethereum right now obviously on the go early test net because we're working with uh with gold okay so that's basically how you you can use a voyager to interact with your contacts so just see what other nice features you can extract you can start from here so let's see how our transaction is doing okay it's still waiting to be included in a block so for
now let me just tell you what else you can do okay so here we did not we use the playground to write code which is actually a less optimal way to go if you want white if you want write or start net contracts more fluently so we have the cairo length package which comes with the compiler and the cli for interacting with stacknet everything is explained in our documentation so please uh feel free to to read it and obviously if you find some explanation lacking or your income
you're encountering some problems uh join our discord and ask any questions in any range of difficulty and we'll definitely answer and for those of you who just want to start from from the ground up there's the stacker tutorial so uh start from there and see where it takes you there are also additional exercises in the notion document um so yeah you have different avenues you can pursue so good luck let's just see what's our status there okay so our transaction was accepted on the on l2 let's just see that i'm getting
the new value right so the poor id was 2022 okay great now the number of esports is one this is very exciting we were able to pass the verification this means all the arguments i previously gave are indeed the correct ecdsa signature for my public key um so thank you very thank you very much for going along with the collecting the contact i hope you enjoyed it i hope you also find it uh found it helpful and again feel free to visit us on discord and if you have cool ideas for dabs on stocknet
let us know yeah i'm feed the fed so feel free to ask ask me anything uh henry if you want to read something no i think uh yep thank you to everyone there are two questions we can answer quickly maybe so where to find a good technical description of how the stock net network does uh works sorry verifier approval or l1 l2 connection on all of these parts so we are we're building that documentation and we are documenting things as we develop them so not everything is documented you will not find that much about verification verifier improver yet but it will come you will be able to run a start at a
full node by the end of year you should be able to do it so um that's going to be a big step um l1 l2 connection this is fairly well documented so you can look up at the documentation so mostly i would encourage you to join our discord and we will publish a discourse platform soon where you'll uh you'll be able to find more information and see the discussions in real time regarding the network at architecture then there's another question about could you talk a bit about the concept of hints is it possible to fetch data from external python code yes but actually no so um the concept of hints is a concept of cairo it's something you can actually
use in cairo but you can't use in stark net so um ariel may correct me if i'm if i'm wrong but basically um the program you are running in your when you want to prove something will basically require you at some point for example to prove that you know the square root of 25 you could supply the value 5 and the program would be fine or you could just run some python code that calculate this value from the point of view of cairo it doesn't change much the important thing is that you have the actual value to verify that the program executed correctly
so this is why in cairo when you're writing a general purpose cairo program you can use ins now in the concert in the context of starknet this is a bit more difficult because the the proof will not be run uh on your computer it will run by the prover and you it's hard to be sure how the hint will work in the provers environment so that's why you can't have generalized hints in stark net smart contract that being said i think we have a white list of hints you can use so you can use some hints but not
anything you would like to add and i hope that answers the question just add that some library functions are actually using a hint so for example if you want to search for an element in a list then doing it non-deterministically would be guessing the guessing the location of this element in the list and then verifying that this is indeed the element we need a hint for that but luckily uh we've implemented it for you this hint is whitelisted and you can do it by simply calling the library function which is pretty cool actually i don't know if you've ever written a solidity smart contract you have to look uh for a value in an array and it's a pain in the ass because it's cost so
much money there's nothing specific for that and now i mean in starkville you can just say yeah do it in python and give me back the answer which is kind of cool anyway so thank you for everything uh i'll uh do join our discord in the conversation um and uh thank you to zikiac for having us uh it was fun yeah thank you so much for the for doing this uh hi arielle we noticed that you were also sporting i don't know if you can take this off um yeah we actually have a ton of t-shirts so i got one but my brother stole it from well we have a lot of them so actually
i'm gonna we're gonna try to find a way to get it out to people if people want these very cool shirts i want to say thank you so much for doing this workshop