EIPs Explained

ERC-7405 · Draft · ERC · 2023-07-26

ERC-7405: Portable Smart Contract Accounts

Lets a user move a proxy-based smart contract account from one wallet provider's implementation to another's using a one-time migration key and a time lock, much like exporting an EOA's private key.

What problem does it solve?

With an externally-owned account (EOA) you can export your seed phrase from one wallet and import it into another. Smart contract accounts (SCAs), such as ERC-4337 wallets, do not work that way: each wallet provider ships its own contract code, so your account address is effectively tied to the provider that deployed it. Switching providers means creating a new account and moving every asset by hand.

ERC-7405 proposes a migration path that works at the proxy layer. Most SCAs are ERC-1967 proxies, so if the proxy can be safely re-pointed to Wallet B's implementation, the user keeps the same address and assets while changing provider.

How it works

Migration key. For each migration, Wallet A generates a brand-new random private key or mnemonic (the "random operator") and shows it to the user. Its address identifies the migration.

Step 1: prepare (Wallet A). The account calls prepareAccountMigration(randomOperator, signature). This must be authenticated as the account itself (for example, coming through the ERC-4337 EntryPoint). It checks the operator's signature, records {account, createTime, lockUntil} in a shared IERC7405Registry, and locks the account.

Lock period. While locked, the account should refuse asset transfers, external calls and changes to its authentication. The owner can call cancelAccountMigration() with normal account auth to abort, which protects against a stolen or malicious migration.

Step 2: handle (Wallet B). The user imports the migration key into Wallet B, which calls handleAccountMigration(newImplementation, initData, signature). This function is deliberately callable by anyone; it relies on the migration-key signature and requires that the lock has expired. It runs Wallet A's cleanup hook, swaps the ERC-1967 implementation slot, calls initData to set up Wallet B, deletes the registry entry and emits AccountMigrated.

Signatures are ERC-191 signatures over abi.encode(chainID, selector, data).

Storage layout. To avoid one wallet's state clobbering another's, implementations must keep all state in a struct at a namespaced slot such as keccak256("foo_wallet_v1.config") - 1, rather than declaring ordinary state variables.

Sample code

The account-side interface:

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

interface IERC7405 {
    event AccountMigrated(address oldImplementation, address newImplementation);

    // Called via the account's own auth (e.g. EntryPoint) on the old wallet
    function prepareAccountMigration(address randomOperator, bytes calldata signature) external;

    // Called via the account's own auth to abort during the lock period
    function cancelAccountMigration() external;

    // Callable by anyone holding a valid migration-key signature, after lockUntil
    function handleAccountMigration(
        address newImplementation,
        bytes calldata initData,
        bytes calldata signature
    ) external;
}

// Namespaced storage, as the spec recommends
library FooWalletStorage {
    bytes32 constant SLOT = bytes32(uint256(keccak256("foo_wallet_v1.config")) - 1);
    struct Layout { address owner; uint256 nonce; }
    function layout() internal pure returns (Layout storage l) {
        bytes32 s = SLOT;
        assembly { l.slot := s }
    }
}

Things to know

  • Status is Draft, and the spec has no reference implementation yet.
  • The registry is meant to be a single shared contract; the spec does not give a deployment address.
  • The migration key is a bearer secret: anyone holding it can complete the migration once the lock expires. The lock period and owner notifications are the main defence.
  • The spec text names the step-2 function handleWalletMigration in one place but handleAccountMigration in the interface; the interface name is the one to implement.
  • The namespaced-storage idea is closely related to ERC-7201.

#account-abstraction #wallet #proxy #migration

Details

Authors
Aaron Yee (@aaronyee-eth)
Status
Draft
Type
Standards Track / ERC
Created
2023-07-26
Requires

Machine-readable: Markdown · JSON