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

Loading player…

ETHWarsaw 2023: Marcus Wentz, Taiko - Workshop

ETH WarsawMon, Oct 7, 2024, 12:00 AM

Workshop - a workshop by Marcus Wentz from Taiko. Follow us for more updates: https://twitter.com/ETHWarsaw

Transcript

hi everyone uh I'm uh Marcus Wentz I'm with Tao and I will be presenting uh how to deploy smart contracts to uh Zer rollups so um I think someone in the audience at the last talk was actually talking about Huff is anyone did anyone go to that talk I'm just curious I guess they left okay so um yeah I'll just kind of first talk about Tao a little bit and then I'll jump into just some smart contract applications and then I can leave the rest of the talk open for just solity discussion in general we jump into any topic it could also be outside of City it could be like Huffer maybe some other EDM language so yeah Tao so what is Tao Tao is a type one uh ZK evm so we're trying to be uh ethereum equivalent as much as possible and uh we're trying to make uh all R nodes permissionless so we're running uh gu as our like main client and uh yeah everything is open source and trying to be permissionless so here you can kind of see like the X and Y AIS of the decentralized or centralized so it's permissionless up here and then type one equivalent and yeah this kind of specifies again like type one you go closer to ethereum but here with if you go to type four you have more optimization for uh the circuits right so first I'll kind of go over uh connecting to Tao right so if I want to connect to any one of these networks right so you have sepolia which is the L1 that we use right so we in our docs we have have a way to just click a button and then you're able to connect to any of these networks so this is our L2 uh Network and then this is our L3 Network as well but for Simplicity we're just going to use the L2 Network all right so we set up our wallet again I'm using metamask and now yes we set up our wallet now we're going to receive tokens so I already have tokens but I think uh the most popular faucet is this one you just need an alemy account and then you should be good to go and I think there's like uh a rate limit of like every 24 hours but they give you more than enough eth on for like a rollup okay so I already have those tokens but again you would just if you were to do this if you didn't have the eth you would click here drop your address here and then send eth but if I do this now it's going to yell at me saying like hey like you already have I didn't do the chapter but it's going to say Hey you already did this so I can't do it right now but I already have e anyway so now we can uh Bridge the tokens so if we go to uh any one of these Bridges so we go here um I would just specify a certain amount of eth to bridge from holia to Tao so I'm just going to switch the network okay so now I'm on sapoia and I'm going to bridge really quick okay so I'll let that run in the background okay so yeah so we set up the wallet got the tokens we're bridging now let's actually jump into uh some of the smart contract development so let me go back so we have most tooling supported so if you want to use tools like uh remix IDE hard hat or Foundry that's all supported uh for our block Explorer we do not use ether scan currently we use uh block Scout as you could see here and I think the brid transaction went through let me just double check I think it's just pending right now from uh yeah just have to claim it really quick so I'm going to sign a message for that okay I tend to put high gas on test Nets but um if everyone does that it'll cause a gas War so just be careful when you do that because it's like a domino effect so let's see all right so while while that's bridging I'll go back to deploying contracts here so I used to use hard hat a lot but now I mainly use a Foundry because it's just so performant and yeah I have an example actually in uh I think vs code let me just open this up so this is a very basic uh contract right so um this command will basically uh compile the contract and then deploy it using the block Scout API there was a there was a pretty big bug with this a couple of weeks ago uh because like with ether scan you need an API key but there's no API key for Block Scout so it's like you just have to with Foundry you have to put it with like the special like ending syntax and it should work but that was that was a blocker for I think a lot of like uh people using Foundry and block scalp to verify their contracts so I'm just going to run this this actually let me dive into this contract first before I deploy the contract here I have um a bunch of custom errors as opposed to require statements to save gas and here I Define the contract I tend to uh lock cility contract types not types but uh versions because if you could do something like this where you put like the upare to be like oh this contract uh version or higher but uh just so that I know what specific version it is later on it makes it easier to verify if I didn't ver verify it otherwise um if you change the version it'll actually change the bite code depending on the compiler version like maybe if you go up like by one or two it might not but uh if if there's a big gap it could lead to issues later on for verification basically so we have a bunch of storage slots here so this is slot zero this is slot one this is a slot two but it's not occupying everything so it's 32 bytes 32 bytes 20 bytes and when we deploy the contract uh we have an owner def find here it's immutable so we're not actually so I I misspoke this is not actually using storage this is uh just written into the uh bite code itself of the contract to save gas hence immutable but um I think if if it was constant you would Define it here but you put it mutable if you wanted to find it in the Constructor at a deployment time uh just a small note here you wouldn't want to put um I think there's another transaction. origin because I I read somewhere that if you do that you are at risk of being front run and someone can actually hijack your contract so it's why never use transaction. origin ever because like there's other like situations where someone could try to do external calls and break your contract by doing that and here we have a bunch of events these events have some arguments this one is index so you can filter for certain uh values and yeah so this function is just setting values it'll throw an error if you're writing the same storage value because you don't want to write a new value if it's already the same value it's pretty wasteful and then it'll write to it'll like uh s store that variable in the uh call data here and then it'll say okay like this is the person that called this function and then uh this is the new value that we had in call data we don't call it from the storage because that would be uh expensive so we're doing it again from memory and yeah I believe the owner so here we're just we're having a check to see like okay like the person calling this function has to be the owner otherwise it's going to revert for the customer and if it is the uh owner calling this uh this function then we're going to record what time they accessed uh this uh this function and the storage uh variable and then we're just going to emit that event here and I believe this is a just another function where so these are not sending eth because they're not payable but this is a payable uh function so if we put anything beside zero here and it uh had no payable then it would revert cuz you shouldn't be sending e to a function that's not payable right so we uh here I'm I'm saying like hey like you can't donate anything of at zero right so we're going to say like okay like you need at least to donate like one way to uh send eth and then here okay this is actually not recommended to do. transfer this is from a while ago this is uh so I'm going to update this uh at a later point but basically uh you would do instead of transfer. send you would do I believe uh call to the address itself and then you would check the state after to see like okay like hey like I have um sent The Ether in a call by forwarding it with all the gas and then checking that and if that isn't true that the Ethan go through then you would uh revert otherwise there could be opco changes in future e uh eips and could cause things to break so I'll update this example later on I have it on uh GitHub and then yeah just a minut an event if this transaction was successful so now now that I went over this contract actually one other thing I wanted to go over really quick is uh just this is like a test uh contract as well I'll just quickly go over this so we have like a fall back and receive function just so that like if there's call data or not we can forward eth so that we know um it's okay to send eth to it and yeah it's just setting up the contracts so we set up a new contract and getting get the initial States and making sure that all the revert paths are all the revert and non- revert paths are hit and all the storage values are expected so yeah now I'm going to just jump into deploying the contract itself okay so I didn't change the contract and I've deployed this contract in the past so what's going to happen with the block Scout uh verifier is is going to say hey I didn't verify this but uh I know there's already a contract that exists with the same bite code right so therefore it's going to be like I don't I don't need to spend more time uh doing that so to speak so let me go to uh the block Explorer block Scout we have a new transaction and let's see the contract practice here okay so the contract is verified but again it says the contract is not verified but it has the same bite code right so what I'm going to do is I'm going to slightly modify this contract to change the bite code okay so we're going to go to the contract okay and this is a new storage value so something like that I could just call it whatever and now I'm going to try to recompile this because it's going to be different okay so the compiler is running I'll just give it a couple seconds because it has to uh just uh be sent through the m poool and then be verified through the box how to explore but um let's see yeah here's the uh GitHub if anyone is uh Curious and again I'm going to update this with the uh call instead of transfer but I I guess in uh if we have time I'll change it at the end but I'll jump to other topics uh after uh this verifies and I go over another example okay so the contract was verified I think let's let's go to the explore okay good we have a new transaction that went through on my uh eoa from metamask and yeah let's see okay okay yeah I went through so now I'm actually going to do a more complicated example with zakres on how to show how to deploy a ZK smart contract so we're using a zero knowledge rollup and we have like a contract that actually has like some hidden information within it so this is a example that I kind of uh created because there was there was a YouTube tutorial uh for zakres that um was explained well but it didn't have like the like a GitHub link to it so that's why I I made this example it's also I believe on GitHub here so I'll just walk through this so here we have our uh circuit and again this is using the zakres plugin so by default you don't have this you just search for it and then it should come up here and install it but it's already installed for me all right so now I'm going to compile this actually no wait before I compile it let me go through a little deeper okay so we have our circuit our circuit starts here with def main so here we have uh four different fields we have just four inputs and they look like they're just like unsigned integers so we take in uh all these fields and for this example we're going to do 00 097 and then when we hash these values and put them into an array uh we're going to start like hey I know what these hash values would turn out to be without revealing Hey I what the inputs are so let's go through this so first we're going to compile the uh circuit and I think there's also various different uh proving schemes but I think the default is grth uh 16 so we're just going to go with that compiled so once we compil we can then compute all right so now we're going to take the values and the comments here okay so 0 zero oh sorry 0 0 97 okay now it's going to compute all right awesome it computed so now we're going to actually do the ceremony that's uh different so I think every time you generate this with this uh setup ceremony it should produce slightly different uh bite code for the evm because of the random it's put into it just going to hit accept it's just asking for consent to run certain files locally and remix IDE and then we just hit generate just going to give consent again okay so here's our proof so it's kind of like a large like array that's like coupled so now we're going to actually export the solidity verifier accept great so this is our verifier contract so I'm going to slightly modify this okay and just for Simplicity I'm going to deploy this within remix ID even though like I could I could run it through Foundry and verify it I just want to quickly do it because I'm already here so I'm going to actually deploy it within uh the remix IDE virtual machine first to show it works I tend to do that uh just for a sanity check unless it's like some type of contract that is dependent on uh stuff from like a fork Network then I would have to probably go to a test net like something like chain link you'd probably want to um deploy to like sapoia and then be like okay like these are the seoa addresses because it might vary or if you're on like a fresh Network like this in the remix IDE environment that those contracts don't exist and you'll just get like null data okay so let let's grab the the proof that we generated here and then let's see if we get true if we get true then it worked okay awesome we got true cool so now I'm going to deploy already deployed it locally let's actually deoy deploy it to Tao okay so we're going to do injected provider with metamask and because I want to go fast I'm going to just put in high gas all right then I'm just going to go to uh my my address on blocks you have to see when it goes through okay awesome I went through okay so I'm going to go back to oh I'm already on this tab for the deployment so again I'm going to just hit verify transaction and it get true as expected from uh the virtual machine for the uh evm locally so yeah that was about it for the demos that I wanted to go through but um I'm just curious like uh what is the like who who would would say from the audience it's like a beginner facility or is everyone like intermediate or Advanced uh does does anyone in the audience want to go over any specific topic with any solity application like multix or any anything like that or erc20 tokens okay let me see if so I'll just say this as a resource like uh one of my favorite YouTube channels for development is a smart contract programmer so he goes from like really basic to very complicated uh topics and he has various uh playlist for like how to do stuff or like it's like hello world or you could go to stuff like reentrancy or just like using custom RPC methods to call uh data that isn't it's like a private storage variable but in reality it's not private if you know what storage variable it's at so just various things that de new developers want to be aware of that are super super helpful so let's see uh let me actually go to soulmate really quick because this is a solidity repository that I've been using quite a bit cuz originally I used to just use uh op upine and I think op upine is great for rc20 and 721 one uh standards but if you want to get a little bit more optimization you know I think I think these are audited but um yeah there's just some unsafe math here and there so if you're using a yeah so if you have unchecked for example this is like a custom command where you can actually do uh math without underflow or overflow checking because before City 0.

