L1SLOAD Cheatsheet Master Direct L1 Reads for Your L2 dApps - ETHGlobal Bangkok 2024
ETHGlobal·Thu, 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
hello hello hello yeah wait hello hello can you hear me I think yeah now now there is s hello guys nice to meet you uh welcome to Scrolls Workshop uh I'm Vincent from scroll Devo team and today's topic G to cover l1s load which which is a super powerful pre comp that allows to uh Direct Read l data from your L2 contract and you can integrate this powerful feature uh into l2d Apps and uh make some very create create creative features 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 L1 SL load it is called L1 SL load so you have to have some basic knowledge about L1 and L2 I will go this very quick because I guess you are professional hackers you you know some some uh some basic information about it so uh in order to solve blockchain tra which well knowns 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 crat 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 rups there's two achievement to build up rups One is using fra proofs also known as optimistic rups another one's 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 tube based on uh serum ecosystem so we can Char characterize scroll as ZK rups instead of The Optimist rups they're using fra proof and have longer 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 a 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 of the ZK rups for now and this is the typical uh structures which the ZK rup looks like you have a sccer uh uh it's a it's a duty for sccer to produce blocks arrange the transactions order and then you uh before you submit to back to L one to do some verification you will have your approver to generate at 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 prove many blocks for example for now scroll maybe one bundle of scroll uh Z key proof can prove over 10 blocks for now and you will you will pass your the key 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 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 ler one especially oner is super secure and is 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 to which you can access the data so that's why we come up with this idea of L1 pre compile because there are so many layer TOS 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 charger let's give you you only need to make your change once all the other layer to can reflect in the change and make some uh very fun uh very F functionality for example if I holding a special token on layer one uh and if I um gain more tokens on on different Layer Two 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 too it is quite hard for people to maintain their Own stat on different layer too so we finish this part and we'll Ure you about what is l1s 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 this is currently now RP instead of our EIP is still in proposal uh stage but is proposed by one one of our co-founder and our CTO hin you can check the details of this proposal under uh RP 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 uh some key information stored on layer one is so-called ethereum and we have two different layer to to can access both access that layer one so for example if I store my key a on layer 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 no encounters a core of the L1 SLO pre compare uh it will go verify if the input is well phone if this W phone is go actually to call uh eum or layer one block RPC cury 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 examing 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 extra uh slope that you want to read 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 divided by slot and ordered one by one with with your order of keys and each of the return slots data contains uh 32 bytes of data and this is a very simple usage when you try to integrate your uh integrate uh L1 SL Lo into your smart contract you can just basically first you need to load the address of L1 SL because it's a pre comp 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 layer 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 doing our demo time and before you actually can use it uh you need to get some testnet token because L1 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 slow devet 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 tet 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 a1s 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 withs 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 0.1 test token for free and I will leave it here uh 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 by doing it 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 provide two smart contracts for you one is called let's scroll token contract which I going to put this uh put this contract on the layer one in this case it will be on eum testet sapoia and then I will use my A2 consumer contract to retrieve our storage data on the let scroll token uh what 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 librar 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 mean 1 million of LTS token to the message account which are going to be my account and let's let's let's examine air2 consumer also uh it is it is actual a 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 radi you can find another details about it it is a powerful it's also a powerful pre compare it provides you L1 block States on Layer Two but we will focus on Layer Two SL load or L1 SL load pre- compel for now this is uh the address of the L1 SL load pre compare deployed on scroll defet like I said it is fixed number so you can just import it and this is the 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 generated from chat GPT if you like to use now here is a 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 in put it will return five things remember we uh when you call L1 s Lo 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 get 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 slow number actually is arranged by orders so it's starting from zero to 1 two 3 4 because I have five 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 recall 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 RS lot 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 zly erc20 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 will 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 are first do um K check K check K check with your uh account account address with not number which is zero you do this quick hash function and you then you get your really uh account balance slots so it's it's whatever it is so I put it 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 something 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 unit 250 u u integer 256 so basically you don't need to do a uh 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 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 only retrieve 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 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 compare compare Layer Two 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 it 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 defend you can also call it L1 SL it doesn't matter uh 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 L L2 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 input so I will put myself as owner and I click deploy and I will uh I will click confirm now we have deploy our l to 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 one uh our let scroll token it will have uh 1 million LT s to the Minter okay to the to a contract Creator so go back to our layer one contract address and put it as a input and because myself is a only owner of this token so I will put myself as account to it I 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 zooming it up zoom in a little bit now so first uh just recall to ERC 20s like those variable first is a balance of your account the second is allance because currently we I do not give another any allowance outside so it's zero and second is the third is to toal 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's scroll and the token 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 sepolia but actually I retrieve data from sapoia this token is deo onia 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 imported 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 yes it's 1 million LTS that I have hold now I want to transfer this to the others I would just send I randomly choose the account maybe I will I will 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 uh 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 lay one is 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 def net does not support either scan so we have to use our own block SC built by it okay that is also provided in our L1 slad 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 uh this is my account address and let's check this contract creation should this this 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 transaction 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 cuz 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 you 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 def net instead of sapoia now let's retrieve this again now now you can see the owner is myself so I think this one is correct and let's retrieve all can see the the the balance of it is actually changed it's not one million again you can read it so uh that's how powerful the the want as load it 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 give all of things up because our time runs out so uh in in East Global in East Global we have provideed two bounties related to L1 SL first is best Innovation on scroll it provides 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 for l1s load it's no matter what type of the IPP you have integrate with l1s load just deploy and uh try to show us the evidence that you actually integrate with l1s 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 what
Automatic transcript — names and jargon may be misspelled.