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 ERC5639, a standard proposing delegation for safer and more convenient signing operations.

The following material is translated, summarized, and supplemented with explanations.

As of October 20, 2023, 5639 was at the Review stage.

I have also covered a range of other ERCs.

Overview

This EIP describes the proposed protocol and its application binary interface (ABI). The protocol and ABI allow one or more delegate wallets to be linked to a vault wallet, enabling those delegates to prove control of the vault wallet and ownership of its assets.

The Delegation Registry contract defines how to link delegate wallets to vault wallets and prove those links.

Delegate wallets can be authorized to act on behalf of vault wallets, typically using another personal wallet. Vault owners can thereby grant specific permissions to trusted delegates.

The protocol aims to improve vault owners' security and access management and make interactions with other wallets easier.

The Delegation Registry is a smart contract that defines how to link delegate wallets to vault wallets and prove a delegate's permissions. This improves security and access management and simplifies interactions.

Motivation

Proving asset ownership to third-party applications is common in the Ethereum ecosystem. Users often sign a data payload to prove their identity before performing a particular operation. However, this approach can be insecure and inconvenient.

Consider the following situations.

  • Editing an OpenSea profile requires signing a message with a wallet.
  • Accessing NFT-gated content requires signing a message with the NFT-owning wallet to prove ownership.
  • Accessing certain events requires signing a message with the wallet that owns the required NFT.
  • Claiming an airdrop requires interacting with a smart contract using an eligible wallet.
  • Proving ownership of an NFT requires signing particular data with the NFT-owning wallet.

In each example, users must interact with the application or smart contract using the wallet itself. This is inconvenient and raises security concerns: these operations should be read-only, but they actually require signatures or interactions from a wallet with write access.

Instead, a mechanism is needed to authorize multiple wallets to authenticate on behalf of a particular wallet.

Existing Approaches and Their Limitations

Users frequently sign malicious data by mistake. In most cases, this results in the loss of assets associated with the delegate address.

Many users also store most of their assets in cold storage. Although cold storage improves security, it tends to make accessing those wallets more difficult.

These barriers arise because improved cold-storage security comes at the cost of accessibility. The specific reasons are as follows.

Offline Storage

Cold storage holds assets offline, so it is generally disconnected from the network. This protects against internet-based attacks and hacking, but accessing the wallet requires manually switching to an online state.

Physical Access

Cold-storage wallets are typically stored on physical devices, such as hardware or paper wallets. Accessing the wallet therefore requires physical access to the device. Users must keep the device secure and retrieve it when needed.

Manual Signing

Signing transactions and performing operations from cold storage are typically manual processes. The signer retrieves transaction data from the device, signs it, and returns it to the device. This manual process reduces convenience and can introduce mistakes or delays.

Strict Security Settings

Cold-storage users must maintain high security standards. These include backups, device encryption, access-code protection, and regular software updates. These steps improve security but also make access more difficult.

Because improved cold-storage security involves costs and access restrictions, users must balance security with convenience.

[Proposal] Using a Delegation Registry

The proposal aims to allow vault wallets to grant permissions to delegate wallets at the wallet, contract, or token level. This makes signing and authentication safer and more convenient, enabling read-only access to a vault wallet through one or more secondary wallets.

The proposal offers two main benefits. First, users can improve security by relegating potentially malicious signing interactions to a more accessible wallet (a hot wallet). This helps them perform important operations safely. Second, users can access wallets that are not frequently used for signing more conveniently while maintaining their intended security assumptions.

The proposal aims to provide a secure, flexible approach and improve wallet permission management.

Safer Interactions With dApps

Many dApps require proof of wallet control before granting access. Existing approaches require using the wallet itself to provide that proof. This introduces security risks. Malicious dApps and phishing sites may induce users to sign malicious data, putting wallet assets at risk.

Using a secondary wallet can mitigate this risk. Malicious interactions are limited to the secondary wallet, which can be configured to hold little or no valuable assets.

Safer Access Across Devices

Using a non-hardware wallet on multiple devices requires importing its seed phrase into each device. Entering the seed phrase on another device increases the risk of compromising the wallet. The risk increases because more devices have access to the seed phrase.

Instead, each device can have its own wallet, authorized as a secondary wallet for the main wallet. If a device-specific wallet is compromised or lost, its authorization can simply be revoked to disable authentication.

