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

Loading player…

Better Dapps with Delegatable by Dan Finlay

Ethereum DenverMon, Oct 9, 2023, 12:00 AM

The Delegatable Framework can enable dapp devs to write less code, reduce onboarding friction, and unlock scalable webs of trust for every function of a contract, all with basically one line of solidity. Stop writing ad-hoc permissions code, and use a framework that lets your users define their access policy freely, while saving gas and simplifying onboarding through use of off-chain permissions signatures. We'll cover the basics of how to use the framework, and then help attendees try applying it to their own projects. Dan Finlay https://twitter.com/danfinlay CoFounder and Group Manager MetaMask Dan Finlay has been facilitating MetaMask development since 2016. During that time he's developed a passion and vision for the future of secure distributed permissionless computing, and is bringing that vision to life through MetaMask

Transcript

uh hello Denver where's my Builders at yeah uh yeah hey hi everybody uh my name is Dan Finlay um it's great to be here this is my first eat Denver uh I've always watched from afar just the biggest fomo of the year every year so I'm here uh I I hope to make metamask uh and uh I'm here to share something I call delegatable um and uh yeah yeah thanks for coming down a lot of friendly faces here uh and um it's it smells like the auction cattle here which I heard they do so for those viewing at home just imagine that hey so first of all why why delegatable is it so what I'm talking about here it's a general purpose delegation thing so so when when we're interacting with smart contracts today we're you know uh maybe you have a method name or maybe you know you're calling a function there's kind of this ambiguous like what are you you know maybe you hope for simulation but where's like the you know um we want like security we want scalability it's a lot of things that we want but uh I'm just going to start with like a Word of Wisdom that I sometimes this grounds me a little bit all I know is that I don't know nothing okay and when I'm interacting with new smart contracts I'm I'm coming at them and the truth is I'm usually not reading their source code and even if I do they might have slipped in something right and and I there's risk right there's risk with every opportunity that you take and uh and and you kind of have to approach things with a little bit of carefulness right and it's not that we don't want to take risks we want to build a society that's better right we want to cooperate we want to do cool stuff but we're in an environment full of these terrible nasty little tricks and bugs and mistakes and and uh we have to navigate those right so how do we how do we it interacts with the smart contract world where we can kind of take careful steps one at a time into the world and uh and cooperate a little better and ideally you know maybe we can learn from from nature a little bit and uh and make Dynamic webs of trust I believe that from simple Primitives we can make highly composable highly secure highly resilient systems and that's kind of some of the underpinning that that contributed to this uh this solidity framework it's a you can add it to any smart contract so what is it it's a tool it's not a standard I'm not trying to force you to adopt it you don't have to you can Fork it you can make your own version of it you can pull request it you can just Fork you know you can just do whatever you want with it as it is it is a usable thing it's a it's a concept it's an approach okay and and I want you to think about how your users interact with your applications in a way that allows them to be safer in general if if you make a contract track that make that users are getting fished on all the time then your contract may have you know interfaces that are a little bit hard for users to reason about so it's our responsibility it's my responsibility as a wallet Builder to make my users as safe as possible but it's a partnership every single application you're trying to keep your assets secure within your users hands too it's a recurring need people are implementing approval methods for basically every single smart contract there is uh ERC 721 has approved and of course uh said approval all which if ERC 1155 only has said approval all so every time you interact with a contract and give it a n f t you give it all your nfts and that's how people get drained for all of their Apes with a single signature there's been several different token standards all slightly different approval interfaces bitdow has one delegate approach compound Dow has another delegate approach well octah has another one there's questions when you delegate is it a full delegation uh can they do everything you can do you can see molocta has a special check they're like oh some things only the delegates can do and some things you can't delegate that seems kind of arbitrary right everybody's kind of got a notion that you should be able to share what you can do with smart contracts but they don't have a generalized approach for it what we need is you know just a lucid way of approaching what does it mean to have something and share it in a selective careful way okay so let's just let's just visualize it in simple terms you've got a contract you've got an account you've got some stuff in it if you're in this audience you might have some stuff in a crypto account just kind of profiling here okay and you might have some friends that don't now kind of the beginning of collaboration whether it's you know starting a local Cooperative or a business or paying a courier to transport something you need to give them access to something right now you could just transfer it all up front but maybe they don't even need all of it right so you give them a signature that gives them some virtual access to what you have you both have access to it we've now expanded the agency of the overall Collective Now you might be concerned could they steal all of my money well I'm glad you asked because on each one of these signed delegations you should be able to add little uh we call them caveats little knobs you can kind of mix and fade down what they can do and you want to be able to tune down what you're granting to the smallest amount necessary for the job to get done this is what a security folks call the principle of least Authority we want to tune it down so if it's money the allowance is the thing right tokens they all have allowance but allowance is just one dimension right is allowance the universal delegation thing no this is a computer we're building on the evm we can do anything right why not a time limit yeah of course timeout limits that's like an obvious one right um streaming payments that's just a different kind of allowance right it's just like a little bit of logic each one of these is a parameter that points at a smart contract that you can deploy it at runtime so these are just completely extensible you can just add new knobs onto this and you can say only this method is only for this long you can make whatever caveats you want if it's your personal token maybe you're sharing mincing rights maybe I'm doing an event and I'm giving out the rights to buy tickets and I say oh you get a tranche of 10 you get 50 you know I don't have to be limited by role-based access control or maybe there's only five no offense right where there's five rules but I could have highly granular every single individual can have their own role or if there's a recurring need you know you can start rubber stamping a set of these caveats and these signatures these signed messages use the EIP 712 format and that means they're inherently readable in basically every ethereum wallet today now the terms uh they're going to be readable soon we got to make those a kind of polymorphic type but what you've got is you can see that we've got a delegate if uh if you've got a great wallet that you're using you'll see your address book entries show up and then you'll have a list of caveats and you should be able to scroll down those and see the exact attenuations that you're applying and so you should be able to have very multi-dimensional uh very fine-grained and deliberate attenuations and eventually wallets can start adding maybe the ability for users to add their own additional attenuations at signing time for example um so uh so that lets you take something that you have share with another account it could be a multi-sig it could be a contract account um there's a fork of the delegatable library today that works with ERC 1271 so contract accounts are able to do this just like any other one and then with the same con with the same signature this is all off chain that multi-sig can assign to their friends they can maybe delegate they could be a whole Dow and they've now got subcommittees and they've issued some sub budgets for example or maybe you're managing your upgradable token contract and you want uh some people to be able to moderate the inflation policy and other people to freeze the whole thing right and maybe they want to delegate because they they get so big their offices are getting very full they need to hire a staff they get some helpers and those helpers are actually they're writing some scripts or Bots or something that they don't want to give their main key to each device right so they can each one attenuate every bot every subcommittee every sub uh you know Dao every friend to exactly the access they need for the overall system to be as empowered as it needs to be and that's all off chain that's not a single transaction there that means every single one of these uh invitations doesn't even need a wallet you can basically make a link that lets somebody redeem this in the website and they can actually perform act they can invite additional people without a wallet and they can they can sign actions that somebody else could submit to the blockchain right to submit to the blockchain someone's got to pay the gas but they can be batched and meta transacted oh yeah and you know indefinitely it's recursive oh hey fun fact did you know that fungal networks from different colonies can connect and share resources in a process called anastomosis just like two different organisms connecting and sharing resources isn't that crazy similarly two different delegation networks could connect and overlap and people from two different organization organizations that was could now have access to Shared resources potentially in a mutually beneficial way we're trying to build a mesh of mutual support right uh so you know it it's uh who knows how that fun fact might apply to you let's just review a couple key terms I just burned past we've got those tickets those are delegations anytime you want to share something that you can do you would sign a delegation message and there was those little knobs those are caveats every knob lets you turn down the delegation you can turn it down in any way every single one of those knobs is defined by a smart contract it's got a really simple interface that you can just Define you can just write them like you your application may have specific needs that you might want to tune and you can just write them and then um yeah the delegation just kind of looks like this it's a really simple struct it's got a delegate it's got an authority which is zero if it's your own ability or it's the hash of the delegation to you if it's a delegation to you and then a list of caveats that you got and the caveats it's just an address of the contract that will do the enforcing and some information that the enforcer will use as its terms that's again that's the part we're going to kind of dig in on in the future and make it more readable basically we have to make a come up with a polymorphic struct type if anybody wants to Riff on polymorphic uh Strokes that's what we have to come up with there we want it to be readable right so we want people to be able to understand the terms they're agreeing to and then lastly there's an invocation message once you've got a delegation the ability to do something you need to be able to do stuff with it normal transactions aren't exactly uh what you would use here because you're not the root account so you need a way to take that delegation and say Here's the transaction that I would like to perform as if I was the original account and so you basically make a transaction like you would before and then the chain of delegations that culminates in yourself so it's like buy the power vested in me I do this it's kind of what what an invocation is like um yeah just like He-Man um okay so uh this is what a caveat looks like if you're wondering how do I make my own little knobs like you've got a custom contract it's one function that you implement you've got the terms that the caveat was given you get the transaction that's being attempted and you get the hash of the delegation you the hash of the delegation allows you to have stateful side effects to the delegation so if it's an allowance this is how the contract would keep track of the current state of the allowance right you don't have to use that um okay so there's actually a lot of ways you can do this like I said this is a tool not a standard it's just a thing it's a pattern you can apply to make your contract more General purposely adaptable and uh you know user empowering so one way is solidity inheritance you can just say inherit you know my contract is delegatable and now you can you get an invoke function and you can submit these invocation function uh payloads and the whole thing just just kind of works automatically uh you can also we have an on-chain relay it's very similar to the 4337 relay um except uh well I mean basically it's good for Eos right 4337 or Eep feet as some are calling it is good for contract accounts to to have uh user operations that get bundled and may be subsidized but EOS or you know accounts that are controlled by a key they they can't benefit from that but they can participate in this so this works with contract accounts and traditional accounts no need to force everybody to migrate at once even though I admit I can't wait to migrate everybody at once um and lastly if you're into upgradable smart contracts like we just got to enjoy in the last talk we do have an uh a diamond facet so anyone who's using the diamond standard today can just basically add this facet to their contract and it will just work so that's the magic of upgradable contracts I really think that it's a great pattern so you know uh I'm sure we could make one of these extensible token versions of it too again it's a tool not a standard um oh yeah same deal as the extensible token thing use use underscore message center this this thing this should be buried somewhere in your smart contract uh which is just um if you're using open Zeppelin libraries you already have a message sender Defender to find somewhere and you just need to override it what this makes the magic happen under the hood basically the uh the account that did the delegating is appended to the end of the call data and the receiving contract respects that as Authority it's kind of patching the thing in ethereum that said only the sender of each transaction can do a thing so we're expanding the definition and clearly it's a I think it's a positive pattern I'm pretty sure our two methods are compatible so my guess is that you're probably better off adding this to whatever your contract is especially if it's extensible um okay so I'm not going to cover all of those approaches we've got some great documentation on delegatable.org thanks uh friend cames um but uh let me show you what it looks like to inherit it in some solidity um this is a Moby mask it was the first delegatable contract on mainnet you can check it out at moviemaths.eath it's not verified on etherscan the goal was to make it the simplest contract to prove out the entire premise um and so it's a Fischer registry it's just a mapping of identifiers like Twitter Fishers to a Boolean that they're a Fisher right if you were just a normal contract there'd be one person who gets to say who's a Fisher or not and don't get me wrong this trust is rooted in me and I'm kind of the one who gets to say who's a Fisher in this registry but I have the ability to share that right and I can do it without a transaction so I've been just giving out these invitations where people can report Fishers and now and everybody who gets an invite can invite their friends and they can invite their friends and you know I mean Fishers are just like Sybil attacking the heck out of social media and Twitter doesn't seem to know how to deal with that they just let everybody pick their own names and pictures right so uh it's going to take a lot of us contributing in a lot of creative ways to to address civil problems so this is an approach sorry that's context how did we make it delegatable you can see on line seven the contract Fischer registry is revocable ownable delegatable now that's like a subclass it's like a flavor of delegatable it comes pre-rolled where the invitations can be revoked right I kind of pre-rolled a caveat enforcer so it's more gas efficient but uh basically that's it so um now you can claim as Fisher and now the whole thing's delegatable um so you can check that out on chain if you want to see how it works and you can go to delegatable.org if you want to read more about it or you can go to github.org.

