Hat IDs

Hat ids are semantic. They have meaning.

Hat ids uint256 bitmaps that create an "address" โ€” more like an web or IP address than an Ethereum address โ€” that includes information about where in the tree a hat is located, including its entire branch of admins.

The 32 bytes of a hat's id are structured as follows:

  • The first 4 bytes are reserved for the top hat id. Since top hat ids are unique across a given deployment of Hats Protocol, we can also think of them as the top level "domain" for a hat tree.

  • Each of the next chunks of 16 bits refers to a single "Hat Level".

There are 15 total hat levels, beginning with the top hat at level 0 and going up to level 14.

Example

Consider the following hat id (in hex): 0x0000000f00020005000a00010000000000000000000000000000000000000000

For convenience, we can reformat it into shorthand, just like an IP address: 15.2.5.10.1

From the id alone, we know a lot about this hat:

  • It is in hat tree 15

  • It is a level 4 hat

  • Its immediate admin (aka parent) is 15.2.5.10

  • Its grandparent is 15.2.5

Other hat id formats

Format
Example

Integer ("raw")

6470400364654781217010529864562902351218663490360806944392503307010048

Hexadecimal

0x0000000f000200050000a00010000000000000000000000000000000000000000

Hexadecimal with level delimiters

0x0000000f.0002.0005.000a.0001.0000.0000.0000.0000.0000.0000.0000.0000.0000.0000 0x0000000f_0002_0005_000a_0001_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000

"IP address"

15.2.5.10.1

Hat Tree Space

A hat tree can have up to 14 levels, plus the top hat (tree root). Within those 14 levels are 224 bits of address space (remember, one level contains 16 bits of space), so the maximum number of hats in a single hat tree is approximately:

2224+1โ‰ˆย 2.696โˆ—10672^{224} + 1 \approx ~2.696 * 10^{67}

which is well beyond the number of stars in the universe.

Last updated