Launch week // DEC 16-20An entire week of new feature announcements

Learn more

Technical dive: EIP7702 with ERC4337

8 min read

EIP7702.svg

Ethereum, the world's leading smart contract platform, is on the brink of a major upgrade that could revolutionize how users interact with the blockchain. Enter EIP-7702, a groundbreaking proposal set to transform Externally Owned Accounts (EOAs) by granting them smart contract capabilities.

What is EIP-7702?

EIP-7702, proposed by Ethereum co-founder Vitalik Buterin and the co-authors of EIP-3074 in May 2024, introduces a new transaction type that allows EOAs to have smart contract code. Initially designed to set EOA account code for a single transaction, the proposal has evolved to allow the code to persist until the next EIP-7702 transaction.

Key Features:

  • Enables EOAs to function as smart contracts
  • Introduces a new transaction type (0x04)
  • Allows for persistent code changes
  • Supports multiple EOA upgrades in a single transaction

The Evolution of EIP-7702

The proposal has undergone significant changes since its inception:

  1. Initial Version: Set EOA account code for one transaction
  2. Current Version: Set EOA account code that persists until the next EIP-7702 transaction

This evolution addresses previous limitations and opens up new possibilities for account functionality and user experience.

How EIP-7702 Works

EIP-7702 introduces a new mechanism that allows Externally Owned Accounts (EOAs) to behave like smart contracts. Let's break down the key components and processes:

Signature Structure

An EIP-7702 signature requires four crucial fields:

  1. MAGIC: A to-be-determined constant that identifies the signature as an EIP-7702 type.
  2. chain_id: Either 0 (for cross-chain compatibility) or the current chain's ID.
  3. address: The smart contract address containing the implementation code.
  4. nonce: The current valid nonce of the EOA.

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


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

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

Transaction Structure

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


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

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.

Upgrade Process

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

  1. Signature Creation: The EOA owner creates an EIP-7702 signature using their private key. This signature authorizes the upgrade and specifies the smart contract address to be used for the account's new functionality.

  2. Transaction Submission: The EIP-7702 transaction is submitted to the network. This can be done by the EOA itself or by a separate relayer service. The transaction includes the authorization_list containing the EIP-7702 signature(s).

  3. Signature Verification: Upon receiving the transaction, the Ethereum network verifies the EIP-7702 signature(s) to ensure they are valid and correspond to the EOAs being upgraded.

  4. Code Update: If the signature is valid, the EOA's account code is updated. The new code is a special delegatecall proxy that points to the address specified in the EIP-7702 signature. This is typically represented as 0xef0100 followed by the 20-byte address of the implementation contract.

  5. Persistence: Unlike earlier versions of the proposal, this code change persists until another EIP-7702 transaction is made for the same account. This allows the EOA to maintain its smart contract functionality across multiple transactions.

  6. Execution: After the upgrade, when transactions are sent to the EOA, they are automatically forwarded to the implementation contract, allowing the account to behave like a smart contract while retaining its original EOA address.

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

  1. Enhanced Functionality: EOAs gain smart contract capabilities
  2. Improved User Experience: Enables features like gas sponsorship and transaction batching
  3. Cross-Chain Compatibility: Signatures with chain_id 0 are valid across all EVM chains
  4. Efficient Upgrades: Multiple EOAs can be converted to smart accounts in one transaction
  5. Flexibility: EOAs retain their original functionality while gaining smart contract features

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:

  1. User initiates a transaction through a dApp interface.
  2. The dApp creates a UserOperation with userOp.sender set to the EOA address.
  3. The UserOperation is sent to a bundler.
  4. The bundler packages multiple UserOperations and sends them to the EntryPoint contract.
  5. The EntryPoint contract calls the upgraded EOA for validation and execution.
  6. The EOA, now behaving as a smart contract, processes the UserOperation according to its ERC-4337 compatible implementation.

Implications for Different Stakeholders

For Users

  • Seamless upgrade to smart account functionality
  • Retention of EOA features and seed phrase importance
  • Improved account security and recovery options

