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 examines ERC6981, a proposal that allows users of external services to have receiving addresses without performing onchain operations and later claim their accounts with valid signatures.

This article translates, summarizes, and expands on the material below.

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

Overview

ERC6981 proposes a mechanism for associating users of external services with Ethereum addresses that can be claimed later. Here, claiming means that users can subsequently secure those addresses as their own wallets.

The service provides each user with a signed message and a unique salt (additional data used to identify the address derivation). Using these, the user can deploy a smart contract wallet at a deterministic address through a registry contract using the contract address derivation mechanism known as create2.

Deterministic means that, given the same signature and salt within the same deployment configuration, the wallet is deployed at the same address regardless of when or by whom the deployment is performed.

For more about create2, see the resource below.

This mechanism lets users have addresses reserved for them without performing any onchain operations. When needed, they can deploy smart contract wallets at those addresses and manage them themselves. External services do not have to custody users' assets, while users can receive assets in advance.

Motivation

Traditionally, external services that want to provide users with blockchain assets have generally used approaches such as:

  • Creating an externally owned account (EOA) for each user, with the service holding the private keys.
  • Deploying a smart contract wallet on behalf of each user and storing its management information in the service's database.
  • Managing an omnibus contract that holds assets belonging to multiple users.

Because the service is responsible for private keys or asset management in these approaches, security concerns remain, including data breaches, insider abuse, and key management failures. A structure in which the service holds assets in custody is also undesirable from a user sovereignty perspective.

ERC6981 presents a new framework intended to avoid these conventional problems. Users can deploy their own smart contract wallets when needed using signed data provided by the service. The service therefore does not need to hold the user's private key, and the user ultimately controls the address.

The mechanism also allows an address for receiving assets to be reserved before a user has interacted with a blockchain. Users can access assets sent to that address later by deploying the wallet. This gives them an onchain identity (an address by which they can be recognized as the same user) without performing any onchain operations, and lets them accumulate assets at that address.

Because no onchain action is required upfront, even users unfamiliar with blockchains can acquire an onchain address in the course of using a service. They can claim the wallet and take control of the address whenever they choose.

Specification

Overview

ERC6981 defines a mechanism for creating reserved accounts with claimable ownership associated with users of external services. It lets users have receiving addresses in advance, even before the accounts are deployed. The service associates user identification information with a salt (a unique value used in address derivation). By querying the registry contract with that salt, the same inputs always yield the same address. The user receives a signed message from the service and can later use it to deploy and claim the account.

An account consists of the following components:

  • Account registry A contract that derives deterministic addresses from salts and enables users to claim accounts after signature verification.
  • Account instance The contract wallet actually owned by the user, deployed at a deterministic address. It can receive assets at that address even before deployment.

The service manages the association between user identifiers and salts and provides a signature when the user passes its authentication process. The user passes the signature and message to claimAccount to claim the account instance.

Account Registry

IAccountRegistry.sol
interface IAccountRegistry {
    /**
     * @dev Registry instances emit the AccountCreated event upon successful account creation
     */
    event AccountCreated(address account, address accountImplementation, uint256 salt);

    /**
     * @dev Registry instances emit the AccountClaimed event upon successful claim of account by owner
     */
    event AccountClaimed(address account, address owner);

    /**
     * @dev Creates a smart contract account.
     *
     * If account has already been created, returns the account address without calling create2.
     *
     * @param salt       - The identifying salt for which the user wishes to deploy an Account Instance
     *
     * Emits AccountCreated event
     * @return the address for which the Account Instance was created
     */
    function createAccount(uint256 salt) external returns (address);

    /**
     * @dev Allows an owner to claim a smart contract account created by this registry.
     *
     * If the account has not already been created, the account will be created first using `createAccount`
     *
     * @param owner      - The initial owner of the new Account Instance
     * @param salt       - The identifying salt for which the user wishes to deploy an Account Instance
     * @param expiration - If expiration > 0, represents expiration time for the signature.  Otherwise
     *                     signature does not expire.
     * @param message    - The keccak256 message which validates the owner, salt, expiration
     * @param signature  - The signature which validates the owner, salt, expiration
     *
     * Emits AccountClaimed event
     * @return the address of the claimed Account Instance
     */
    function claimAccount(
        address owner,
        uint256 salt,
        uint256 expiration,
        bytes32 message,
        bytes calldata signature
    ) external returns (address);

    /**
     * @dev Returns the computed address of a smart contract account for a given identifying salt
     *
     * @return the computed address of the account
     */
    function account(uint256 salt) external view returns (address);

