ERC-5005 Zodiac modular account standard (Zodiac Modular Accounts)
Stagnant · Accounts & wallets · created 2022-04-14
A standard that separates a contract account (avatar) from its authentication and execution logic (modules, guards) via standard interfaces, allowing programmable accounts such as DAOs to freely swap and combine control tools.
Why it is needed
Most current DAO tools and programmable accounts are built with a monolithic structure, where authentication logic and execution logic are mixed together in a single contract or a tightly coupled set of contracts. This makes switching how an account is controlled, or moving to different tooling, costly, resulting in lock-in to a specific platform. It also makes it difficult to use multiple control mechanisms simultaneously, build cross-chain governance, or design flexibly so that governance can be progressively decentralized as a community matures.
What to implement
event EnabledModule(address module);: An event emitted when a module is enabled.event DisabledModule(address module);: An event emitted when a module is disabled.event ExecutionFromModuleSuccess(address indexed module);: An event emitted when a transaction execution requested by a module succeeds.event ExecutionFromModuleFailure(address indexed module);: An event emitted when a transaction execution requested by a module fails.function enableModule(address module) external;: Callable only by the avatar; enables a new module.function disableModule(address prevModule, address module) external;: Callable only by the avatar; disables a specific module by specifying the previous module's address in the linked list.function execTransactionFromModule( address to, uint256 value, bytes memory data, Enum.Operation operation ) external returns (bool success);: Allows an enabled module to execute a transaction (call or delegatecall) through the avatar.function execTransactionFromModuleReturnData( address to, uint256 value, bytes memory data, Enum.Operation operation ) external returns (bool success, bytes memory returnData);: Same as above, but also returns the execution result data.function isModuleEnabled(address module) external view returns (bool);: Returns whether a given address is an enabled module.function getModulesPaginated(address start, uint256 pageSize) external view returns (address[] memory array, address next);: Retrieves the list of enabled modules in pages.function checkTransaction( address to, uint256 value, bytes memory data, Enum.Operation operation, uint256 safeTxGas, uint256 baseGas, uint256 gasPrice, address gasToken, address payable refundReceiver, bytes memory signatures, address msgSender ) external;: Called by a guard to perform a pre-execution check before a module or modifier executes a transaction.function checkAfterExecution(bytes32 txHash, bool success) external;: Called by a guard after transaction execution finishes, to check the transaction hash and whether it succeeded.event ChangedGuard(address guard);: An event emitted when the guard address is changed.function setGuard(address _guard) external;: Sets the guard address that will perform checks before and after transaction execution. Passing the zero address disables the guard.function getGuard() external view returns (address _guard);: Returns the currently configured guard address.
In depth
Four core concepts
This standard is composed of four concepts: Avatar, Module, Modifier, and Guard. The avatar is the externally referenced programmable account that holds balances, owns the system, and executes transactions; it MUST implement IAvatar. A module is a contract containing execution logic that has been enabled by the avatar. A modifier is a contract that sits between a module and the avatar and modifies the module's behavior, for example imposing a delay or restricting the scope of every function the module tries to execute, and it MUST implement IAvatar. A guard is optionally set on a module or modifier and performs pre- and post-checks for each transaction execution, and it MUST implement IGuard.
The IAvatar interface
IAvatar manages modules via enableModule (callable only by the avatar, emits an EnabledModule event on success) and disableModule (takes the previous module's address, prevModule, in the linked list and the module to remove, emits DisabledModule). execTransactionFromModule and execTransactionFromModuleReturnData can only be called by enabled modules, execute a transaction using to, value, data, and operation (0 = call, 1 = delegatecall), and emit ExecutionFromModuleSuccess on success or ExecutionFromModuleFailure on failure. isModuleEnabled returns whether a module is enabled, and getModulesPaginated retrieves the list of modules in pages.
IGuard and Guardable
For a module, modifier, or avatar to support guard functionality, it must inherit Guardable, and MUST call checkTransaction before triggering execution and checkAfterExecution after execution completes. checkTransaction receives all parameters of a Safe transaction (to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, signatures, msgSender), but module transactions only use the first four (to, value, data, operation) and the rest are fixed at 0. setGuard checks whether the address being set as the guard supports the IGuard interfaceId via ERC165, and reverts with a NotIERC165Compliant error if not.
Operation and transaction types
Enum.Operation has two values, Call and DelegateCall; as the operation argument to execTransactionFromModule(ReturnData), 0 means call and 1 means delegatecall. Allowing delegatecall means a module can execute arbitrary code within the avatar's storage context, so since this interface design exposes that value directly, trust in the module is critical.
Design goal: compatibility with existing tooling
The interface defined by this standard is designed to be as compatible as possible with most programmable accounts currently in wide use. The source states this is meant to allow the standard to be adopted without major changes to existing tooling.
Backward compatibility
The source explicitly states that this standard introduces no backward compatibility issues.
Proposal status
This proposal is in Stagnant status, meaning it is no longer actively discussed or progressed. It should be kept in mind that the content of the standard may change or may never be adopted.
Things to watch out for
- Modules hold absolute control: Once a module is enabled, it gains absolute control over that avatar, so every module implementation must be treated as critically important for security, and only fully trusted modules should be enabled.
- Race conditions between multiple modules: Multiple modules can be enabled simultaneously on an avatar, and each has sole control over the avatar, so race conditions can arise between different modules or different control mechanisms.
- Risk of the avatar becoming inoperable: Since there is no built-in safeguard for adding or removing modules, removing every module capable of controlling the avatar can leave the avatar unable to operate and lock up all funds it holds.