Skip to main content

About namehashing


Before being used in RNS, names are hashed using the namehash algorithm. This algorithm recursively hashes components of the name, producing a unique, fixed-length string for any valid input domain. The output of namehash is referred to as a node.


First, an RNS domain name is divided into labels by splitting on periods (.). So, hello.ron becomes the list [hello, ron]. The namehash algorithm then recursively hashes the labels of the name, starting from the root label. The root label is the top-level domain .ron. The labels are hashed one by one, starting from the leftmost label. For example, the namehash of the RNS name hello.ron would be generated as follows:

  1. Hash the root label ron: sha3('ron')
  2. Hash the next label hello: sha3('hello' + sha3('ron'))
  3. The final namehash is the hash of the previous result: sha3(sha3('hello' + sha3('ron')))

The following is a sample implementation in Python:

import hashlib

def namehash(name):
"""Computes the namehash of an RNS name.

name: The RNS name to hash.

The namehash of the RNS name.

if name == '':
return '\0' * 32
label, _, remainder = name.partition('.')
return hashlib.sha3(namehash(remainder) + hashlib.sha3(label)).hexdigest()

The namehash algorithm is a critical part of the RNS, because it allows for the unique identification of RNS names. It's also used to generate the hashes of RNS records, which are used to store the data associated with RNS names in the Ronin blockchain.

Was this helpful?
Happy React is loading...