Skip to content
Business logic Write-up Intermediate

What is a ENS Domain?

The ENS metadata service did not validate that a registered name containing a dot character was a legitimate subdomain, allowing an attacker to register a name like 'eth-usd.data.eth' without owning 'data.eth'. This could deceive buyers on NFT marketplaces into purchasing a spoofed domain.

Hacxyk Follow

Published on medium.com

Bounty$15,000 View original

Chances are you have already seen a ETH domain (on Twitter) even if you didn’t know what it was.

Hacxyk, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

ENS (Ethereum Name Service) domains look like ordinary internet domains, except the suffix is .eth instead of .com. They are used for sending and receiving Ethereum payments and occasionally for IPFS. A user needs a user agent or a browser extension such as MetaMask that supports ETH domains to resolve them.

From the original on medium.com

The interesting part for security work is how registration differs from the traditional DNS model. Traditional domains are case-insensitive and only allow alphanumeric characters and the hyphen; international domains are just punycode and still abide by the same rules. This is enforced at the registrar level. ENS domains have no such restrictions at the registrar level, because the ENS smart contract does not store the domain name in plain text. It stores only the Keccak-256 hash of the name. The registrar therefore does not know which domain name is being registered and cannot place any restrictions on it. As the report puts it, this makes ENS domains easily spoofable.

ENS names are also NFTs, so they can be sold on marketplaces such as OpenSea and LooksRare. Each ENS NFT has a name ID, which is a combined result of several Keccak-256 hashes. For example, nick.eth's name ID is calculated as follows:

Text
keccak256("\0" * 32, keccak256("nick"))

If a domain has multiple levels, the process is done recursively.

Because the smart contract only stores a hash, marketplaces need a way to turn a hash back into a human-readable name. ENS officially provides a metadata service for deriving the name from a lookup table. For example, this request:

returns:

JSON
{"is_normalized":true,"name":"nick.eth","description":"nick.eth, an ENS name."}

From this we know the hash (name ID) 42219085255511335250589442208301538195142221433306354426240614732612795430543 represents nick.eth. The metadata service is where the flaw was found.

Setup

The report does not describe any particular accounts, roles, tooling or versions. The work consisted of registering ENS names and querying the public metadata service, then observing how OpenSea and LooksRare displayed the resulting NFTs. The precondition for the attack is simply the ability to register an ENS name whose string contains characters the metadata service does not expect.

Finding it

The researchers started from known spoofing techniques and tested how the metadata service handled each of them.

Homograph attack

Using non-ASCII characters can make two domains look identical visually. Browsers have a set of rules to determine whether a domain is intended to deceive people. For ENS, any non-ASCII domain is simply marked non-normalised and a warning is displayed. The warning comes from the metadata service.

From the original on medium.com

Spoofing with uppercase letters

Not being able to use non-ASCII characters eliminates a lot of possibilities, but there is a known attack vector that uses uppercase letters. For example, Bitcoin and bitcoin have different hashes. The metadata service did not consider this scenario and did not return a warning. This was since patched.

From the original on medium.com

Spoofing with a subdomain

ENS supports subdomains. The researchers discovered that the metadata service did not consider that a name can contain the dot character. It was possible to register an ENS domain with foo.bar as the name, and the metadata service would return foo.bar.eth instead of marking it invalid.

The report contrasts the two name IDs:

