-
Notifications
You must be signed in to change notification settings - Fork 155
/
delegation.tex
474 lines (448 loc) · 14 KB
/
delegation.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
\section{Delegation}
\label{sec:delegation}
An agent owning a key that can sign new blocks can delegate its signing rights
to another key by means of \textit{delegation certificates}. These certificates
are included in the ledger, and therefore also included in the body of the
blocks in the blockchain.
There are several restrictions on a certificate posted on the blockchain:
\begin{enumerate}
\item Only genesis keys can delegate.
\item Certificates must be properly signed by the delegator.
\item Any given key can delegate at most once per-epoch.
\item Any given key can issue at most one certificate in a given slot.
\item The epochs in the certificates must refer to the current or to the next
epoch. We do not want to allow certificates from past epochs so that a
delegation certificate cannot be replayed. On the other hand if we allow
certificates with arbitrary future epochs, then a malicious key can issue a
delegation certificate per-slot, setting the epoch to a sufficiently large
value. This will cause a blow up in the size of the ledger state since we
will not be able to clean $\var{eks}$ (we only clean past epochs). Also note
that we do not check the relation between the certificate epoch and the slot
in which the certificate becomes active. This would bring additional
complexity without any obvious benefit.
\item Certificates do not become active immediately, but they require a certain
number of slots till they become stable in all the nodes.
\end{enumerate}
These conditions are formalized in \cref{fig:rules:delegation-scheduling}.
Rule~\ref{eq:rule:delegation-scheduling} determines when a certificate can
become ``scheduled''. The definitions used in these rules are presented in
\cref{fig:defs:delegation-scheduling}, and the types of the system induced by
$\trans{sdeleg}{\wcard}$ are presented in
\cref{fig:ts-types:delegation-scheduling}. Here and in the remaining rules we
will be using $k$ as an abstract constant that gives us the chain stability
parameter.
\begin{figure}[htb]
\emph{Abstract types}
\begin{equation*}
\begin{array}{r@{~\in~}lr}
c & \DCert & \text{delegation certificate}\\
\var{vk_g} & \VKeyGen & \text{genesis verification key}\\
\end{array}
\end{equation*}
\emph{Derived types}
\begin{equation*}
\begin{array}{r@{~\in~}l@{\qquad=\qquad}r@{~\in~}lr}
\var{e} & \Epoch & n & \mathbb{N} & \text{epoch}\\
\var{s} & \Slot & s & \mathbb{N} & \text{slot}\\
\var{d} & \SlotCount & s & \mathbb{N} & \text{slot}
\end{array}
\end{equation*}
\emph{Constraints}
\begin{align*}
\VKeyGen \subseteq \VKey
\end{align*}
\emph{Abstract functions}
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\fun{dbody} & \DCert \to (\VKey \times \Epoch)
& \text{body of the delegation certificate}\\
\fun{dwit} & \DCert \to (\VKeyGen \times \Sig)
& \text{witness for the delegation certificate}\\
\fun{dwho} & \DCert \mapsto (\VKeyGen \times \VKey)
& \text{who delegates to whom in the certificate}\\
\fun{depoch} & \DCert \mapsto \Epoch
& \text{certificate epoch}\\
\var{k} & \mathbb{N} & \text{chain stability parameter}
\end{array}
\end{equation*}
\caption{Delegation scheduling definitions}
\label{fig:defs:delegation-scheduling}
\end{figure}
\begin{figure}[htb]
\emph{Delegation scheduling environments}
\begin{equation*}
\DSEnv =
\left(
\begin{array}{r@{~\in~}lr}
\mathcal{K} & \powerset{\VKeyGen} & \text{allowed delegators}\\
\var{e} & \Epoch & \text{epoch}\\
\var{s} & \Slot & \text{slot}\\
\end{array}
\right)
\end{equation*}
\emph{Delegation scheduling states}
\begin{equation*}
\DSState
= \left(
\begin{array}{r@{~\in~}lr}
\var{sds} & \seqof{(\Slot \times (\VKeyGen \times \VKey))} & \text{scheduled delegations}\\
\var{eks} & \powerset{(\Epoch \times \VKeyGen)} & \text{key-epoch delegations}
\end{array}
\right)
\end{equation*}
\emph{Delegation scheduling transitions}
\begin{equation*}
\var{\_} \vdash
\var{\_} \trans{sdeleg}{\_} \var{\_}
\subseteq \powerset (\DSEnv \times \DSState \times \DCert \times \DSState)
\end{equation*}
\caption{Delegation scheduling transition-system types}
\label{fig:ts-types:delegation-scheduling}
\end{figure}
\begin{figure}[htb]
\begin{equation}
\label{eq:sdeleg-bootstrap}
\inference
{
\var{sds_0} \leteq \epsilon
&
\var{eks_0} \leteq \emptyset
}
{
{\left(\begin{array}{l}
\mathcal{K}\\
e\\
s
\end{array}\right)}
\vdash
\trans{sdeleg}{}
\left(
\begin{array}{l}
\var{sds_0}\\
\var{eks_0}
\end{array}
\right)
}
\end{equation}
\nextdef
\begin{equation}
\label{eq:rule:delegation-scheduling}
\inference
{
(\var{vk_s},~ \sigma) \leteq \dwit{c}
& \verify{vk_s}{\serialised{\dbody{c}}}{\sigma} & vk_s \in \mathcal{K}\\ ~ \\
(\var{vk_s},~ \var{vk_d}) \leteq \dwho{c} & e_d \leteq \depoch{c}
& (e_d,~ \var{vk_s}) \notin \var{eks} & 0 \leq e_d - e \leq 1 \\ ~ \\
d \leteq 2 \cdot k & (s + d,~ (\var{vk_s},~ \wcard)) \notin \var{sds}\\
}
{
{\left(\begin{array}{l}
\mathcal{K}\\
e\\
s
\end{array}\right)}
\vdash
{
\left(
\begin{array}{l}
\var{sds}\\
\var{eks}
\end{array}
\right)
}
\trans{sdeleg}{c}
{
\left(
\begin{array}{l}
\var{sds}; (s + d,~ (\var{vk_s},~ \var{vk_d}))\\
\var{eks} \cup \{(e_d,~ \var{vk_s})\}
\end{array}
\right)
}
}
\end{equation}
\caption{Delegation scheduling rules}
\label{fig:rules:delegation-scheduling}
\end{figure}
\clearpage
The rules in Figure~\ref{fig:rules:delegation} model the activation of
delegation certificates. Once a scheduled certificate becomes active
(see~\cref{sec:delegation-interface-rules}), the delegation map is changed by
it only if:
\begin{itemize}
\item The delegating key ($\var{vk_s}$) did not activate a delegation
certificate in a slot greater or equal than the certificate slot ($s$). This
check is performed to avoid having the constraint that the delegation
certificates have to be activated in slot order.
\item The key being delegated to ($\var{vk_d}$) has not been delegated by
another key (injectivity constraint).
\end{itemize}
The reason why we check that the delegation map is injective is to avoid a
potential risk (during the OBFT era) in which a malicious node gets control of
a genesis key $\var{vk_m}$ that issued the maximum number of blocks in a given
window. By delegating to another key $\var{vk_d}$, which was already delegated to
by some other key $\var{vk_g}$, the malicious node could prevent $\var{vk_g}$
from issuing blocks. Even though the delegation certificates take several slots
to become effective, the malicious node could calculate when the certificate
would become active, and issue a delegation certificate at the right time.
As an additional advantage, by having an injective delegation map, we are able
to simplify our specification when it comes to counting the blocks issued by
(delegates of) genesis keys.
Note also, that we could not impose the injectivity constraint in
Rule~\ref{eq:rule:delegation-scheduling} since we do not have information about
the delegations that will become effective. We could of course detect a
violation in the injectivity constraint when scheduling a delegation
certificate, but this will lead to a complex computation and larger state in
said rule.
Finally, note that we do not want to reject a scheduled delegation that would
violate the injectivity constraint (since delegation might not have been
scheduled by the node issuing the block). Instead, we simply ignore the
delegation certificate (Rule~\ref{eq:rule:delegation-nop}).
\begin{figure}[htb]
\begin{align*}
& \unionoverrideRight \in (A \mapsto B) \to (A \mapsto B) \to (A \mapsto B)
& \text{union override}\\
& d_0 \unionoverrideRight d_1 = d_1 \cup (\dom d_1 \subtractdom d_0)
\end{align*}
\caption{Functions used in delegation rules}
\label{fig:funcs:delegation}
\end{figure}
\begin{figure}[htb]
\emph{Delegation environments}
\begin{equation*}
\DEnv =
\left(
\begin{array}{r@{~\in~}lr}
\mathcal{K} & \powerset{\VKeyGen} & \text{allowed delegators}
\end{array}
\right)
\end{equation*}
\emph{Delegation states}
\begin{align*}
& \DState
= \left(
\begin{array}{r@{~\in~}lr}
\var{dms} & \VKeyGen \mapsto \VKey & \text{delegation map}\\
\var{dws} & \VKeyGen \mapsto \Slot & \text{when last delegation occurred}\\
\end{array}\right)
\end{align*}
\emph{Delegation transitions}
\begin{equation*}
\_ \vdash \_ \trans{adeleg}{\_} \_ \in
\powerset (\DEnv \times \DState \times (\Slot \times (\VKeyGen \times \VKey)) \times \DState)
\end{equation*}
\caption{Delegation transition-system types}
\label{fig:ts-types:delegation}
\end{figure}
\begin{figure}[htb]
\begin{equation}
\label{eq:adeleg-bootstrap}
\inference
{
\var{dms_0} \leteq \Set{k \mapsto k}{k \in \mathcal{K}} &
\var{dws_0} \leteq \Set{k \mapsto 0}{k \in \mathcal{K}}
}
{
\left(
\mathcal{K}
\right)
\vdash
\trans{adeleg}{}
\left(
\begin{array}{l}
\var{dms_0}\\
\var{dws_0}
\end{array}
\right)
}
\end{equation}
\nextdef
\begin{equation}\label{eq:rule:delegation-change}
\inference
{
\var{vk_d} \notin \range~\var{dms} & (\var{vk_s} \mapsto s_p \in \var{dws} \Rightarrow s_p < s)
}
{
\left(\mathcal{K}\right)
\vdash
\left(
\begin{array}{r}
\var{dms}\\
\var{dws}
\end{array}
\right)
\trans{adeleg}{(s,~ (vk_s,~ vk_d))}
\left(
\begin{array}{lcl}
\var{dms} & \unionoverrideRight & \{\var{vk_s} \mapsto \var{vk_d}\}\\
\var{dws} & \unionoverrideRight & \{\var{vk_s} \mapsto s \}
\end{array}
\right)
}
\end{equation}
\nextdef
\begin{equation}\label{eq:rule:delegation-nop}
\inference
{\var{vk_d} \in \range~\var{dms} \vee (\var{vk_s} \mapsto s_p \in \var{dws} \wedge s \leq s_p)
}
{
\left(\mathcal{K}\right)
\vdash
\left(
\begin{array}{r}
\var{dms}\\
\var{dws}
\end{array}
\right)
\trans{adeleg}{(s,~ (\var{vk_s},~ \var{vk_d}))}
\left(
\begin{array}{lcl}
\var{dms}\\
\var{dws}
\end{array}
\right)
}
\end{equation}
\caption{Delegation inference rules}
\label{fig:rules:delegation}
\end{figure}
\clearpage
\subsection{Delegation sequences}
\label{sec:delegation-sequences}
This section presents the rules that model the effect that sequences of
delegations have on the ledger.
\begin{figure}[htb]
\begin{equation}
\inference
{
{\begin{array}{l}
\var{delegEnv}
\end{array}}
\vdash
\trans{\hyperref[eq:sdeleg-bootstrap]{sdeleg}}{}
\var{delegSt}
}
{
{\begin{array}{l}
\var{delegEnv}
\end{array}}
\vdash
\trans{sdelegs}{}
\var{delegSt}
}
\end{equation}
\nextdef
\begin{equation}
\label{eq:rule:delegation-scheduling-seq-base}
\inference
{}
{
\var{delegEnv}
\vdash
\var{delegSt}
\trans{sdelegs}{\epsilon}
\var{delegSt}
}
\end{equation}
\nextdef
\begin{equation}
\label{eq:rule:delegation-scheduling-seq-ind}
\inference
{
\var{delegEnv}
\vdash
\var{delegSt}
\trans{sdelegs}{\Gamma}
\var{delegSt'}
&
\var{delegEnv}
\vdash
\var{delegSt'}
\trans{\hyperref[fig:rules:delegation-scheduling]{sdeleg}}{c}
\var{delegSt''}
}
{
\var{delegEnv}
\vdash
\var{delegSt}
\trans{sdelegs}{\Gamma; c}
\var{delegSt''}
}
\end{equation}
\caption{Delegation scheduling sequence rules}
\label{fig:rules:delegation-scheduling-seq}
\end{figure}
\begin{figure}
\begin{equation}
\inference
{
{\begin{array}{l}
\var{delegEnv}
\end{array}}
\vdash
\trans{\hyperref[eq:adeleg-bootstrap]{adeleg}}{}
\var{delegSt}
}
{
{\begin{array}{l}
\var{delegEnv}
\end{array}}
\vdash
\trans{adelegs}{}
\var{delegSt}
}
\end{equation}
\nextdef
\begin{equation}
\label{eq:rule:delegation-seq-base}
\inference
{}
{
\var{delegEnv}
\vdash
\var{delegSt}
\trans{adelegs}{\epsilon}
\var{delegSt}
}
\end{equation}
\nextdef
\begin{equation}
\label{eq:rule:delegation-seq-ind}
\inference
{
\var{delegEnv}
\vdash
\var{delegSt}
\trans{adelegs}{\Gamma}
\var{delegSt'}
&
\var{delegEnv}
\vdash
\var{delegSt'}
\trans{\hyperref[fig:rules:delegation]{adeleg}}{c}
\var{delegSt''}
}
{
\var{delegEnv}
\vdash
\var{delegSt}
\trans{adelegs}{\Gamma; c}
\var{delegSt''}
}
\end{equation}
\caption{Delegations sequence rules}
\label{fig:rules:delegation-seq}
\end{figure}
\subsection{Deviation from the \texttt{cardano-sl} implementation}
\label{sec:delegation:deviation-cardano-sl-imp}
In the \texttt{cardano-sl} implementation, the block issuer needs to include a
delegation certificate in the block, which witness the fact that a genesis key
gave the issuer the rights of issuing blocks on behalf of this genesis key. The
reasons why this was implemented in this way in \texttt{cardano-sl} are not
clear, since the delegation certificates are posted on the chain, so the ledger
state contains the information about who delegates to whom. Hence in the
current specification we use a heavyweight delegation scheme, i.e. where the
certificates are posted on the chain, but an implementation of this rules that
aims at being compatible with the implementation in \texttt{cardano-sl} has to
take the fact that delegation certificates are also present in a block into
account.