Wallet authorizations can also be chained: a secondary wallet may authorize one or more tertiary wallets, allowing them to sign on behalf of both the secondary address and the root main address. Each team can thereby have its own signers, while the main wallet can revoke the entire delegation tree at its root.

Greater Convenience

Many people use hardware wallets to achieve the highest level of security. However, this can be inconvenient. As discussed in the limitations of existing wallets, carrying a hardware wallet everywhere is impractical.

Instead, authorizing a non-hardware wallet for authentication (such as one on a mobile device) lets users access most dApps without having their hardware wallet on hand.

Specification

  • vault
    • The vault is the address for which authentication or asset ownership is being proven.
    • It is the important address or wallet the user is protecting.
  • delegate
    • The delegate is the address intended to sign on behalf of the vault.
    • It is a wallet or address authorized to act on behalf of the vault.

The Delegation Registry must implement the IDelegationRegistry interface. This interface defines the standard and rules for delegation-related functionality and settings. The registry is used to establish and manage relationships between vaults and delegates. It therefore provides a mechanism for controlling which delegates can act on behalf of each vault.

javascript
/**
 * @title An immutable registry contract to be deployed as a standalone primitive
 * @dev New project launches can read previous cold wallet -> hot wallet delegations
 * from here and integrate those permissions into their flow
 */
interface IDelegationRegistry {
    /// @notice Delegation type
    enum DelegationType {
        NONE,
        ALL,
        CONTRACT,
        TOKEN
    }

    /// @notice Info about a single delegation, used for onchain enumeration
    struct DelegationInfo {
        DelegationType type_;
        address vault;
        address delegate;
        address contract_;
        uint256 tokenId;
    }

    /// @notice Info about a single contract-level delegation
    struct ContractDelegation {
        address contract_;
        address delegate;
    }

    /// @notice Info about a single token-level delegation
    struct TokenDelegation {
        address contract_;
        uint256 tokenId;
        address delegate;
    }

    /// @notice Emitted when a user delegates their entire wallet
    event DelegateForAll(address vault, address delegate, bool value);

    /// @notice Emitted when a user delegates a specific contract
    event DelegateForContract(address vault, address delegate, address contract_, bool value);

    /// @notice Emitted when a user delegates a specific token
    event DelegateForToken(address vault, address delegate, address contract_, uint256 tokenId, bool value);

    /// @notice Emitted when a user revokes all delegations
    event RevokeAllDelegates(address vault);

    /// @notice Emitted when a user revoes all delegations for a given delegate
    event RevokeDelegate(address vault, address delegate);

    /**
     * -----------  WRITE -----------
     */

    /**
     * @notice Allow the delegate to act on your behalf for all contracts
     * @param delegate The hotwallet to act on your behalf
     * @param value Whether to enable or disable delegation for this address, true for setting and false for revoking
     */
    function delegateForAll(address delegate, bool value) external;

    /**
     * @notice Allow the delegate to act on your behalf for a specific contract
     * @param delegate The hotwallet to act on your behalf
     * @param contract_ The address for the contract you're delegating
     * @param value Whether to enable or disable delegation for this address, true for setting and false for revoking
     */
    function delegateForContract(address delegate, address contract_, bool value) external;

    /**
     * @notice Allow the delegate to act on your behalf for a specific token
     * @param delegate The hotwallet to act on your behalf
     * @param contract_ The address for the contract you're delegating
     * @param tokenId The token id for the token you're delegating
     * @param value Whether to enable or disable delegation for this address, true for setting and false for revoking
     */
    function delegateForToken(address delegate, address contract_, uint256 tokenId, bool value) external;

    /**
     * @notice Revoke all delegates
     */
    function revokeAllDelegates() external;

    /**
     * @notice Revoke a specific delegate for all their permissions
     * @param delegate The hotwallet to revoke
     */
    function revokeDelegate(address delegate) external;

    /**
     * @notice Remove yourself as a delegate for a specific vault
     * @param vault The vault which delegated to the msg.sender, and should be removed
     */
    function revokeSelf(address vault) external;

    /**
     * -----------  READ -----------
     */

    /**
     * @notice Returns all active delegations a given delegate is able to claim on behalf of
     * @param delegate The delegate that you would like to retrieve delegations for
     * @return info Array of DelegationInfo structs
     */
    function getDelegationsByDelegate(address delegate) external view returns (DelegationInfo[] memory);

