Skip to content
Business logic Audit finding Advanced

The expiry of the parent node can be smaller than the one of a child node, violating the guarantee policy

The expiry of a parent node can become smaller than that of its child node because unwrapping a node sets its expiry to zero, removing the constraint that normally limits a child's expiry to the parent's. An attacker could create a sub-sub-domain with a long expiry, unwrap the intermediate sub-domain, then re-wrap it with a shorter expiry, violating the guarantee that a child's expiry never exceeds its parent's.

PwnedNoMore Follow

Originally disclosed on Code4rena

Submitted by PwnedNoMore

NameWrapper.sol#L504 NameWrapper.sol#L356

By design, the child node’s expiry can only be extended up to the parent’s current one. Adding these restrictions means that the ENS users only have to look at the name itself’s fuses and expiry (without traversing the hierarchy) to understand what guarantees the users have.

When a parent node tries to setSubnodeOwner / setSubnodeRecord, the following code is used to guarantee that the new expiry can only be extended up to the current one.

function _getDataAndNormaliseExpiry(
    bytes32 parentNode,
    bytes32 node,
    uint64 expiry
)
    internal
    view
    returns (
        address owner,
        uint32 fuses,
        uint64
    )
{
    uint64 oldExpiry;
    (owner, fuses, oldExpiry) = getData(uint256(node));
    (, , uint64 maxExpiry) = getData(uint256(parentNode));
    expiry = _normaliseExpiry(expiry, oldExpiry, maxExpiry);
    return (owner, fuses, expiry);
}

However, the problem shows when

  • The sub-domain (e.g., sub1.base.eth) has its own sub-sub-domain (e.g., sub2.sub1.base.eth)
  • The sub-domain is unwrapped later, and thus its oldExpiry becomes zero.
  • When base.eth calls NameWrapper.setSubnodeOwner, there is not constraint of sub1.base.eth’s expiry, since oldExpiry == 0. As a result, the new expiry of sub1.base.eth can be arbitrary and smaller than the one of sub2.sub1.base.eth

The point here is that the oldExpiry will be set as 0 when unwrapping the node even it holds child nodes, relaxing the constraint.

Specifically, considering the following scenario

  • The hacker owns a domain (or a 2LD), e.g., base.eth

  • The hacker assigns a sub-domain to himself, e.g., sub1.base.eth

    • The expiry should be as large as possible
  • Hacker assigns a sub-sub-domain, e.g., sub2.sub1.base.eth

    • The expiry should be as large as possible
  • The hacker unwraps his sub-domain, i.e., sub1.base.eth

  • The hacker re-wraps his sub-domain via NameWrapper.setSubnodeOwner

    • The expiry can be small than the one of sub2.sub1.base.eth

The root cause seems that we should not zero out the expiry when burning a node if the node holds any subnode.

Suggested Fix

  • Potential fix 1: auto-burn CANNOT_UNWRAP which thus lets expiry decide whether a node can be unwrapped.
  • Potential fix 2: force the parent to have CANNOT_UNWRAP burnt if they want to set expiries on a child via setSubnodeOwner / setSubnodeRecord / setChildFuses

Proof of Concept / Attack Scenario

For full details, please see original warden submission.

Arachnid (ENS) confirmed


The original report as published on Code4rena, by PwnedNoMore. 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

Root cause

Likely the expiry is zeroed when a node is unwrapped even if it still has child nodes, so the parent's expiry no longer constrains the child's expiry.

What the attacker needed

Attacker owns a domain or 2LD; attacker can create subdomains; attacker can unwrap and re-wrap

The fix

The expiry should not be zeroed when burning a node if the node holds any subnode, or alternatively auto-burn CANNOT_UNWRAP or force the parent to have CANNOT_UNWRAP burnt when setting child expiries.

How it was found

  1. The attacker owns a domain (or a 2LD), e.g., base.eth
  2. The attacker assigns a sub-domain to himself, e.g., sub1.base.eth, with the expiry as large as possible
  3. The attacker assigns a sub-sub-domain, e.g., sub2.sub1.base.eth, with the expiry as large as possible
  4. The attacker unwraps his sub-domain, i.e., sub1.base.eth
  5. The attacker re-wraps his sub-domain via NameWrapper.setSubnodeOwner with a smaller expiry

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.

In ENS, names can have subnames, and a subname's expiry should never be later than its parent's. This report shows that by unwrapping and re-wrapping a middle name, someone can make a subname expire after its parent, breaking that rule.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by PwnedNoMore

View all

8 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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.