    /**
     * @dev Fallback signature verification for unclaimed accounts
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4);
}

Events

AccountCreated
javascript
event AccountCreated(address account, address accountImplementation, uint256 salt);

An event emitted when a new account is created. It is emitted when createAccount creates an account instance. It records the account address, the implementation contract used, and the salt used for creation.

Parameters

  • account
    • The address of the newly created account instance.
  • accountImplementation
    • The address of the implementation contract referenced by the account instance.
  • salt
    • The salt used to compute the deterministic address.
AccountClaimed
javascript
event AccountClaimed(address account, address owner);

An event emitted when a user claims an account. It is emitted when claimAccount succeeds and ownership of the account passes from the registry to the user. It records which account was assigned to which owner.

Parameters

  • account
    • The address of the claimed account instance.
  • owner
    • The address of the new owner.

Functions

createAccount
javascript
function createAccount(uint256 salt) external returns (address);

Deploys an account instance using the specified salt. The function deploys an account instance at a deterministic address derived using the salt. If it has already been deployed, the function returns the existing address without deploying another instance. The instance is created using an ERC1167 minimal proxy, and its initial owner is the registry. On successful creation, AccountCreated is emitted.

Arguments

  • salt
    • A unique salt used to create the account.

Return value

  • address
    • The address of the created account instance.
claimAccount
javascript
function claimAccount(
    address owner,
    uint256 salt,
    uint256 expiration,
    bytes32 message,
    bytes calldata signature
) external returns (address);

Allows a user to claim ownership of an account instance. If the account corresponding to the specified salt has not been created, it is deployed automatically as part of the claim. The signature is also checked for validity. The signature is created using the user address, salt, and expiration, and is verified using ECDSA for an EOA or ERC1271 for a contract wallet. If the expiration is not zero, the current time must be no later than that expiration.

For more about ERC1271, see the article below.

[ERC1271] Verifying Signatures with Smart Contracts

If verification succeeds, the registry relinquishes its authority over the account and transfers ownership to the designated user using setOwner. After a successful claim, AccountClaimed is emitted.

Arguments

  • owner
    • The new owner of the account.
  • salt
    • The identifying salt of the account to be claimed.
  • expiration
    • The signature expiration time.
    • A value of zero means the signature does not expire.
  • message
    • The message formed by hashing owner / salt / expiration together.
  • signature
    • The signature used for verification.

Return value

  • address
    • The address of the account instance whose ownership has been claimed.
account
javascript
function account(uint256 salt) external view returns (address);

Returns the account address corresponding to the specified salt. It returns the deterministic address computed using the salt. The address can be computed even if the account has not actually been deployed.

Arguments

  • salt
    • The salt used to identify the account.

Return value

  • address
    • The computed account address.
isValidSignature
javascript
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4);

Performs signature verification for an unclaimed account. When an account has not been claimed, this function provides fallback verification. The signature is generated over a composite hash combining the original message hash and the account address. The function reconstructs the composite hash and checks whether the signature is valid for the registry's signer.

Arguments

  • hash
    • The original message hash.
  • signature
    • The signature to verify.

Return value

  • bytes4
    • A value indicating whether the signature is valid, in accordance with ERC1271.

Account Instance

IAccount.sol
interface IAccount is IERC1271 {
    /**
     * @dev Sets the owner of the Account Instance.
     *
     * Only callable by the current owner of the instance, or by the registry if the Account
     * Instance has not yet been claimed.
     *
     * @param owner      - The new owner of the Account Instance
     */
    function setOwner(address owner) external;
}

Functions

setOwner
javascript
function setOwner(address owner) external;

Sets the owner of the account instance. Only the current owner or the registry (if the account has not yet been claimed) can call this function. Updating the owner transfers authority to operate the account to the new address.

Arguments

  • owner
    • The address of the new owner.

Account Instance Signatures

ERC6981 account instances implement ERC1271, and signature handling depends on the account's state.

The behavior for each state is as follows:

State Description
Deployed and claimed The owner signs, and the account verifies the signature according to ERC1271.
Deployed and unclaimed The registry signer signs the composite hash, and the account delegates verification to the registry's isValidSignature.
Not deployed The registry signer signs the composite hash, and the signature is wrapped in ERC6492 format.

Signature verification ultimately follows the ERC6492 flow.

Additional Details

Service-Owned Registry Instances