    /**
     * @notice Returns an array of wallet-level delegates for a given vault
     * @param vault The cold wallet who issued the delegation
     * @return addresses Array of wallet-level delegates for a given vault
     */
    function getDelegatesForAll(address vault) external view returns (address[] memory);

    /**
     * @notice Returns an array of contract-level delegates for a given vault and contract
     * @param vault The cold wallet who issued the delegation
     * @param contract_ The address for the contract you're delegating
     * @return addresses Array of contract-level delegates for a given vault and contract
     */
    function getDelegatesForContract(address vault, address contract_) external view returns (address[] memory);

    /**
     * @notice Returns an array of contract-level delegates for a given vault's token
     * @param vault The cold wallet who issued the delegation
     * @param contract_ The address for the contract holding the token
     * @param tokenId The token id for the token you're delegating
     * @return addresses Array of contract-level delegates for a given vault's token
     */
    function getDelegatesForToken(address vault, address contract_, uint256 tokenId)
        external
        view
        returns (address[] memory);

    /**
     * @notice Returns all contract-level delegations for a given vault
     * @param vault The cold wallet who issued the delegations
     * @return delegations Array of ContractDelegation structs
     */
    function getContractLevelDelegations(address vault)
        external
        view
        returns (ContractDelegation[] memory delegations);

    /**
     * @notice Returns all token-level delegations for a given vault
     * @param vault The cold wallet who issued the delegations
     * @return delegations Array of TokenDelegation structs
     */
    function getTokenLevelDelegations(address vault) external view returns (TokenDelegation[] memory delegations);

    /**
     * @notice Returns true if the address is delegated to act on the entire vault
     * @param delegate The hotwallet to act on your behalf
     * @param vault The cold wallet who issued the delegation
     */
    function checkDelegateForAll(address delegate, address vault) external view returns (bool);

    /**
     * @notice Returns true if the address is delegated to act on your behalf for a token contract or an entire vault
     * @param delegate The hotwallet to act on your behalf
     * @param contract_ The address for the contract you're delegating
     * @param vault The cold wallet who issued the delegation
     */
    function checkDelegateForContract(address delegate, address vault, address contract_)
        external
        view
        returns (bool);

    /**
     * @notice Returns true if the address is delegated to act on your behalf for a specific token, the token's contract or an entire vault
     * @param delegate The hotwallet to act on your behalf
     * @param contract_ The address for the contract you're delegating
     * @param tokenId The token id for the token you're delegating
     * @param vault The cold wallet who issued the delegation
     */
    function checkDelegateForToken(address delegate, address vault, address contract_, uint256 tokenId)
        external
        view
        returns (bool);
}

DelegationType

javascript
enum DelegationType {
    NONE,
    ALL,
    CONTRACT,
    TOKEN
}

Overview An enumeration representing the types of delegation.

Parameters

  • NONE
    • No delegation.
  • ALL
    • Delegation for all assets.
  • CONTRACT
    • Contract-level delegation.
  • TOKEN
    • Token-level delegation.

DelegationInfo

javascript
struct DelegationInfo {
    DelegationType type_;
    address vault;
    address delegate;
    address contract_;
    uint256 tokenId;
}

Overview A struct representing a single delegation for on-chain enumeration.

Parameters

  • type_
    • The delegation type (the DelegationType enum).
  • vault
    • The vault address.
  • delegate
    • The delegate address.
  • contract_
    • The contract address.
  • tokenId
    • The token ID.

ContractDelegation

javascript
struct ContractDelegation {
    address contract_;
    address delegate;
}

Overview A struct representing a single contract-level delegation.

Parameters

  • contract_
    • The contract address.
  • delegate
    • The delegate address.

TokenDelegation

javascript
struct TokenDelegation {
    address contract_;
    uint256 tokenId;
    address delegate;
}

Overview This struct represents a single token-level delegation.

Parameters

  • contract_
    • The contract address.
  • tokenId
    • The token ID.
  • delegate
    • The delegate address.

DelegateForAll

javascript
event DelegateForAll(address vault, address delegate, bool value);

Overview An event emitted when a user delegates their entire wallet.

Parameters

  • vault
    • The vault address.
  • delegate
    • The delegate address.
  • value
    • Whether delegation is enabled (true) or disabled (false).

