forked from IntersectMBO/cardano-ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
address-binary.tex
109 lines (92 loc) · 3.32 KB
/
address-binary.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
\section{Binary Address Format}
\label{sec:address-binary}
\newcommand{\binary}[1]{\ensuremath{\mathsf{#1}}}
Excepting bootstrap addresses,
the binary format for every address has a 1-byte header, followed by a payload
(bootstrap addresses use the binary encoding from the Byron era).
The header is composed of two nibbles (two 4-bit segments),
indicating the address type and the network id.
$$
\begin{array}{r@{~=~}l}
\mathsf{address} & \mathsf{header\_byte}|\mathsf{payload} \\
& \mathsf{addr\_type\_nibble}|\mathsf{network\_nibble}|\mathsf{payload}
\end{array}
$$
\subsection{Header, first nibble}
\label{sec:address-binary-header-first-nibble}
The first nibble of the header specifies the type of the address.
Bootstrap addresses can also be identified by the first nibble.
\begin{center}
\begin{tabular}{ |c|c|c|c| }
\hline
address type & payment credential & stake credential & header, first nibble \\
\hline
\hline
base address & keyhash & keyhash & \binary{0000} \\
base address & scripthash & keyhash & \binary{0001} \\
base address & keyhash & scripthash & \binary{0010} \\
base address & scripthash & scripthash & \binary{0011} \\
\hline
pointer address & keyhash & ptr & \binary{0100} \\
pointer address & scripthash & ptr & \binary{0101} \\
\hline
enterprise address & keyhash & - & \binary{0110} \\
enterprise address & scripthash & - & \binary{0111} \\
\hline
bootstrap address & keyhash & - & \binary{1000} \\
\hline
stake address & - & keyhash & \binary{1110} \\
stake address & - & scripthash & \binary{1111} \\
\hline
future formats & ? & ? & \binary{1001}-\binary{1101} \\
\hline
\end{tabular}
\end{center}
\subsection{Header, second nibble}
\label{sec:address-binary-header-second-nibble}
Excepting bootstrap addresses, the second nibble of the header specifies the network.
\begin{center}
\begin{tabular}{ |c|c| }
\hline
network & header, second nibble \\
\hline
\hline
testnets & \binary{0000} \\
mainnet & \binary{0001} \\
future networks & \binary{0010}-\binary{1111}\\
\hline
\end{tabular}
\end{center}
\subsection{Header, examples}
\label{sec:address-binary-header-examples}
On a \textbf{testnet},
the header for a \textbf{pointer} address whose payment credential is a \textbf{keyhash} is:
$$\binary{00000100}$$
On \textbf{mainnet}, the header for a \textbf{pointer} address whose payment credential is a \textbf{keyhash} is:
$$\binary{00010100}$$
On \textbf{mainnet}, the header for a \textbf{pointer} address whose payment credential is a \textbf{scripthash} is:
$$\binary{00010101}$$
\subsection{Payloads}
\label{sec:address-binary-payloads}
The payload for the different address types are as follows:
\begin{center}
\begin{tabular}{ |c|c| }
\hline
address type & payload \\
\hline
\hline
base address & two 28-byte bytestrings \\
\hline
pointer address & one 28-byte bytestring,
and three variable-length unsigned integers \\
\hline
enterprise address & one 28-byte bytestrings \\
\hline
stake address & one 28-byte bytestrings \\
\hline
\end{tabular}
\end{center}
The variable-length encoding used in pointers addresses is the base-128 representation
of the number, with the most significant bit of each byte indicating continuation
(this is sometimes called a variable-length quantity, or VLQ).
If the significant bit is $1$, then another byte follows.