Text
✔️ Correct name ID: keccak256(keccak256("\0" * 32, keccak256("bar"), keccak256("foo"))
❌ Invalid name ID : keccak256("\0" * 32, keccak256("foo.bar"))

The first is labelled the correct name ID for a subdomain structure. The second is the hash of a single label that happens to contain a dot. The metadata service treated the second as a valid name and rendered it as foo.bar.eth, which reads exactly like a subdomain of bar.eth.

Exploitation

Step 1: register a name containing a dot

The researchers registered eth-usd.data.eth as a single ENS name, despite not owning data.eth, which belongs to Chainlink. Because the registrar only sees the hash, nothing prevented the registration.

Step 2: query the metadata service

The metadata service did not mark the name invalid, so it was presented as if it were a subdomain of data.eth.

Step 3: observe the marketplaces

Both OpenSea and LooksRare displayed the NFT without a warning. The report shows the result:

From the original on medium.com

Anyone who bought this domain believing it to be a legitimate Chainlink subdomain would lose their money.

Root cause

The ENS smart contract stores only the Keccak-256 hash of a name, so the registrar cannot enforce character rules on the plaintext. That is a design property of ENS rather than a bug in itself, but it moves all validation to the consumers of the hash, in this case the metadata service.

The metadata service derived a display name from the lookup table and did not account for the fact that a single registered label can contain the dot character. It therefore rendered foo.bar.eth for the hash of the single label foo.bar, which is indistinguishable from a genuine subdomain structure. The earlier uppercase issue shows the same pattern: the service did not consider a class of inputs that produce visually confusable names, and returned no warning. The homograph case was handled by marking non-ASCII names non-normalised, but the dot case was not covered by that check.

Impact

An attacker could register a name that renders as a subdomain of a domain they do not own, and have it displayed without warning on marketplaces that rely on the ENS metadata service. In the demonstrated case the impersonated domain was data.eth, owned by Chainlink. A buyer who believed the name was a legitimate subdomain could pay for it and lose their money. The impact depends on the marketplace trusting the metadata service's output and on a victim purchasing the spoofed name.

Fix

The issue was fixed in the ENS metadata service, and hence in LooksRare and OpenSea, which rely on it. The uppercase issue had also been patched in the metadata service. The report does not describe the code change itself.

The disclosure was handled as follows:

  1. April 6th: issue reported to ENS, LooksRare and OpenSea.
  2. April 6th: LooksRare received the report and contacted ENS.
  3. April 6th: ENS pushed a fix.
  4. April 9th: OpenSea closed the report as out of scope.
  5. April 11th: ENS awarded $15k for the issue.

LooksRare stated that the issue was on the ENS side and contacted ENS. OpenSea closed the report as "Phishing is out of scope".

Variants to test

  1. Register a name containing a dot and query the metadata service for its name ID. A positive result is a response with is_normalized true and a name that reads as a subdomain of a domain you do not own.
  2. Register names that differ only by case and compare their name IDs and metadata responses. A positive result is two visually identical names with different hashes and no warning from the service.
  3. Register names mixing scripts or using lookalike characters and check the is_normalized flag. A positive result is a non-normalised name that is still rendered without a warning by a marketplace.
  4. Check other consumers of the metadata service, such as wallets and block explorers, with the same spoofed names. A positive result is any interface that displays the spoofed name as legitimate.
  5. Test other naming systems that store hashes rather than plaintext, and their metadata or reverse-lookup services, with labels containing separators. A positive result is a display name that implies a hierarchy the registrant does not control.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

A group of security researchers found a way to make a fake Ethereum domain name look like a real one that belonged to somebody else. They reported it to the companies involved, one of them fixed it quickly and paid a $15,000 reward, and another one closed the report as out of scope. This article walks through what they did, step by step, assuming you have never read a security report before.

What is an ENS domain?

You have probably seen an Ethereum domain on Twitter without realising what it was.

From the original on medium.com

An ENS domain looks like a normal website address, except the ending is .eth instead of .com. ENS stands for Ethereum Name Service. Instead of pointing at a website, an ENS name is mostly used to send and receive Ethereum payments, and occasionally to point at IPFS, a decentralised way of storing files.

To use one you need software that understands .eth names: a wallet or a browser extension such as MetaMask. A normal browser does not know what to do with .eth.

How registration works, and why it matters

This is the part that makes the whole story possible, so it is worth slowing down.

On the ordinary internet, domain names follow strict rules. They are case-insensitive, meaning Example.com and example.com are the same name, and they may only contain letters, digits and the hyphen. International names in other alphabets are converted into a restricted encoding called punycode, which still obeys the same rules. These rules are enforced by the registrar, the organisation that sells the name.

ENS has no such rules at the registrar level. Why? Because of how ENS stores names. The ENS smart contract, a small program that runs on the Ethereum blockchain, does not store the name in readable text. It stores only a fingerprint of the name, a hash. A hash is a fixed-length string of characters produced from any input by a mathematical function; the same input always gives the same hash, and you cannot work backwards from the hash to the input. ENS uses a particular hash function called Keccak-256.

Because the registrar only ever sees the fingerprint, it has no idea which letters you typed. It cannot refuse a name for containing odd characters, because it never sees the characters. As the researchers put it, this makes ENS domains easily spoofable: easy to imitate.

ENS names are also NFTs

An NFT is a non-fungible token, a unique digital item recorded on a blockchain that can be bought and sold. Each ENS name is an NFT, so it can be traded on marketplaces such as OpenSea and LooksRare, which are websites for buying and selling NFTs.

Every ENS NFT has a name ID. This is a fingerprint built by combining several Keccak-256 hashes. For example, the name ID of nick.eth is calculated like this:

Text
keccak256("\0" * 32, keccak256("nick"))

Line by line: the inner part, keccak256("nick"), takes the word nick and produces its fingerprint. The outer part takes that fingerprint together with 32 zero bytes, written "\0" * 32, and hashes the combination again. The result is the name ID. If a name has several levels, the same process is repeated for each level.

The metadata service

Here is the problem the researchers spotted. If the blockchain only stores a fingerprint, how can a marketplace show you the readable name? It cannot reverse the hash.

The answer is a metadata service: a public web service run by ENS that keeps a lookup table from fingerprint back to name. You send it a name ID and it tells you the name. In web terms it is an API, an interface one program uses to ask another program for data over the internet. For example, this request:

Line by line: GET is the method, meaning "give me this". The path contains mainnet, the name of the real Ethereum network, then a long hexadecimal address starting 0x57f1887a..., which identifies the ENS contract, then a very long number, which is the name ID being looked up. HTTP/1.1 is the version of the web protocol. The Host line says which server is being asked, here metadata.ens.domains.

The service answers:

JSON
{"is_normalized":true,"name":"nick.eth","description":"nick.eth, an ENS name."}

Line by line: this is JSON, a common text format for structured data. is_normalized is a true/false flag saying whether the name is in a standard, expected form. name is the readable name. description is a human-friendly sentence. So the response tells us that the long number 42219085255511335250589442208301538195142221433306354426240614732612795430543 represents nick.eth.

This metadata service is what marketplaces rely on, and it is where the flaw was found.

Setting up

The report does not describe any particular accounts, roles, tools or software versions. The work consisted of registering ENS names and asking the public metadata service about them, then watching how OpenSea and LooksRare displayed the resulting NFTs. The only precondition for the attack is being able to register an ENS name whose text contains characters the metadata service does not expect.

Finding it

The researchers started from spoofing techniques that were already known and tested how the metadata service handled each one.

Homograph attack

A homograph attack uses characters from different alphabets that look the same. For instance, the Latin letter a and the Cyrillic letter а look identical on screen but are different characters. Two domains can therefore look the same to a human while being completely different names.

Browsers have rules to decide whether a domain is trying to deceive people. For ENS, any name containing non-ASCII characters is simply marked non-normalised, and a warning is shown. The warning comes from the metadata service.

From the original on medium.com

Spoofing with uppercase letters

If non-ASCII characters are blocked, many tricks are ruled out. But there is a known attack that uses uppercase letters. Bitcoin and bitcoin look the same to a reader, yet they produce different hashes, because the hash function treats capital and small letters as different characters. The metadata service did not consider this case and returned no warning. This has since been patched.

From the original on medium.com

Spoofing with a subdomain

ENS supports subdomains, the same way blog.example.com is a subdomain of example.com. The researchers discovered that the metadata service did not consider that a name can contain the dot character. It was possible to register an ENS domain whose name was literally foo.bar, and the metadata service would return foo.bar.eth instead of marking it invalid.

The report contrasts the two name IDs:

Text
✔️ Correct name ID: keccak256(keccak256("\0" * 32, keccak256("bar"), keccak256("foo"))
❌ Invalid name ID : keccak256("\0" * 32, keccak256("foo.bar"))

Line by line: the first line is the fingerprint of a genuine subdomain structure, where foo sits under bar. It hashes bar and foo separately and combines them with the 32 zero bytes. The second line is the fingerprint of a single label that happens to contain a dot: it hashes the whole string foo.bar in one go. These are two different fingerprints for two different things. The metadata service treated the second one as a valid name and displayed it as foo.bar.eth, which reads exactly like a subdomain of bar.eth.

Exploitation

Step 1: register a name containing a dot

The researchers registered eth-usd.data.eth as a single ENS name, even though they did not own data.eth, which belongs to Chainlink, a well-known cryptocurrency data provider. Because the registrar only sees the hash, nothing stopped the registration.

Step 2: query the metadata service

The metadata service did not mark the name invalid, so it was presented as if it were a subdomain of data.eth. The name was therefore presented as if it were a subdomain of data.eth.

Step 3: observe the marketplaces

Both OpenSea and LooksRare displayed the NFT without any warning. The report shows the result:

From the original on medium.com

Anyone who bought this domain believing it to be a legitimate Chainlink subdomain would lose their money.

Root cause

The ENS smart contract stores only the Keccak-256 hash of a name, so the registrar cannot enforce character rules on the readable text. That is a design property of ENS rather than a bug in itself, but it moves all checking to whoever consumes the hash, in this case the metadata service.

The metadata service built a display name from its lookup table and did not account for the fact that a single registered label can contain the dot character. It therefore rendered foo.bar.eth for the hash of the single label foo.bar, which is indistinguishable from a genuine subdomain structure. The earlier uppercase issue shows the same pattern: the service did not consider a class of inputs that produce visually confusable names, and returned no warning. The homograph case was handled by marking non-ASCII names non-normalised, but the dot case was not covered by that check.

Impact

An attacker could register a name that renders as a subdomain of a domain they do not own, and have it displayed without warning on marketplaces that rely on the ENS metadata service. In the demonstrated case the impersonated domain was data.eth, owned by Chainlink. A buyer who believed the name was a legitimate subdomain could pay for it and lose their money. The impact depends on the marketplace trusting the metadata service's output and on a victim purchasing the spoofed name.

Fix

The issue was fixed in the ENS metadata service, and hence in LooksRare and OpenSea, which rely on it. The uppercase issue had also been patched in the metadata service. The report does not describe the code change itself.

The disclosure was handled as follows:

  1. April 6th: issue reported to ENS, LooksRare and OpenSea.
  2. April 6th: LooksRare received the report and contacted ENS.
  3. April 6th: ENS pushed a fix.
  4. April 9th: OpenSea closed the report as out of scope.
  5. April 11th: ENS awarded $15k for the issue.

LooksRare stated that the issue was on the ENS side and contacted ENS. OpenSea closed the report as "Phishing is out of scope".

Variants to test

  1. Register a name containing a dot and query the metadata service for its name ID. A positive result is a response with is_normalized true and a name that reads as a subdomain of a domain you do not own.
  2. Register names that differ only by case and compare their name IDs and metadata responses. A positive result is two visually identical names with different hashes and no warning from the service.
  3. Register names mixing scripts or using lookalike characters and check the is_normalized flag. A positive result is a non-normalised name that is still rendered without a warning by a marketplace.
  4. Check other consumers of the metadata service, such as wallets and block explorers, with the same spoofed names. A positive result is any interface that displays the spoofed name as legitimate.
  5. Test other naming systems that store hashes rather than plaintext, and their metadata or reverse-lookup services, with labels containing separators. A positive result is a display name that implies a hierarchy the registrant does not control.

Glossary

  • API: an interface one program uses to ask another program for data over the internet.
  • Blockchain: a shared record of transactions that many computers keep in sync and that no single party controls.
  • Block explorer: a website for looking up transactions and addresses on a blockchain.
  • ENS: Ethereum Name Service, a naming system on Ethereum whose names end in .eth.
  • Ethereum: a blockchain network that runs programs called smart contracts and has its own cryptocurrency, ether.
  • Hash: a fixed-length fingerprint produced from any input by a mathematical function; the same input always gives the same hash, and you cannot work backwards from it.
  • Homograph attack: using characters from different alphabets that look identical to make two different names appear the same.
  • HTTP: the protocol browsers and servers use to exchange web requests and responses.
  • IPFS: a decentralised way of storing and sharing files.
  • JSON: a common text format for structured data, made of keys and values.
  • Keccak-256: the specific hash function ENS uses.
  • Metadata service: a public ENS service that turns a name ID back into a readable name.
  • MetaMask: a browser extension and wallet that understands .eth names.
  • Name ID: the fingerprint that identifies an ENS name, built by combining several Keccak-256 hashes.
  • NFT: non-fungible token, a unique digital item recorded on a blockchain that can be bought and sold.
  • Non-normalised: not in the standard, expected form; the metadata service flags such names with a warning.
  • Punycode: a restricted encoding that lets international domain names obey the ordinary character rules.
  • Registrar: the organisation or contract that sells and records domain names.
  • Smart contract: a small program that runs on a blockchain and cannot be changed by any single party.
  • Spoofing: making something fake look like something genuine.
  • Subdomain: a name that sits under another name, such as blog.example.com under example.com.
  • Wallet: software that holds cryptocurrency keys and can send and receive payments.

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.