DelegateForContract

javascript
event DelegateForContract(address vault, address delegate, address contract_, bool value);

Overview An event emitted when a user delegates a specific contract.

Details

  • vault
    • The vault address.
  • delegate
    • The delegate address.
  • contract_
    • The contract address.
  • value
    • Whether delegation is enabled (true) or disabled (false).

DelegateForToken

javascript
event DelegateForToken(address vault, address delegate, address contract_, uint256 tokenId, bool value);

Overview An event emitted when a user delegates a specific token.

Details

  • vault
    • The vault address.
  • delegate
    • The delegate address.
  • contract_
    • The contract address.
  • tokenId
    • The token ID.
  • value
    • Whether delegation is enabled (true) or disabled (false).

RevokeAllDelegates

javascript
event RevokeAllDelegates(address vault);

Overview An event emitted when a user revokes all delegations.

Details

  • vault
    • The vault address.

RevokeDelegate

javascript
event RevokeDelegate(address vault, address delegate);

Overview An event emitted when a user revokes a specific delegate.

Details

  • vault
    • The vault address.
  • delegate
    • The delegate address.

delegateForAll

javascript
function delegateForAll(address delegate, bool value) external;

Overview Grants or revokes a delegate's permissions for all contracts.

Details Calling this function grants or revokes the specified delegate's permissions for all contracts associated with the user's wallet. Set value to true to enable the permission or false to revoke it.

Arguments

  • delegate
    • The delegate address.
  • value
    • Whether the permission is enabled (true) or disabled (false).

delegateForContract

javascript
function delegateForContract(address delegate, address contract_, bool value) external;

Overview Grants or revokes a delegate's permissions for a particular contract.

Details Calling this function grants or revokes the specified delegate's permissions for a particular contract. Set value to true to enable the permission or false to revoke it.

Arguments

  • delegate
    • The delegate address.
  • contract_
    • The contract address.
  • value
    • Whether the permission is enabled (true) or disabled (false).

delegateForToken

javascript
function delegateForToken(address delegate, address contract_, uint256 tokenId, bool value) external;

Overview Grants or revokes a delegate's permissions for a particular token.

Details Calling this function grants or revokes the specified delegate's permissions for a particular token. Set value to true to enable the permission or false to revoke it.

Arguments

  • delegate
    • The delegate address.
  • contract_
    • The contract address.
  • tokenId
    • The token ID.
  • value
    • Whether the permission is enabled (true) or disabled (false).

revokeAllDelegates

javascript
function revokeAllDelegates() external;

Overview Revokes all delegates.

Details Calling this function revokes the permissions of all delegates.


revokeDelegate

javascript
function revokeDelegate(address delegate) external;

Overview Revokes a particular delegate's permissions.

Details Calling this function revokes the specified delegate's permissions.

Arguments

  • delegate
    • The delegate address.

revokeSelf

javascript
function revokeSelf(address vault) external;

Overview Revokes delegation from a vault for which the caller is a delegate.

Details Calling this function revokes the delegation from a particular vault that has designated the caller as a delegate.

Arguments

  • vault
    • The address of the vault whose delegation is being revoked.

getDelegationsByDelegate

javascript
function getDelegationsByDelegate(address delegate) external view returns (DelegationInfo[] memory);

Overview Returns all active delegations available to the specified delegate.

Details Calling this function retrieves information about all active delegations that the specified delegate can claim. Delegation information is returned as an array of DelegationInfo structs.

Arguments

  • delegate
    • The delegate address.

Return Value

  • info
    • An array of DelegationInfo structs.
    • Each DelegationInfo contains information about a delegation.

getDelegatesForAll

javascript
function getDelegatesForAll(address vault) external view returns (address[] memory);

Overview Returns an array of all wallet-level delegates for the specified vault.

Details Calling this function retrieves an array of addresses for all wallet-level delegates configured by the specified vault.

Arguments

  • vault
    • The address of the delegate's vault.

Return Value

  • addresses
    • An array of delegate addresses.

getDelegatesForContract

javascript
function getDelegatesForContract(address vault, address contract_) external view returns (address[] memory);

Overview Returns an array of all contract-level delegates associated with the specified vault and contract.

Arguments

  • vault
    • The address of the delegate's vault.
  • contract_
    • The contract address.

Return Value

  • addresses
    • An array of delegate addresses.

