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

Loading player…

L1SLOAD Cheatsheet Master Direct L1 Reads for Your L2 dApps - ETHGlobal Bangkok 2024

ETHGlobalThu, Oct 9, 2025, 12:00 AM

Join us for a workshop with Chuhan Jin from Scroll titled, "L1SLOAD Cheatsheet Master Direct L1 Reads for Your L2 dApps." We’ll walk you through everything you need to know about using L1SLOAD, a powerful precompile contract that allows your Layer 2 (L2) dApps to directly read state storage from Ethereum Layer 1 (L1). Whether you’re new to Scroll or looking to enhance your dApp with efficient cross-layer data access, this cheatsheet will guide you step-by-step on how to implement L1SLOAD in your project. ETHGlobal Bangkok 2024 was a 3-day hackathon that took place November 15 to 17, 2024, and brought together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com

Transcript

[Music] welcome to Scrolls Workshop uh I'm Vincent from scroll Dev team and today's topic going to cover l1s load which which is a super powerful pre compare that allows to uh direct reach L1 data from your L2 contract and you can integrate this powerful feature uh into l2d Apps and uh make some very create creative feature playful features uh in your in your project and today's uh we will split our content into four different uh part I will went through I will go go through first two really quick because we have limited time of 30 minutes I want to reserve as many time as in our demo part I will show you some code example about how you use l1s load so uh first let's discuss the idea behind the l1s load it is called L1 as l so you have to have some basic knowledge about L1 and L2 I will go this very quick because I guess you are the professional hackers you you know some some uh some basic information about it so uh in order to solve a blockchain tra which will knows it is in almost very high security very high decentralized level and super scalable for every uh blockchain especially uh we know Bitcoin and ethereum has facing those CR those problem they are very secure they are very decentralized but they ability so in order to solve this we have build up Layer Two so-called lups there's two achievement to build up rups One is using fra proofs also known as optimistic rups another one is using ZK proof uh which means it's using mathematic equation to uh guarantee that your input is definitely correct so scroll is a ZK evm Layer Two based on uh eum ecosystem so we can Char characterize grow as ZK rups instead of The Optimist rups they using fra proof and have longer uh exess window because they have to uh pass the challenge time usually takes seven days but when you use ZK proof it can be verified very fast like scroll has very fast fality time uh for example if you withdraw your asset front scroll to eum L one it's only for now it's only take you less than 40 minutes and I think it's the fastest among all the ZK rups for now and this is the typical uh structures which the ZK rup looks like you have a screener or uh it's a it's a duty for scrar to produce blocks arrange transactions order and then you uh before you submit to back to L one to do some verification you will have your prover to generate uh zq proofs for your blocks and there's a special aggregator which can aggregate many many blocks together so that uh you only submit once but you can proved many blocks for example for now scroll maybe one bundle of scroll uh zy proof can prove over 10 blocks for now and you will you will pass your Z proof to a Smart contract as a verifier which Deploy on ethereum if it passed it can mathematically prove that all of your transaction within the blocks are correct so people people's transaction are correct then you can release your uh assets from Layer Two to layer one it's it's it's a very fast process but there's still many reason to use l1's data directly from an L2 why because uh there's few there's few Advantage first it's uh the data stores on layer one especially on is super secure and it's also decentralized guarantees and also um the the data on the layer one is also acceptable for all of the other chain blockchains or layer twos so once you accessing data on layer one you can also reflecting your change on different Layer Two which can access the data so that's why we come up with this idea of L1 s Lev pre compile because there's so many leres right now uh if you if a user want to manage account States uh the most efficient way I think is they both reading the data from layer one instead of on different Layer Two and they have to communicate with each other let's give you you only need to make your change once all the other Layer Two Can reflecting the change and make some very fun uh very fun functionality for example if I holding a special token on layer one uh and if I um gain more tokens on on different layer too if they can rate my balance on layer one and they can do a corresponding action for example if I accumulate my token over 1,000 I can get some free nft mint but if if you read data from another layer to it is quite hard for people to maintain their own States on different Layer Two so we finish this part and we Ure you about what is elb load so l1s load is a pre compile that I uh just explained before we want to enable user to directly rate L1 data uh through a in integrate with L1 uh l2d apps it is currently now RP instead of our EIP is still in proposal uh stage but is uh proposed by one one of our co-founder and our CTO hyen you can check the details of this uh proposal under uh rip 7728 and if you uh think it's very useful you can vote for it and we hope we can pass this to become a real EIP in very short amount of time uh this is basically idea um for for example we have the some key information stored on layer one is so-called ethereum and we have two different Layer Two can access both access that layer one so for example if I store my key a on L one and scroll both scroll and op can read that key and if I uh replace my key a to key B we do the the scroll and op Network can automatically reflecting this change without uh asking again because now they they're accessing Keb now uh let's go through some implementation details about l1s load you don't need to worry about too much I just want to emphasize uh the actual implementation which is under the uh this part uh explain you how L1 SL actually works so when the L2 node encounters a call of the L1 SL pre compare uh it will go verify if the input is W phone if this W phone is go actually to call uh eum or L one block RPC query to this one uh is get storage at address so basically it will fetch the data from the L1 uh node and then it will give you output buffer to your uh to which the smart contract or user called L1 SLO pre compare we want to also examine the uh how the input and how the how the output looks like and how the gas fee you cost uh basically right now the standard is uh it have the fix gas C 2,000 for each of the extra uh slope that you want to read you adding more 2,000 to your call and right now the maximum uh call slots per time is five it doesn't mean it does not mean from zero to five slots it's you can you can choose uh which whichever slot that you like but the maximum number of slots you can retrieve one time is five and the the output or the return type it looks like this it will divide it by slot and ordered one by one with with your order of keys and each of the return slots data contains uh 32 bites of data and this is a very simple usage and you try to integrate your uh integrate uh L1 SL into your smart contract you can just basically first you need to load the address of L1 SL because it's a pre compare uh this contract address is fixed I will give you the contract address later but when you want to use it you just call the address static call uh in encode with your uh lay one contract address and your key keys also means slot number if you know your slot number you can access whatever data that you stored on layer one I will give you code example during our demo time and before you actually can use it uh you need to get some testnet token because L1 SL is not available on scroll sapoia uh currently it's we we have created a separate uh test net for it it's called scroll L1 SL Dev net and we have special faet for it uh it is uh uh it is a telegram Bol uh if you want to uh gain some token you can scan this QR code and and uh you know get access to this uh both telegram group this is very easy you just simply uh type SL job with your destinate address then you can receive 0.1 testet token on it and we also create many useful reference and guides for uh using l1s load this is a very typical one and I think it's very useful you can scan a QR code at private to private provide to you and this is all the network setting that you needed to connect with scroll defet which uh L1 s load is available I will pause there for a few seconds for you to scan the code and I think everything's ready now we can start our journey with want s load this is a telegram group for a telegram group that I just mentioned uh here is just some use case you job SL job with your uh uh account address and then you can get one a 0.1 test token for free and I will leave it here probably uh drag it back to my main window and I will drag the uh my code example here oh it's to operating in different window is really uh challengeable but I hope I doing okay cool cool cool so I'm using remix it's a well-known uh web uh web coding Explorer and it's very easy for everyone to use it and debugging your smart contract I have provided two smart contracts for you one is called let's scroll token contract which I going to put this put this contract on the layer one in this case it will be on eum test net spolia and then I will use my A2 consumer contract to retreat our storage data on the left scroll token uh what I going to do I going to try to retrieve the balance of it and retrieve the name and token symbol on it and to give idea about how L1 SL looks like let's first examine this uh contract token contract in details so L1 L1 uh this L1 tokens it's um erc20 I have using the libraries from open zipling erc20 I will explain to you why I want to use it because uh I want you to be aware of some uh small things because if you forget forget uh that forget to understand the slot Arrangement then you may encounter into some trouble when you're trying to load your SLO and then I provide few V variables here and we're trying to retrieve them later okay but uh let's see what this contract looks like it's it's very simple when you deploy it it will me uh 1 million of LTS token to the message sender account which are going to be my account and let's let's let's examine A2 consumer also uh it is it is actual uh code example to using l1s load so for uh let's skip this blocks L1 blocks address first because uh this is another pre- compile we're probably going to cover it in the different Workshop or uh online video you can find another details about it it is a powerful it's also a powerful pre compar it provides you L1 block States on Layer Two but we will focus on Layer Two s load or L1 s load pre compare for now this is uh the address of the L1 Lo pre compile deploy it on scroll depn net like I said it is fixed number so you can just import it and this is a a customized by 32 to string function you can border the code directly and this this code example is also lived in our uh guides so if you go back to scan our QR code you will find this code code base you can just copy paste if you want to read some uh if you want to convert your B 32 to Strings I I I will not cover this details because um this code example you can easily generate it from chat jpt if you like to use now here is the important part retrieve all uh this is a function that I write by myself um it takes the L1 contract address also take my account address as input it will return five things remember we uh when you call L1 aslo it's maximum give you five slots per call so I want to retrieve all five uh all five data from my A1 account and I need to give the uh give I need to calculate the SN number first in fact it is very simple because it's it's it's it's all uh the SLO number actually is arranged by orders so it's starting from zero to one two 3 four because I have five uh five different variables I want to retrieve in instead of zero why I put this as account balance stops because uh if you call the erc20 let's go back to uh our let's go token that's one why I use erc20 because I want you to be aware ours slot one is not this owner it's actually it's actually it's actually the variables in this variable in this smart contract erc20 because we import open zc20 into our account into our smart contract so actually the the slot zero is this one is this one the slot one is this one the slot two is this one the slot three is this one the slot four is this one instead of our owner and receiver you will see it um later and also for slot zero it's a mapping structure it's mapping address to uh some number so it's not zero because when solidity compiler compile your mapping structure it we are using a very specific uh algorithm to contain the actual slots which I provided here first of all you have your base slot is zero like I expanded this mapping is placed on the slot zero and then you have to finding out the actual slot number mapping with your account address so we first do um K check K check K check with your uh account account address with s number which is zero you do this quick Cas function and then you then you get your really uh account balance slots so it's it's whatever it is so I put this on a zero and then we have one two three four it's just follow the orders and you can get all the data and then uh when you when you get back the data remember the data is row data you need to do some trans you need to do some conversion uh I I was using the assembly code to do the uh conversion uh because the first three are the units to 250 u u integer 256 so basically you don't need to do a actual conversion you just let uh you just read you just read it but for the last two it's h token name and token symbol it's string so it is time when we bring back our by 32 to string function you remember that conversion function that I uh expanded at the very beginning uh I want to transfer uh convert convert my by 32 to string so I use it and then I get a uh data back okay and this is for later uh this is just retrieve one it's only Tre only retrieve one slot number whatever the slot number you put it give you uh the result I will use this for another example so let's first trying to retrieve all and see what going to happen so I have deployed uh the last scroll token on the sapoia I guess 20 minutes ago uh this is the contract address yeah it's like 20 minut 12 minutes ago I would like to uh copy copy is this copy yeah copy the address first and then go back to remix I want to I want to deploy my L2 consumer and then so that I can retrieve data on layer one so let's do compile compile lay to Consumer cool and then I go to deployment be be sure that you on the correct Network currently it's on it's on spolia because the network I isn't a scroll dep net when you success successfully setting up your network you will be able to switching it through your metamask I will uh try to find yeah I call my uh customer Network scroll dep then you can also call it L1 SL it doesn't matter H let's check the check the chain ID again now it's correct so I will deploy it uh to deploy it I because I made my a A2 consumer ownable it's it's not manager it's just my preference because I do want do not want to clear deploy accidentally so uh whenever whenever I want to click deploy it requires me to uh put my owner as a input so I will put myself as owner and I click deploy and I will uh I will click confirm now we have deployed our L2 consumer and let's use it to retrieve data on layer one uh this one I it's one thing I really like remix because after you deploy it provide you the real smart contract interface to you that you can directly interact with so now let's go to uh retrieve let's do retrieve all to check if the data is correct so uh just just want you recall what we have done before so we deploy our L uh our let's scroll token it will have uh 1 million LTS to the Minter okay to the to a contract creature so go back to our layer one contract address and put it as an input and because myself is a only owner of this token so I will put myself as account to it I have will copy my account address and put into this input I just call it now you can see the uh output I'm not so sure if you can see it clearly Maybe I zoom it up zoom in a little bit now so first uh just recall to ERC 20 is like those variable first is a balance of your account the second is allowance because currently we I do not give another any allowance outside so it's zero and second is uh the third is total supply of your token it's 1 million because it has 18 digits so it looks so long and uh and then we successfully retriev the token symbol let scroll and the token uh token name let's scroll and token symbol LTS this is so powerful because it show you because currently I'm on scroll devet you see the chain ID it's not on spolia but actually I retrieve data from spolia this token is deo on spolia so that's the user case now I want to do some functions I want to I want to switch back to sapoia and transfer 1,000 LTS to another address and let's see if if the balance of this can be actually changed first I want to import that tokens yeah let's go back to our uh smart contract I copy I copy the address and I import the token now you see it's LTS right uh and has 18 digits let's see how many I have look like looks like currently I have 1 million yeah yes it's 1 million LTS that I have hold now I want to transfer this to the others I will just send a randomly choose the account maybe I will I will send 1,000 let's click the continue submit wait until it's finished at the meantime I want to go back to yeah it's finished uh I want to switch my network back to uh scroll devet so now I'm on the different I'm on the different network let's see if I can retrieve the change if the if the change successfully reflecting on Layer Two by using our layer one uh layer One S load contract but first because I switch my network my previous interface has gone I need to get it back uh but it's very easy if you click add St add address with your uh previous deploy smart contract and you can retrieve it back so uh because our uh scroll Dev net does not support either scan so we have to use our own uh block SC built by it okay that is also uh provided in our L1 SL guide you can find everything you need over under this guide uh including the block Explorer I have I have shared this QR code before so you can it should be easy to uh find it uh let's see this is one of our this is my account address and let's check this contract creation should this is one should be uh the one that I just created for uh for reading L1 consumer just in case I need to I want to refresh it to get the the latest one Okay click the transsection let's find the contract address I think this one is the one that we need okay so let's retrieve this interface back again let's see if it's uh let's check the owner I'm just I'm just assuming this is a correct one because my eyes cannot uh read it clearly but let's let's try retrieve it let's see if it works looks like this is not our account uh contract address let me uh re oh yeah because uh this is not this is not this is not at our uh scroll devet uh just be sure this is a common mistake that people would have do not you forget change your uh Network so let's go back to uh the actual Network now it's back to um scroll defet instead of sapoia now let's retrieve this again yes now now you can see the owner is myself so I think this one is correct and let's retrieve all you can see the the balance of it is actually changed it's not 1 million again you can read it so uh that's how powerful the L1 SL load is and based on that you can do a lot of you can do a lot of very cool features you see uh for example if you holding that amount of token on layer one then you can have a free means of nft so you can based on that you can you can do a lot of creativity things and I want to really quickly go back to my um back to my slides and give you some information about our Bounty so yeah let's let's give all of things up because our time runs out so uh in in is global in is global we have provide two bounties ready to L1 SLO the first is best Innovation on scroll provide maximum 10K USD at entire price pool if you have deployed your smart contract which integrate with l1s load and Deploy on scroll defet you will have a chance to win that Bounty and another one we have a specific track only for l1s load uh it's a best use case with l1s load it's no matter what type of DPP you have integrated with L1 s load just deploy and uh try to show us the evidence that you actually integrate with L1 s load and reading some L1 data through it then you are also have a chance to win and you can if you do that you can both apply for these two tracks to increase the chance that you win price okay and I will I will like because the time is up so I need to end up this thank you thank you very much [Music]

Automatic transcript — names and jargon may be misspelled.