Gnosis Safe 🛠Safe modding 101: Create your own Safe module
ETHGlobal·Sun, Oct 9, 2022, 12:00 AM
Join Germán MartÃnez of Gnosis Safe for a workshop titled, "Safe modding 101: Create your own Safe module." This workshop is part of ETHNewYork 2022, a three-day in person hackathon that will feature hackers, mentors, enthusiasts, sponsors and speakers who are all gathering in New York June 24-26, 2022 to talk about the future of money, finance, the web, ownership, the way software works and the way power is distributed. We're excited about a new frontier. ---------------------------------------------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com
Transcript
foreign [Applause] [Music] like to introduce you or to talk about safe modules and a little bit of safeguards how to create your own save module so first of all I would like to ask a few quick questions please raise your hands who knows what nausea safe is okay but a lot of people who's using the nosy safe currently individually or in a team who has built anything uh related with nurses safe development okay and finally who knows what safeguards and safe modules are just a few then that's good we will talk about that today so uh the key points of this talk are gonna be the save modules architecture what are the different components that form uh the safe architecture what they are the site modules applications like why are they useful safe modules management how to use them you we can enable disabling them execute transactions using modules and finally uh some repositories where you can find some examples of safe modules so where to find them you have probably noticed that we have the what the why the how the where and we are missing who and when well that's obvious I guess who is you and when is this hackathon so let's start thank you safe modules architecture if we talk about uh external loan accounts we see that we see the that the architecture is simple we have a private key and a public key and the private key needs to sign every transaction in order to execute it however with a safe because we are a smart contract and a multi-signature wallet we need to define a list of signers and with their private keys they need to sign every transaction we can Define how many of them are required to sign each transaction and after that they become executable that happens on chain if we also have some services that allow us to collect the signatures of chain and once we have the transaction and the signatures we can just call the contract once to afford some gas and make the user experience easier so this is the regular flow of a transactional execution where signers need to sign each transaction but there are also another flow and this is using safe modules safe modules are well are used by Third parties that are external accounts that they can call a safe module and as a module is a smart contract that is deployed in the same network then the nosy safe and it has root access to execute transactions in the safe they are very powerful but also we need to take care because it's critical they have root access meaning that they can execute transactions without the confirmation of or the approvals of designers so the developers need to define a different logic in the safe modules and the transactions will become executable or not if those checks are passed so we have the regular flow with assigners and the other with the modules in case uh designers become unavailable or the private keys are lost the safe modules flow is still available and If we have a safe module for example that implements a recovery mechanism we could somehow replace the original signers and add new ones there are also another type of modules and these are the site modifiers save modifiers are usually called by save modules that are used by Third parties so safe modifiers are placed between safe modules and the safe and they allow to add some filters to the transactions that are triggered from a module so we are allowed to chain different type modifiers and run a transaction from a third party is sent to a safe module the transaction is relayed in case we have a complex architecture that is not needed and we should try to simplify everything as possible but this transaction could go through every safe module and modifier and having some text there the site wallet allows to have multiple safe modules that offer extra functionality also safe modifiers allowed to have safe modules plugged into them and of course we can also have multiple site modifiers so save modules allow to expand the functionality of the safe and we also have another piece of another element that are safeguards safeguards can be enabled to a save and they can execute some text before a transaction is executed and after a transaction is executed so there uh every transaction that is triggered even if it's from a safe module or from the signers will pass those checks if any of these texts after or before reverts then the transaction will be reverted also very critical element so let's see some applications that modules and guards can offer we have the multi-signature control the common flow and we also can add some functionality to implement roles recovery mechanism add protection layers and some things modifiers allow us regarding roles we can create for example a safe module that gives or grants admin rights to some specific accounts so you could imagine having a safe module where some roles are defined and this role could refer to what are the kind of transactions that can be executed like what are the Target contracts that can be called which specific functions could be called which uh range of parameters of the values could be used and give some accounts those roles we could also Implement a token voting where a safe module is related with a near C20 token and do something similar like those do where the holders of this token have both in power in order to execute transactions we could also have a safe module that handles the spending limits so we could allow some accounts to withdraw a specific amount of funds for a specific token without the need of creating of all designers approving each of these withdrawals regarding recovery for example we could Implement a social recovery mechanism where we Define uh some accounts that belong to our friends or family and at some point we could or they together could execute a transaction via that module and replace the original signers of the safe if the private keys were lost we could also for example these are just examples you see we could Implement secret questions if you remember long time ago in web 2 pages if you forgot your password they would allow you to answer a question like what was the name of your first teacher what was the name of your first dog whatever here you could Implement something like that where you put a submit an answer and if you it is the correct one then replace the owners or allow uh custodial recovery party to execute that kind of transactions regarding the safeguards for example because all the transactions pass through the text that the guards have we could Implement and allow or deny list where we allow some well it would be like a filter for all the transactions checking what the Target contract is and allow or not to execute a transaction we could freeze an account if before executing it uh there's a parameter that designers can turn on and off Etc also with modifiers that have multiple safe modules plugged into it we could add a modifier that implements for example a queue and all the transactions that are coming from these modules would stay in that queue for one day for example there are unlimited possibilities that you could explore so how we can manage these modules and use them the the different operations that can be done are enabling a safe module disable it uh check if a module is enabled or not into a specific save getting all the enabling the enabled modules in a safe and finally execute a transaction for the setup we will need to deploy a safe or use an existing one deploy a safe module or use an existing one if that module is built in a way that allows multiple safe to use it and finally execute a transaction via that module so let's see from the nurses safe smart contract side and from the module side some code so here we see two contracts the first one is a super simplified nozi safe contract that is a module manager module manager is one of the core contracts of the safe that has all the functionality that allows to enable modules disable them Etc so when we set up a new save inside the function setup there is a call to the setup modules function inside the module manager and if we see below the module manager we have two variables one is a mapping called modules where the keys and values are addresses and we use a sentinel module that is the address 0x1 that we use in the beginning and at the end of this mapping to see uh well to navigate it so I'm not going to talk very deep about this uh we can enable a module enable a module uh it cannot be null or the Sentinel the address we are using it for the module and also modules cannot be added twice we can disable a module and making sure that the module was already enabled before we also can see if a module is enabled or Not by checking this modules mapping we can get the enabled modules list that is patient and we can iterate on it and finally and the most interesting thing is that we can execute a transaction so in the save contract there's uh there are two methods except execute transaction that uses the regular flow checking the signatures of the signers and then we have the method exact transaction from module this is a public method that can be called by any account however inside of it there is a check where the message dot sender and needs to be inside of the modules mapping meaning that the the message dot sender the account that is calling this method is a module that is enabled that was in the side of the nurses save contracts and now if you decide to build a custom module you could create a contract in this case we call it custom module that is a module module is an interface uh that defines well it is an abstract class that defines the methods that are required and that can be implemented here so uh for this case we have the custom method function that receives some parameters of a transaction like the two value data and operation and inside of it we are calling a Target this target is an address that was set before and if this is a module the target can be a modifier or a nosy safe and there we can call the function exact transaction from module and pass all these parameters so this way we are relaying the transaction from the module to the save now let's see a little bit how to use the safeguards equally to the to the saved modules we can have a safe deploy a safeguard enable a guard into the safe or disable it the difference is that saves only allowed to have one safeguard instead of well we can have multiple modules but just one safeguard safeguards are enabled in the safe by designers and then when the in the safe contract there is the function exact transaction and inside of it I I just simplify the code here but the signatures are checked and then we get the Safeguard we see or we check if that guard is different than the address 0 meaning that we indeed are using a guard if that is correct and we are using it then we will call the method check transaction then the transaction will happen and after it there will be another call to the guard calling the method check after execution if one of these methods reverts everything will reverse and a custom guard could be implemented with two functions check transaction that receives all the parameters from the from another safe transaction and also the function checked after execution that receives the transaction hash and if the transaction was successful or not so uh some module repositories and examples you can read we have the safe contracts repo in the safe Global user on GitHub there you can find the core contracts the module manager and the guard manager that implements the functions to manage this element then we have the save modules Repository where there are some examples of modules that are used and also a very interesting one is the zodiac a repository under the nurses user zodiac is a dow tooling standard that implements multiple safe modules for towers that are built on top of the of the safe and you probably will find that interesting here I will provide the slides in the in the Discord of is global so you could check these links there so we have the modules that implement or that indicate what are the functions that are required to implement if you build a module and well here we have some examples of modules and modifiers sorry I'm running out of time same for the cards we have a base guard and also an example of uh of a guard that debugs a transaction checking the data before and after the transaction is executed and now the question is will you build the next build big safe module or regard well we hope so you can find us on Twitter now see safe we also have a Discord and Forum on chat or forum.nosis-safe.io and we also have a channel nosy safe in its Global Discord also feel free to come to our booth and claim your nosy safe is New York pop-up and for the hackathon we have ten thousand nut dollars up for grabs and two bounties the first one is a wild card like any integration with the nosy safe on different layers on the front end infra or contract layer in the front end you could create a new a new front end use our sdks like the Safeguard SDK if you are building an app that runs a standalone and separated from our app or the safe apps SDK if you want to build a safe app that runs inside our safe apps store in the infra if you want to play around signatures that are that sorry like collecting all the signatures of chain before a transaction is executed or in the contract Ledger if you want to play around with modules and guards that is the first Bounty and the second one would be specifically related to the roles module from zodiac the the best use case for it so thank you very much uh we are going to stay here all the weekend at our booth feel free to uh to pop up and well we can help you with your questions and good luck with the hackathon
Automatic transcript — names and jargon may be misspelled.