EIPs Explained

ERC-5639 · Review · ERC · 2022-09-09

ERC-5639: Delegation Registry

An on-chain registry where a cold "vault" wallet can name hot "delegate" wallets that may prove ownership on its behalf, so you never have to connect your valuable wallet to a dApp.

What problem does it solve?

Many dApps ask you to sign a message or send a transaction from the wallet that holds an asset: to claim an airdrop, enter a token-gated site, edit a marketplace profile or prove you own an NFT. These actions are essentially "read only", yet they force you to use the wallet with full write access to your assets. If that wallet is a hardware wallet or multisig it is inconvenient; if you sign a malicious payload by mistake, you can lose everything in it.

ERC-5639 proposes a shared Delegation Registry. The valuable vault wallet records, once, which delegate wallets may act for it. Apps then check the registry and accept the delegate (a hot wallet holding little or nothing) as proof of the vault's ownership.

How it works

The vault calls the registry to grant delegation at one of three levels:

Level Write function Meaning
All delegateForAll(delegate, value) Delegate may act for the whole vault
Contract delegateForContract(delegate, contract_, value) Only for assets of one contract
Token delegateForToken(delegate, contract_, tokenId, value) Only for one specific token

value = true grants, false revokes. The vault can also call revokeAllDelegates() or revokeDelegate(delegate), and a delegate can drop itself with revokeSelf(vault). Each change emits an event (DelegateForAll, DelegateForContract, DelegateForToken, RevokeAllDelegates, RevokeDelegate).

Checks are hierarchical: checkDelegateForToken returns true if the delegate has token-, contract- or vault-level rights; checkDelegateForContract accepts contract- or vault-level rights. The registry also supports on-chain enumeration (getDelegationsByDelegate, getDelegatesForAll, getContractLevelDelegations, …) so a frontend can show a connected hot wallet which vaults it can speak for.

Delegation can be chained in practice: a delegate may itself have delegates, and revoking at the root cuts off the whole tree.

Sample code

A claim contract that lets a delegate claim on behalf of an NFT holder:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IDelegationRegistry {
    function checkDelegateForToken(address delegate, address vault, address contract_, uint256 tokenId)
        external view returns (bool);
}

interface IERC721 {
    function ownerOf(uint256 tokenId) external view returns (address);
}

contract DelegatedClaim {
    IDelegationRegistry public immutable registry;
    IERC721 public immutable nft;
    mapping(uint256 => bool) public claimed;

    constructor(IDelegationRegistry r, IERC721 n) { registry = r; nft = n; }

    /// Caller is either the vault itself or a delegate of the vault.
    function claim(uint256 tokenId, address vault) external {
        require(nft.ownerOf(tokenId) == vault, "not owner");
        if (msg.sender != vault) {
            require(
                registry.checkDelegateForToken(msg.sender, vault, address(nft), tokenId),
                "not delegate"
            );
        }
        require(!claimed[tokenId], "claimed");
        claimed[tokenId] = true;
        // send the reward to `vault`, not to msg.sender
    }
}

Things to know

  • Status is Review: the interface may still change. Use the exact ABI of whichever deployed registry you integrate with.
  • The registry only answers "is this address allowed to speak for that vault?". It never moves assets. Your contract decides what a delegate may do, and should usually send rewards to the vault, not the delegate.
  • The spec suggests the dApp pass a hint about which delegation level applies, so the contract can call the cheapest check function.
  • For off-chain logins, combine a delegate's Sign-In with Ethereum signature with a registry lookup; contract wallets as vaults may also need ERC-1271 signature checks.
  • Delegation is only as safe as the delegate key for the actions an app chooses to accept. Revoke unused delegates.

#delegation #registry #security #nft #wallet

Details

Authors
foobar (@0xfoobar), Wilkins Chung (@wwhchung) <[email protected]>, ryley-o (@ryley-o), Jake Rockland (@jakerockland), andy8052 (@andy8052)
Status
Review
Type
Standards Track / ERC
Created
2022-09-09

Machine-readable: Markdown · JSON