- taytems.eth
ENSIP-X: Universal Resolution
Abstract
This ENSIP defines a universal entrypoint for resolving ENS names, via an interface (i.e the UniversalResolver).
Motivation
The process of resolving ENS names traditionally requires multiple onchain calls, and that an implementing developer has in-depth knowledge of ENS. Resolution is becoming more involved over time, especially with the introduction of wildcard resolution (ENSIP-10), and more recently cross-chain reverse resolution (ENSIP-19). These factors mean there is a relatively high burden to implement ENS, with high latency, and a large amount of developer hours to spend to understand and implement the correct resolution process.
Given these factors, there are significant incentives for incorrect/incomplete ENS implementations, or implementations that do not rely on Ethereum as the source of truth.
Beyond the implementation burdens, maintaining many resolution implementations means that any change to ENS resolution that an ENSIP might provide becomes a challenging task to propagate amongst the ecosystem, and as such significantly limits the growth of the ENS protocol with novel concepts.
As a solution for these challenges, this specification proposes an interface that allows universally resolving any ENS name, or any reverse name.
Specification
A compliant implementation of the UniversalResolver must implement the following interface:
interface IUniversalResolver {
error ResolverNotFound(bytes name);
error ResolverNotContract(bytes name, address resolver);
error UnsupportedResolverProfile(bytes4 selector);
error ResolverError(bytes errorData);
error ReverseAddressMismatch(string primary, bytes primaryAddress);
error HttpError(uint16 status, string message);
function resolve(
bytes calldata name,
bytes calldata data
) external view returns (bytes memory result, address resolver);
function reverse(
bytes calldata lookupAddress,
uint256 coinType
)
external
view
returns (
string memory primary,
address resolver,
address reverseResolver
);
}
resolve
The resolve
function should be used by any ENS client as a complete replacement for offchain resolution methods.
Similar to that of ENSIP-10, this function takes two parameters:
name
: The DNS-encoded name to resolvedata
: The encoded calldata for a resolver function
If intending to resolve multiple requests, the data
parameter can be encoded via the following multicall interface:
interface IMulticallable {
function multicall(bytes[] calldata data) external view returns (bytes[] memory results);
}
Decoding the result of a multicall should be done by using the output of the same interface.
Errors are returned in the results array of a multicall, and can be checked with len(result) % 32 == 4
.
Example of a multicall:
function getData(name: string) {
const encodedMulticallData = encodeFunctionData({
name: "multicall",
args: [
[
encodeFunctionData({
name: "addr",
args: [namehash(name)],
}),
encodeFunctionData({
name: "text",
args: [namehash(name), "url"],
}),
],
],
});
const [encodedMulticallResult, resolverAddress] =
await universalResolver.resolve(dnsEncodeName(name), encodedMulticallData);
const decodedMulticallResults = decodeFunctionResult({
name: "multicall",
data: encodedMulticallResult,
});
decodedMulticallResults.forEach((result) => {
if (result.length % 32 === 4) {
throw new Error("Error in result");
}
});
return {
results: decodedMulticallResults,
resolverAddress,
};
}
The output of this function is:
bytes
: The data returned by the resolveraddress
: The address of the resolver that resolved the name
reverse
The reverse
function can be used by any ENS client as a complete replacement for offchain reverse name resolution methods.
This function takes two parameters:
lookupAddress
: The address to resolve the name for, in decoded form (as per ENSIP-9).- Example: with an Ethereum address of
0x314159265dD8dbb310642f98f50C066173C1259b
, this value would be314159265dd8dbb310642f98f50c066173c1259b
. - Example: with a Bitcoin address of
1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
, this value would be0062e907b15cbf27d5425399ebf6f0fb50ebb88f18
.
- Example: with an Ethereum address of
coinType
: The coin type to resolve the name for, as defined by ENSIP-9 and ENSIP-11.
The output of this function is:
name
: The verified reverse resolved name.resolver
: The address of the resolver that resolved theaddr
record for the name (i.e. forward verification).reverseResolver
: The address of the resolver that resolved thename
record.
In the scenario that a name is not set for the given parameters, all outputs will resolve to 0x
.
Errors
- ResolverNotFound
- A resolver could not be found for the given name.
- Parameters
bytes name
: The name a resolver could not be found for.
- Can throw from all functions.
- ResolverNotContract
- The resolver found for the given name is not a contract.
- Parameters
bytes name
: The name the resolver was found for.address resolver
: The address of the resolver that is not a contract.
- Can throw from all functions.
- UnsupportedResolverProfile
- The resolver for the given name did not respond, i.e. responded with
0x
. - Parameters
bytes4 selector
: The function selector that the resolver did not respond to.
- Can throw from all functions.
- Can be propagated up from an internal resolver error.
- The resolver for the given name did not respond, i.e. responded with
- HttpError
- An HTTP error occurred on a resolving gateway, either from a gateway used by the UniversalResolver itself, or by the resolver for the given name.
- Parameters
uint16 status
: The HTTP error status, e.g. 400, 404string message
: The HTTP error message, e.g. "Resource not found"
- Can throw from all functions.
- Can be propagated up from an internal resolver error.
- ReverseAddressMismatch
- The resolved address from reverse resolution does not match the resolved address for the primary name.
- Parameters
string primary
: The resolved primary name from reverse resolution.bytes primaryAddress
: The resolved address for the primary name, from reverse resolution. In decoded form (as per ENSIP-9).
- Can throw from the reverse function.
- ResolverError
- The resolver for the given name threw an unrecognised error. Used to distinguish between a resolution error and an internal resolver error.
- Parameters
bytes errorData
: The error data thrown from the resolver.
- Can throw from all functions.
Backwards Compatibility
The UniversalResolver is intended to be a complete replacement for offchain resolution methods, and should be used as such.
Security Considerations
None.
Copyright
Copyright and related rights waived via CC0.