-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnano.tex
More file actions
133 lines (113 loc) · 4.42 KB
/
nano.tex
File metadata and controls
133 lines (113 loc) · 4.42 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
% \begin{document}
\chapter{Nano}
TODO: add this to reference\newline
https://content.nano.org/whitepaper/Nano\_Whitepaper\_en.pdf
\section{Requirement}
\section{Spec}
\begin{tla}
Init ==
/\ lastHash = NoHash
/\ distributedLedger = [n \in Node |-> [h \in Hash |-> NoBlock]]
/\ received = [n \in Node |-> {}]
\end{tla}
\begin{tlatex}
\@x{ Init \.{\defeq}}%
\@x{\@s{16.4} \.{\land} lastHash \.{=} NoHash}%
\@x{\@s{16.4} \.{\land} distributedLedger \.{=} [ n \.{\in} Node \.{\mapsto}
[ h \.{\in} Hash \.{\mapsto} NoBlock ] ]}%
\@x{\@s{16.4} \.{\land} received \.{=} [ n \.{\in} Node \.{\mapsto} \{ \} ]}%
\end{tlatex}
\begin{itemize}
\item Every node is a ledger in this system, initialized to NoBlock
\item Every node's received set is initialized to empty set
\end{itemize}
\begin{tla}
Next ==
\/ \E account \in PrivateKey : CreateGenesisBlock(account)
\/ \E node \in Node : CreateBlock(node)
\/ \E node \in Node : ProcessBlock(node)
\end{tla}
\begin{tlatex}
\@x{ Next \.{\defeq}}%
\@x{\@s{16.4} \.{\lor} \E\, account \.{\in} PrivateKey \.{:}
CreateGenesisBlock ( account )}%
\@x{\@s{16.4} \.{\lor} \E\, node \.{\in} Node \.{:} CreateBlock ( node )}%
\@x{\@s{16.4} \.{\lor} \E\, node \.{\in} Node \.{:} ProcessBlock ( node )}%
\end{tlatex}
\newline
PrivateKey represents the identity of the account, create the genesis block for
every account. Let us look at how a genesis block is created:\newline
\begin{tla}
HashOf(block) ==
IF \E hash \in Hash : hashFunction[hash] = block
THEN CHOOSE hash \in Hash : hashFunction[hash] = block
ELSE CHOOSE hash \in Hash : hashFunction[hash] = N!NoBlock
CalculateHashImpl(block, oldLastHash, newLastHash) ==
LET hash == HashOf(block) IN
/\ newLastHash = hash
/\ hashFunction' = [hashFunction EXCEPT ![hash] = block]
CreateGenesisBlock(privateKey) ==
LET
publicKey == KeyPair[privateKey]
genesisBlock ==
[type |-> "genesis",
account |-> publicKey,
balance |-> GenesisBalance]
IN
/\ ~GenesisBlockExists
/\ CalculateHash(genesisBlock, lastHash, lastHash')
/\ distributedLedger' =
LET signedGenesisBlock ==
[block |-> genesisBlock,
signature |-> SignHash(lastHash', privateKey)]
IN
[n \in Node |->
[distributedLedger[n] EXCEPT
![lastHash'] = signedGenesisBlock]]
/\ UNCHANGED received
\end{tla}
\begin{tlatex}
\@x{ HashOf ( block ) \.{\defeq}}%
\@x{\@s{8.2} {\IF} \E\, hash \.{\in} Hash \.{:} hashFunction [ hash ] \.{=}
block}%
\@x{\@s{8.2} \.{\THEN} {\CHOOSE} hash \.{\in} Hash \.{:} hashFunction [ hash
] \.{=} block}%
\@x{\@s{8.2} \.{\ELSE} {\CHOOSE} hash \.{\in} Hash \.{:} hashFunction [ hash
] \.{=} N {\bang} NoBlock}%
\@pvspace{8.0pt}%
\@x{ CalculateHashImpl ( block ,\, oldLastHash ,\, newLastHash ) \.{\defeq}}%
\@x{\@s{8.2} \.{\LET} hash \.{\defeq} HashOf ( block ) \.{\IN}}%
\@x{\@s{8.2} \.{\land} newLastHash \.{=} hash}%
\@x{\@s{8.2} \.{\land} hashFunction \.{'} \.{=} [ hashFunction {\EXCEPT}
{\bang} [ hash ] \.{=} block ]}%
\@pvspace{8.0pt}%
\@x{ CreateGenesisBlock ( privateKey ) \.{\defeq}}%
\@x{\@s{16.4} \.{\LET}}%
\@x{\@s{32.8} publicKey \.{\defeq} KeyPair [ privateKey ]}%
\@x{\@s{32.8} genesisBlock \.{\defeq}}%
\@x{\@s{49.19} [ type\@s{12.75} \.{\mapsto}\@w{genesis} ,\,}%
\@x{\@s{49.19} account \.{\mapsto} publicKey ,\,}%
\@x{\@s{49.19} balance\@s{1.73} \.{\mapsto} GenesisBalance ]}%
\@x{\@s{16.4} \.{\IN}}%
\@x{\@s{16.4} \.{\land} {\lnot} GenesisBlockExists}%
\@x{\@s{16.4} \.{\land} CalculateHash ( genesisBlock ,\, lastHash ,\,
lastHash \.{'} )}%
\@x{\@s{16.4} \.{\land} distributedLedger \.{'} \.{=}}%
\@x{\@s{31.61} \.{\LET} signedGenesisBlock \.{\defeq}}%
\@x{\@s{52.01} [ block \.{\mapsto} genesisBlock ,\,}%
\@x{\@s{52.01} signature \.{\mapsto} SignHash ( lastHash \.{'} ,\, privateKey
) ]}%
\@x{\@s{31.61} \.{\IN}}%
\@x{\@s{31.61} [ n \.{\in} Node \.{\mapsto}}%
\@x{\@s{44.87} [ distributedLedger [ n ] {\EXCEPT}}%
\@x{\@s{59.95} {\bang} [ lastHash \.{'} ] \.{=} signedGenesisBlock ] ]}%
\@x{\@s{16.4} \.{\land} {\UNCHANGED} received}%
\end{tlatex}
\newline
Every account maintains its own chain of blocks. The first block in the account
chain is the genesis block. The genesis block contains the type, account name,
and genesis balance. The genesis block is then hashed and signed.
% \chapter{Nano Blockchain}
TODO: add this to reference\newline
https://content.nano.org/whitepaper/Nano\_Whitepaper\_en.pdf
% \end{document}