getDelegatesForToken

javascript
function getDelegatesForToken(address vault, address contract_, uint256 tokenId)
    external
    view
    returns (address[] memory);

Overview Returns an array of all token-level delegates associated with the specified vault, contract, and token.

Arguments

  • vault
    • The address of the delegate's vault.
  • contract_
    • The contract address.
  • tokenId
    • The token ID.

Return Value

  • addresses
    • An array of delegate addresses.

getContractLevelDelegations

javascript
function getContractLevelDelegations(address vault)
    external
    view
    returns (ContractDelegation[] memory delegations);

Overview Returns all contract-level delegation information configured by the specified vault.

Details Calling this function retrieves an array of ContractDelegation structs containing all contract-level delegation information configured by the specified vault.

Arguments

  • vault
    • The vault address for which delegation information is retrieved.

Return Value

  • delegations
    • An array of ContractDelegation structs.
    • Each ContractDelegation contains contract-level delegation information.

getTokenLevelDelegations

javascript
function getTokenLevelDelegations(address vault) external view returns (TokenDelegation[] memory delegations);

Overview Returns all token-level delegation information configured by the specified vault.

Details Calling this function retrieves an array of TokenDelegation structs containing all token-level delegation information configured by the specified vault.

Arguments

  • vault
    • The vault address for which delegation information is retrieved.

Return Value

  • delegations
    • An array of TokenDelegation structs.
    • Each TokenDelegation contains token-level delegation information.

Checking Delegations

Before performing a particular action, a dApp or smart contract must check that the delegate is properly authorized. The check is performed through the Delegation Registry. The following summarizes how the checks work.

  1. Check delegation for a vault
    • The dApp or smart contract uses checkDelegateForAll to determine whether the delegate is authorized for a particular vault.
    • Check the return value of checkDelegateForAll and permit the vault-related action if the delegate is authorized.
  2. Check delegation for a contract
    • The dApp or smart contract uses checkDelegateForContract to determine whether the delegate is authorized for a particular contract.
    • Check the return value of checkDelegateForContract and permit the contract-related action if the delegate is authorized.
  3. Check delegation for a token
    • The dApp or smart contract uses checkDelegateForToken to check whether a particular token is owned by the vault.
    • Check the return value of checkDelegateForToken and permit the token-related action if the delegate is authorized for that token.

Delegates can perform different actions depending on the delegation level. For example, a token-level delegation allows the delegate to act on the token. Similarly, a contract-level delegation allows the delegate to act on the contract. To save gas when checking delegation within a smart contract, a hint indicates the delegation level so that the most efficient verification method can be selected.

These checks ensure that delegates are properly authorized before actions involving vaults or contracts are performed, limiting unauthorized access.

Additional Details

Supporting Vault-, Contract-, and Token-Level Delegation

Allowing delegation at the vault, contract, and token levels supports different delegation use cases. Under the proposed specification, a vault can delegate access to all assets it controls, assets from a particular contract, or a particular token. Vaults can thereby control asset security at a granular level, granting third-party wallets only limited access to the relevant assets.

On-chain Enumeration

The specification supports enumeration to simplify integration and adoption. On-chain enumeration allows a dApp frontend to identify the delegations available to the connected wallet and present a selector in its UI.

Without on-chain enumeration, dApps would have to ask users to enter vault addresses manually or index every delegation event. This makes delegation configuration more flexible and improves the dApp user experience.

Security Considerations

The primary goal of this EIP is to improve security and facilitate secure authentication of wallet control and asset ownership when the main wallet itself is not needed or its assets do not need to be moved. This can be viewed as read-only authentication of assets.

This EIP provides a way to prove wallet ownership and improve wallet security when assets do not need to be moved. It protects asset security by enabling safe authentication when the main wallet itself is not required.

Citation

foobar (@0xfoobar), Wilkins Chung (@wwhchung) wilkins@manifold.xyz, ryley-o (@ryley-o), Jake Rockland (@jakerockland), andy8052 (@andy8052), "ERC-5639: Delegation Registry [DRAFT]," Ethereum Improvement Proposals, no. 5639, September 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5639.

Conclusion

This article covered ERC5639, a standard proposing delegation for safer and more convenient signing operations. I hope you found it useful.

If you have questions, feel free to contact me by direct message on Twitter.

Twitter @cardene777

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

https://chaldene.net/