<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alexandre Carvalheira on Medium]]></title>
        <description><![CDATA[Stories by Alexandre Carvalheira on Medium]]></description>
        <link>https://medium.com/@axxcar?source=rss-1df2647e37e7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*vB_hHKBBztcGxQGE</url>
            <title>Stories by Alexandre Carvalheira on Medium</title>
            <link>https://medium.com/@axxcar?source=rss-1df2647e37e7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 13:08:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@axxcar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Minimal Modular Smart Accounts Contracts Overview (ERC-7579)]]></title>
            <link>https://blog.contenta.xyz/minimal-modular-smart-accounts-contracts-overview-erc-7579-e08559d5b7d6?source=rss-1df2647e37e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e08559d5b7d6</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contract-wallet]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[web3]]></category>
            <dc:creator><![CDATA[Alexandre Carvalheira]]></dc:creator>
            <pubDate>Wed, 02 Oct 2024 23:35:42 GMT</pubDate>
            <atom:updated>2024-11-17T17:40:54.472Z</atom:updated>
            <content:encoded><![CDATA[<h4>Account Abstraction and the implementation of Modular Smart Accounts.</h4><h3>TL;DR</h3><h4><strong>Overview of ERC-7579</strong></h4><ul><li>ERC-7579 builds upon what was introduced by ERC-4337.</li><li>The standard introduces modular smart accounts, outlining the minimal requirements needed for interoperability, making customisation easier.</li></ul><h4><strong>Module Types and Functionality</strong></h4><ul><li>Validation Modules: handle the signature verification and play a highly security role on access control.</li><li>Execution Modules: extend account capabilities and can perform different actions during transaction execution.</li><li>Fallback Modules: adds diverse functionality to the account not covered by other functions on the account.</li><li>Hook Modules: enforce specific behavior and can be triggered before or after the execute function.</li><li>Module Managers and its role on managing installed modules.</li></ul><h4><strong>Smart Account Implementation</strong></h4><ul><li>Utilizes a ModeCode system for flexible execution handling, maintaining simplicity for basic implementations.</li><li>Key functions such as execute( ), executeFromExecutor( ), and isValidSignature( ).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*dlqxckMcdeWi6N81b_N3aw.jpeg" /></figure><h3>Personal Motivation</h3><p>Recently, on the last project I was working on as a FullStack Dev, I got a grant to implement Account Abstraction (AA). It happened to be a project that required a lot of transactions and our main goal was to make UX better while also sponsoring user’s gas. I came across a lot of different implementations and even though any path taken would probably work just fine at the time, I was worried about something: how would I add new features, such as session keys, passkeys validation, or custom features related to our project effectively and easily? So that was when I first heard about ERC-7579.</p><p>At that time, The ERC wasn’t audited yet, and besides the official proposal at the Ethereum forum, it had little to no articles about it. I figured the only way to understand how it works was to dive into the repo and figure out each step of the process.</p><p>A few weeks after that, I had an opportunity to put what I learned into action, implementing ERC-7579 on zksync at the Aleph Hackathon in Argentina. After winning the AA category with this <a href="https://dorahacks.io/buidl/15180/"><em>project</em></a>, I decided to write about it to make things clearer in my own head and, hopefully, help anyone that is curious about it.</p><h3>Account Abstraction: An Introduction</h3><p>AA (Account Abstraction) was introduced with ERC-4337, which put together a standard needed for account abstraction implementation without requiring the EVM to be modified. Now we have four core components working together on a “layer” over it: bundlers, EntryPoint contracts, paymasters and Smart Contract Accounts.</p><p>Prior to ERC-4337, we had two types of accounts: Externally Owned Account (EOA) and Contract Account (smart contracts). However, only EOA were capable to initiate and sign transactions, such transfers and smart contract interactions. Smart Contracts took more of a passive role, requiring a transaction to be triggered by an EOA or another contract. Smart Contract Accounts (from now on referred only as Smart Accounts), changes the game, taking an active role when it comes to initiate and sign transactions, without relying on a EOA to pull the trigger. With Smart Accounts we’ve got programmable execution and validity within the user’s account, so it can initiate transactions and pay for gas when some criteria are met.</p><p>Smart Accounts work together with bundlers, which receive the transaction, verify it off-chain and if it is valid, make a bundle with other transactions and send it to the EntryPoint contract. This contract acts as a gatekeeper that unpack the bundles, verify the transactions and if the transactions are valid, execute them on chain. For better understanding of each ERC-4337 component, I suggest reading this article <a href="https://paragraph.xyz/@chaskin/from-abstract-to-accessible-ethereums-journey-towards-programmable-accounts"><em>here</em></a>.</p><p>Since a Smart Account allows you to determine how verifications and executions are made, it holds the potential to change Web3 UX for good. Transaction batching, gas abstraction, to sign transactions with biometric methods, subscription payments with ERC-20, all of these are possible. However, we are not there yet due to some limitations when it comes to customisation.</p><h3>ERC-7579 enters the game</h3><p>Smart Accounts used to be static contracts, meaning that if you wanted to add any features, you had to fork an existing implementation and add whatever you needed or you’d have to start from zero, paying for audits and to redeploy everything. Also, Smart Accounts used to be difficult to migrate (not to say impossible) from one vendor to another, causing user fragmentation. I said “used to”, because ERC-7579 is meant to change that by outlining minimal required components for modular smart accounts. Once we have some core pieces standardized, interoperability can be guaranteed and development becomes easier. Devs won’t need to build from the ground, but solely focus on building and pushing new features, knowing that any smart account, built with standard modules, would easily adopt them.</p><p>In the following section, I will make an effort to explain a couple of components of Modular AA: modules and accounts.</p><h3>Modules Types</h3><p>Modules are what makes ERC-7579 super cool and we have different types of modules to cover while understanding how module functions work.</p><h4>The basics: IModule Interface</h4><p>The IModuleinterface is the interface that all modules need to inherit. IModule defines the basic structure and requirements for modules that can be installed and used with Smart Accounts. It includes:</p><pre> function onInstall(bytes calldata data) external;</pre><p>This is the function to install the module on <em>Modular Smart Wallet. </em>It takes a bytes parameter that may be required on the module. Here’s an example:</p><pre>// SimpleExecutionValidator by @erc7579-implementation<br><br>  mapping(address =&gt; bool) internal _initialized;<br><br>  function onInstall(bytes calldata data) external override {<br>      if (isInitialized(msg.sender)) revert AlreadyInitialized(msg.sender);<br>      _initialized[msg.sender] = true;<br>    }</pre><p>It first checks if the module has already been initialized for calling the Smart Account (msg.sender) using the isInitializedfunction. The data parameter allows for passing arbitrary initialization data, though it’s not used in this simple implementation. This function also ensures that the module can only be initialized once per Smart Account., preventing potential security issues from multiple initializations.</p><pre>function onUninstall(bytes calldata data) external;</pre><p>It will basically set to false the module initialized mapping and could take the same bytes data parameter. Using the same module as an example:</p><pre>// SimpleExecutionValidator by @erc7579-implementation<br><br>function onUninstall(bytes calldata data) external override {<br>    if (!isInitialized(msg.sender)) revert NotInitialized(msg.sender);<br>    _initialized[msg.sender] = false;<br>}</pre><p>This function ensures that the module can only be uninstalled if it was previously initialized for the Smart Account.</p><pre>// SimpleExecutionValidator by @erc7579-implementation<br><br>function isInitialized(address smartAccount) public view returns (bool) {<br>    return config[smartAccount].nominee != address(0);<br>}</pre><p>the function that checks if the module is Installed on the Smart account, and finally:</p><pre>function isModuleType(uint256 moduleTypeId) external view returns (bool);</pre><p>It will validate the type of the module.</p><p>Here I’m gonna go over the module types, starting with…</p><h4>Validation (type id: 1)</h4><p>During the validation phase, the EntryPoint contract (as seen previously on ERC-4337 recap) calls the validateUserOp<em> </em>function on the smart account. This is done to determine if a UserOperation (UserOp) is actually valid. The function can either return 0 or 1. If it returns 0, the EntryPoint will consider it valid, and returning 1 or reverts, the EntryPoint will not execute that and move on to the next UserOp.</p><p>The developer can decide how the signature validation actually happens, meaning that any modular validation logic can be added or removed at any point down the line.</p><p>Validators modules are called during this phase. Their primary function is to verify the signature of a UserOp and determine whether it is valid (you dont say!) and should be executed. Validator modules are the core mechanism when it comes to enforce access control.</p><p><strong>IValidator</strong></p><p>On top of the IModule, IValidator also implements two new functions that will be called on the validation phase:</p><pre>function validateUserOp(<br>    PackedUserOperation calldata userOp,<br>    bytes32 userOpHash<br>    ) external returns (uint256);<br>        <br>function isValidSignatureWithSender(<br>        address sender,<br>        bytes32 hash,<br>        bytes calldata data<br>    ) external view returns (bytes4);</pre><p>We can see that it’s basically the same validation function as the Smart Account, but what happens here is that the module is doing a validation on behalf of the account.</p><p>isValidSignatureWithSender<em> </em>is used for ERC-1271 validation as well.</p><h4>Execution (type id: 2)</h4><p>Once the validation is successfully done, the EntryPoint calls the smart account again with the calldata from the UserOp. The <em>validateUserOp </em>is always called by the EntryPoint during validation, however there is no such restriction in the execution phase, so accounts may implement a variety of execution functions and the client would be able to choose the exact one to call depending on the transaction intent.</p><p>How execution occurs is not stipulated, so it is possible to build modules for the execution phase as well.</p><p>Executors are the modules called in the execution phase of a UserOp and they allow a different set of actions to be performed by the account and are able to automate some action triggered outside the regular execution flow. An executor could do something like swap tokens when some criteria are met, like a price threshold.</p><p>Executors don’t need to implement any specific functions, meaning that you can have any logic to be executed by the Smart Account. The main difference here is that the executor module has to call <em>executeFromExecutor</em> function on the Smart Account to execute its logic. More on that later, when we get into the Smart Account contract.</p><h4>Fallback (type id: 3)</h4><p>Fallbacks are modules for additional functionality into the account. Called by the fallback function, they get triggered only if a transaction sent to the account does not match any other existing functions on the account.</p><p>We won’t be talking about fallbacks in this article.</p><h4>Hooks (type id: 4)</h4><p>Hooks are modules that can be used to enforce certain behaviors before or after execution. A hook module can, as an example, ensure that a contract is audited before allowing a transaction to happen.</p><p>A Hook module shares the</p><p>IModule interface and require two functions on top of that:</p><pre>function preCheck(<br>   address msgSender,<br>   uint256 msgValue,<br>   bytes calldata msgData<br>) external returns (bytes memory hookData);</pre><p>This function will be called on the execution phase, but before the execute function. On a Deadman Switch Hook, we would update here the last access by the account.</p><pre>function postCheck(bytes calldata hookData) external;</pre><p>And just like the <em>preCheck</em> function, this function is called on the execution phase, but after the execute function. It can be used to assert what happened on the execution or to check if the <em>preCheck </em>return value is what you expected.</p><h4>ModuleManager.sol and HookManager.sol</h4><p>And finally, managers abstract contracts that the Smart Account will inherit to manage modules. Although they are in different files, I’ll walk through contracts as if they are just one manager.</p><pre>modifier onlyExecutorModule() {<br>      SentinelListLib.SentinelList storage $executors = $moduleManager()<br>         .$executors;<br>   if (!$executors.contains(msg.sender)) revert InvalidModule(msg.sender);<br>      _;<br>    }</pre><pre>modifier onlyValidatorModule(address validator) {<br>    SentinelListLib.SentinelList storage $valdiators = $moduleManager()<br>        .$valdiators;<br>   if (!$valdiators.contains(validator)) revert InvalidModule(validator);<br>        _;<br>    }<br>    <br>modifier withHook() {<br>        address hook = _getHook();<br>        if (hook == address(0)) {<br>            _;<br>        } else {<br>            bytes memory hookData = IHook(hook).preCheck(<br>                msg.sender,<br>                msg.value,<br>                msg.data<br>            );<br>            _;<br>            IHook(hook).postCheck(hookData);<br>        }<br>    }</pre><p>These are the modifiers the Smart Account needs to use to ensure it is only called by the executor or validator. The <em>withHook</em> modifier shouldn’t be used on the validation functions and each module has its own function.</p><p>ModuleManager.sol and HookManager.sol are the contracts that handle all module installs, uninstalls and also checks if a module is installed or not.</p><p>That’s all about module types. Now we’ve to go through…</p><h3>ERC-7579 Account Interface</h3><p>Ok, here is where we connect all the dots.</p><p>The Modular Smart Account inherits the ERC-4337 Account, the managers explained above and also implements its own functions. Before going into each function, I need to explain the ModeCode system.</p><p>The ModeCode system is a bytes32 argument that is passed to execute functions that tell the account how to deal with the execution. The Smart Account can use all bytes to support multiple types or just the most significant one. This system allows for flexible and extensible Smart Account execution while maintaining simplicity for basic implementations.</p><p>The bytes32 ModeCode is divided into several parts:</p><ul><li>CALLTYPE (1 byte): Determines how to decode the execution calldata (e.g., single, batch, delegatecall).</li><li>EXECTYPE (1 byte): Specifies how the account should handle execution (e.g., revert on failure or continue).</li><li>UNUSED (4 bytes): Reserved for future use.</li><li>ModeSelector (4 bytes): Optional selector for custom account vendor behaviors.</li><li>ModePayload (22 bytes): Additional data for Smart Account execution</li><li>ExecutionCallData: Contains the actual data for execution, encoded as bytes.</li></ul><p>Basically, when we call the execute function, we use ModeCode as parameter, then the function should check the mode and execute the calldata accordingly. Here’s the assembly code to decode it:</p><pre>assembly {<br>        calltype := mode<br>        execType := shl(8, mode)<br>        modeSelector := shl(48, mode)<br>        modePayload := shl(80, mode)<br>}</pre><p>and here the main execute function:</p><pre>function execute(<br>    ModeCode mode,<br>    bytes calldata executionCalldata<br>) external payable;</pre><p>This function needs to manage the adequate authorization control and can add the <em>withHook</em> modifier.</p><p>We should also implement an <em>executeFromExecutor </em>function, which should only be called by the executor module and also can add the <em>withHook</em> modifier:</p><pre>function executeFromExecutor(<br>    ModeCode mode,<br>    bytes calldata executionCalldata<br> )<br>    external<br>    payable<br>    returns (bytes[] memory returnData);</pre><p>The last logic function on the account is the <em>isValidSignature</em> one:</p><pre>function isValidSignature(<br>    bytes32 hash,<br>    bytes calldata data<br>) external view returns (bytes4);</pre><p>This is the function that checks if there’s a Validator Module and pushes the data to the validator to validate.</p><p>This concludes the Minimal Modular Account overview. In Part 2, I plan to go over the process of module implementation.</p><p>Any feedback is welcomed and If you want to discuss it further, you can send me a message on tg @axxcar or leave a comments down below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e08559d5b7d6" width="1" height="1" alt=""><hr><p><a href="https://blog.contenta.xyz/minimal-modular-smart-accounts-contracts-overview-erc-7579-e08559d5b7d6">Minimal Modular Smart Accounts Contracts Overview (ERC-7579)</a> was originally published in <a href="https://blog.contenta.xyz/">Contenta.xyz</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>