One possible approach would be to provide a shared registry for external services. However, ERC6981 allows each service to have its own account registry. This lets services operate their registries according to their own management processes, authentication methods, and usage policies.

With a dedicated registry, each service can control signature verification and permissions for account creation. Managing a registry according to its own rules is important for operating it securely on behalf of users.

ERC6981 also provides a Registry Factory as a reference implementation. External services can use it to deploy their own account registries easily. The Registry Factory has the following features:

  • A mechanism that fixes the implementation contract referenced by account instances so its address cannot be changed.
  • Signature verification during claimAccount using ECDSA for an EOA or ERC1271 for a smart contract.
  • A mechanism allowing the service that deployed the registry to change the address used for signature verification later.

This lets services operate their own signature verification infrastructure for new users.

Relationship Between the Account Registry and Account Implementation

Account instances are created using ERC1167 minimal proxies. In this mechanism, the implementation contract address referenced by the proxy also affects the address computation for the instance. In other words, changing the implementation address changes the resulting account address even if the salt remains the same.

For that reason, ERC6981 fixes one implementation contract per registry. This keeps the mapping between salts and addresses consistent, allowing service users to use the same address for a given salt.

A service can help earn users' trust by deploying a registry associated with a trustworthy implementation contract. For users, the implementation on which their account is built matters, so this mechanism helps improve transparency and trust.

The implementation behind the proxy can itself be designed to be upgradeable, however, so users need not be permanently restricted to the implementation logic originally used by the registry. This provides flexibility if they want to migrate to another mechanism in the future.

Why Separate createAccount and claimAccount?

ERC6981 deliberately separates account creation (createAccount) from the operation of claiming ownership (claimAccount). This enables a service to provide users with signatures usable before account deployment (in ERC6492 format).

This separation has important advantages:

  • Users can generate and verify signatures as if the account already existed, even before deployment.
  • The service can issue messages for authentication before the user performs any onchain operations.

Users can therefore defer deployment until they actually want to use the account, reducing the upfront burden. A flexible workflow becomes possible: authenticate using a signature first, then deploy the account when needed.

Reference Implementation

Account Registry Factory

AccountRegistryFactory.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.13;

/// @author: manifold.xyz

import {Create2} from "openzeppelin/utils/Create2.sol";

import {Address} from "../../lib/Address.sol";
import {ERC1167ProxyBytecode} from "../../lib/ERC1167ProxyBytecode.sol";
import {IAccountRegistryFactory} from "./IAccountRegistryFactory.sol";

contract AccountRegistryFactory is IAccountRegistryFactory {
    using Address for address;

    error InitializationFailed();

    address private immutable registryImplementation = 0x076B08EDE2B28fab0c1886F029cD6d02C8fF0E94;

    function createRegistry(
        uint96 index,
        address accountImplementation,
        bytes calldata accountInitData
    ) external returns (address) {
        bytes32 salt = _getSalt(msg.sender, index);
        bytes memory code = ERC1167ProxyBytecode.createCode(registryImplementation);
        address _registry = Create2.computeAddress(salt, keccak256(code));

        if (_registry.isDeployed()) return _registry;

        _registry = Create2.deploy(0, salt, code);

        (bool success, ) = _registry.call(
            abi.encodeWithSignature(
                "initialize(address,address,bytes)",
                msg.sender,
                accountImplementation,
                accountInitData
            )
        );
        if (!success) revert InitializationFailed();

        emit AccountRegistryCreated(_registry, accountImplementation, index);

        return _registry;
    }

    function registry(address deployer, uint96 index) external view override returns (address) {
        bytes32 salt = _getSalt(deployer, index);
        bytes memory code = ERC1167ProxyBytecode.createCode(registryImplementation);
        return Create2.computeAddress(salt, keccak256(code));
    }

    function _getSalt(address deployer, uint96 index) private pure returns (bytes32) {
        return bytes32(abi.encodePacked(deployer, index));
    }
}

Account Registry

AccountRegistryImplementation.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.13;

/// @author: manifold.xyz

import {Create2} from "openzeppelin/utils/Create2.sol";
import {ECDSA} from "openzeppelin/utils/cryptography/ECDSA.sol";
import {Ownable} from "openzeppelin/access/Ownable.sol";
import {Initializable} from "openzeppelin/proxy/utils/Initializable.sol";
import {IERC1271} from "openzeppelin/interfaces/IERC1271.sol";
import {SignatureChecker} from "openzeppelin/utils/cryptography/SignatureChecker.sol";

