ERC-5131 ENS hot wallet authentication standard (SAFE Authentication For ENS)
Stagnant · Signatures & auth · created 2022-06-03
A standard that links a hot wallet to a main wallet via an ENS TEXT record, letting the hot wallet handle read-only signing and authentication on its behalf without moving assets.
Why it is needed
Today, accessing a dApp or proving NFT ownership requires signing directly with the main wallet that actually holds the assets. Profile edits, access to NFT-gated content or events, airdrop claims, and proof of ownership are all read-only purposes, yet they still require signing with a wallet that has write access, so a malicious dApp or phishing site that induces a malicious signature can drain assets outright. Also, the more assets are kept in cold storage, hardware wallets, or multisigs for security, the less accessible they become since they must be taken out to sign each time, and using them across multiple devices means repeatedly entering the seed phrase, increasing exposure. Existing solutions required a separate registry contract or new protocol, making adoption difficult, and no standard existed for this.
What to implement
function resolver(bytes32 node) external view returns (address);: Returns the resolver contract address for the given node from the ENS registry.function addr(bytes32 node) external view returns (address);: Returns the Ethereum address the given ENS node points to, from the resolver.function name(bytes32 node) external view returns (string memory);: Returns the reverse ENS name for the given node, from the resolver.function text(bytes32 node, string calldata key) external view returns (string memory);: Returns the value of the specified key's TEXT record stored at the given node in the resolver.
In depth
Definitions of key terms
mainAddress is the target wallet whose control and asset ownership are to be proven, and mainENS is the ENS string from mainAddress's reverse lookup. authAddress is the wallet used to sign on behalf of mainAddress, and authENS is the ENS string from authAddress's reverse lookup. authKey is an arbitrary string in the format [0-9A-Za-z]+ that serves as an identifier distinguishing multiple authAddresses registered under a single mainENS.
Four conditions for authentication to hold
authAddress is considered to have authenticated and proven ownership on behalf of mainAddress only if all of the following are true: mainAddress has an ENS resolver set and its reverse record points to mainENS, authAddress also has an ENS resolver set and its reverse record points to authENS, authENS has an eip5131:vault TEXT record in the format <authKey>:<mainAddress>, and mainENS has an eip5131:<authKey> TEXT record.
Procedure for registering an auxiliary wallet
mainAddress must set an ENS resolver and reverse record, and it is recommended that authAddress also set these for automatic discovery. The procedure is to first choose an unused authKey, then set the TEXT record eip5131:<authKey> on mainENS to the value authAddress, followed by setting the TEXT record eip5131:vault on authENS to the value <authKey>:mainAddress. There is no upper limit on the number of authAddresses that can be registered.
Authentication verification procedure
If authAddress is msg.sender or signs the message, verification proceeds as follows: look up authENS's resolver, read its eip5131:vault TEXT record, and decompose it into <authKey>:<mainAddress>. Next, it is mandatory to confirm that mainAddress's reverse record actually matches that mainENS (skipping this would allow creating another ENS node pointing to mainAddress for fraudulent authentication), and finally confirm that mainENS's eip5131:<authKey> TEXT record matches authAddress. This verification can be done on the client or server side as well as in smart contracts, so no separate external interface is defined.
Revocation method
To revoke authAddress's authorization, delete mainENS's eip5131:<authKey> TEXT record or change it to a different address value.
Rationale for the one-to-many design
This standard uses a one-to-many structure in which a single mainAddress approves multiple authAddresses, while conversely a single authAddress can authenticate only for itself or for exactly one mainAddress. This design lets client and contract code immediately determine, without any extra user input, which mainAddress an authAddress is signing on behalf of. This can be used to design a UX that displays the assets held by authAddress and mainAddress respectively and automatically selects the address matching the asset the user intends to authenticate.
Why EIP-137 was adopted, and its limitations
Rather than creating a new registry scheme or protocol, this standard reuses the already widely used EIP-137 (ENS) and EIP-634 (TEXT records) as is. The drawback, however, is that authAddress needs a small amount of ETH to directly set authENS's reverse record and eip5131:vault TEXT record. It is noted that this can be solved with a separate reverse-lookup registry that lets mainAddress set the record on authAddress's behalf using only a signed message, and that as L2 and ENS's layer-2 features advance, off-chain verification will become possible even for domains spanning other chains.
Reference implementation and current status
The TypeScript (ethers.js) implementation looks up the reverse record from an address, then verifies by cross-checking the eip5131:vault and eip5131:<authKey> records in sequence. Services with a backend can use this result together with EIP-1271 (the contract signature verification standard) to cheaply confirm whether the signer is an authenticated address, and for use without a backend, a Solidity library (LinkedAddress's validate, validateSender) is also provided that calls the ENS registry and resolver directly. This proposal is currently Stagnant, a draft that is no longer actively discussed and has stalled.
Things to watch out for
- Limited to read-only authentication: The purpose of this standard is read-only authentication that proves control and asset ownership without directly moving the main wallet. It assumes that this method is not used for operations that require actually moving assets from the main wallet.