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

Loading player…

Scroll 🛠 Getting started with the Scroll Messenger

ETHGlobalWed, Oct 9, 2024, 12:00 AM

In this ETHOnline 2023 workshop we will take a look at the scroll architecture a zk rollup and deploy smartcontracts to interact with the bridge. ETHOnline 2023 has grown into one of the most exciting events on our calendar, anticipated by hackers all over the world. ETHOnline is a three week long online hackathon with over $200,000 USD in prizes as well as a series of curated summits, celebrating some of the most significant happenings & learnings from the past 12 months in web3. ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

[Music] thanks e Global for uh having me as scroll excited to talk to the devs uh about the scroll messenger and also deploying on scroll uh oops Yeah uh so we're gonna talk a little bit about zero knowledge and scaling ethereum being uh that the the reason why scroll is into space what is scroll uh talk a little bit about rollups and then uh will dive into the bridge side of things which is the scroll messenger short intro about myself um you know I'm Raza uh coding nerd you can find me everywhere at Raza codes and definitely check out scroll. uh as a quick uh uh notification to everyone if you have a question or anything is not clear please feel free to interrupt me uh would love to answer anything as we go uh and also a quick reminder on our prizes we've got 20K in prizes a price pool of 4K which means you just deploy and verify your smart contract and you're already eligible uh for a part of the price pool we've got three prizes of 2K per team and 10 prizes of 1K per team you can read the criteria here they're also on the eth global website um and if you have any questions regarding them feel free to approach me either on Twitter um and or we have a telegram Group which I will uh just quickly share inside uh the chat so if you have uh if you have a need of let's say testet e or if you have any any questions feel free to join this telegram group and uh the there the scroll team will be there to answer any questions so let's dive into it ZK rollups we're going to talk a little bit about rollups uh and and the distinguishment between rops ZK rolls specifically as mentioned by vitalic the holy Grill of scaling Solutions so very quickly what is a rollup I won't Dive In Too Deep I mean crypto Twitter is always added uh and everyone has their definition but simply put a roll up batches transactions off chain so not on an L1 L1 being ethereum and then post the resulting data on chain meaning in this case L1 ethereum so how does it solve scalability problems well an L1 doesn't need to re-execute the transactions uh however uh an L1 does need to prove that these transactions has been have been processed correctly and typically there are two types of proofs uh validity proofs which we will talk about and fraud proofs if you're familiar with optimistic rollups they utilize fraud proofs and they work slightly different but we won't talk about optimiz scroll UPS in this talk as the talks the time is obviously limited so validity proofs are utilized in a ZK rollup a ZK rollup submits transactions together with a ZK proof that the transactions are valid and a ZK roller will generate this ZK proofs primarily to prove the states and that everything uh is updated correctly so ethereum knows hey um the transactions are correct but how does ethereum know it well that's because on ethereum there's a smart contract that can verify the transactions uh sorry verify the proof uh along with the transactions that are posted on that smart contract so typically speaking if you look at the ZK RS space right now this is a graph from the article from vitalic where he explained the different types of ZK VMS ZK robes out there uh I usually like to look at it simplified like this and I'll touch upon in a moment why this is important so typically speaking right now if you look at all the different types of ZK rollups you can either be very close to ethereum I.E being evm compatible uh or there's a trade of be made in the performance the time to generate a proof now what does this mean the to generate a a zero proof requires quite a bit of computation and overhead so if we go back you can see that as you go move down in the type IE you go closer to type one it takes a long time to generate the proof that's because if a ZK rollup wants to stay close to the evm I.E act and behave just like ethereum it takes a long time to generate the proof because of all the behaviors that needs to be proven that would normally occur for a smart contract in evm if you would uh pick a a different type of virtual machine the the trade-off is is that you know you wouldn't have an evm compatible chain but You' be able to generate faster proofs now if you look at the typical examples uh typical notif qualification it's usually evm compatible versus language compatible uh ZK rollups an example language compatible is starkware and ZK sync uh and evm compatible being ethereum so why would you choose for evm compatible even though it takes a longer time to generate proofs well that is because uh you as a developer will be able to use all your existing skills I.E U uh solidity uh Viper and your existing Dev tools just the way you would utilize them on ethereum so the major benefit of evm compatibility is is that even though the performance of time to generate proof takes longer for the developer the developer experience is much more pleasant because it's a lift and shift from what you're used to in the ethereum ecosystem so let's talk a little bit about how scroll works and this will be essential to understand why we need why we need a bridge something like scroll messenger in order to let's say move assets or send data back and forth so the scroll architecture like I mentioned before we a ZK rollup so on the first layer you can see here that's that would be ethereum where we have mainly two contracts the bridge contract we will dive out in a bit and the rollup contract on on our uh ZK rollup we basically have two different uh I wouldn't do two different layers one is a sequencing layer you might have heard of a sequencer this is a node that processes all the transactions so any user that interacts with scroll you would interact with it just like with ethereum it's just an RPC URL change you would send any transactions to that RPC endpoint and the execution node takes care of that what happens simultaneously is that there's a different network of nodes the proving Network that takes care of generating the proof and not to dive into to de if you have any questions feel free to approach me uh or or drop in telegram group but simply put what we do is transactions are batched into blocks blocks are batched into chunks and then we generate appr proof for uh every chunk and then the prover Network so this is done in a parallel parallelized manner the proving network uh generates a proof uh an aggregated proof over all these proof that are generated per turn sends it to the coordinator and that's sent to the rollup node and then the rollup noes sends it to the rollup contract and remember uh in my story I explained that if you have an L1 such as ethereum uh a rollup posts the batches of transactions on ethereum but ethereum needs to understand hey are these correct or not and so there's a smart contract on ethereum that has the ability to verify the proof that a rollup a ZK rollup also posts and that happens over here so that's in a nutshell how the scroll architecture works and over here you can see an overview of what each of these nodes uh do one quick uh comment I would like to make is that our proven Network today is actually decentralized it is permissioned but uh it's one of the things that scroll is very much focused on is that um some components right now are centralized most of some components are decentralized we're now on the road to making sure that everything will be decentralized and our objective is to make sure that everything's decentralized and permissionless so I briefly spoke about the the architecture and over here you can see a more Deep dive of the transaction life cycle again we won't Dive In Too Deep into this because I want to show to you guys how easy it is to to deploy on scroll the main benefit of being EV and compatible and then also dive to the bridge side of things so over here you can see a user just like any other user just sorry just like ethereum would send their transactions the execution note batches them together sends it to the rollup note which posts it on the rollup contract and side by side you have the coordinator that takes care of uh the that that coordinates the Prov network uh and the proof Network generates a ZK proof it goes back and the RO of notes posts it on the RO contract you can by the way find all of these uh uh images on on our docs but we also have a good explanation so whole transaction life cycle is documented probably something to mention is the phases of a transaction so I'm going to go back and forth between this slide phase one is when a user submits a transaction and what happens is is that a uh the sequencer basically processes these transactions and generates the block this usually takes two to three uh one two seconds and this is known as the pre-committed phase at this stage transactions are available on the ZK rollup the second phase is when the blocks of transactions are committed on L1 so before we commit the ZK proof we already commit the badges of transaction so that would be in this case over are you can see in a matter of minutes we commit the badges of transactions on ethereum and then the phase number three is when we have generated the ZK proof and committed and verified it on chain as well and that takes roughly 10 minutes now I just want to quickly pause here you might think hey 10 minutes that takes quite a bit of time and this is something that is being improved over time and we will see great things in the in the zero knowledge scaling space but the tra the the comparison is not necessarily Instant versus 10 minutes but 10 minutes versus uh for instance when you look at optimistic rollups where there's an arbit period now if you've know if you know about the arbitrary period um sorry if you don't know about about the arbitrary period I'm just going to briefly touch upon it which is as you might know in an optimistic rollup it's also a rollup commits the Bates of transaction and then there is an arbitrary period meaning a set of Def predefined period that can be either three days can be one day can be one week where anyone can challenge these transactions and if there's a fraud is there a malicious transaction a fraud proof can be committed so I know there is a whole debate about what the arbitrary period is but let's assume that it's around 3 days or seven days that's the that's basically the comparison to make that it's 10 minutes versus uh the the seven days or three days that that an optimist scoll up would uh have to uh be exposed to so um that was in a nutshell uh how scroll works now again scroll is an L2 ZK roll up meaning the it's a different blockchain network but it commits everything back to a layer one and this is a very important point that I will touch upon again when we we're we're going to go and talk about the bridge but now I want to quickly showcase to everyone how easy it is to actually deploy your score so I'm just going to uh show over here my code editor I'm going to launch here and I've I've set everything up um oops there terminal uh I just want to showcase um the benefit of evm compatibility so this is just a basic uh smart contract that I grabbed from the smart uh solidity by example website if you don't know it it's a great resource for you to look at solidity examples and it's B it's a basic ether wallet and over here I have a deploy script that will utilize to deploy this uh smart contract I'm going to showcase the uh hard head config and over here I'm going to I'm going to utilize truffle dashboard now if you know a little bit about truffle unfortunately it has been decommissioned or they're going to stop supporting it I'm still going to use it till the end my it's where my journey started and I think it's a great uh tool to use uh but we'll utilize the Truffle Dash to deploy and um over here I have configured the URL the RPC URL for spolia scroll um for local test if need be you can find these uh all this information inside our docs as well so what I'll do is is I'll just compile my contract already compiled it so stting to compile and then what I'll do is I will run this command which will basically launch uh send this the the buy code to the Truffle dashboard to deploy uh on Scrolls I'm going to just going to go ahead and pull up first the trule dashboard so you guys could see it as well and check if I'm connected to the right Network I am by the way a very easy uh way to uh connect to any network that you you would like is chain list so I'm just going to show that to everyone if you type over here scroll sapoia over here you can see the correct Network and you can click atamas I won't do that because I've already done that if you add it to metamask uh it's a very easy way for you to um uh add the scroll network uh to your wallet and by the way if you want to add it manually to your uh to your uh Dev tool this is a page of our developer quick start and over here you can see the RPC URL the chain ID everything that you basically need in order to connect to the scroll Network so I'm just GNA go back I'm just going to go back and remove this and over here you can see the Truffle dashboard I will go ahead and run the command go back to the dashboard and over here you can see that the transaction has been sent I'm going to click click on confirm metam M pops up confirm transaction and over here we can see the contract that's being deployed we'll give it a second and it's confirmed we can feel it on a block Explorer we've got an ether scan block Explorer and over here you can see 15 seconds ago uh it's a success and we deployed our smart contract so the same way you could do that if you've added to metamask uh the the scroll Network you can do utilize um remix for instance uh and it is as easy as that to deploy on scroll it's just an RPC URL change you copy paste and you basically deploy to scroll uh if your favorite dev tool is maybe uh a because you like python or Foundry you've been red pilled uh and you like Foundry nowadays it all works out of the box uh the same way as well it's just an RPC endpoint change um so now that I've showcased on how deployers Pro I quickly want to touch upon Bridges so I've mentioned that am I good on time yes so I've mentioned that um you know scroll is a different network and blockchain networks are isolated I.