import {Address} from "../../lib/Address.sol";
import {IAccountRegistry} from "../../interfaces/IAccountRegistry.sol";
import {ERC1167ProxyBytecode} from "../../lib/ERC1167ProxyBytecode.sol";

contract AccountRegistryImplementation is Ownable, Initializable, IAccountRegistry {
    using Address for address;
    using ECDSA for bytes32;

    struct Signer {
        address account;
        bool isContract;
    }

    error InitializationFailed();
    error ClaimFailed();
    error Unauthorized();

    address public accountImplementation;
    bytes public accountInitData;
    Signer public signer;

    constructor() {
        _disableInitializers();
    }

    function initialize(
        address owner,
        address accountImplementation_,
        bytes calldata accountInitData_
    ) external initializer {
        _transferOwnership(owner);
        accountImplementation = accountImplementation_;
        accountInitData = accountInitData_;
    }

    /**
     * @dev See {IAccountRegistry-createAccount}
     */
    function createAccount(uint256 salt) external override returns (address) {
        bytes memory code = ERC1167ProxyBytecode.createCode(accountImplementation);
        address _account = Create2.computeAddress(bytes32(salt), keccak256(code));

        if (_account.isDeployed()) return _account;

        _account = Create2.deploy(0, bytes32(salt), code);

        (bool success, ) = _account.call(accountInitData);
        if (!success) revert InitializationFailed();

        emit AccountCreated(_account, accountImplementation, salt);

        return _account;
    }

    /**
     * @dev See {IAccountRegistry-claimAccount}
     */
    function claimAccount(
        address owner,
        uint256 salt,
        uint256 expiration,
        bytes32 message,
        bytes calldata signature
    ) external override returns (address) {
        _verify(owner, salt, expiration, message, signature);
        address _account = this.createAccount(salt);

        (bool success, ) = _account.call(
            abi.encodeWithSignature("transferOwnership(address)", owner)
        );
        if (!success) revert ClaimFailed();

        emit AccountClaimed(_account, owner);
        return _account;
    }

    /**
     * @dev See {IAccountRegistry-account}
     */
    function account(uint256 salt) external view override returns (address) {
        bytes memory code = ERC1167ProxyBytecode.createCode(accountImplementation);
        return Create2.computeAddress(bytes32(salt), keccak256(code));
    }

    /**
     * @dev See {IAccountRegistry-isValidSignature}
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4) {
        bytes32 expectedHash = keccak256(abi.encodePacked(hash, msg.sender));
        bool isValid = SignatureChecker.isValidSignatureNow(
            signer.account,
            expectedHash,
            signature
        );
        if (isValid) {
            return IERC1271.isValidSignature.selector;
        }

        return "";
    }

    function updateSigner(address newSigner) external onlyOwner {
        uint32 signerSize;
        assembly {
            signerSize := extcodesize(newSigner)
        }
        signer.account = newSigner;
        signer.isContract = signerSize > 0;
    }

    function _verify(
        address owner,
        uint256 salt,
        uint256 expiration,
        bytes32 message,
        bytes calldata signature
    ) internal view {
        address signatureAccount;

        if (signer.isContract) {
            if (!SignatureChecker.isValidSignatureNow(signer.account, message, signature))
                revert Unauthorized();
        } else {
            signatureAccount = message.recover(signature);
        }

        bytes32 expectedMessage = keccak256(
            abi.encodePacked("\x19Ethereum Signed Message:\n84", owner, salt, expiration)
        );

        if (
            message != expectedMessage ||
            (!signer.isContract && signatureAccount != signer.account) ||
            (expiration != 0 && expiration < block.timestamp)
        ) revert Unauthorized();
    }
}

Example Account Implementation

ERC1967AccountImplementation.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.13;

/// @author: manifold.xyz

import {IERC1271} from "openzeppelin/interfaces/IERC1271.sol";
import {SignatureChecker} from "openzeppelin/utils/cryptography/SignatureChecker.sol";
import {IERC165} from "openzeppelin/utils/introspection/IERC165.sol";
import {ERC165Checker} from "openzeppelin/utils/introspection/ERC165Checker.sol";
import {IERC721} from "openzeppelin/token/ERC721/IERC721.sol";
import {IERC721Receiver} from "openzeppelin/token/ERC721/IERC721Receiver.sol";
import {IERC1155Receiver} from "openzeppelin/token/ERC1155/IERC1155Receiver.sol";
import {Initializable} from "openzeppelin/proxy/utils/Initializable.sol";
import {Ownable} from "openzeppelin/access/Ownable.sol";
import {IERC1967Account} from "./IERC1967Account.sol";

import {IAccount} from "../../interfaces/IAccount.sol";

/**
 * @title ERC1967AccountImplementation
 * @notice A lightweight, upgradeable smart contract wallet implementation
 */
contract ERC1967AccountImplementation is
    IAccount,
    IERC165,
    IERC721Receiver,
    IERC1155Receiver,
    IERC1967Account,
    Initializable,
    Ownable
{
    address public registry;

    constructor() {
        _disableInitializers();
    }

    function initialize() external initializer {
        registry = msg.sender;
        _transferOwnership(registry);
    }

    function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
        return (interfaceId == type(IAccount).interfaceId ||
            interfaceId == type(IERC1967Account).interfaceId ||
            interfaceId == type(IERC1155Receiver).interfaceId ||
            interfaceId == type(IERC721Receiver).interfaceId ||
            interfaceId == type(IERC165).interfaceId);
    }

    function onERC721Received(
        address,
        address,
        uint256,
        bytes memory
    ) public pure returns (bytes4) {
        return this.onERC721Received.selector;
    }

    function onERC1155Received(
        address,
        address,
        uint256,
        uint256,
        bytes memory
    ) public pure returns (bytes4) {
        return this.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address,
        address,
        uint256[] memory,
        uint256[] memory,
        bytes memory
    ) public pure returns (bytes4) {
        return this.onERC1155BatchReceived.selector;
    }

    /**
     * @dev {See IERC1967Account-executeCall}
     */
    function executeCall(
        address _target,
        uint256 _value,
        bytes calldata _data
    ) external payable override onlyOwner returns (bytes memory _result) {
        bool success;
        // solhint-disable-next-line avoid-low-level-calls
        (success, _result) = _target.call{value: _value}(_data);
        require(success, string(_result));
        emit TransactionExecuted(_target, _value, _data);
        return _result;
    }

    /**
     * @dev {See IAccount-setOwner}
     */
    function setOwner(address _owner) external override onlyOwner {
        _transferOwnership(_owner);
    }

    receive() external payable {}

    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4) {
        if (owner() == registry) {
            return IERC1271(registry).isValidSignature(hash, signature);
        }

        bool isValid = SignatureChecker.isValidSignatureNow(owner(), hash, signature);
        if (isValid) {
            return IERC1271.isValidSignature.selector;
        }

        return "";
    }
}

