Description
A universal entrypoint for resolving ENS names.
Status
draft
Created
2024-10-14
Author
  • 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:

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:

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:

The output of this function is:

In the scenario that a name is not set for the given parameters, all outputs will resolve to 0x.

Errors

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.