Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article covers ERC7405, a proposal for safely and easily migrating smart contract accounts to other wallets.

This article translates, summarizes, and expands on the following specification.

I also cover a range of EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs.

Overview

Portable Smart Contract Accounts (PSCA) address a limitation of smart contract accounts (SCAs): the inability to migrate to another wallet. SCA implementations differ between wallets, making it difficult for users to switch providers. PSCA uses the ERC1967 proxy architecture to let users move their SCAs to another wallet.

For more on ERC1967, see the following article.

[ERC1967] How contract upgrades work

Migration uses a newly generated random migration key. The experience resembles exporting an externally owned account (EOA) using a private key or mnemonic.

PSCA combines signatures and a timelock to secure migration. Even after approving migration, users can inspect its details during the timelock period and cancel it if something is wrong. This helps prevent unauthorized migration requests from succeeding.

PSCA does not require changes to the underlying SCA implementation logic, keeping adoption costs low and making migration between different implementations, such as Wallet A and Wallet B, easier. This improves interoperability and extensibility in the account abstraction (AA) ecosystem.

Motivation

ERC4337 has made account abstraction (AA) more widely available, and more wallets are adopting SCAs. Unlike EOAs, however, the code of an SCA depends on the wallet. SCA users therefore face several problems.

For more on ERC4337, see the following article.

[ERC4337] Implementing account abstraction without changing the protocol

  • Each wallet has a different contract implementation.
  • As a result, users cannot simply transfer their accounts to another provider's wallet.
  • Without migration functionality, users may remain tied to the SCA they originally created for a long time.

Some proposals suggest making SCA implementations modular, but this requires wallets to adopt similar designs and can increase adoption costs. Given the different implementation strategies used by wallet providers, a standardized modular approach is not necessarily suitable for every wallet.

PSCA instead adds functionality at the proxy (ERC1967) layer. This offers several benefits.

  • Adoption requires minimal changes to existing wallet implementations.
  • Migration between wallets does not depend on internal SCA logic.
  • The approach can coexist with modular architectures and improve extensibility across the AA ecosystem.
  • The user experience resembles exporting an EOA private key.

As shown below, an SCA can move from Wallet A to Wallet B while retaining the same SCA proxy address.

Smart contract account migration from Wallet A to Wallet B https://eips.ethereum.org/EIPS/eip-7405

The original diagram is retained; any Japanese labels remain untranslated.

PSCA's central goal is to remove dependence on particular wallet implementations and let users choose their wallets freely. This makes the AA ecosystem more open and interoperable.

Specification

Terminology

The following are the main terms used in PSCA.

Term Description
Wallet Provider A provider of wallet services. Providers use incompatible SCA implementations that lack portability.
Random Operator A new random private key or mnemonic generated for account migration. The address corresponding to its public key is treated as the randomOperator.
BIP44 A common standard for deriving keys from mnemonics. The derivation path used here is m/44'/60'/0'/0/0'.

Interface

IERC7405.sol
interface IERC7405 {
    /**
     * @dev emitted when the account finishes the migration
     * @param oldImplementation old implementation address
     * @param newImplementation new implementation address
     */
    event AccountMigrated(
        address oldImplementation,
        address newImplementation
    );
    
    /**
     * @dev prepare the account for migration
     * @param randomOperator public key (in address format) of the random operator
     * @param signature signature signed by the random operator
     *
     * **MUST** check the authenticity of the account
     */
    function prepareAccountMigration(
        address randomOperator,
        bytes calldata signature
    ) external;

    /**
     * @dev cancel the account migration
     *
     * **MUST** check the authenticity of the account
     */
    function cancelAccountMigration() external;

    /**
     * @dev handle the account migration
     * @param newImplementation new implementation address
     * @param initData init data for the new implementation
     * @param signature signature signed by the random operator
     *
     * **MUST NOT** check the authenticity to make it accessible by the new implementation
     */
    function handleAccountMigration(
        address newImplementation,
        bytes calldata initData,
        bytes calldata signature
    ) external;
}

Events

AccountMigrated
javascript
event AccountMigrated(
    address oldImplementation,
    address newImplementation
);

Emitted when account migration is complete. The event is emitted when the SCA switches from Wallet A's implementation to Wallet B's implementation. It records the old and new implementation addresses so external observers can verify that migration occurred.

Parameters

  • oldImplementation
    • The implementation contract address before migration.
  • newImplementation
    • The implementation contract address after migration.

Functions

prepareAccountMigration
javascript
function prepareAccountMigration(
    address randomOperator,
    bytes calldata signature
) external;

Prepares the account for migration. Wallet A signs with a randomly generated key and passes the corresponding public key address as randomOperator. This function checks the authenticity of the SCA, verifies the signature, registers the migration, and locks the account. Once this function executes, the account remains locked until migration is completed or canceled.

Arguments

  • randomOperator
    • The address corresponding to the public key generated specifically for migration.
  • signature
    • A signature made with the migration private key.