8 .0 you didn't have uh safe math inally built in So you you're basically always at risk of doing that underflow overflow with every like math operation but like post U sorry at 0.8.0 and after uh you already have that but if you know for sure like hey like I know there's no way that I'm going to overflow or underflow then yeah you could use unchecked so like one example could be like hey like if you need to send ether to a contract uh to increase like a certain value then you're most likely not going to be at risk of going over U and 256 because like you need U 256 ether and that's that's a lot of ether but it really just depends or if you're doing like some type of like very small like bounded Loop like if you're doing a for Loop and you're incrementing like I like there's no reason to like uh check the math for I if it's only going to 20 or some very small value that is like deterministic so see I think one other thing I'll go over really quick is uh multi- signature contracts see I can find one yeah multi- wallet yeah so from a high level I'm not going to go through the whole thing cuz it's kind of long but we'll just look at the advanc go over some of the high Lev Concepts so uh the idea of a contract like this is like you have like like NOA safe has uh these uh kind of features where you have a set of like people that will approve a transaction as opposed to just one eoa where it's one signature you're good um and yeah so you you confirm these transactions and let's do a simple example so like a good starting point would be like let's say uh you have three different uh EAS but you need two confirmations right so you have some level of consensus as opposed to just like one person so let's assume that we have two confirmations right and then once we have at least two confirmations we can then execute because we have at least two people coming to a consensus saying hey we want to execute this but um the more the better typically like I think like having five eoas and like maybe three uh confirmations for consensus could be good too so you have an extra um layer of security with more wallets and um yeah this is very important because vitalic has an EA but he also has a multisig as well so he's a very big advocate for account abstraction so um I think that's about it unless anyone wants to talk about uh any slty topic or maybe Huff or any other evm type of uh topic okay well I think uh that should be it so thank you okay

Automatic transcript — names and jargon may be misspelled.