New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Polygon 🛠 Getting Started with the Polygon zkEVM

ETHGlobalWed, Oct 9, 2024, 12:00 AM

Join us for a workshop titled, " Getting Started with the Polygon zkEVM". Embark on a journey with ETHIndia, where innovation thrives, collaboration knows no bounds, and hierarchies fade into self-sovereign ownership. The most skilled web3 developers, designers and product builders from all around the globe came together for a weekend-long adventure to advance the Ethereum ecosystem at ETHIndia in December of 2023! ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

[Music] thanks for uh coming for this Workshop in this workshop I'll very quickly show you uh how you can get started with ZK AVM how you can build your projects on uh ZK AVM but first of all uh gmgm or I should say uh zmzm because we are uh moving into this world of ZK right so uh what is polygon zkm so polygon zkm is an uh evm equivalent ZK rollup uh it harnesses the power of ZK to uh reduce the transaction cost and increase the throughput and uh why polygon ZK uh we feel that it's the next chapter of ethereum scaling so uh it's very exciting for developers because uh you can use the all the same tools and techn technologies that you have been uh familiar with like different wallets uh uh like tools for uh developing smart contracts like Foundry hard art you can code in solidity so it it it works pretty seamlessly they all work out of the box just I need to highlight that uh we the only thing is that uh that I want to call out is that we don't support three pre-compile outputs so if you're building on that uh just be uh just uh be aware otherwise everything works pretty seamlessly uh which is you know very great for a Dev so first half of ZK evm is ZK uh I'll explain this with an example so everyone must have played this game called Where is Waldo in their childhood basically it's it's kind of a puzzle and you want to find out uh like you need to figure out where Waldo exactly is right so uh so what if I say I know the location of wdo but uh I can prove to you without actually revealing the actual location of it how how am I going to do it so I'm going to take a big piece of black paper I'll cut out the shape of wo and I'll place it over the picture so in this way I can prove to you the exact location of wo but I could have placed the uh the puzzle in any any of the corners or anywhere around the black paper so in this way you don't know what's the location uh only I know but I can I have proof to you that uh you know I I I know the location so this is uh technically how uh ZK works right so in in in real life uh ZK works with complex maths and cryptography uh to prove uh the prove a validity of a statement uh without actually revealing that statement so we have talked about zero knowledge but what exactly is a rollup so zero knowledge rollups are layer to scaling solutions that increase the throughput uh that increase basically they scale ethereum by increasing the throughput and reducing the transaction cost uh uh yeah so in case of a uh ZK ZK rollup uh ZK evm rollup so ZK evm rollup is technically a ZK rollup that is designed to mimic the same transaction uh execution environment as main net ethereum uh or polygon POS or any other evm chain uh so what's the benefits and features uh so it enhs the ethereum's battle tested security so the proof is being posted on ethereum and ethereum has been running successfully for years right so we trust it we love it for D5 it's scalable we uh we achieve this scalability by batching many transactions together to unlock High uh higher performance right and obviously it brings down the cost uh like uh uh gradually low and uh it's uh it's evm equivalent so the benefit as I explained before is that you can use all the tools uh out of the box so I'll uh I'll quickly explain the uh architecture of polygon ZK evm uh so uh think about this as a uh transaction life cycle so we'll get get into a small Journey from where a transaction is sent by user till this transaction is completely Final on ethereum right so we start by receiving this transaction on the the node send by a wallet or any script uh based if if you are working on a project so this transaction goes to a pending transaction pool and at some point the sequencer uh you can see there uh the top uh like right uh it's it's part of the node it picks up the uh transactions uh it executes these transactions and then puts them into an order so this ordering uh is actually what we call as The Trusted State uh it's trusted because uh it's not yet on layer one and the sequencer essentially just says that hey this transaction will be included in this block this info is uh then can be shared to the other nodes in the network by the Broadcasting Service and this information can be shared to the users as well so this is the uh this this is where we actually uh achieve the first level of finality or first level of confirmation right then after a certain uh time the sequencer have uh when when it has accumulated enough transactions in The Trusted State uh it'll it'll send this transaction in a batch to layer one uh it sends it to the uh rollup contract that's called as polyon zkm doou to be precise so you can see the contract there uh this so the main goal of this interaction is to put the da the data availability on ethereum uh the basically the data of the transactions uh to ethereum after we have done that the key point is that any node in the network can then read this ethereum smart contract and rebuild the state using this info uh and we can rely on the data that is posted on ethereum because uh what's on ethereum it will stay there for uh well uh long enough uh we we hope right uh and now because of this we can rely on the uh state of layer to roll up as it's on ethereum right uh it is what we call as virtual State now here we realize that we haven't talked much about ZK right it's ZK evm so here here's the thing although we have this data on ethereum but uh like the ethereum smart contract doesn't understand the processing of these transactions it just knows that this bunch of data and in order to make it a aware of the latest state of Layer Two uh it's when we need the ZK proof uh there is another role in the node called aggregator which will fetch this data and generate a ZK proof after talking to the another service called prover and say hey after processing uh this data the state of the network is this and of course we compress the uh this state into a hash uh a Merle route to be precise uh and then submit this uh ZK proof to ethereum this uh state is called Consolidated State and uh that's how uh you know we are scaling transaction while we are inheriting the uh security of ethereum so these are the three uh the three stages of finality that I talked before the trusted virtual and Consolidated so it's the trusted state where the bad generation and uh the broadcast happens to the L2 node and uh it's basically given by The Trusted sequencer then we have the virtual state where we are putting the data availability onto ethereum and then we have the Consolidated state where we are generating the proof and we are actually uh putting this proof on ethereum so yeah uh some of the uh industry use cases and things uh that we are really excited you you all will be build building this uh weekend are uh defy and in uh trade space when you are trans transferring value uh so like when when you are transferring value uh you want high levels of security so for finance we uh highly suggest using ZK AVM uh even like in other use cases like healthcare gaming uh supply chain you need high level of trust we highly recommend using po polygon ZK AVM when you are choose when you are figuring out what chain to go for so to to get started with uh building with polygon you first need to uh brid some funds from uh ethereum and technically you need to bridge ether from uh ethereum to get ZK evm e that you can uh use to uh submit transactions pay for gas fees Etc right so you can do that by going to wallet. poly. technology there you can just select based on if you want to go for test net or uh main net you can select the network you can select ethereum and then uh basically you can just click the button start bridging and uh you you will have uh ZK AVM eth in your wallet so for mainnet it's obviously you need to Bridge Over the real e but for uh net what else you can do is go to f.p poly. technology uh paste your wallet address there and uh click polygon ZK AVM there uh the network and you'll receive ZK AVM e uh yeah so as you can see it's very simple to deploy and get started with ZK AVM uh and you know swapping your enir uh development environment from ethereum or any other evm chain uh that you're using to polygon ZK AVM and this can happen just by changing one line uh that is basically changing the uh Json RPC so that's really what you need to do so I'll just uh I'll just show you how uh we can do this very quickly using uh hard heart so I'll just jump to vs code so this is a very basic project of hard art and uh I have a contract here called greeter soul that you get out of the box with hard Ard so in this contract you can see we have the obviously we have the pr pragma statement then uh we have a Constructor function we have U A View function that is GRE uh to actually see the value of uh greeting that uh we have defined here so the contract is maintaining the state of this particular variable uh we can use this function to get the value of greeting uh we can use the set greeting function here to actually see uh what what is the current value of uh uh greeting and we have this Constructor function to set the initial value for greeting then uh I've written this small deploy do JS script uh this is to actually deploy this contract so I'm using this dependency called U hard at ethers and I'm calling this deploy contract method to uh create an instance of the contract and then deploying it uh then I'm just printing this uh printing the address for the uh the contract that I've deployed right uh so what I was mentioning was that how you can just uh Deploy on polygon you just need to change one uh line of code right so it's it's this simple uh line of code that I was referring to that's the Json RPC so in the net this is the config file right so in the uh I've I've named the network as ZK AVM I'm mentioning the URL and I'm also uh mentioning what my uh private key is to so so that to uh make harded aware of from what account I want to deploy my contract from it so I've put the value for this in my uhv file so if you just want to uh deploy this contract what you can do is uh say in PX hard heart run and I I want to run this particular deploy dogs file so I'll just say uh scripts it's in scripts folder say deploy dogs and I'll just select the network which is in this case is uh ZK AVM I'll just hit enter Don there that minut yeah as you can see the contract I'll just move this up a little bit so as you can see the contract is deployed to this particular address we can go and have a look as well for that uh we we have the Explorer at ZK avmp poly.