cancelAccountMigration
javascript
function cancelAccountMigration() external;

Cancels account migration. After checking the authenticity of the SCA, the function unlocks the account and removes the migration information from the registry. Wallet A uses it to abort migration.

handleAccountMigration
javascript
function handleAccountMigration(
    address newImplementation,
    bytes calldata initData,
    bytes calldata signature
) external;

Completes migration and switches the account to the new implementation. Wallet B calls this function, which is designed to be accessible without the original account authentication check. It verifies the signature and registry information, runs Wallet A's pre-migration logic, changes the ERC1967 proxy implementation address, runs initialization, removes the registry entry, and emits the migration event.

Arguments

  • newImplementation
    • The address of Wallet B's new implementation contract.
  • initData
    • The data needed to initialize Wallet B's implementation.
  • signature
    • A signature made with the migration private key.

MigrationOp and Signatures

PSCA uses signatures made with a randomly generated migration private key for all migration operations.

Structs

MigrationOp
javascript
struct MigrationOp {
    uint256 chainID;
    bytes4 selector;
    bytes data;
}

Represents the details of a migration operation. It contains the chain ID, the function identifier (selector), and the data passed to the function. An ERC191 signature over this data protects it against tampering.

For more on ERC191, see the following article.

[ERC191] Using signed data securely

Parameters

  • chainID
    • The identifier of the chain covered by the signature.
  • selector
    • The identifier of the function to call.
  • data
    • Additional data encoded according to the selector.

Signature Scheme

MigrationOp is signed using the ERC191 signature scheme.

selector Target function data contents
0x50fe70bd prepareAccountMigration abi.encode(randomOperator)
0xae2828ba handleAccountMigration abi.encode(randomOperator, setupCalldata)

The data used to produce the hash to sign is encoded as follows.

text
abi.encode(chainID, selector, data)

Registry (IERC7405Registry)

A shared registry manages migration information. It lets wallets find the target account using only the random key and maintains consistency throughout migration.

IERC7405Registry.sol
interface IERC7405Registry {
    struct MigrationData {
        address account;
        uint48 createTime;
        uint48 lockUntil;
    }

    /**
     * @dev check if the migration data for the random operator exists
     * @param randomOperator public key (in address format) of the random operator
     */
    function migrationDataExists(
        address randomOperator
    ) external returns (bool);

    /**
     * @dev get the migration data for the random operator
     * @param randomOperator public key (in address format) of the random operator
     */
    function getMigrationData(
        address randomOperator
    ) external returns (MigrationData memory);

    /**
     * @dev set the migration data for the random operator
     * @param randomOperator public key (in address format) of the random operator
     * @param lockUntil the timestamp until which the account is locked for migration
     *
     * **MUST** validate `migrationDataMap[randomOperator]` is empty
     */
    function setMigrationData(
        address randomOperator,
        uint48 lockUntil
    ) external;

    /**
     * @dev delete the migration data for the random operator
     * @param randomOperator public key (in address format) of the random operator
     *
     * **MUST** validate `migrationDataMap[randomOperator].account` is `msg.sender`
     */
    function deleteMigrationData(address randomOperator) external;
}

Structs

MigrationData
javascript
struct MigrationData {
    address account;
    uint48 createTime;
    uint48 lockUntil;
}

Stores migration information. It records which account is associated with a given randomOperator and when the lock expires.

Parameters

  • account
    • The address of the account being migrated.
  • createTime
    • The time of registration.
  • lockUntil
    • The time at which the account's lock period ends.

Functions

migrationDataExists
javascript
function migrationDataExists(address randomOperator) external returns (bool);

Checks whether migration data exists for the specified randomOperator. During preparation, it is used to determine whether the same randomOperator is already in use.

Arguments

  • randomOperator
    • The address to look up.

Return value

  • bool
    • Whether the data exists.
getMigrationData
javascript
function getMigrationData(address randomOperator) external returns (MigrationData memory);

Retrieves migration data associated with randomOperator. Wallet B calls this function during migration to identify the target account and check the lock status.

Arguments

  • randomOperator
    • The address to look up.

Return value

  • MigrationData
    • The associated migration data.
setMigrationData
javascript
function setMigrationData(address randomOperator, uint48 lockUntil) external;

Registers new migration data. The function first verifies that migrationDataMap[randomOperator] is empty. Wallet A calls it during its prepare operation.

Arguments

  • randomOperator
    • The public key address used for migration.
  • lockUntil
    • The time at which the lock period ends.
deleteMigrationData
javascript
function deleteMigrationData(address randomOperator) external;

Deletes migration data. migrationDataMap[randomOperator].account must match msg.sender. This function is used when Wallet A cancels migration or Wallet B completes it.

Arguments

  • randomOperator
    • The public key address whose migration data is to be removed.

Expected Behavior

An SCA migrates from Wallet A to Wallet B as follows.