com delegatable to read the code um I'm going to go through some code examples I don't want to bore everybody to tears but you want to see that's possible Right like it's not all the prettiest code but I'll show you okay so seven one eip712 means every signature has some data at the beginning that says what contract you're signing to and that's how you know that when you sign that message it's not also useful somewhere else right it's the context so you make your contract info and then you sign your delegations just like we said before so like who's your delegate what's your Authority and do you have any caveats I'm doing it lazy here no caveats um and we've got a little delegatable util um you you generate it with the contract info and then you can sign the delegation you can dig into that it's just doing a little bit of uh seven one two signing 712 signing looks a little ugly because you include all the types and there's this big types blob so you can crack that open it's kind of ugly it's Json but all the code and delegatable is generated from that type blob so it's uh it's like pretty solid it's passing all sorts of tests and it's a lot easier to use this way when somebody has the delegation they construct a transaction on that first line yeah sorry there's a lot I'm not going to make you read all this that first line you can see this cool ether's utility you say populate transaction this is how you make some a transaction data like as if somebody else was making it right because the delegation you're doing it on behalf of someone else so we need to make that transaction that they would make and then we form this invocation method um and it supports batchings and then then we create a typed message and we sign it and then you can see it on the last line we uh we're connecting our second address so a different account is relaying it and then we invoke so the invoke function is how you batch a bunch of these delegation uh invocations um I think there's a lot of ux opportunities that come from this um e thing you don't need gas to invite people so I mean onboarding right like what are the key onboarding struggles we have we've got getting a wallet getting a backup getting your first ether for gas okay if you can just send somebody an invite link and it's attenuated down to an amount that you're okay being an invite link you can just send an invite link and the first thing they do can just be in an app and if it's just something like checking in for uh for a you know an event or maybe claiming an nft right you can make a claim an nft link and it'd be free so so yes you can mint nfts for free with this right I mean I should have just started with that that right that should probably sell itself um but uh so so yeah and you could you could then share the right to get the nft or you could have a few or whatever um having wallet onboarding wallet onboarding don't get me wrong I'm not trying to sell you off wallets uh I have a I've got a wallet a little vested interest in wallets um but uh but I'm not trying to tell you that every app should start by making you get a wallet and forcing everybody to back up a seed phrase that's a terrible user experience and nobody wants to do it and most users get confused by that and they're like they're just annoyed and it's probably totally strangling the whole ecosystem um so what what how much later could we introduce the wall it's kind of for backing up and it's kind of for paying gas I think backup is kind of the big thing so so if you don't need to back up yet if it's a small thing we can do small things for free okay like we just let's do a bunch of small stuff let's have games let's do fun things let's have events let's do tickets you know bring back some fun Dynamic Innovation creativity right and or if they want to submit their own transaction uh yeah I messed up the thing now but yeah if they want to submit their own transaction today that's the other thing you need to meet through to do that although uh I know you're uh you're biting waiting for me to say something about it uh okay some some opportunities okay yeah I I'll get to that in a second here's a couple examples if you're a here as a hackathon participant and you're still looking for what you might want to do today I'll just throw out a couple random ideas um making Dallas fast and decisive I think the norm endows today is kind of a little bit of a slow bureaucracy right there's like usually like a proposal period and you know maybe only so many people are really participating and they don't get me wrong more and more Dows have delegation but it's usually like one hop deep and then those delegates feel all burdened down like oh like I better you know I got my Twitter followers expecting me to vote or whatever like make it make it fast make it flexible let your delegates delegate you know just like spread around the influence some if you don't like how somebody's representing you revoke it you know we should have Dynamic organizations that move as fast as we need to be moving because the kinds of problems that we should be trying to solve are not uh in the increments of proposal periods um maybe sharing exclusive perks I mentioned like events I really think if you're trying to engage your audience uh something like claiming nfts participating in your token sale whatever like like bring back taking responsibility for how you give out rights everybody's trying to airdrop or like automate something or like verify it on GitHub and like I think that's kind of shirking the responsibility if you know people that you want to share digital rights for take that responsibility do it yourself whatever methods you have it's off chain you can be creative you can be iterative you can iterate every single Reddit account it's it's free it's off chain you can give out these rights and the only Gas payment is when somebody uses these rights um oh uh a future version of it would allow you to add a fee to referrals so you could give somebody a right to do something on condition of payment I believe there's a breaking change we have to make or an extension uh to do that um and oh yeah the the whole thing of keeping your your assets on colder and colder devices so everybody wants to not take risks right with or you know just take the risks you want to take so you want you're like you want to keep your ape on your cold device but then well I don't know if you want to is there any way to use it okay tell you what we'll we'll get to worm XYZ and delegate cash in a second if you're just claiming nfts you might want a different kind of Delegation but if you've got like a functional like voting token some ens tokens and it's an uncomfortable amount you might want the ability to transfer them cold but you might want the ability to vote hot and then you could delegate that right to vote hot you could give partial you know amounts of tokens to vote perhaps uh hot so the ability to keep your assets cold keep some things warmer and still be able to log into things selectively I think there's a lot of potential to keep people safer you know actually use your things that you have safely um session Keys is an example of that right a delegation that's time limited to an application means fewer confirmations so you you log in it can do stuff it doesn't bother you it may not even have gas payment or maybe it sends it to the back end to submit the transaction meaning you're not bothering users with as many confirmations or Gas payment maybe not even requiring ether at all if you're willing to subsidize your transactions you might not need your users to hold any ether okay uh okay relation to eat feed um so epeat is a great way it's a like a gas market for contract accounts now delegatable does feature a batching mechanic but it's kind of feature overlap if you have a contract account that has batching you don't really need the delegatable batching features so we're probably going to make a non-batched invoke method that's basically the answer otherwise they're compatible one is concerned with a gas market for contract accounts the other one is a method for any contract to make its resources very shareable um oh uh oh uh-huh I'll just talk through everything I just said yep like I said oh yeah and delegated will also provides batching for traditional eoa type accounts so that's pretty cool so batching for everybody I think that's nice uh you know take care of all your users not just the early adopters um okay now I'll compare to a couple other Uh current delegation Frameworks I've been saying 2023 is looking like the year of Delegation there's a lot of people who are kind of waking up to realize hey wait a minute I I don't want to keep all my assets on my metamask frankly you know and I don't want to um and I want to be able to take smaller risks but I still want to do stuff and a lot of people claiming airdrops and then getting all of their money taken right and that's like kind of a repeating pattern trying to claim free stuff getting your money taken okay um so delegatable like you just saw it lets you grant anything you can do on a contract to another account it's got an open-ended caveat system so you can attenuate those the ability you're sharing in any way that you want and that can let you keep hot while it's cooler um but by limiting what they can do but they can still do stuff on chain now delegate cache and worm XYZ provide a registry on chain that lets you report another account as your delegate now notice that that is not touching the uh the contract that holds your asset so you're not sending a transaction to your nft account you're just saying to this registry hey hey everybody that's my delegate okay so that delegate account can't do anything with that account okay so that's why it's extra safe they can't do anything you you you're perfectly safe if you can't do anything and that's really what I want you to take away here you if you don't do anything you're perfectly safe um now that is great for proving ownership if you want to token gate membership into a chat room if you want to gate who gets a second nft if you want a gate who gets a erc20 this is a popular use case I don't want to I don't want to diminish it too much even though obviously my interests are a little bit more in sharing what you can do on chain okay so so if you're somebody who is trying to keep up with all the latest airdrops you should sign up for those delegate Registries sign up for both of them there's no problem it's two Registries if somebody comes out with 10 more as long as you're not falling for a phishing attempt when you try to sign up for one there's really no harm in it okay um uh okay so uh that's my talk uh three minutes to spare whew what will you do with it it was not rhetorical I was trying to ask you I was trying to ask the audience sorry but with three minutes uh I think the I mean you can ask whatever you want but I would love to hear if somebody has a different kind of contract or that than I talked about and you want to riff real quick three minutes Super Jam let's think of a new use case or any question can you make a Merkle tree with delegation arguably a delegation tree is a Merkle tree can you just make one just like for fun I mean yeah you you bet any serious questions besides some of the standard enforcers like you know block number time stamp is there anything else that you see might be interesting for enforcers whether it's like governance proposals or something else that hasn't been written yet yeah okay so besides the four hypothetical caveats I included okay so like in allowed methods enforcer is one of the ones that's like really essential like what are you letting them do I think a lot of this stuff comes down to what is the contract good at like it might be that you have certain parameters on a function that you want to confine I mean I'm not an expert in every Dao's interface so a lot of this comes down to what's your Dow doing for what kinds of things you'd want to share so like ens if you've got an ens name uh well yeah it already lets you share who can do a sub a sub domain but that subdomain owner can't share the right to update the subdomain so sharing the right to just share that function that's good but yeah other other caveats so yeah we've got time are there other oh let's say it was a sub domain I might say Hey you can update our you can make a subdomain that's anything that has like your name in it or something you know I can make little rules just custom rules and it's not a very compelling use case but like I mean it really is I think use case driven like what are the ways in which you want to attenuate uh the access you're sharing um yeah yeah we're going to really make you run all over the place you want to shout it no you know hey you're uh outlayed in a loud environment yes get get better sleep when you when you have a tree of delegations and you revoke does the revoke cut off an entire branch of the tree fun fun question yeah yeah so if if I've invited someone and they invited someone and they invite someone and then I'd revoke that first one uh yes it totally breaks the whole tree Downstream because when you call invoke with your chain right remember the invocation has a a an array of delegations culminating in yourself and in order to process it the smart contract walks down the delegations and verifies each one's validity and walks on the caveats and attracts each one's validity and yeah that that means each invitation adds a little gas costs and stuff but it also means that anybody who starts feeling sensitive about who they invited you don't want to and this is like a real problem with other Access Control mechanisms right you invite somebody to a chat room and then they invite a whole bunch of other Fishers and you like you kick out the the first scammer but you don't know where everybody else is like like so yeah yeah you you want to kick everybody else out yeah because the problem with Merkle trees is you have to regenerate the entire thing if you want to change one part of it you turn into a call back to my I'm trying to redeem myself yeah oh yeah yeah no yeah yeah you're right yes so if you change that part yeah it updates the whole Miracle tree sure yes um okay I'm a little over time I assume there's a speaker whose time I was stepping on but yeah last another question can contracts delegate as well yes um so in the current version if you just go to github.com delegatable the main branch currently doesn't but there's a pull request open I think it's like number 17 or something it says ERC 1271 support and that supports contract accounts we're probably going to tweak it a little bit more and we're not going to merge it till it we also have like a full docs site like so we want we're gonna we're gonna cover it real good but yeah it's like it's a schema update so we want to make sure that if you land on the website you understand how to use it but you know all the tests are updated so if you are comfortable copy pasting code you can jump in there and it works with contract accounts it's super cool as long as that contract account implements 1271 correctly right and correctly means actually enforce your contract accounts logic I don't like these contract accounts where they delegate to one signer for their 1271 signatures you just gave up your whole multi-sig thing okay for a little while I thought 1271 was a bad idea because everyone was doing it wrong and then I realized it can be done right so please make sure your contract accounts are implementing 1271 in a coherent way I have a quick question around sub grantees so I receive grants from a grantor who receives it from the federal government and then I give a certain amount of money to all these individuals and they can use it for very specific things so is this a use case this sounds like a really good use case for transparency and reducing like losing the money right not getting it spent on the right thing having to prove it was spent on the right thing right this is this would be an extremely compelling use case for government contracts no yeah yeah yeah I think like the way I originally had the idea was like thinking about how like small organizations would like actually because I'm not sure if people have wallets yeah none of these people are on chain exactly but these are all like money that needs to be tracked efficiently yeah yeah so so yeah you get transparency and who has a budget also if they don't use their budget it's not leaving the main account and if they don't use the budget you can revoke it and you still have it um and uh yeah so it's standing who has access to it with a very concrete budget but without but yeah while keeping and in fact you could you can kind of use this as like fractional Reserve delegation right you could you could have a hundred bucks and you could say hey I'm looking for I'm looking to buy this 100 thing uh any of you who can find it you know please buy it for me and as long as you think they're not going to betray you but first come first serve you know you can trust your friend uh this is a construct sometimes called the incentive trees look up the red balloon challenge it's super cool foreign yeah we got oh we've got a Discord uh come come down to us after the talk for an invite to it yeah another question here no no cool yeah hey thanks for coming everybody [Applause]

Automatic transcript — names and jargon may be misspelled.