E a network uh such as L1 such as ethereum uh cannot natively communicate with an L2 such as scroll so enter blockchains and here is just like a a very simple example as an use case of what if you would like to transfer an asset from one blockchain to another well the way that happens is through something called Bridge contracts so one Bridge contract would communicate with another and the diff the specific methods of transferring the tokens you know they differ uh it could be that you know there are wrap tokens being minted uh there could be a different form of asset where this bridge contract actually holds specific ass assets ear c20s and sends them to the uh to the users's wallet once the uh the contract has been triggered but you might see something missing actually in this overview because like I said blockchains are isolated so how do these two Bridge contracts communicate well that's usually through a third party service or a relayer so this is actually how a a bridge usually works is where a bridge has a contract on both sides on a blockchain a and a blockchain b also refers sometimes as a source uh blockchain and the target blockchain so the target blockchain is where you're going and then utilizing a relayer which is usually a service that listens to both contract and make sure that communication either in one way or both ways is possible and that's uh what the scroll messenger is the scroll messenger is a bridge and so over here what you see is what I'll showcase to you guys in the in the smart contract is we're going to send a message from L1 so a test net sepolia to the scroll test net and then we'll send a message from the scroll test net to L1 back uh to sepolia and we'll take that step we'll do that step by step now very important to not when I say message I mean that's arbitrary data meaning it's just any data if you would like to transfer erc20 assets if you would like to transfer an nft that's all possible and we've got specific guides for that right now I will showcase to you the bare bone version of this I.E any data that you would like to send from left to right I in this case from ethereum to scroll so what happens over here is and I'll show the code in a bit we have one smart contract and this can be any smart contract in this case it's called the operator uh that we have deployed on sepolia and what we want to do is is say hey from this operator we want to change the message that is on L2 inside our Greer contract now what will happen is is that we will uh uh tell this smart contract hey talk to the scroll messenger the bridge contract and we want to Target this smart contract and we want and then we send an arbitrary piece of data now when we do that we send a little bit of e and that has to do with the fact that when you send a message or a data from an L1 to an L2 the L the transactions on L2 have to be processed and the uh the the L2 messenger needs some uh e in order to update the state of in this case the greeter smart contract now you might notice saying hey you know I'm not seeing the third party relay and that's because when we go from L1 to L2 I'm just going to go back a couple of slides over here you can see that we have in our sequencer on L2 a syn service and what this does is it listens to the bridge contract and it pulls in any L1 transactions that are committed on the bridge contract and this is the scroll messenger contract on L1 so that's why in this specific overview you can't see that but this is a simplified overview so when we go back I'm going to I'm going to pull up remix remix here and over here have a set of four contracts I'm just going to go to the this one and I'm just going to walk everyone through the the set to uh to the set of contracts that delivered a message from L1 to L2 so I'm just going to open these contracts there's this contract and this contract so over here you can see we have a greeter on scroll so I'm going to go back that's this one this is our smart contract on al2 and the Greer on scroll looks something like this it's a very simple smart contract it has a variable where it say where where with a string says hello world and over here you can see um a function that where that allows this variable greeting to be updated now if you play close attention you can see that the variable is actually called hello world but over here when I call the variable it says hello world from sepolia and that is because prior to this uh session I actually sent a message from L1 to L2 and I'm going to show you how I did it I won't do it during the the workshop being that it can usually take up to four five minutes up to 10 minutes and at the risk of uh you know during a demo everything breaks I'm just going to Showcase how to how it works but again feel free to approach me or any of the team if you run into something so again we have a Greer contract on L2 and that's where we want want to change State when we say change State we just want to update we want to update some data some arbitrary data so I'm going to go and showcase the operator contract on spolia so this is on L1 and what this contract does is is actually a very very simple a bunch of things what it will do is we need to send we need to tell this contract what the smart contract address of this L1 Bridge contract is so that's what I done over here if you're wondering where you can get this information over here in the docs we have two places oh I'm sorry I need to remove um just lift this yeah we have in our docs uh all the contracts that are available on uh all our scroll scroll smart contracts so over here you can see the L1 and L2 messenger in this case I need the L1 messenger because remember I'm want to send a message from L1 to L2 so what I do first is this contract I copy and paste it in the scroll messenger address the second thing I need to tell uh tell the scroll uh Bridges is Which smart contract I'm targeting on L2 in this case remember we want the greeter contract and that is smart contract over here so I copy and paste that address we send zero value because in this case we're not actually sending any e uh to the Target address and over here you can see the greeting that I sent and we set a gas limit this gas limit just is pretty high I mean 10,000 would work as well but um and then the only G that actually be utilized um will be spend and then and the remaining will be sent back and so over here you can see that as soon as I click here transact which I won't do right now um basically what happens is is that the state on L2 will be updated and over here you can see that's what I did a moment ago quick side note again when we send it from L1 to L2 we want to send some e along doesn't need to be a lot but we want to make sure that our transaction doesn't revert on L2 and so we send a little bit e to L2 uh sorry to along with the smart contract so the transactions can be processed something that I've noticed right now I hav mentioned is the native currency on scroll is e and again evm compatible staying close to the ethereum ecosystem so when you develop on scroll you use eth as a native currency to pay your gas transactions the way you get your eth there is is um through the scroll Bridge uh or if you're just want some test e remember to join our telegram group and we will send you some so this is how we send it from L1 to L2 now if you go back to our slide and we want to send it from L2 to L1 there's there's one addition that we need to take need to consider now when we send the message from L2 to L1 ethereum needs to know hey uh first of all is this transaction uh correct or not and remember when when we look at all the transactions and then messages at the end of day is also a transaction they're batched together and they're sent to L1 so the ZK proof is generated for that as well but also on L1 we want to make sure that the user uh the correct user is allowed to withdraw uh any data so in order to do that on L1 we're going to need something called Merkle proof and so I'm just going to uh go back to remix and over here uh what I'll do is I'll showcase uh a part of our doc which is important to just dive in if uh if you need uh any more information but basically what we're going to do is is we're going to make a call we have a we have a relay service for this and what this does is over here you can see the API call that you can make is by sending the the the smart contract address of your operator you will make an API call and I'll show you what it looks like it looks like something like this and that looks like a lot I'm just going to increase the size of my screen and basically what it will give you back is all the transaction data uh that you will need to fill in in a specific page I'll show you that in a bit you will need to tell the L1 messenger uh smart contract messenger hey um I've got this transaction was either sent for me or is sent by me and uh I have the proof and that starts over here you can see proof I have the miracle proof to withdraw this piece of data and that will allow to update State and I think I've got a couple of minutes and then I'll show you guys a video of how it exactly looks like so over here on the E scoia if you click on the on the uh on the link inside the docs it will take you to the messenger contract and over here you fill out all the data and I'm just hope I'm not walking through this too quickly but over here you can see I'll quickly uh showcase a video that uh all when all your data is filled in what you can do is uh uh click on right and I will send the transaction and and over here uh and this will this can view the transaction and then once the transaction is sent as you can see over here I'm just going to click back again once transaction is sent successfully uh to the L1 messenger and the proof has been submitted over here you can see I click reading and it changed from uh hello world to hello from scroll all right uh we one minute left on the clock uh I'm not sure if there are any questions uh would love to answer some I hope this was useful I know it was kind of like a speed run but again I dropped telegram link any questions you have feel free to approach us we would love to help you uh super stok to see what you guys will build

Automatic transcript — names and jargon may be misspelled.