2

The algorithm is described in eip-137.

1

The recursion this EIP refers to is the following line:

return sha3(namehash(remainder) + sha3(label))

I am not sure of all of the reasons for this, but I do know that hashing the values (specifically the user generated remainder and label in some cases) allows for visual verification that the remainder and label are truly the expected values.

ENS had an issue early on with zero-width spaces that allowed people to register what seemed like ethereum.eth, but in reality was eth​er​eum.eth with one or more whitespaces in them. Visual inspection would have told you that these were the same values, but hashing the two values produce a different result.

There may be additional reasons for the recursive hashing, but this is one that I know of.

| improve this answer | |
1

Thanks for the help @shane!

The zero-width spaces are a problem handled by the normalization and the UI.

I have found more use cases in the ENS doc and from what I understand now is that the recursive call in namehash enables some nice lookup functionality similar to existing DNS as well as fixed length keys in the registry store.

As everything is hashed I can register a subdomain by sending namehash('bar.eth'), web3.sha3('foo') without exposing foo in clear text on chain. Very nice design.

| improve this answer | |
  • recursive hashing also allows ownership creation and transfer for subdomains via function setSubnodeOwner(bytes32 node, bytes32 label, address owner) just like for the DNS: you are owner of bar.eth and register lib1.bar.eth – KNK Jun 28 '19 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.