Technical dive: EIP7702 with ERC4337

Technical dive: EIP7702 with ERC4337

·

7 min read

EIP-7702 marks a pivotal step forward in Ethereum's journey, aiming to bridge the gap between traditional Externally Owned Accounts (EOAs) and smart contracts. Let’s break down its significance, features, and implications for the ecosystem.

What is EIP-7702?

Proposed in May 2024 by Vitalik Buterin and co-authors of EIP-3074, EIP-7702 introduces smart contract capabilities to EOAs, redefining how users interact with the blockchain. The proposal has evolved to allow EOAs to retain persistent smart contract code until another EIP-7702 transaction modifies it.

Key Features

  • EOAs as Smart Contracts: Enables EOAs to function like smart contracts.

  • New Transaction Type (0x04): Facilitates code updates for EOAs.

  • Persistent Code Changes: Code persists until explicitly updated.

  • Batch Upgrades: Multiple EOAs can be updated in a single transaction.

How Does EIP-7702 Work?

  1. Signature Creation:

An EIP-7702 signature requires four crucial fields:

  • MAGIC: A to-be-determined constant that identifies the signature as an EIP-7702 type.

  • chain_id: Either 0 (for cross-chain compatibility) or the current chain's ID.

  • address: The smart contract address containing the implementation code.

  • nonce: The current valid nonce of the EOA.

The signature is created by signing the keccak256 hash of these components:

1sign(keccak256(MAGIC || rlp([chain_id, address, nonce])))

This structure ensures the integrity and authenticity of the upgrade request.

  1. Transaction Structure

EIP-7702 introduces a new transaction type (0x04) with the following format:

[
    chain_id,
    nonce,
    max_priority_fee_per_gas,
    max_fee_per_gas,
    gas_limit,
    destination,
    value,
    data,
    access_list,
    authorization_list,  // New field for EIP-7702
    signature_y_parity,
    signature_r,
    signature_s
]

The authorization_list is a new field that contains an array of EIP-7702 signatures and associated data, allowing multiple EOAs to be upgraded in a single transaction.

  1. Upgrade Process

The upgrade process for an EOA to gain smart contract functionality involves several steps:

  • Signature Creation: The upgrade begins with the creation of an EIP-7702 signature. This is done by the EOA owner, using their private key to authorize the transition to smart contract functionality. Key details embedded in the signature include:

    • The smart contract address that the EOA will adopt for its functionality.

    • Validation components like the chain ID and nonce.

This ensures secure and explicit authorization for the upgrade.

  • Transaction Submission: Once the signature is created, an EIP-7702 transaction is crafted and submitted to the Ethereum network.

    • The transaction includes a critical new field: the authorization_list. This contains one or more EIP-7702 signatures, enabling batch upgrades of multiple EOAs in a single transaction.

    • Submissions can be made by the EOA itself or facilitated by third-party relayer services.

  • Signature Verification: Upon receiving the transaction, the Ethereum network undertakes a rigorous signature verification process. This ensures:

    • The signature corresponds to the EOA initiating the upgrade.

    • The upgrade request adheres to all security and format requirements.

Successful verification is a prerequisite for moving to the next step.

  • Code Update: If the signature passes validation, the EOA's account code undergoes a significant update:

    • A delegatecall proxy is introduced, linking the EOA to the smart contract implementation specified in the signature.

    • The proxy is represented by 0xef0100 followed by the 20-byte address of the smart contract.

This enables the EOA to inherit and execute the functionalities of the designated smart contract.

  • Persistence: One of EIP-7702’s standout features is persistent upgrades. Unlike earlier iterations of the proposal where upgrades were temporary:

    • The new account code remains active until the EOA executes another EIP-7702 transaction.

    • This persistence simplifies the user experience, enabling long-term smart contract functionality without frequent interventions.

  • Execution: Post-upgrade, the EOA seamlessly behaves like a smart contract:

    • Incoming transactions to the EOA are automatically forwarded to the implementation contract specified during the upgrade.

    • The EOA retains its original address while now functioning with advanced capabilities.

Multi-Account Upgrades
One of the powerful features of EIP-7702 is the ability to upgrade multiple EOAs in a single transaction. This is achieved through the authorization_list in the transaction structure. Each entry in this list corresponds to a different EOA, allowing for batch upgrades which can significantly reduce gas costs and simplify the upgrade process for service providers or wallet operators.

Benefits of EIP-7702

  • Enhanced Functionality: Combines EOA simplicity with smart contract features.

  • Improved UX: Enables gas sponsorship, batching, and flexible upgrades.

  • Cross-Chain Compatibility: Supports EVM chain interactions with chain_id 0.

  • Efficiency: Batch upgrades reduce transaction costs for service providers.

Addressing Concerns

  1. Storage Collisions:

    • Mitigated by EIP-7201, introducing namespaced storage layouts.
  2. Security Risks:

    • Wallets ensure one-time-use EIP-7702 signatures and user-controlled updates.
  3. Legacy Compatibility:

    • Developers must adapt contracts relying on EOA checks (tx.origin == msg.sender).
  4. Complexity:

    • Gradual rollout, testing, and auditing to ensure ecosystem stability.
  5. Gas Costs:

    • Modular smart contract designs minimize frequent upgrades.

