1/5
## Understanding Account Abstraction: The Future of Web3 Wallets Account Abstraction (AA) fundamentally redefines user accounts in Web3. Instead of traditional Externally Owned Accounts (EOAs) controlled solely by a private key, AA allows user accounts to be smart contracts. This paradigm shift enables programmable validity conditions – dictating who can send transactions and under what circumstances – and custom execution logic, offering unprecedented flexibility and security. These smart contract-based accounts are often referred to as "smart contract wallets." This lesson explores minimal implementations of AA smart contract wallets for both Ethereum (via an ERC-4337-like approach) and zkSync (leveraging its native AA capabilities), highlighting their distinct architectures and empowering developers to craft bespoke transaction flows. ## Ethereum's Approach to Account Abstraction: ERC-4337 The Ethereum ecosystem primarily tackles Account Abstraction through the ERC-4337 standard. This standard introduces a decentralized infrastructure layer without requiring consensus-level protocol changes. **Key Components of ERC-4337:** * **`EntryPoint.sol`:** This is a globally recognized, trusted smart contract. It acts as the central coordinator for AA transactions. Bundlers submit `UserOperations` to this contract, which then orchestrates their validation and execution against the target smart contract wallet. * **`UserOperation`:** Instead of standard Ethereum transactions, users (or dApps on their behalf) create `UserOperation` objects. These objects detail the intended action, signature, gas parameters, and other necessary data for the smart contract wallet. * **Alt-Mempool:** `UserOperations` are not broadcast to the standard Ethereum transaction mempool. Instead, they are sent to a separate, alternative mempool (often called an "alt-mempool"). * **Bundlers:** These are specialized actors who monitor the alt-mempool. They select `UserOperations`, bundle them into a single standard Ethereum transaction, and submit this bundle to the `EntryPoint.sol` contract. Bundlers pay the gas for this Layer 1 transaction and are subsequently reimbursed, typically from the smart contract wallet or a Paymaster. **Minimal Ethereum AA Implementation: `MinimalAccount.sol`** The `MinimalAccount.sol` contract, found within the `src/ethereum/` directory of the `github.com/Cyfrin/minimal-account-abstraction` repository, serves as a foundational example of an ERC-4337 compatible smart contract wallet. Its primary design goal is simplicity, offering a clear starting point for developers. * **Core Functionality:** * It permits transaction initiation by either its "owner" (the EOA that deployed it) or the `EntryPoint.sol` contract. * The `validateUserOp` function is crucial for verifying an incoming `UserOperation` from the `EntryPoint`. It typically checks signatures and other conditions. * The `execute` function is called by the `EntryPoint` after successful validation to perform the actual transaction logic (e.g., calling another contract). * **Extensibility:** While minimal, `MinimalAccount.sol` is designed for extension. Developers can incorporate: * **Paymaster Logic:** To allow third parties (Paymasters) to sponsor transaction fees. * **Custom Signature Schemes:** Integrating alternative signature validation, potentially via a Signature Aggregator. * **Spending Allowances/Limits:** Enforcing rules on transaction values or frequencies. * **Session Keys:** Implementing temporary, permission-restricted keys (e.g., using Google session keys) for specific interactions. **Ethereum AA Transaction Flow (ERC-4337):** 1. **UserOperation Creation:** A user, often interacting through a dApp, signs data that forms a `UserOperation`. 2. **Submission to Alt-Mempool:** The `UserOperation` is sent to an alt-mempool. 3. **Bundler Action:** Bundlers retrieve `UserOperations` from the alt-mempool, package them into a standard Ethereum transaction, and submit this bundle to the `EntryPoint.sol` contract on-chain. 4. **Validation:** The `EntryPoint.sol` contract calls the `validateUserOp` function on the target smart contract wallet (e.g., an instance of `MinimalAccount.sol`). This function verifies the operation's legitimacy (e.g., signature, nonce). 5. **Execution:** If `validateUserOp` succeeds, the `EntryPoint.sol` contract then calls the `execute` function on the smart contract wallet, which carries out the intended action (e.g., an ERC20 token transfer or a smart contract interaction). 6. **Optional Paymaster Involvement:** A Paymaster contract can be specified in the `UserOperation` to cover the gas fees, enabling gasless experiences for the end-user. ## zkSync's Native Account Abstraction: A Built-in Solution zkSync approaches Account Abstraction differently by integrating it directly into its Layer 2 protocol. This native implementation offers a more streamlined experience and distinct characteristics compared to Ethereum's ERC-4337. **Key Differences and Features in zkSync Native AA:** * **No Alt-Mempool:** AA transactions on zkSync are submitted to the regular zkSync mempool, just like EOA transactions. There's no need for a separate mempool infrastructure. * **Type 113 Transactions:** AA transactions are designated as `Type 113` (hexadecimal `0x71`). This specific type signals to the zkSync protocol that the transaction originates from a smart contract account and requires special handling. * **Bootloader:** A critical system-level component in zkSync, the Bootloader plays a central role in processing AA transactions. During both the validation and execution phases of an AA transaction, the `msg.sender` to the smart contract wallet will be the Bootloader's address. * **Smart Contract as `from` Address:** A significant distinction is that in zkSync, the `from` field of a `Type 113` transaction can be the address of the smart contract wallet itself. This contrasts with Ethereum, where the `from` field is always an EOA. **Minimal zkSync AA Implementation: `ZkMinimalAccount.sol`** The `ZkMinimalAccount.sol` contract, located in `src/zksync/` of the repository, demonstrates a basic smart contract wallet utilizing zkSync's native AA. * **Important Contract Functions:** * `validateTransaction(bytes32 _txHash, bytes32 _suggestedSignedHash, Transaction _transaction)`: This function is paramount. It's called by the Bootloader to validate the incoming transaction. Responsibilities include verifying signatures against `_suggestedSignedHash` (which is `keccak256(abi.encodePacked(txHash, EIP1271_SUCCESS_RETURN_VALUE))`) and, crucially, incrementing the account's nonce to prevent replay attacks. * `executeTransaction(bytes32 _txHash, bytes32 _suggestedSignedHash, Transaction _transaction)`: After successful validation, the Bootloader calls this function to execute the actual logic defined in the `_transaction` payload. * `payForTransaction(...)`: This function (or logic within `validateTransaction`) handles the payment of transaction fees, ensuring the account can cover the costs or that a Paymaster will. **zkSync Native AA Transaction Flow:** The lifecycle of a `Type 113` transaction on zkSync involves two main phases, orchestrated by the zkSync system and the Bootloader: * **Phase 1: Validation** 1. **Submission:** The user (or dApp) sends the `Type 113` transaction to a zkSync API client. The `from` field of this transaction is the address of the `ZkMinimalAccount.sol` instance. 2. **`msg.sender` is Bootloader:** For both validation and execution phases, the `msg.sender` to the `ZkMinimalAccount.sol` will be the Bootloader. 3. **Nonce Check (System):** The API client, interacting with the NonceHolder system contract, verifies the uniqueness of the transaction's nonce for the account. 4. **Account Validation Call:** The API client (via the Bootloader) calls `validateTransaction` on the `ZkMinimalAccount.sol`. This function *must* perform signature checks and update the account's nonce. 5. **Nonce Update Verification (System):** The API client checks if the `ZkMinimalAccount.sol` correctly updated its nonce. 6. **Fee Payment Check (System):** The API client calls `payForTransaction` on the account (or invokes Paymaster logic if specified) to ensure the transaction fees can be covered. 7. **Bootloader Payment Verification (System):** The API client confirms that the Bootloader will be compensated for processing the transaction. * **Phase 2: Execution** 1. **To Sequencer:** The validated transaction is passed from the API client to the main zkSync node/sequencer. 2. **Account Execution Call:** The main node (via the Bootloader) calls `executeTransaction` on the `ZkMinimalAccount.sol`, which then performs the intended operations. 3. **Post-Transaction (Optional):** If a Paymaster was involved, its `postTransaction` method might be called. ## Comparing Implementations: Ethereum (ERC-4337) vs. zkSync Native AA Understanding the practical differences is key when observing on-chain activity. * **zkSync Sepolia Example (Native AA):** * Consider a transaction approving USDC spending from a deployed `ZkMinimalAccount` (e.g., `0xCB38...5691`). * On the zkSync Sepolia explorer, the **`from` address** of this transaction (hash `0x4322...d0fd`) will be the `ZkMinimalAccount` smart contract address itself. This directly demonstrates the smart contract initiating the call. * **Ethereum (Arbitrum Example with ERC-4337):** * Consider a similar USDC approval from a `MinimalAccount` deployed on Arbitrum (an Ethereum L2 that can support ERC-4337). * On Arbiscan, the transaction (hash `0x03f9...154b`) will show its **`from` address** as a **Bundler** (e.g., `0x9EA9...F6fC`). * The transaction's **`to` address** will be the `EntryPoint.sol` contract (e.g., version 0.7.0 at `0x000...032`). * However, by inspecting the transaction logs, one would find an `Approval` event emitted by the USDC contract where the `owner` (the account granting approval) is the `MinimalAccount` smart contract wallet address (e.g., `0x83Ad...AAf`). This confirms that, despite the Bundler being the transaction submitter, the smart contract wallet was the effective initiator of the state change via the EntryPoint. ## Core Components: Paymasters and Signature Aggregators Both ERC-4337 and zkSync's native AA can be enhanced with optional components: * **Paymasters:** These are smart contracts that can sponsor transaction fees on behalf of users. This enables "gasless" transactions for the end-user, where the dApp, a protocol, or another entity covers the costs. Paymasters are integrated into the validation flow, agreeing to pay if certain conditions are met. * **Signature Aggregators:** In scenarios involving multiple `UserOperations` (especially in ERC-4337) or complex multi-signature schemes within a single account, Signature Aggregators can validate multiple signatures in a batch. This can lead to significant gas savings by reducing the on-chain verification overhead. ## Building Your Own: Code Overview and Extensibility The provided code repository at `github.com/Cyfrin/minimal-account-abstraction` offers skeletal implementations: * `src/ethereum/MinimalAccount.sol`: For ERC-4337 compatible chains. * `src/zksync/ZkMinimalAccount.sol`: For zkSync and its native AA. These minimal contracts are designed as starting points. The true power of Account Abstraction is unlocked by extending their validation logic (`validateUserOp` on Ethereum, `validateTransaction` on zkSync). Developers can build upon these bases to incorporate: * **Advanced Paymaster integrations.** * **Novel signature schemes** (e.g., BLS signatures, quantum-resistant signatures). * **Granular spending allowances** or time-based spending limits. * **Session keys** for enhanced dApp interactions, allowing temporary, restricted access without exposing primary owner keys. For example, a game might be granted a session key that can only sign transactions related to in-game actions for a limited duration. ## Unlocking Advanced Use Cases with Account Abstraction The customizability offered by these minimal AA frameworks paves the way for sophisticated wallet features: * **Session Keys:** Granting temporary, limited permissions to dApps or other services for specific actions (e.g., a gaming session key that can only sign game-related transactions for a set period). * **Custom Multisig:** Implementing complex N-of-M signature schemes beyond standard multisigs, potentially involving role-based access or conditional approvals (e.g., requiring 2 out of 3 specific signers plus a time-locked passcode). * **Social Recovery:** Enabling users to regain access to their accounts through a set of trusted guardians or social connections, rather than relying solely on a seed phrase. * **Gas Sponsorship:** Facilitating frictionless onboarding and interaction by allowing dApps or protocols to cover transaction fees for their users via Paymasters. ## Key Takeaways for Developers Building and experimenting with both the Ethereum ERC-4337 style and zkSync's native Account Abstraction implementations provides invaluable insight into their respective nuances, strengths, and trade-offs. The core innovation lies in the programmable validation logic within the smart contract wallet itself (`validateUserOp` or `validateTransaction`). This programmability is what empowers developers to create highly secure, user-friendly, and feature-rich Web3 experiences, moving beyond the limitations of traditional EOA wallets. By understanding these foundational patterns, developers can choose the most suitable AA approach for their target blockchain and application needs.
An enlightening exploration of Account Abstraction: The Future of Web3 Wallets on Ethereum & zkSync - Discover how smart contract wallets are reshaping user experience, comparing Ethereum's ERC-4337 (EntryPoint, Bundlers) with zkSync's native AA (Bootloader). Learn from minimal examples to unlock custom transaction logic and advanced features.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Advanced smart contract development
How to develop a stablecoin
How to develop a DeFi protocol
How to develop a DAO
Advanced smart contracts testing
Fuzz testing
Manual verification
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Guest lecturers:
Juliette Chevalier
Lead Developer relations at Aragon
Nader Dabit
Director of developer relations at EigenLayer
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on May 12, 2025
Solidity Developer
Advanced FoundryDuration: 36min
Duration: 3h 06min
Duration: 5h 02min
Duration: 6h 02min
Duration: 2h 47min
Duration: 1h 23min
Duration: 4h 28min
Duration: 1h 19min
Duration: 1h 10min
Course Overview
About the course
Advanced smart contract development
How to develop a stablecoin
How to develop a DeFi protocol
How to develop a DAO
Advanced smart contracts testing
Fuzz testing
Manual verification
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Guest lecturers:
Juliette Chevalier
Lead Developer relations at Aragon
Nader Dabit
Director of developer relations at EigenLayer
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on May 12, 2025