Skip to content
DoS Audit finding Intermediate

Offchain name resolution would fail despite the located DNS resolver being fully functional

The OffchainDNSResolver contract calls supportsInterface on a DNS resolver without first checking that the resolver implements ERC165, so the call reverts for resolvers that do not support ERC165. This prevents resolution through such resolvers, even if they are otherwise functional.

Trust Follow

Originally disclosed on Code4rena

Submitted by Trust

In OffchainDNSResolver, resolveCallback parses resource records received off-chain and extracts the DNS resolver address:

		// Look for a valid ENS-DNS TXT record
		(address dnsresolver, bytes memory context) = parseRR(
			iter.data,
			iter.rdataOffset,
			iter.nextOffset
		);

The contract supports three methods of resolution through the resolver:

  1. IExtendedDNSResolver.resolve
  2. IExtendedResolver.resolve
  3. Arbitrary call with the query parameter originating in resolve()

Code is below:

            // If we found a valid record, try to resolve it
            if (dnsresolver != address(0)) {
                if (
                    IERC165(dnsresolver).supportsInterface(
                        IExtendedDNSResolver.resolve.selector
                    )
                ) {
                    return
                        IExtendedDNSResolver(dnsresolver).resolve(
                            name,
                            query,
                            context
                        );
                } else if (
                    IERC165(dnsresolver).supportsInterface(
                        IExtendedResolver.resolve.selector
                    )
                ) {
                    return IExtendedResolver(dnsresolver).resolve(name, query);
                } else {
                    (bool ok, bytes memory ret) = address(dnsresolver)
                        .staticcall(query);
                    if (ok) {
                        return ret;
                    } else {
                        revert CouldNotResolve(name);
                    }
                }
            }

The issue is that a resolver could support option (3), but execution would revert prior to the query call. The function uses supportsInterface in an unsafe way. It should first check that the contract implements ERC165, which will guarantee the call won’t revert. Dynamic resolvers are not likely in practice to implement ERC165 as there’s no specific signature to support ahead of time.

Impact

Resolution with custom DNS resolvers are likely to fail.

Recommended Mitigation Steps

Use the OZ ERC165Checker.sol library, which addresses the issue:

    function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
        // query support of both ERC165 as per the spec and support of _interfaceId
        return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);
    }

Arachnid (ENS) disputed and commented:

ERC165 support is required in order to be a valid resolver. Any resolver that doesn’t support it is incorrectly implemented.

LSDan (judge) commented:

This is easy to protect against. Issue stands.

Arachnid (ENS) commented:

There’s no point building a protection for this; either way the result is a failed resolution.

LSDan (judge) commented:

The OZ implementation would guarantee that the else clause gets triggered and the error returned is understandable / sane. In this case, a very simple fix will significantly enhance the composability of the protocol and improve the experience of dev users.

Arachnid (ENS) commented:

I continue to disagree this is an issue. ERC165 support is a baseline requirement for a resolver; checking it’s supported is a pointless waste of gas.

IllIllI (warden) commented:

https://github.com/code-423n4/2023-04-ens/blob/83836eff1975fb47dae6b0982afd0b00294165cf/contracts/utils/UniversalResolver.sol#L498-L510 this code shows that at least in other areas, the possibility failure is acknowledged and handled.


The original report as published on Code4rena, by Trust. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

Resolution with custom DNS resolvers that do not implement ERC165 is likely to fail.

What the attacker needed

Resolver does not implement ERC165

The fix

Use the OpenZeppelin ERC165Checker library, which checks ERC165 support before querying the interface, so the call does not revert.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract tries to ask a DNS resolver if it supports certain features by calling a function called supportsInterface. But if the resolver doesn't implement the standard that defines that function, the call fails and the whole resolution stops. The fix is to first check that the resolver follows that standard before asking.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by Trust

View all

77 more disclosed reports, best first.

More from ENS

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.