Security

Front-running

Front-running is the act of a third party observing the contents of a transaction before it is included in a block and submitting a similar transaction ahead of it. On Ethereum, transactions can circulate in the mempool, allowing a malicious actor to monitor them and submit a higher-priority transaction that may execute first.

In ERC6981, front-running is theoretically possible when deploying a reserved account through the account registry using createAccount. For example, a third party could observe a transaction in which the intended user calls createAccount and execute createAccount with the same salt first.

The important point, however, is that the design prevents the attacker from taking over the account even if the front-running attempt succeeds.

A malicious actor trying to benefit would attempt to change the owner (owner) of the deployed account to themselves. They might try to modify the transaction's calldata by replacing the information corresponding to owner, but the ERC6981 account registry performs signature verification during claimAccount. The signature is created over a message containing owner, salt, and the expiration time. If the attacker substitutes a different owner, the signature will not match, and the registry will reject it and revert the transaction.

Thus, tampering with owner causes the transaction to fail and does not allow the attacker to seize account ownership.

On the other hand, if the attacker does not alter the calldata and simply executes createAccount first, the transaction succeeds, but the same account instance intended for the user is simply deployed at the same address. The address is computed from create2, the salt, the implementation address, and other inputs. Given the same inputs, the account is deployed at the same address regardless of who calls createAccount.

In this case, the attacker has merely paid the gas to deploy the account first, and the intended user's right to claim ownership remains intact. When the user with the correct signature subsequently calls claimAccount, the registry verifies the signature and sets the user as the owner. After confirming that the signature is valid, the registry relinquishes its authority and transfers ownership to the user through the account's setOwner.

With this design, even successful front-running cannot change the account address or take over its ownership, so this particular attack does not cause substantive harm. At worst, the attacker pays the account deployment cost on the user's behalf.

Conclusion

This article covered ERC6981, a proposal allowing users of external services to obtain receiving addresses without onchain operations and later claim their accounts with valid signatures. I hope you found it useful.

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

Twitter @cardene777

I also publish on other platforms, so feel free to explore them.