Compatibility with ERC-4337

When an EOA is upgraded using EIP-7702, it can point to a smart contract implementation that is ERC-4337 compatible. This allows for the following workflow:

  • User initiates a transaction through a dApp interface.

  • The dApp creates a UserOperation with userOp.sender set to the EOA address.

  • The UserOperation is sent to a bundler.

  • The bundler packages multiple UserOperations and sends them to the EntryPoint contract.

  • The EntryPoint contract calls the upgraded EOA for validation and execution.

  • The EOA, now behaving as a smart contract, processes the UserOperation according to its ERC-4337 compatible implementation.

Implications of EIP-7702 for Different Stakeholders

For Users

  1. Seamless Upgrade

    • Users can transition to smart account functionality without losing their original account address or familiarity with seed phrase-based recovery.
  2. Retention of EOA Features

    • Despite the upgrade, users retain key EOA traits, ensuring compatibility with existing tools and workflows.
  3. Enhanced Security and Recovery

    • Upgrades introduce better mechanisms for security (e.g., multi-sig functionality) and recovery options in case of account compromise.

For Developers

  1. New Interaction Possibilities

    • dApps can interact with upgraded EOAs as smart contracts, enabling features like native multi-call support or meta-transactions.
  2. Contract Updates

    • Existing contracts that rely on distinguishing EOAs (e.g., tx.origin == msg.sender) may need updates to ensure compatibility.
  3. Leverage Enhanced Accounts

    • Developers can build on the enhanced features of upgraded accounts, such as modularity and extensibility, for innovative use cases.

For Wallet Providers

  1. Stronger Security Requirements

    • Providers must implement robust measures to prevent unauthorized or malicious upgrades (e.g., strict signature validation processes).
  2. Improved User Experience

    • Smart account features, such as gas abstraction and programmable controls, allow providers to enhance the wallet experience.
  3. Maintenance of Trust

    • Clear communication about upgrade implications and recovery mechanisms will be essential to maintaining user confidence.

Potential Concerns and Mitigations

1. Storage Collisions

  • Concern: Switching implementations can result in overlapping storage slots, causing corruption or unintended behavior.

  • Mitigation:

    • Implement EIP-7201 (Namespaced Storage Layout) to segregate storage by hashing namespaces and local indices.

    • Example:

        solidityCopy codebytes32 private constant MAIN_STORAGE_LOCATION =
            keccak256(abi.encode(uint256(keccak256("example.main")) - 1)) & ~bytes32(uint256(0xff));
      
        function _getMainStorage() private pure returns (MainStorage storage $) {
            assembly {
                $.slot := MAIN_STORAGE_LOCATION
            }
        }
      

2. Security Risks

  • Concern: Persistent upgrades could allow a malicious actor to compromise accounts indefinitely.

  • Mitigation:

    • Restrict EIP-7702 signatures to one-time use during initialization.

    • Users can reset or revert to a standard EOA using a new EIP-7702 transaction.

    • Education: Wallet providers should offer clear, intuitive interfaces to guide users.

3. Compatibility with Existing Contracts

  • Concern: Legacy smart contracts relying on EOA checks may fail or behave unpredictably with upgraded accounts.

  • Mitigation:

    • Promote best practices for account verification that don’t rely on tx.origin or simplistic checks.

    • Transition dApps and contracts to handle all account types gracefully.

4. Increased Complexity

  • Concern: Upgradeable EOAs introduce additional layers of complexity, which could result in unforeseen vulnerabilities.

  • Mitigation:

    • Rigorous testing and auditing before mainnet deployment.

    • Gradual adoption and robust community feedback loops.

    • Proactive issue resolution during post-deployment phases.

5. Gas Costs and Network Load

  • Concern: Frequent implementation upgrades could increase costs and burden the network.

  • Mitigation:

    • Encourage modular smart account designs (e.g., EIP-7579, EIP-6900) to minimize the need for frequent upgrades.

    • Explore optimizations to reduce gas costs for upgrades in future Ethereum protocol updates.

Future Outlook

EIP-7702 is expected to be included in the Pectra Hardfork, scheduled for early 2025. Its implementation could lead to:

  • Accelerate smart account adoption.

  • Encourage developers to leverage enhanced dApp functionality.

  • Inspire new wallet designs for intuitive user experiences.

Conclusion

EIP-7702 represents a transformative leap in Ethereum's quest for account abstraction. By empowering EOAs with smart contract capabilities, it aligns the blockchain with the evolving needs of users and developers. As Ethereum advances, EIP-7702 sets the stage for a more dynamic and inclusive blockchain ecosystem.

What’s Next

Check out a couple of Bundles, UserOperations, and their fees on JiffyLabs to distill the information.

Want to help build or use a low-cost bundler for wallet owners, or explore Account Abstraction-based blockchain usage? Get in Touch!

Note: If you need real-time data on 4337, do check out our leading API.

We will be releasing more deep dives, walkthroughs, and quickstart tutorials for 4337 regularly in the coming weeks. Follow on JiffyLabs to stay updated.