Skip to content
Smart contracts Audit finding Advanced

It is possible to create fake ERC1155 NameWrapper token for subdomain, which is not owned by NameWrapper

A re-entrancy flaw in NameWrapper's transfer-and-burn-fuses routine lets a contract callback unwrap a subdomain before the new owner and fuses are written, leaving a fake ERC1155 NameWrapper token for a domain the wrapper no longer owns. An attacker could sell that token and later re-wrap the domain to steal it back.

panprog Follow

Originally disclosed on Code4rena

Submitted by panprog, also found by Aussie_Battlers, brgltd, cryptphi, peritoflores, and wastewa

NameWrapper.sol#L820-L821 NameWrapper.sol#L524 NameWrapper.sol#L572

Due to re-entrancy possibility in NameWrapper._transferAndBurnFuses (called from setSubnodeOwner and setSubnodeRecord), it is possible to do some stuff in onERC1155Received right after transfer but before new owner and new fuses are set. This makes it possible, for example, to unwrap the subdomain, but owner and fuses will still be set even for unwrapped domain, creating fake ERC1155 NameWrapper token for domain, which is not owned by NameWrapper.

Fake token creation scenario:

  1. Account1 registers and wraps test.eth domain
  2. Account1 calls NameWrapper.setSubnodeOwner for sub.test.eth subdomain with Account1 as owner (to make NameWrapper owner of subdomain)
  3. Contract1 smart contract is created, which calls unwrap in its onERC1155Received function, and a function to send sub.test.eth ERC1155 NameWrapper token back to Account1
  4. Account1 calls NameWrapper.setSubnodeOwner for sub.test.eth with Contract1 as new owner, which unwraps domain back to Account1 but due to re-entrancy, NameWrapper sets fuses and ownership to Contract1
  5. Account1 calls function to send ERC1155 token from Contract1 back to self.

After this sequence of events, sub.test.eth subdomain is owned by Account1 both in ENS registry and in NameWrapper (with fuses and expiry correctly set to the future date). Lots (but not all) of functions in NameWrapper will fail to execute for this subdomain, because they expect NameWrapper to have ownership of the domain in ENS, but some functions will still work, making it possible to make the impression of good domain.

At this point, ownership in NameWrapper is “detached” from ownership in ENS and Account1 can do all kinds of malcious stuff with its ERC1155 token. For example:

  1. Sell subdomain to the other user, transfering ERC1155 to that user and burning PARENT_CANNOT_CONTROL to create impression that he can’t control the domain. After receiving the payment, Account1 can wrap the domain again, which burns existing ownership record and replaces with the new one with clear fuses and Account1 ownership, effectively stealing domain back from unsuspecting user, who thought that ERC1155 gives him the right to the domain (and didn’t expect that parent can clear fuses when PARENT_CANNOT_CONTROL is set).
  2. Transfer subdomain to some other smart contract, which implements onERC1155Received, then take it back, fooling smart contract into believing that it has received the domain.

Proof of Concept

Copy these to test/wrapper and run: yarn test test/wrapper/NameWrapperReentrancy.js

https://gist.github.com/panprog/3cd94e3fbb0c52410a4c6609e55b863e

Recommended Mitigation Steps

Consider adding nonReentrant modifiers with ReentrancyGuard implementation from openzeppelin. Alternatively just fix this individual re-entrancy issue. There are multiple ways to fix it depending on expected behaviour, for example saving ERC1155 data and requiring it to match the data after transfer (restricting onERC1155Received to not change any data for the token received):

function _transferAndBurnFuses(
    bytes32 node,
    address newOwner,
    uint32 fuses,
    uint64 expiry
) internal {
    (address owner, uint32 saveFuses, uint64 saveExpiry) = getData(uint256(node));
    _transfer(owner, newOwner, uint256(node), 1, "");
    uint32 curFuses;
    uint64 curExpiry;
    (owner, curFuses, curExpiry) = getData(uint256(node));
    require(owner == newOwner && saveFuses == curFuses && saveExpiry == curExpiry);
    _setFuses(node, newOwner, fuses, expiry);
}

Arachnid (ENS) confirmed


The original report as published on Code4rena, by panprog. 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 transfer helper calls the recipient's onERC1155Received callback before writing the new owner and fuses, so the callback can change the wrapper's state and leave it inconsistent with the ENS registry.

Impact

The attacker could sell the fake token and later re-wrap the domain to steal it back, or fool a contract into believing it received the domain; many NameWrapper functions would fail for the detached subdomain.

What the attacker needed

Attacker controls a wrapped parent domain; attacker can deploy a contract with a callback; victim buys or trusts the fake token

The fix

The report recommends adding nonReentrant modifiers from OpenZeppelin's ReentrancyGuard, or checking that the token's owner and fuses are unchanged after the transfer callback before setting new fuses.

How it was found

  1. Register and wrap a parent domain.
  2. Call setSubnodeOwner to create a subdomain owned by the attacker.
  3. Deploy a contract whose onERC1155Received unwraps the subdomain and can send the token back.
  4. Call setSubnodeOwner with that contract as new owner, triggering the unwrap during the callback.
  5. Call the contract to send the ERC1155 token back to the attacker.

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 can be told to run code when it receives a token, and here that code runs before the contract finishes updating who owns the token. The attacker uses that gap to unwrap the domain while the wrapper still records the attacker's contract as owner, so the token looks real but the wrapper no longer controls the domain. The attacker can then sell that misleading token and later take the domain back.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by panprog

View all

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

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.