EIP-4337 Account Abstraction introduces a new transaction model where users send 'user operations' to an alternate mempool, which are bundled by 'bundlers' and submitted to an 'entry point contract' for validation and execution. This standard enables programmable smart contract wallets that can implement custom validation logic (such as time-based restrictions, multi-signature requirements, or token-based conditions) through the 'validateUserOperation' function, while also allowing gas sponsorship and more flexible authentication methods beyond traditional private key signatures.
EIP-4337 Account Abstraction: A Solidity Deep Dive | ERC-4337 Wallet Mechanics & Smart Contract Accounts
Added:uh most people have already heard it or anything uh welcome to the new faces here um cook Dorado is like the local sort of a house for blockchain stuff um in Denver area um I mean every other Thursday meetups going on uh just hang out kind of happy hour thing at seedstock Brewing over on West Colfax I think crypto Mondays has ramped back up on Alternate Mondays so one Thursday is uh seed stock the next Monday is crypto Mondays and they're finding a new home for that slowly deep Dives on there basically if you want to know what's going on with crypto stuff it's a good place to start also a Discord Channel you can jump in talk to people hang out ask for things etc etc they are the people who brought us the Waterloo and the cold beer this time and the pizza and then bullet network is responsible for the space Colin I used to work there so he gets to show pull a network yeah I used to work there and my boss still wants that my old boss wants to still sponsor this I can kind of contribute to the project like here and there a little bit um but yeah Ebola network is like a uh on-chain accounting invoice payments payroll platform they were kind of the first folks to figure out like or maybe not figure out but just we implemented for the first time like oh like what happens if you nft an invoice you essentially own your credit that's kind of cool and been messing around with that idea hopefully the next month will actually go live with an integration with human Finance which allows you to get like instant access to liquidity uh based on like um certain like parameters so if you're a pretty good uh creditor you could you know Factor your on-chain invoices against like a D5 liquidity pool um that that we would sponsor or or yeah we might look at doing some Partnerships with um some bigger uh web 3 companies that are that are handling like payroll that could kind of onboard um payroll factoring but yeah that's what bowl Network's up to um it's also just tries to be a hub for all your transactions so we're about to launch a transaction Journal feature which helps which pulls in from all the ether scan chains that we support all your transaction data and you can sort of like uh Journal it and then save it in in Bola and then see kind of your your p l of the Year export export it like if you've ever made random erc20 transactions and have wanted to document what they were for you could use the tool to do that as well so it's like kind of like a personal finance Suite is what's moving into but does a lot of different things nice yeah I just did my crypto taxes so the more tools that help out with that definitely better oh dude yeah like last February it's like I don't know why I sent 30 bucks to this address that I've never like what was I doing yeah I may or may not have looked at a bunch of um GMX transactions and had no idea what was going on and so I may or may not have tried to figure out the thirty dollars that I chucked into there to get a token drop yeah right why not show up on somebody's uh oops well probably probably it did but maybe it didn't probably did maybe it didn't plausible deniability yeah this isn't recorded right yeah cool awesome well I thought if you couldn't tell Colin's the matching this behind all the actual knowledge transfer stuff here it's pretty casual um I'll let him kind of intro the topic and get us started on that but questions common side remarks are welcome pretty much throughout the whole thing um I think you know I feel like we're lights off people I'm gonna shut the lights off so it just feels a little more VR lights off more intimate and you can see the screen a little better yep sure cool true um yeah I've got the I've got a link for under the repo in the in the Meetup and uh yeah so today we are going to have a little chat about account abstraction um who here is uh has heard about count abstraction okay two three yep new four three three seven yeah here we are oh wait this is the auto report here we are so this is the EIP for account obstruction also uh could someone please sanity check the stream for me real quick to make sure that I'm I'm streaming I uh didn't do that a few times ago and now I'm forever scarred ah okay cool stream is good very good um okay let me just throw the throw that link in there um here we are the toss uh yep stream link and then here's the the link to just a forked repo and then I'll also throw this as a comment in here perfect okay sweet so uh yeah uh so most of us are unfamiliar with account abstraction 4337. so there's this issue of yeah this is like a pretty pretty um big change to to ethereum and how wallets will work I remember having the experience when I first started Consulting that like wow this whole dab thing is crap like literally you have to ask someone to download an extension and like set it up for 20 minutes before they can even use your app for the first time it's ridiculous so there's been a lot of discussion ever since like EAP 80 something um about like how you can have programmable accounts so the thing with uh how how ethereum works is your the reason why you have an account and the reason why you have a wallet here is you have a private key and a public key and that private key comes from that like very secret seed phrase that that you have when you set up your your wallet or your Hardware wallet um and that seed phrase will end up just being like a very very very big number that very big number represents a point on an elliptic curve and it's just uh if if you're interested in this like look into encryption web3 is what got me into into cryptography and encryption and it's you know the basis for the word cryptocurrency right is that your private key no one knows but you can derive a public key from that and your your private key will sign a piece of data and then anyone can verify um that that private key signed or authorized that piece of data without revealing what the private key actually is so that's just kind of due to the nature of elliptic curve and elliptic curve math is that you can prove that someone kind of holds a private key without the person having to actually reveal what that private key is it's how we have encryption it's how we have things like TLS it's how we have things like SSL it's what's it's it's what happens when you see this little lock icon on a on your browser right is it's kind of the basis for encryption is that like you know everything is is sort of private key based um and it's a way to to manage manage these secrets right so when you're signing a transaction you're saying I authorize you to deduct ether from my account and put this transaction on the blockchain on my behalf so that's what's happening right so when when you sign a transaction on ethereum you get a blob of data to your wallet your wallet takes all that data and then signs it with your private key and then passes it out the node will verify that your private key uh it will that the address that signed that piece of data relates to your ethereum address that's your public key um and then it'll post it on chain so that's like that's kind of how normally that's how the normal wallet setup works is wallets can do one thing is they can just sign transactions um they can I mean they can technically sign any piece of arbitrary data we put a lot of guardrails around wallets to make sure what they can and can't sign um but yeah so you can sign messages you can sign transactions uh but the point is really is that um private Keys sign transactions and those transactions go on the blockchain this would be changing the the the structure or not changing but but adding a new way for you to put transactions uh on the blockchain Via instead of transactions what's called a user operation so normally when you sign your transaction you put that transaction into a mem pool and it's just where kind of all these transactions float around until they get picked up by a minor who's willing to mine the transaction based on based on your parameters so this suggests a way for you to have an alternate mempool and so instead of having [Music] um the mempool uh let's see I believe there's a little more uh no I guess that was the only yeah so I guess instead of uh of your transactions going into a mem pool to get picked up by a miner your user operations could go into an alternate mempool to get picked up by a bundler who will then take a bunch of transactions and then submit those bundled transactions on chain so it's like an alternate decentralized mempool for someone else to essentially like relay your transactions on your behalf so this seems really simple at first but it allows for things like uh smart contract accounts it allows for you to basically create Wallets on behalf of your user it would allow you to deploy like um you know if your user gives you an email address you could sponsor the gas and have it deploy a gnosis safe with uh you know some sort of private key that will like end up being a signer on that safe that's that's that they still own right so um it abstracts this concept of of it allows you to start to abstract this concept of wallets and gas from uh from transactions so hopefully in the next like year year and a half when wallets really adopt the standard and push it forward uh we'll start to see a world where like you can authenticate with Twitter or with Google and you can get um kind of like a semi semi-decentralized wallet to get started in blockchain right like I think the the coolest part about crypto is that like you can kind of do all this crazy self-custody but self-custody is a massive overhead and it's really difficult to get right like it's all the horror like all the horror stories that we've we've heard about with wallets and losing funds and all my apes are gone right like all the memes it's uh the ux is horrible but this will probably give us like a progressive decentralization path towards allowing people to use a blockchain that is kind of has self-custody as a first-class citizen but also has this alternate route to get people onboarded right maybe you could have a wallet that's completely authenticated based on a session key right like a normal Json web token or right that says like I I allow this you I allow this website to make as many transactions for me in the next hour as as as uh as long as I'm logged into this website right so kind of the possibilities become a little bit um a little bit endless and so this is I think the gonna be the decided upon way to handle transactions um and yeah so my thought for tonight is that we would go through um go through the repo because actually besides the alternate mempool which is a bunch of node stuff um like ethereum node kind of client stuff uh it's actually mostly solidity contracts so that's why they I believe they chose this EIP in favor of um other eips is because um uh there were actually no underlying protocol changes to ethereum like there was another EIP that suggested that there would be a new OP code called off call which would allow um uh contracts to do things on behalf of other contracts which is not really possible now um so it's like consensus layer changes to ethereum where this doesn't have any consensus layer changes it's a smart contract and it is a well it's a couple different smart contracts it's a standard for a smart contract wallet and it's this kind of tertiary standard for what an alternate mempool would look like um and kind of for miners to become bundlers as well says do you know none of the other uh account abstraction phds are going to move forward or is that still TBD or like do the other approaches have like extra features that come at extra cost but it still might end up coming through yeah um I don't think I I don't know I like the honest answer is I I have no idea it just seems like the temp check is that this is the one that we're kind of all moving forward with um because there's like not any consensus layer changes um so yeah I think the yeah short answer is I don't know um I don't I also saw that on the off call one um that other EIP that I don't remember the name of uh there's just like a lot of Nefarious ways that transactions can be mixed together to be kind of dangerous and it's really hard with a turing complete language like or a tour and complete blockchain you know like ethereum to to introduce completely new ways of authenticating transactions while also not bricking any preview or uh or putting uh any current systems at risk right so um ideally develop well since developing solidity is dangerous as it is ideally we wouldn't make it more dangerous by introducing more complex architecture um and so I think this is like a pretty solid Way Forward because it just sort of abstracts out wallets instead of kind of throwing in a new way to authenticate calls into the blockchain oh so any any thoughts or um you got questions or before we before we dive in I feel like we could dive into the repo and then maybe even like screw around and try to make our own um uh 4337 compatible wallet even we have for the time we're doing those safe hackathon this month oh yeah that does all this stuff still sick nice yeah that would be great um honestly I got back from a work trip um just last night so this is pretty thrown together so we're gonna all have to kind of come together on this one because I haven't really looked through the spec a ton but um I like kind of understand the the frame of it and um yeah maybe we can just like seep into points of interest that people see in the code uh kind of once we have like a mental a mental model for it has a sound cool um yeah so let's look at the EIP real quick um because I think nailing the mental model first will be a good thought so yeah let's talk about let's talk about [Music] um transactions real quick so if you come to previous [Music] um meetups here you'll know that ethereum transactions like I said kind of have this like it's just a data blob and uh so it's like kind of looks like this right where you have uh you have a two field which is um you know uh so you have you have a two uh uh yeah so just to just to demonstrate here you have a two field which is like um string a from field which is uh oh yeah I can't keep the trust um so I guess this is like the layout of every transaction sorry I'm trying to gather my thoughts here so so really you have you have two you have value which is like a number that's the amount of ether you're sending you have data which is like kind of like uh a byte string of of whatever of whatever you want um and then you have uh uh like a signature which is the the signature of the wallet that that signed it um you have a yeah like a maximum maximum amount of gas you're willing to pay um I kind of forget all the EIP uh 11 something uh whatever the gas one added some new things in here which bases like you know Max uh base fee for gas or something but basically your wallet gets this like little transaction object and then you'll sign it and then it'll go to the mempool and if the signature matches what was signed then it you know the blockchain is down to include that so this instead of a transaction type we have like a user operation type now and so that's going to have um that's going to have a few a few different things oh yeah also I forgot this does have a nonce which is just the amount of transactions that your wallet has ever sent to make sure that like no one can kind of take this transaction and like um uh execute it multiple times because say for example if this transaction had the nonce of one this when you sign it with your private key the signature that comes back will include you signing that unique nonce and so if someone tries to use this transaction over and over again but they change the nonce to two right like now the signature won't match the data that was signed so nonses are are necessary to prevent what's called a replay attack so it looks like this is um instead users package up the action they want in their account and take it into an ABI encoded struct called the user operation which has the sender field which is like from has the nonce which is an anti-replay parameter has a few different things like a knit code so this could be like an optional initialization code of an account so like if it's this account's first transaction you could say like part of it's a knit code is like deploying a nose is safe or um you know paying five cool tokens to get a cool wallet right like it could be completely arbitrary right the cool thing about ethereum like bytes and ethereum is that you can package up these um these calls to just be executed arbitrarily and all a transaction is on ethereum is just a string of bytes um so next you have uh there's call data called gas limit verification gas limit which will get into the verification step in a minute um uh so this is the actual data that's being sent in the transaction it like really it's it Maps one to one to to data um and then uh you have um like a oh you might have a straggler nope that's my landlord I move out into my view yeah he will be a straggler um so and then there's some some gas limits that we see around verification we'll talk about that as well and there's also this concept of paymaster and then finally we reach signature it's kind of all this to say is that like a user will signify what they're trying to do if it's first time they get to signify also like some initialization code which will make this super flexible um it also specifies how much gas they're willing to pay for for doing that and then them actually their signature of of all this stuff right um so users send user operation objects to a dedicated user operation mempool which we talked about we're a specialized class of actors called bundlers so either you know block block Builders uh like miners right um kind of using running special purpose code or users that can relay transactions to the block Builders through like a bundle Marketplace so like you know it's kind of like a bid ask system where it's like hey I'm willing to pay this much gas or this much to include this transaction do it for me um and then it will create and bundle transactions uh they a bundler will bundle multiple user operations into a into a single call and then there is a handle Ops Call on a pre-published published global entry point contract so I guess I wish I had a oh maybe I could find like emp4 337 diagram because this would be super helpful for us yes perfect okay um all right so here we go uh so we have users which used it previously with just like submit inside transactions now they're signing or they're creating these user operations and they send them to the user operation then pool which is just an alternate Nimble these get picked up by the bundler the bundler will take all these transactions and they'll submit them to what's called an entry point contract so we have we not we're now having three kind of like three separate entities here we have users like uh we we have we yeah we have users we have this mempool and then we have this entry point contract so this is actually entering in this is actually kind of on chain right like this is we're entering into the on-chain domain here but this is a this is an ethereum smart contract called entry point which is going to exist at like a fixed uh address on every single chain um and it receives and parses and executes all these user operations so the entry point to the entry point is going to be this handle Ops function so like the bundler will submit all these user transactions to the handle Ops function um uh and then the entry point contracts will validate all the user operations to make sure that they they actually can be executed and then it will execute them all together so that's that's sort of this new architecture is it actually sends it to to a Smart contract instead um yeah so so there's going to be um the gas impact is going to be quite quite a bit bigger than uh than the normal um I I don't know it's it's so so right so like you have to do a lot of computation on chain to make sure that um uh the transactions can be executed and that you handle uh who executes them and who gets like a refund for for doing the execution but also if you remember the base price for an ethereum excuse me the base price for a uh ethereum transaction is like 20K gas so by bundling transactions you you uh kind of void that that base fee of even submitting a good transaction anyway so it's like it's going to be a little more expensive um but you know theoretically if you bundle a bunch of transactions it will be a little you know like you kind of make some of it back up in a way um so just to just to show show what this looks like this is the eye entry point interface so this is not actual uh code but this is like this is just the function signature so it takes in an array of these user operations um and also like the beneficiary to receive any kind of fees um and then if we go to the actual uh entry point contract itself in the contracts repo handle Ops um yeah so it uh executes a batch of these are operations um yep uh uh so it gets the Ops length and then it uh I guess creates this new user Ops info and so it will looks like there are two we see two four Loops here um it validates the uh it validates prepayment and then also uh there's this concept of uh paymaster which we haven't talked about yet um and then so it will essentially it just has two steps right for all the Ops it validates them and then it executes the the operations and then it will compensate the beneficiary so it's kind of the basic structure is uh I guess is is everyone like following are we clear on that cool yeah um so kind of like we discussed uh the entry point is a Singleton contract that will exist at one fixed address and it just contains the logic for for validating and for um uh um refunding the sender or any any address and it's up to the bundler to choose which you know which transactions are going to be uh economically viable for it right so you actually have to you have to create you have to in the same way like you can submit transactions to the ethereum mempool and say that you're willing to pay zero gas for them and they'll sit in the mempool until they expire right because you're not actually creating it's not a good bad ask system this will be just the exact same way um so it's really flexible here because it it tries to create like an open market for like um economically viable user operations that either I'm willing to front the cap the cost on myself because like I want to onboard my users and I just got their email address and I want to spin up an account for them or like you just kind of like send them to the Sharks and allow users to create uh transactions that like maybe I want to pay my gas using usdc and I'm willing to pay an extra 30 cents bump to make that happen right and if a bundler finds that to be economically um like interesting uh because of the current like gas environment and you know usdc is great so uh you then they would just pick up that transaction and execute it is the bundler getting a reward for submitting because you're describing like where the gas fee is but normally right yeah correct yeah so it's it's arbitrary right the bundler could so the bundler in this case could be um the bundler in this case the the person calling handle Ops could be um could be the beneficiary that would probably make sense in an open market uh the beneficiary could be a zero address right like saying like there's like no beneficiary because there's like like I'm paying for this operation um and all my user operations actually don't give this person any refund um or uh or like the beneficiary could be any yeah it could be any address right like I could ask my friend to be a bundler and send them a transaction and they really on my behalf right so it's a it's a completely flexible open market it just builds it builds the rail for people to say hey like there are these user operations which would kind of protect and give users flexibility because users want to do stuff on chain and then here are the rails for how users might refund or create a market now go play go figure out how to make a market go go figure out whatever you want to do whether it's you do like a um you know whether you drop your operation and your signature to your friend in an email and they call handle Ops for you because you have gas or you submit it to this alternate mempool the user operation mempool it's totally up to you um because you mentioned like paying your gas in uscc like how yeah uh let's Let's uh let's crack into that actually it's about F12 and it compensate great no definition found um here we go so uh compensate with an amount so oh I guess compensate can't be the zero address so looks like um there's a there's a beneficiary for every single uh handle Ops transaction and then it just uh this drug in here is just solidity um speak for send this person ether uh and then um it just requires that that ether success uh ether transfer was successful so it's not yours in 2013.
um so what someone just used this interface so so it this is a way to handle like native tokens but I think we would have to go one level deeper right so I think we would have to go to the execute user operation because that might handle how payment is actually executed maybe part of the user's operation is his swap to the bundler from uh from from you it like maybe maybe part of this user operation is at the end of the user operation I'm actually going to I've signed a Transat a pre-signed a transaction to swap usdc for eth and send it back to this contract which then compensate calls and like returns to the bundler at the market value at that time right and the bundler decided that that was economically viable at the moment that it executed it and was willing to take up that transaction so like I I bet you it's handled on a meta level not on a not on a level that is um explicit here we've been building with it so gelato is more than one of those trying to do a lot of this they have a loud tokenist or now it's wrapped that might be it actually really like so no way yeah you're grabbing the erc20 unwrapping usually 20 yeah and obviously there's no risk there but I think what Colin said and eventually maybe swaps it wheelchair right yeah yeah that'd be I mean it's gonna be an interesting world right because you're saying like hey do this transaction and then also I execute a market buy for you to like swap my token in a native token to sponsor this transaction back into the native token so I I don't really know how that would look but um there might be some there's some samples in here that we can go through and that might have some some examples um uh there's also this uh uh there's a idea of a paymaster which I didn't go into I just went into the entry point and to the base contract stuff um so I think uh from this point I think seems like we all sort of understand that they're these user Ops they get picked up by a bundler whoever that bundler is they throw them into the entry point contract which then validates that the uh the the user operations can be executed executes them and then handles any sort of like refund um given that what sounds interesting to people to to dive into we have here are the core contracts so like base account um and the entry point um and the paymaster it requires the paymaster I believe has to have a certain amount of stake in the entry point in order to refund transactions so yeah I don't know if people are more interested if we want to look into what like a base account looks like for the wallet abstraction code itself or do you guys want to look at um this entry point contract or do you guys want to look at figure out like what the heck a pay Master is but these are these are kind of like the five or five things we're working with here so the samples certain families that's the example of what there's a token paymaster oh yeah so okay cool yeah so here's some of the here's some of the samples right looks like there's some with gnosis safes there's one that does uh uses BLS signatures instead of ecdsa signatures um there's one that uses I guess token callback I don't know what that is um yeah one that uses safe nurses safe um we we have a sample account here and then uh a token paymaster so we can look into all of these as well probably looking at the implementation the sample will give us a clue um into how the underlying thing works so yeah uh thoughts thoughts guys consensus here account abstraction would be cool to look at yeah the actual uh base account itself yeah how does everyone feel about that yeah cool yeah I think that sounds like that would be the meat and potatoes of this um the rest is kind of like infrastructure layer stuff so I think it'd be really interesting to go into base account as well uh and then maybe even like screw around and make our own um base account uh so okay as we go through the base account code um feel free to stop me at any time if something doesn't make sense or if you're curious about like a solidity design pattern um this library is super great the guy who made this uh is a wizard he's been working on eth for like uh since 2018 he has worked on a bunch of different projects um he's been a software engineer for 30 years and uh yeah it's very very sharp sharp guy so you'll see a lot of patterns in here that are nods to other eips that are solidity best practices so this is going to be like cream of the crop kind of stuff to be implemented at an ERC level uh so yeah feel free to stop and um we'll all learn something maybe we can start at I uh the interface for for accounts first um which is pretty easy so it looks like there is one function on uh on the account interface called validate user operation so let's just read this real quick validate a user signature and nonce the entry point will make the call to the recipient only if this validation returns successfully signature failure should be reported by returning a constant this allows for making a simulation call without a valid signature so it allows this contract to simulate without failing right because that if you've had a con if you asked a contract if a call was valid by actually running it then the ethereum transaction would revert and then you would have to like Not only would you pay for that transaction execution but like um it might be dependent on another transaction and might be dependent on something else so it's completely delegating to the account itself if a transaction is is valid so looks like the entry point calls this validate user op and I believe I believe if we open up the uh entry point we saw this validate user opcall yeah so in part of validate account we do a try call to validate user operation and we say that you know validate this user operation with only as much gas as the user is specified in the transaction and then it passes all the parameters and then it handles all the all the try catching and all the all the errors and the validation itself so this is some this is some close to the metal code for sure is that um um let's look yeah a verification gas limit so yeah looks like n user op oh so that just means memory so they've moved the user operation from call data into memory um because they're just they're two separate spots in the evm um so memory is like memory is like a like a volatile byte array um and so you can put anything in it right and so it's up to the language to determine how it wants to use that byte array but call data is a separate space it's immutable and it's part of the transaction input so when a new transaction begins um every transaction that happens on ethereum a new instance of the evm is like spun up like a new frame almost right and any cascading call Will kind of do that same thing and spin up like a fresh frame of the ebm and part of that frame is the transaction uh call data right so like you could all you could do you have access to these things yeah like tx.origin uh you know message dot sender uh you know tx.data TX dot value or no message message.data and then message.value those all exist kind of as immutable in each transaction itself and so yeah I don't know if that was like helpful for anyone but yeah it just moves the user operation from this call data spot this immutable position um as part of the ethereum transaction into uh us into into memory where the user can mutate it and so if we remember if we go to user operation um part of the definition of user operation is the verification gas limit so you can imagine if why would I want a verification gas limit I guess let's just pose the question so uh first thing that I thought of is that like if I had a special account object which needed to check certain parameters on chain um like arbitrarily then someone could create a griefing contract which runs a for Loop infinitely and so when my account checks if if a transaction is valid and does a call to my uh to like the arbitrary contract it will run a for Loop arbitrarily and cause the entire call to fail essentially like briefing that accounts user operation because like um I like I can't use that bundle anymore I can't use that signed piece of data because someone created some sort of like verification flow that uh that ultimately is unexecutable I'm sure there's other reasons too but that was just like first thought best thought I guess um yeah so back to back to account right so we know we know that in the entry point uh you know in this in this for Loop without uh yeah in this for Loop validate prepayment is called and it checks and part of that validate prepayment call is the fact that it checks um validate the user operation on the wallet uh on the account sorry not wallet but account on the account that actually authorized the operation okay how's everyone feeling about that um yeah here this is uh I just wanted to make sure where is this validate user op I let it user off yeah so the sender right the sender is the user operation Dot message now sender I'm going to actually pin this user operation uh so that we have it available here as a definition so the sender whoever authorized this call notice online 404 it calls it calls that user to ask if this transaction is okay so it's like a layer of programmability um sorry about the noise tonight guys by the way a little distracting you just rolling with it I guess um yeah so must validate it so so this kind of gives us an arbitrary interface for what a wallet that you know uh an ERC 4337 wallet has to has to implement right so if we made our own wallet we did like you know con contracts our cool wallet we would say it is account right and then we would see that our cool wallet should be marked as abstract and the reason why this is such a crappy error message I hate this um maybe if we used uh oh yeah my terminal is broken for some reason maybe if we used uh um an npx hard hat compile we would see that oh yeah let me save if I use MPX Hardware hack compile I would see actually why so our cool wallet should be marked as abstract which is the worst error message ever but the actual it says note missing implementation so it just means that we were supposed to override validate user operation um but we didn't right so part of what an i what an i account is mean is is that it has this function and you know we didn't uh actually implement it so when if we write our own cool wallet um we would have to uh override this by taking the function signature and then we would say uh let's see it's external so we would call it you know external override returns uh un256 and then that should be and then we would looks like it would return validation data so it looks like there's a whole schema for not only is there a schema for user operation but looks like there's a schemer for validation data as well um which says like there is a there's an authorizer and there is a valid until timestamp and a valid after timestamp so it looks like we could say that something is valid we can say who validated it and we can say when it's valid until or when it's valid um and and or when it will be valid and when it's valid until so you could only execute it on Tuesday or you could execute it until um uh I don't know 2035 or you could never execute it right the user can actually sign on that so that's that's actually that's super cool yeah absolutely yeah um let's pop let's let's unpack some time stamping so yeah if we notice here that this compiles now so we get a bunch of warnings because we're not actually doing anything here but it compiles because I've successfully written an eip4337 wallet that enter that you know inherits account um yeah what do we want to talk about in terms of timestamp us yeah so the methodology say hey do this thing unless it's not until Tuesday it doesn't conceptually make sense on and steals the thing I can't ask the outside world for information except for oracles ah correct correct so um yeah yeah no I hear you there so that's that's super true and if you're a developer you have you have dealt with timestamps and they make you cry um so if we could write uh a cool uh just like a pure function here um uh I don't think the I think free functions cannot be um external so um we have this function called get timestamp and it returns uh returns un256.
so how ethereum um is synced to uh you next time so it's synced to um and it it synced to Epoch time so Epoch is the amount of seconds since January 1st oh my gosh yep clearly your headphones guy because that's like not even that distracting to me yeah I'm absolutely a headphones guy I'm an airpods guy I like air pods and white noise I want to hear nothing yeah exactly uh but anyway yeah so it's the Epoch time is the amount of seconds um is he is he yeah right it's pretty distracted um I'm trying to sleep with my eyes open standing up what do you do you should be running this meet up man what am I doing here I'm literally looking up what a uint is so no I should not be wrong with me though do perfectly valid um yeah sorry my brain is just getting pulled a million places but quick quick and dirty ethereum runs off of Epoch time so it's it's UTC right Universal coordinate Coordinated Time zero zero right and it's the amount of seconds since January 1st 19. uh 1970. right and so here's the current Epoch time we see it like increment in in seconds uh and there it is so this value is accessible um the uh uh the Via like a global in solidity called uh block Dot timestamp yeah so it's available via block dot timestamp right um some quick caveats to cover about blocked out timestamp it is it's it is uh manipulatable by the the executor by The Miner um to a certain amount like around like 30 seconds it can they can pull it up or down if they're the if they're executing the block um so you know it can be basically someone could buy a race condition is what I'm saying um by like making something execute a little bit earlier than you'd expect um so like use block number if you're writing a program that's dependent on kind of like the current time you were gonna say Dave so I think what you're saying is it's not actually my tongue monotonic across so second with the decentral like a floating window yeah centralized system though what I'm trying to figure out is if the validators all run this and their clocks are different how would they possibly agree on the execution well I mean I think that's that's probably solved in the consensus mechanism right because like I would assume that like part part of the node syncing to one another and the whole like Byzantine generals problem is probably sinking to you next time like at the very minimum right like if you can't think about Unix time you probably can't think about transactions sink though like I don't think they're doing like an MTP what I'm wondering though is maybe whoever's proposing the block puts a time stamp on it and as long as the validators agree that it's plus or minus the 30 seconds you were saying yeah maybe they just accept that and use so yeah oh yeah look higher than the previous yeah oh yeah yeah exclamation point three right so I'm sure that's in the yellow paper the consensus mechanism yellow paper that says like as long as it's you know larger than the last then you're you're good to go um so there's no ntp no you can trust in that space sure yeah yeah theoretically everyone's getting every single block couldn't manipulate it to be just one millisecond in here or one whole second yeah that's true but I think I think if you have um I mean you would but but the block number always has to be sequentially incremented and so that's more trust trustworthy I think I think the fact that like the same block Builder would be executing multiple blocks is actually impossible at this point uh because of stake but uh I I don't I don't know how the yellow paper implements proof of stake that's above my pay grade but but yeah uh but I think that's kind of like the tldr is like do not rely on blocked on timestamp or block hash as a source of Randomness or as a source of like hey things can happen up until now because people can kind of like buy their way to do something first um so it's not a fair mechanism uh is is the point um uh so yeah I guess I guess one one quick note about blocked out timestamp last last quick note um is it is if you have a struct a blockout timestamp normally is returned as a un256 which is way too much memory space for what you actually need um in in a time stamp uh currently you can use a uh you can use a uint32 timestamp and so if we if we do the math here if we say 2 to the power of of 32 um that is this large number here right uh oh wait two uh Mac okay if we say 2 to the power of 32 and then if I copy this value um and then uh maybe say drop it into a date object because I'm actually still a script kid at heart right so if we date object takes in milliseconds so so here's the amount of seconds right so you could say that the amount of the the amount of seconds that uh from now to or from 1970 to uh however long the space it takes to fill up an entire u132 it would take you to the year um uh 2106 right so that's like you know plenty of time to have a cool failed blockchain startup that only lasts three years but if you if you're if you're trying to like theoretically future proof your time stamps um then you can use a uint 40.
and so if you use you went 40 if we go 2 to the power of 40 you could say that if your program relies on like uh on on timestamps that that last until uh if your program has like a domain definition for what a timestamp is and that's typed hard type to you went 40 uh that could take you to the year either 36 000 right so um just like a quick note on typing is that like if you used a un256 that would take up an entire slot and you would just have a lot of wasted you'd be paying for a lot of wasted zeros but if you use a uint 40 you're pretty much you're safe um and I bet you uh I bet you if we search for for validation data um struct validation data yeah so they even use a un48 so there's plenty of time here uh and the reason the reason they're they're using this is because like they have this address here which is a un 160 and then uh you know a uint 48 and then a un48 uh that fills an entire slot so that's 256 which is 32 bytes which will be one slot in storage which means you're paying to write one time um versus if these were both 256s you would have your users paying to write three storage units in ethereum which would be you know three times as expensive so yeah sorry that was that was a little long-winded my okay cool good any other thoughts on on time stamp sir writing scripts to execute a bunch of ethereum transactions where broadcasts failed on some of them and and then like the nons like the non-spigette like messed up yes keep on going or whatever and then and then actually you could kind of Replay attack that if you knew like exactly where the transactions were because maybe now you don't want to execute like all those Trend not exactly a replay attack but like you could do a transaction that did like the nonce that was missing and then all the other ones would execute afterwards so you don't really want them to so like in a case like that having the hey only run this in the next 15 minutes uh is it is a nice feature to have yeah it's it's pretty cool um like like one thing that's definitely underutilized especially by wallets is that like part of the 2612 permit signatures which allows you to you know those annoying like excuse me erc20 approved transactions that you have to do normally they're annoying but they're really important they're bad ux but great ux at the same time because you still have all your money but uh that's kind of been replaced if you've ever done a a signature like a Gasol signature to a proof spend that has a that has a time stamp in it so it's um I forget what the what the name is but you'll see it in there as a time stamp and like literally unless you're a Dev and you know the spec you could and you copy it into your console and like create a new data object right like it's theoretically though it's a it's a way for you to specify the maximum amount of time for your token approval which I think is cool right you're like hey I approved this dap to use a thousand tokens but only for the next five minutes right it's like versus the whole infinite approval thing I really like narrowing the scope of approval and I think it'll make things a lot safer anyway drift oh so like what you were describing with the 30 seconds or whatever yeah but uh apparently the this month was stagnant and here the actual proposal I think is for 15 seconds 15. yeah okay yeah I like that I mean that makes sense because the you know the block uh each block it's about 15 seconds now at proof of stake it's like kind of locked in at about 15. the other thing uh that I was reading about here is it says from another paper that the actual time itself is the output of unix's time function so oh cool Unix system time nice which is nice with the exception that I mean today in existent time is a 32-bit integer assigned integer not unsigned oh so that means uh two to the 31 20 36 or 2037. so if we pour that below this up but sure they'll update it at some point yeah so so no that's that that's actually a great like computer science no we'll just like we'll talk about that right so like 32 bytes so like a uint32 is uh it gives you 32 bytes of member space to do stuff right after that because it's fine no uh you will you have one less you have one less bite yeah so you you when you say that something's an INT 32 instead of having 32 bytes of space um wait 32 bits of space apologies big difference instead of having 32 bits of space you have 31 bits of space because the first bit is used to determine the sign so if it's a one it's negative if it's a zero it's positive right so like if they're using sat if they're using side integers to do Unix time this is our new number because now we only have so we kind of have like one less exponential uh increase so yeah oh yeah that's the 2038 problem so if it's assigned if it's a signed 32 uh bit int then it'll only take you to uh you went uh well it'll only take you to January 18th 2038 38 but to the extent that ethereum is prepared for a larger amount of time at some point if Unix systems update to a 64-bit or something else and then it looks like ethereum would just handle it gracefully yeah so right yeah no true yeah I mean ethereum is built for that right like there are bigger problems like uh like we'll have to do uh post Quantum uh signature verification before we'll have to do you know un 30 uh you know 31 timestamps but like this is the Y2K problem right so like when a 31 uh signed integer uh overflows it will just add it'll it'll add one bit anyway so it'll be interpreted as as a minus so meaning that everything will flip to December 13th 1901.
um if you don't update so maybe maybe you'll find some fun Legacy systems on you know January 18th 2038 that that now read 1901 uh and you'll go back in time for a day and giggle about it think about this Meetup yeah right true maybe that's what it was about all along uh no but good good boy there um Okay cool so so here I think we kind of naively inherited off of I account usually you know we would inherit off a base account so this is the basic account implementation it provides the basic logic for implementing the I account interface which has the validate user op function that we're looking at the specific account implementation should inherit from it and provide account specific logic so here's that constant that we were talking about so this is an abstract constant right so like any contract that we would write inherits off of this with this abstract um uh like key here it allows us to do like weird things like Define function signatures without implementing them right so um this is a virtual function and there's no implementation which means the inheriting contract is forced to uh write its own implementation um same with same with entry point which just Returns the address of the the entry point um this validate uh uh user operation this is like I guess a um yes this is an external override but it's also overrideable itself because it uses that virtual keyword um so this in the simple case validates the user's signature and nonce um the subclass doesn't need to override this method it's instead it should override the specific internal verification methods so it looks like it should leave this method as is but override the required from entry point validate signature and pay pre-fund functions probably so this is probably let's let's just step through these real quick this is a this is a short file um so yeah it requires from entry point which means that like this is an internal function used in the validate user op to say that only the entry point can validate a user operation write that message sender equals the entry point um I'm sorry it went a bit faster the validate signature scheme this Returns the validation data which is encoded as we as we see here in the in the return data [Music] um we're supposed to override these validate and update nods oh yeah here so let me let me split this out um it told us to to override these internal functions and not to override this and here we're seeing these virtual stubs for all these all these functions that we're supposed to uh override ourselves right validate and update nons pay prefund um let's see sends to the entry point the missing funds for this transaction uh so so the subclass May override this function for better funds management if it wants to do something custom um but it doesn't it doesn't have to looks like so there are a few things that we're seeing here we're seeing um kind of like these uh these these stubs that the contract wants us to inherit off of um or sorry write our own implementation for whenever we inherit so I think probably the the next best move is going to be uh going into a quick base account or a simple account sample so we see how kind of everything is finally combined together and we can kind of make a 4337 wallet but any any thoughts or musings before we jump forward cool um looks like this is using the user operation lid for user operation which um that might be interesting to take a look at to I'm sure there's yeah there's there's ways given a user operation to extract certain types of data in here get the gas price looks like pack and unpack so you know how you kind of convert and manipulate this data to take a user operation and cast it down to a byte string how to Hash it um so just some like oh yeah this isn't the user operation file that we already had pinned so nice cool all right let's look at a simple account so samples simple account all right so looks like a simple account inherits base account um interestingly it has a it inherits a token callback Handler and it's also upgradable as well which is interesting so it says that this is a minimal account and it's a minimal sample account so it's just like a sample implementation it's not part of the EIP it has execute an eth handling methods and it has a single signer that can send requests through the entry point so like you know if my wallet was abstracted this simple account would be it would represent my wallet so looks like it Stores um the nonce and the the owner right so in the same way um we're kind of getting the exact same definition that we have in normal like uh ethereum uh maybe it's on my Brave browser um I think I have the ethereum handbook somewhere here but this is like the ethereum handbook is really interesting to uh to look over uh and uh ethereum handbook notion where is this I I put it I put it somewhere in evm handbook there it is here it is um but there's some really really solid uh kind of deep dives into how um ethereum ethereum works and part of the evm Illustrated which is really nice part of part of this is like how um like what is actually stored in in different types of of accounts um yeah yeah this is somewhere in here so an account yep so here's here's an account right every ethereum address now every eoa has a nonce and a balance and then um uh smart contract accounts have like storage hashes and code hashes which we're talking about storage hashes um for storage proofs but um yeah so we're kind of seeing this exact same thing happen is we're having like the owner which is like kind of the address actual the address itself and then we're also seeing the knots here as well so it kind of has its own ways to manage its own um nonce it's also storing the entry point address which is the address that's allowed to call it so it has a public view function for the nonce to see like what the announce of an account is which is pretty sweet currently like one limitation with solidity and I think maybe the evm in general is I don't think there's yeah with evm in general there's no way to get the nonce of an account so I couldn't say like address I couldn't say like you know message sender like what's the nonce of this account um like it doesn't it doesn't exist as a member on address and there's no way to call on on chain uh there's no way to read an account's nonsense you have to do it off chain um and so this is a nice this is nice because it's like a big Improvement is you could actually read the now the nods of an account so you could say like you know you could do like an airdrop or you know some sort of verification for people who have done over a thousand uh transactions right because like they're nonsense incremented um that wouldn't really be secure but that's neither here nor there uh this is interesting this is a receive function so this allows the smart contract to receive ether so we talked about this we've talked about this I think in length at some other meetups that we've done here but they're like there's a receive and a fallback function um every time you create a new transaction to send ether from one account to another the receiving account will be invoked and so if the receiving account is a smart contract account and it doesn't have code and it doesn't have code to handle that invocation um with solidity it'll revert by default so this is a signal in the solidity contract that says hey this contract is allowed to just like arbitrarily receive ether and since this block is empty it's just a no off so it does nothing you could do something crazy like you could you could you know um you could emit an event uh you know uh right you could omit an event that like says how much you got paid you could do whatever you want here um because you were in receiving ether you receive func you receive the function execution and you can do whatever you want but in this case it just handles The Ether and then passes back the function execution to the Kali uh this is a Constructor so uh just this handle is kind of the initialization of the contract um uh there looks like like kind of like a only owner modifier right um it looks like it has a function for uh execution so you execute from either the entry point or the owner which means that I could have I could hold this smart contract account so like imagine this simple account is like a Nosa safe right whereas like I have my own metamask wallet here right and this is my eoa um but then I could also create like a gnosis safe and do other stuff with it this is going to be the same thing so it's like kind of like a it's like a smart contract account that exists external for my eoa I could do things on here anyway as long as I'm the owner but I could also do things in a way that's gas abstracted if I'm the entry point um so yeah and what this execute does is it calls this internal call function um which yeah just calls the target with the call data and the call Value and uh Return To Success if it was successful otherwise it will revert so like this we're starting to see like some uh repeating patterns here from the gnosis logic um because kind of like smart contract wallets are are all pretty similar to each other uh for the most part um this is pretty cool this has uh execute batch right so like sense um I can do arbitrary things on this smart contract account I could also like execute batch transactions so I can finally bundle my token approvals and whatever I want to do into one transaction called execute batch which could be sponsored from an entry point so like this kind of we start to see these we start to see how um this is solved right how we solve these web through ux problems and we solve each Problem by writing these custom accounts so you know if you wanted to write a Social wallet then you would write your own sample account which inherits off of Base contract right and you can do whatever you want in that contract but part of it is you kind of create this like you follow the you follow the EIP Logic for what an entry point can and can't do in the same way when you want to make your own token you use the erc20 spec to say hey here's what you call when you want to say balance up here's what you do when you want to say transfer from um it's all kind of the same it gives you like a rough interface but then you can tweak the inner workings behind the scenes um so yeah so I think that that is all pretty this is the initializer function um yeah this is requires that the entry point is the message sender or the owner this will handle how you validate and update that nonce so notice how it asked us to override that stuff in the base account so if I crack open yeah so if I crack open base account on the right hand side and go back to this validate user op one it wanted us to override require from entry point which we have done not done oh that's already written here um it wants us to yep override validate signature so validate signature that's what we that's what we wrote and it'll uh and then it also wants us to implement this so if we say validate let's look at this validate signature implementation so in the entry point calls validate user op with all the user data um what this does is it takes in the user operation data and the user operation hash which is just like the kind of the unique identifier for whatever user operation I want to do [Music] um what it's going to do is it's going to use uh EC recover which is the elliptic curve recover basically it just checks hey given a signature and a hash who signed this and so that this recover call will return um an owner so it returns address right and it will this is using open Zeppelin's library but like you could you could do the built-in for solidity is called EC recover um and you would also have to split the signature into a V and R and an S so you take the hash and the r that s and the V because it's backwards in this case and this will this will this is like what's called a pre-compile contract and it just runs the elliptic curve the ecdsa signature recovery and it will spit out an address so it says hey this address signed this cache um and that's exactly what the node does as well so it takes when I do my transaction normally now it just hashes the data down signs it and then um checks that the the user is the sender and the user has enough balance and then puts it on the Chain so it looks like this is just kind of like a really simple one-for-one replacement of kind of like my normal eoa externally owned account wallet it's doing just the same EC elliptic curve signature verification and looks like it returns zero if it was successful and returns one if it was failed which that really bugs me because that's not it's not how you program [Music] um but yeah yes that's exactly oh seriously it's the reverse that way yeah one is on dude zero is off even on your Mac if you run something on the command line if you after if you type Echo dollar sign question mark yeah if it's a zero it ran successful if it's any other number it represents oh you're right no even in node yeah process exit one is fail and process Exit Zero is success that's yeah you're right dang there it is um but yeah I know we just hit time uh uh yeah that looks like a I guess like a pretty brief overview of like an implementation it allows you to I think I guess maybe just to recap right alternate mempool for these cool user operations which can be bundled by anyone and sponsored um it returns a uh I guess it defines a standard for like what an entry point is which is just kind of like this um executor right the executor and then it also defines the interface for an account which uh allows the executor to check if a transaction is valid before it actually goes and executes it on behalf of that account um you can write whatever you want in the account and I think really the powerful this is the powerful function here is the very last one right is you know validate signature is like you know you could write anything you want in here if the user has enough money if there's enough you know if there's enough multi-sig um verification as part of the signature if you know like it just the list goes on and on right you could do you could pass whatever data you want in the user app and you could pass however long the signature you want in the Ops you could write a signature on your own curve you could write a ZK signature you could um verify your signature against another function you could say this wallet can only execute if usdc depegs right like you can check any on-chain parameters you could check the time you could uh you could do so many cool stuff with this and it all kind of resides in this validate signature function kind of like I think the world is your oyster and this is like this is where you wanna this is where you want to handle all the all the cool custom wallet stuff that you could ever want to do so yeah cool thoughts final notes excited because I've been in a user experience space for since like Bitcoin days so I'm gonna work online the early wallets yeah right that continues to be the case it's like yes ux is so hard so hard even like he was mentioning we did like the whole Vega with the options platform part of what gets me inside is like hey let me make these things accessible and right a lot of work to make things yes there is only so much that you can do right okay I I am user and I'm trying to try not to do this and you say well you have to pick all these things I know because water is kind of like your entry point yeah it is yeah it is right you see that like connect with metamask page and you're like like one why would you name a piece of software metamask into why do I need it can I just like poke around your app and it's like oh sorry like we we need it for the provider and we need you to sign messages right it's like it's like we're still developing apps for ourselves you know yeah yeah right yeah exactly yeah yeah let me put on my iCloud back up I know it's uh yeah I like love this idea of progressive decentralization where like I mean we trust every day right for you to be that like plaid is secure enough for you to like pull in financial data and like execute transactions on in my bank account right uh you know PayPal authentication is is secure enough right like it we we trust these things every day in web 2 to get people onboarded and so like I think it's powerful enough to say that we can keep trusting those layers for now but like it's like uh we we lower the the barrier to entry uh but we still allow you to like you're like yeah like if you came on your options platform and I like authenticated with my bank account right in the background you once that authentication happens on your back end you create a wallet that can an account abstracted wallet you front the gas for that transaction the user just Waits 10 seconds while their account is being created and then they do things with like normal buttons that they click but like if they're ever in their settings menu and they want to try on blockchain for real to hit the eject Account button and then they just get all their like they get all they get their user migrated they get their keys basically right and so they've taken custody on like their blockchain Journey but you started them by like the things that they know and trust so I've been yeah I've learned to like hopefully good habits but like as you it's so weird now clicking a button and not getting the second pop-up and giving myself a second chance like okay what's gas what's right all this stuff like because yeah using like a social login sponsored wallet you can just proof of concept yeah but like hitting a button and then not really or like having a better understanding of what's going to happen is like actually like jarring for me for other people like yeah it's like yeah I don't I don't want to I don't wanna know right right it's weird it is yeah you leave the world of yeah when I see metamask I think I'm like that that uh that you know the older lady with the calculus floating around her head I'm like that Meme I'm like do I here this is me I'm like I'm like thinking I'm like do I do I really want to sign this transaction anyway I think right like I think the I don't know when we are paranoid now like at least for me it was a complete change because I came yeah right and then my first company was like oh I don't you know people have a lot like Off the Grid yeah it's sort of and but it really you know it's like you're like oh you've got to you have to do that right you know within seconds life changes for you yeah no it's like it's like 1997 again right it's like it's a new version of the internet first joined by my first uh somebody like oh I'm like I'm 20 BBC in this wallet and I I don't know where my keys are wow yeah but I have a password can can you send me a reset password link they're like no there's nothing no it's always a password oh man that's heartbreaking and I think that hasn't yeah no it really hasn't because last year so so we did an nftc it was interesting to see like the question that most people have because what's happening is more and more people are asking onboarding into crypto and it's it continues to be hard to talk to a new person like people weren't even able to buy crypto on our platforms it's it's very hard like the ux side is is hard and yeah unfortunately the the new users don't care about security they don't care about right they like to press the button it's fun to press the button yeah I know true very true [Music] the cold side is just kind of you know watching out for you and taking care of you like you don't have to know all the technicals you don't have to understand all the yeah you shouldn't right yeah I mean if it's ever going to reach adoption you shouldn't have to you're right no but well cool thanks guys for thanks guys for coming uh oh wait there's a question on the stream uh does it have to be a signature can it be a zero knowledge proof an arbitrary function we try to get biometric to work with account abstraction yeah I mean so like that's the cool thing right is if if you return one from this uh if you return zero if you return zero from this function your thing executes so you can do whatever you want in there it's pretty cool how's it going man yeah uh thanks for thanks for coming if you guys want to stick around and like mess around with more solidity stuff I'll probably be chilling here for another like 10-15 minutes we can keep jamming but you gotta go I want to respect the time so I have two pieces of pizza left it's gonna go home with somebody also yeah Brent shout out thanks for coming man and and chilling in the Stream for like hour and a half execute batch is lit and we hope to see you in person one of these days we know you're far away so all right gang
Up Next

Gasless Transactions in Web3: A Technical Comparative Guide
@thirdweb_
5.9K views•2023-05-24

Torrent File Format & Bencoding: A Technical Deep Dive
@AsliEngineering
12.5K views•2022-08-08

Operational Security Essentials: A Guide for Hacktivists (OPSEC)
@hitbsecconf
157.4K views•2012-11-26

Understanding Ethereum: A Comprehensive Beginner's Overview
@99Bitcoins
3.1M views•2018-06-26
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Blockchain & Crypto






