1. Wallet A prepares migration

  1. Generate a new random migration key (a mnemonic or private key) and provide it to the user.
  2. Sign MigrationOp and call prepareAccountMigration.
  3. Check the authenticity of the SCA (for example, in ERC4337, verify that the call comes from the EntryPoint).
  4. Verify the signature and check randomOperator.
  5. Check that the same randomOperator does not already exist in the registry.
  6. Register the migration with setMigrationData and lock the account.

The account remains locked until migration is canceled or completed.

2. Wallet B completes migration

  1. Import the migration key and sign MigrationOp.
  2. Call handleAccountMigration. No original account authentication check is performed at this point.
  3. Verify the signature from randomOperator.
  4. Retrieve migrationData from the registry and verify that the lock period has elapsed.
  5. Run Wallet A's pre-migration logic, _beforeWalletMigration().
  6. Switch the proxy to Wallet B's implementation.
  7. Run Wallet B's initialization logic using initData.
  8. Delete the migration data from the registry.
  9. Emit AccountMigrated.

3. Wallet A cancels migration

  1. Authenticate the SCA.
  2. Unlock the account and delete the registry data.

Storage Layout

PSCA defines the following rules to prevent storage collisions between wallet implementations.

  • State variables must not be declared directly in the implementation contract.
  • All state variables must be grouped in a struct and stored at a specific slot.
  • Each wallet must choose a unique slot index.

Slot ID Design

Item Rule
namespace Only A–Z, a–z, 0–9, and _ are permitted.
Recommended format wallet名_メジャーバージョン (wallet name and major version; e.g., foo_wallet_v1)
slotID {namespace}.{customDomain} (e.g., foo_wallet_v1.config)
Actual slot index bytes32(uint256(keccak256(slotID) - 1))

Further Explanation

Smart Contract Account (SCA) implementations vary between wallets. When a user wants to move to another wallet, this lack of compatibility makes the transition difficult. Wallet-specific implementations are common in SCA architectures, but the result is account lock-in.

One approach to solving this problem is to make SCAs modular. However, this requires wallets to adopt new structures and support modules, increasing the adoption burden. Maintaining compatibility with existing wallet implementations and controlling operating costs are also challenges.

PSCA therefore builds on the ERC1967 proxy and introduces a migration mechanism resembling EOA export using a private key or mnemonic. Following a familiar workflow makes it intuitive and easy for users to operate.

To meet the security requirements of SCAs, a new random migration key is generated for each migration. The address corresponding to this key is treated as randomOperator and used to verify signatures throughout the migration process. The resulting experience resembles exporting an EOA private key while providing the security needed for SCA migration.

Another major element is the shared registry. A registry at the protocol layer makes migration information easy to look up and lets wallets identify the SCA using only the migration key. This substantially simplifies the migration procedure.

Different wallet implementations also use different SCA storage layouts, which can lead to collisions during migration. The recommended design groups all state variables in a struct and stores them at unique slots. This allows safe, consistent migration between different wallets without storage collisions.

Compatibility

Because PSCA is based on the ERC1967 proxy, it is compatible with all SCAs already using ERC1967. SCAs that do not comply with ERC4337 can also use it.

PSCA does not require a special structure or additional functionality in the underlying SCA implementation contract. It only requires implementing the common interface needed for migration, so many existing SCAs can adopt it without changing their underlying logic. This provides broad compatibility without dependence on a particular wallet implementation.

Security

PSCA introduces several important mechanisms to secure the migration process.

First, it uses a newly generated migration key each time. Avoiding key reuse prevents signature reuse (replay attacks). Using a random, one-time key for every migration operation reduces the risk of abuse.

Second, wallet implementations have different storage structures, so storage collisions after migration must be avoided. The recommended design groups storage in a struct and places it at an independent slot. Following this rule preserves security by preventing collisions with the original storage even when the destination implementation is different.

PSCA also introduces a timelock to prevent malicious third parties from immediately completing migration. Once migration begins, the account is locked and migration cannot complete until a specified period has elapsed. During the lock period, the user can cancel migration using the original authentication method (for example, the SCA owner's signature). This gives the user a way to prevent harm if an unexpected migration is initiated.

In particular, the following operations are prohibited while the account is locked.

Prohibited operation Reason
Asset transfers Prevents assets from being taken during a malicious migration.
External contract calls These may lead to asset transfers or other dangerous operations.
Changes to account authentication factors Prevents account takeover during migration.
Any operation affecting the above Maintains the security of the locked state.

Finally, wallet providers are advised to notify users when migration begins. Using available channels such as email or in-app notifications helps users detect unauthorized operations promptly.

References

Aaron Yee (@aaronyee-eth), "ERC-7405: Portable Smart Contract Accounts [DRAFT]," Ethereum Improvement Proposals, no. 7405, July 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7405.

Conclusion

This article covered ERC7405, a proposal for safely and easily migrating smart contract accounts to another wallet.

If you have questions, feel free to contact me via Twitter direct messages.

Twitter @cardene777

I also publish articles on other platforms.