technology uh sorry zkv m.p polygon scan.com and uh for test net it's test net test net-en zm. polygon.com so right now uh as I have deployed it on testnet you can I I've just copied the address I just paste it here as you can see it it was deployed uh 1 minute ago so I was able to do it because I had some uh funds uh in my wallet but for you to get it again you can just go to wallet.

poly. technology to bridge over the eth or you can go to faet if you're developing on testnet so so yeah that'll be all from my side thank you uh anyone has any questions oh they still y right or more gas what so yeah so uh the gas price is definitely uh lot less than ethereum uh but for for a uh for nft use case probably I'll say you can choose whether uh you can you can go for POS or you can go for ZK AVM ZK what ZK AVM gives you uh like other than p is that uh it gives you a high level of sec security as it's a rollup so yeah okay yeah thanks the question yeah same uh hello I could not quite understand what was meant by changing one line in the module uh what was meant by changing one line in the module do exports Yeah Yeah so basically uh if if you're developing on ethereum or you're you were developing on uh any evm chain let's say polygon POS uh and you you are already uh you you already have your contracts right you must have deployed them using any any of the uh smart contract development framework like hard Foundry or you know you can do it via remix as well so technically uh the whole idea was that you don't need to change anything uh with respect to contracts right you can just connect to the RPC and deploy your contract there so in in the line uh and show you U I'm just mentioning which network I need to connect in so if let's say I just uh mention the RPC URL of uh ethereum here the contract would be deployed to ethereum or if I mention the RPC URL of polygon PS it'll Deploy on P so so the the whole idea of of this on line change is that uh it's it's very easy to deploy on zkm that you don't need to change anything uh the daps that you are already familiar with or you you already have built they can straight work out of the box at zkm so actually how can you say that you are how can you say that you can you are aching much through rather than the traditional method although you are doing watching of computation to the jsk calculation you doing so how can you say that you have like achieving one more through in km process rather than the pr isal uh so you're saying with respect to ethereum yeah yeah so in ethereum as you uh as you know the uh there's a block time of 15 seconds right so the throughput is really less and here what traditionally we are doing is we are batching all the transactions and then submitting them on ethereum and if you see if if you just in ethereum whenever you want to transact the uh there a separate transaction for every transaction that you doing right every uh thing that you need to change the state of ethereum for right but with zkm what you're traditionally doing is that you're batching all those transactions and then just submitting one transaction on ethereum uh basically that's uh submitting the validity proof to it so the throughput is much more than that beware the D any other questions we have plenty of time so please take advantage of the time we still have a whole another 10 minutes if anyone would like to ask a question come on closer to so he can hear you better for those in the back uh can you hear me yeah all right uh I have a bunch of questions I guess U so as I understand like like the whole system is basically zero knowledge proofs based rollups right uh how it is being batched and how it is being uh submitted to ethereum right now from a evm perspective uh do you have anything extra that has been added which which uh sort of gives smart contracts maybe Z zero knowledge proof sort of functionalities or something like that that you can execute no uh so from from Smart contract level it's exactly the same uh from uh if you compare it with ethereum and P what we are leveraging zero knowledge proofs is just to scale for for for basically the rollup thing and the exactly now which that also means that the transactions on the on the whole system are actually visible uh they the transactions themselves are not zero knowledge right yeah yeah uh are there any plans in which like you have either this network upgraded to or maybe a new network in which the whole network itself is zero knowledge so that like you basically cannot see who is doing what yeah so so the thing here is that with zero knowledge uh yeah so zero knowledge here how uh how it is being used is that when I'm transacting on polygon ZK AVM uh I I am uh like all the transactional data stays on ZK AVM itself it's just that the summary is posted on ethereum right so if you see ethereum doesn't know about that data but still it knows the state of ZK AVM so in that sense it's uh zero knowledge for ethereum right but uh to your point uh I think we don't have any plans for that because technically uh if you want the whole chain to be zero knowledge that that'll be that's actually the role of Consortium or uh private blockchains right and uh as you know our main vision is to scale ethereum which is a public chain so we are going to have a public chain yeah got it I mean you can have a public chain also in which you have uh zero knowledge based transaction I think I think Aztec initially was trying to do that or something like that uh but uh but yeah like that completely depends upon how what what the plans are um but yeah thank you ex uh so through jkm we are creating a JK proof of our smart contract can we say that no you you uh technically you can say that uh you you are technically just creating a proof of the latest state of ZK AVM and then posting it on ethereum so that ethereum is aware of the latest state of uh ZK AVM this is uh this is uh you know this is very useful when you are uh bridging basically so to bridge if you see if you want to do it from ethereum to ZK avum you can just uh ZK avum can just fetch the state of ethereum and know that you have deposited your funds right but in order to withdraw back to ethereum ethereum Smart contracts or ethereum should also know be aware of the state of ZK AVM right so that is done via the ZK proofs okay thanks thank you hello yeah yeah so from my understanding uh so it's like we are having a normal polygon chain and this zero knowledge chain is like a different one right yeah uh both are uh you know very different so the zkm is uh is a rollup and uh that's traditional POS chain this uh this works on a consensus mechanism known as proof of efficiency yeah so yeah uh completely different chains yeah so my question is like uh just from a perspective of one Who develops the dabs or just a contract so when can I like decide uh okay this is the right time to do use this zero knowledge uh chain so like uh can you give like uh maybe a direction like Yeah so basically if uh you still have a lot of transactions or uh you don't really uh if if if let's say you are building a Dap uh in in D right or you're building a d product then security is very essential for you right you don't want your funds to be uh you don't want someone to steal your funds or go somewhere else uh I'm not saying that P is not secured but zkm is much more secured than uh P right so uh the thing is that uh if if security is your thing you should go for ZK AVM but use case some use cases like nfts where you you uh want uh a lot of transactions and uh if if you see the uh the gas fees it's still uh the gas fees on POS is cheaper than ZK AVM right so if you want to go for uh like bulk transactions and low gas fees you can select POS actually our uh one of our use case is like we want to include a lot of nft meeting so would you suggest like go for the zero knowledge change yeah you can totally go for ZK evm in that case uh it'll work totally fine okay thank you cool EXC uh uh can we visualize the JK Pro any like what is the JK proof of our smart contract and can we verify the JK proof we are generating is actually representing our smart contract is there any way of doing that uh so you're basically saying of of your smart contract yeah like uh our smart contract we are creating the J proof of smart contract so like can we say is there any way to verify that the group we are creating is actually mimicking the smart contract of like okay so so the you're not creating a proof for the smart contract you when you are transacting with that smart contract you're creating a proof for that right and then basically uh when you're submitting the proof so let's say uh uh let's say you send a transaction and that changes the state of uh ZK AVM right now for ethereum to be aware of that state you are sending that uh uh proof there so yeah yeah I got it yeah thank you uh yeah can you hear me oh here yeah y so you mentioned that um you have some certain op codes which are not compatible with the zkm right it's it's just three uh pre-compile op codes other than that all the op codes work are supported yeah like so how can we know which are those op op Cod so we can like you know avoid it in our contracts when deploying yeah so for the that you can just go to uh vicky. polygon.com so there the quick start guide to actually you can find the RPC details about uh the test net and ZK AVM and if you go to FAQs and you go to evm equivalence uh yeah you can just see that these uh pre-compiled are not supported it's sh 256 Blake and pairings other than that all the op codes are supported thank you any other questions still have three minutes actually I'm uh trying to build our dab d daap uh which is trying which is trying to run a job for and that job will be containing hundreds of transaction so can I do that in uh zero knowledge uh zkm you mean yeah totally okay because in main ethereum main net the gas prices are exorbitant yeah so if you see with polygon zkm uh the trans uh the transaction fees are very low as compared to ethereum so even if you see the contract that I deployed uh it's it's like only it's 0.0025 uh eth is the transaction fee uh in case of ethereum it it would have been much uh much more than that yeah so you you can totally use ekm for deploying It app

Automatic transcript — names and jargon may be misspelled.