For Developers

  • New possibilities for dApp interactions
  • Potential need to update smart contracts that rely on EOA checks
  • Opportunity to leverage enhanced account features

For Wallet Providers

  • Need for robust security measures to prevent malicious upgrades
  • Potential for improved user experience through smart account features

Potential Concerns and Mitigations

While EIP-7702 offers significant benefits, it also introduces new considerations that need to be carefully addressed:

1. Storage Collisions

Concern: When an EOA upgrades from one smart contract implementation to another, there's a risk of storage collision. Different implementations might use the same storage slots for different purposes, leading to data corruption or unexpected behavior.

Mitigation: EIP-7201 (Namespaced Storage Layout) has been proposed to address this issue. It introduces a standard way of organizing contract storage:

  • Each module or major component of a contract uses a unique namespace.
  • Storage slots are calculated using a hash of the namespace and a local index.
  • This approach significantly reduces the risk of collisions when switching between different implementations.

Example of EIP-7201 implementation:


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

2. Security Risks

Concern: The persistent nature of the upgrade means that a single malicious EIP-7702 signature could potentially compromise an account indefinitely.

Mitigation:

  • Wallet providers are expected to implement strict security measures around EIP-7702 signatures, potentially limiting them to one-time use during account initialization.
  • Users retain the ability to submit new EIP-7702 transactions to update their account's code or revert to a standard EOA, providing a mechanism to recover from malicious upgrades.
  • Education and clear user interfaces will be crucial to help users understand the implications of EIP-7702 upgrades.

3. Compatibility with Existing Contracts

Concern: Some existing smart contracts rely on checking whether an address is an EOA (often by using tx.origin == msg.sender). These contracts might behave unexpectedly with upgraded EOAs.

Mitigation:

  • Developers will need to update contracts that rely on EOA checks to account for EIP-7702 upgraded accounts.
  • New best practices will emerge for distinguishing between different types of accounts without relying on outdated methods.

4. Increased Complexity

Concern: The addition of upgradeable EOAs increases the overall complexity of the Ethereum ecosystem, which could lead to unforeseen issues or vulnerabilities.

Mitigation:

  • Extensive testing and auditing of EIP-7702 implementations before mainnet deployment.
  • Gradual rollout and adoption to allow time for the ecosystem to adapt.
  • Ongoing monitoring and quick response mechanisms for addressing any issues that arise post-deployment.

5. Gas Costs and Network Load

Concern: If a large number of EOAs frequently change their implementation, it could lead to increased network load and higher gas costs.

Mitigation:

  • Encouraging the use of modular smart account implementations (like those proposed in EIP-7579 and EIP-6900) that reduce the need for frequent upgrades.
  • Potential future optimizations to reduce the gas cost of EIP-7702 upgrades.

Future Outlook

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

  • Rapid adoption of smart account features
  • Evolution of dApp interactions to leverage new account capabilities
  • Increased focus on wallet UX and transaction simulation

Conclusion

EIP-7702 represents a significant leap forward in Ethereum's account abstraction journey. By bridging the gap between EOAs and smart contracts, it paves the way for a more flexible, user-friendly blockchain experience. As the Ethereum community prepares for this upgrade, developers, users, and businesses should stay informed about the potential impacts and opportunities that EIP-7702 will bring to the ecosystem.

FAQs

  1. What is the main purpose of EIP-7702? EIP-7702 allows Externally Owned Accounts (EOAs) to have smart contract functionality, enhancing their capabilities and improving user experience on the Ethereum network.

  2. When is EIP-7702 expected to be implemented? EIP-7702 is anticipated to be included in the Pectra Hardfork, scheduled for early 2025.

  3. Will EIP-7702 affect my existing EOA? EIP-7702 is opt-in, meaning your existing EOA will not be automatically affected. You can choose to upgrade your EOA to have smart contract functionality.

  4. Is EIP-7702 compatible with existing dApps? Most existing dApps should remain compatible, but some may need updates to fully leverage the new features provided by EIP-7702.

  5. How does EIP-7702 improve security? EIP-7702 enables advanced security features like multi-factor authentication and account recovery options, which were previously only available to smart contract wallets.

Share this article