This repository was archived by the owner on Aug 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathrules.tex
1706 lines (1470 loc) · 71.4 KB
/
rules.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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% -*- latex -*-
\documentclass{article}
%% packages %%
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{unicode-math}
\usepackage{newunicodechar}
\usepackage[dvipsnames]{xcolor}
\usepackage[tikz]{bclogo}
\makeatletter
\AtBeginDocument{
\usepackage
[ raiselinks=false
, breaklinks=true
, colorlinks=true
, citecolor=blue
, urlcolor=blue
, linkcolor=PineGreen
%
, pdfpagemode=UseOutlines
, bookmarksopen=true
%
, pdftitle={\@title}
, pdfauthor={\@author}]
{hyperref}
}
\makeatother
%% /packages %%
%% Marginal notes %%
\usepackage{xargs}
\usepackage[colorinlistoftodos,prependcaption,textsize=tiny]{todonotes}
\newcommandx{\unsure}[2][1=]{\todo[linecolor=red,backgroundcolor=red!25,bordercolor=red,#1]{#2}}
\newcommandx{\info}[2][1=]{\todo[linecolor=green,backgroundcolor=green!25,bordercolor=green,#1]{#2}}
\newcommandx{\change}[2][1=]{\todo[linecolor=blue,backgroundcolor=blue!25,bordercolor=blue,#1]{#2}}
\newcommandx{\inconsistent}[2][1=]{\todo[linecolor=blue,backgroundcolor=blue!25,bordercolor=red,#1]{#2}}
\newcommandx{\critical}[2][1=]{\todo[linecolor=blue,backgroundcolor=blue!25,bordercolor=red,#1]{#2}}
\newcommand{\improvement}[1]{\todo[linecolor=pink,backgroundcolor=pink!25,bordercolor=pink]{#1}}
\newcommandx{\resolved}[2][1=]{\todo[linecolor=OliveGreen,backgroundcolor=OliveGreen!25,bordercolor=OliveGreen,#1]{#2}} % use this to mark a resolved question
%% /Marginal notes %%
%% macros %%
\newenvironment{record}{\begin{description}[font=\it]}{\end{description}}
\newenvironment{currentvalue}{\begin{bclogo}[noborder=true,
logo=\bcinfo, epBarre=3, couleurBarre=YellowOrange]{Value in Cardano}}{\end{bclogo}}
\newenvironment{implementationhint}{\begin{bclogo}[noborder=true,
logo=\bccrayon, epBarre=3, couleurBarre=PineGreen]{Implementation hint}}{\end{bclogo}}
\newenvironment{treacherous}{\begin{bclogo}[noborder=true,
logo=\bcdz, epBarre=3, couleurBarre=Red]{Beware}}{\end{bclogo}}
\newcommand{\powerset}[1]{\mathcal{P}(#1)}
\newunicodechar{⧵}{\ensuremath{\smallsetminus}}
\newcommand{\lists}[1]{{#1}^*}
\newcommand{\nelists}[1]{{#1}^+}
\newcommand{\emptylist}{ε}
\newcommand{\pos}[2]{{#2}_{#1}}
\newcommand{\length}[1]{|#1|}
\newcommand{\rem}[2]{\mathrm{rem}_{#1}(#2)}
\newcommand{\supportsize}[1]{|#1|}
\newcommand{\extension}[2]{{#1}^*{#2}}
\newcommand{\kronecker}[2]{[#1 = #2]}
\newcommand{\idsof}[1]{\mathcal{I}\!_#1}
\newcommand{\id}{\mathsf{id}}
\newcommand{\txs}{\mathcal{T}}
\newcommand{\txids}{\idsof{\txs}}
\newcommand{\txinit}{\txs_{\!\mathsf{init}}}
\newcommand{\blocks}{\mathcal{B}}
\newcommand{\rblocks}{\mathcal{B}_r}
\newcommand{\bblocks}{\mathcal{B}_b}
\newcommand{\blockids}{\idsof{\blocks}}
\newcommand{\agentids}{\idsof{\mathcal{A}}}
\newcommand{\bootstrapstakeholders}{\mathcal{A}_{\mathsf{bootstrap}}}
\newcommand{\slotleader}[3]{\mathsf{sl}(#1,#2,#3)}
\newcommand{\recipient}[1]{\mathsf{recipient}(#1)}
\newcommand{\amount}[1]{\mathsf{amount}(#1)}
\newcommand{\transactions}[1]{\mathsf{transactions}(#1)}
\newcommand{\inputs}[1]{\mathsf{inputs}(#1)}
\newcommand{\outputs}[1]{\mathsf{outputs}(#1)}
\newcommand{\intrans}[1]{\mathsf{trans}(#1)}
\newcommand{\inindex}[1]{\mathsf{index}(#1)}
\newcommand{\witnesses}[1]{\mathsf{witnesses}(#1)}
\newcommand{\minimumfee}[1]{\mathsf{minfee}(#1)}
\newcommand{\stakedistributions}{\mathcal{D}}
\newcommand{\seeds}{\mathcal{S}}
\newcommand{\initialdistribution}{d_{\mathsf{init}}}
\newcommand{\initialseed}{s_{\mathsf{init}}}
\newcommand{\initialdelegation}{g_{\mathsf{init}}}
\newcommand{\transitivefix}[1]{{#1}^ω}
\newcommand{\delegations}[1]{\mathsf{deleg}(#1)}
\newcommand{\epoch}[1]{\mathsf{epoch}(#1)}
\newcommand{\epochslot}[1]{\mathsf{slot}_\mathsf{epoch}(#1)}
\newcommand{\epochindex}[1]{\mathsf{epoch}_\mathsf{index}(#1)}
\newcommand{\epochseed}[1]{\mathsf{seed}(#1)}
\newcommand{\epochdistribution}[1]{\mathsf{distr}(#1)}
\newcommand{\currentdistribution}[1]{\mathsf{distr}_0(#1)}
\newcommand{\blocktrees}{\mathcal{G}}
\newcommand{\blockchains}{\mathcal{D}}
\newcommand{\maxchains}[1]{\mathcal{M}(#1)}
\newcommand{\height}[1]{\mathsf{height}(#1)}
\newcommand{\delegator}[1]{\mathsf{delegator}(#1)}
\newcommand{\delegatee}[1]{\mathsf{delegatee}(#1)}
\newcommand{\delegationcertificates}[1]{\mathsf{certificates}_\mathsf{delegation}(#1)}
\newcommand{\selectrichman}[1]{\mathsf{select}_\mathsf{bootstrap}(#1)}
\newcommand{\stakerepartitions}{\mathcal{R}}
\newcommand{\repartition}[1]{\mathsf{repartition}(#1)}
\newcommand{\bootstraprepartition}{r_\mathsf{bootstrap}}
\newcommand{\stakeof}[2]{\mathsf{stake}(#1,#2)}
\newcommand{\maxmempoolsize}{\mathsf{max}_{\mathsf{poolsize}}}
\newcommand{\quality}[1]{\mathsf{quality}(#1)}
\newcommand{\commitphase}{\mathsf{phase}_\mathsf{commitment}}
\newcommand{\openphase}{\mathsf{phase}_\mathsf{open}}
\newcommand{\recoveryphase}{\mathsf{phase}_\mathsf{recovery}}
\newcommand{\epochcommitments}[1]{\mathsf{commitments}(#1)}
\newcommand{\epochopens}[1]{\mathsf{opens}(#1)}
\newcommand{\epochrecoveries}[1]{\mathsf{recoveries}(#1)}
\newcommand{\richmen}[2]{\mathsf{richmen}(#1,#2)}
%% /macros %%
\title{Rule-based specification of the blockchain logic}
\author{Erik de Castro Lopo, Nicholas Clarke \& Arnaud Spiwack}
\begin{document}
\maketitle
\tableofcontents
\section*{Status}
\label{sec:status}
\begin{description}
\item[Draft 0, Mar 14, 2018 (Arnaud)] Outline
\item[Draft 1, Mar 20, 2018 (Arnaud)] First version of the block
validation rules
\item[Draft 2, Mar 28, 2018 (Arnaud)] Slot leader selection rules
\item[Draft 3, Apr 9, 2018 (Nicholas)] Review by Nicholas Clarke
\item[Draft 4, Apr 13, 2018 (Arnaud)] Partial specification of stake
delegation and longest chain selection
\item[Draft 5, Apr 17, 2018 (Arnaud)] Specification of delegation
\item[Draft 6, May 16, 2018 (Arnaud)] Specification of mempool,
description of parameter, various accuracy improvement, appendix
\item[Draft 7, May 31st, 2018 (Arnaud)] Specification of block
issuance, specification of secret sharing
\item[Draft 8, Jun 01, 2018 (Nicholas)] Editing
\end{description}
\section{Introduction}
\label{sec:introduction}
This document describes the rules underpinning the blockchain data
structure of Cardano's settlement layer. These rules are described
independently of any network or communication mechanism: it is assumed
that some mechanism provides us with, \emph{e.g.}, blocks, and that
our task is to assume that they are accepted or not. Notably, we make
no distinction between rejecting a block and storing it for later use.
A direct consequence of ignoring the communication mechanisms, is that
we do not have to serialise data, hence data is represented in
abstract syntax, with no reference to a binary representation.
As a further simplification, we ignore any unknown data, unparsed
parameters, and versioning issues. This document specifies the system
as it is.\improvement{We may want to add something about protocol
updates, though.}
\section{Terminology \& notations}
\label{sec:notations}
\begin{description}
\item[Lists] Given a set $A$, we write $\lists{A}$ for the set of lists of
elements of $A$, and $\nelists{A}$ for the set of non-empty lists of elements
of $A$. For an element $a∈A$ we write simply $a$ for the singleton list. For
two lists $l,r∈\lists{A}$, we write $l,r$ for their concatenation. We write
$\emptylist$ for the empty list. For a list $l∈\lists{A}$, we write
$\length{l}$ for its length. We write $\pos{i}{l}$ for the $i$-th element of
the list (the head of the list is $\pos{1}{l}$). We sometimes abuse notation
and write $x∈l$ for $l = l',x,l''$.
\item[Support] Let $f$ be a function $f∈X⟶R$ where $R$ is a
commutative monoid (typically the additive monoid of $ℕ$, $ℤ$, $ℚ$,
$ℝ$, …), the \emph{support} of $f$ is $\{ x∈X | f(x)≠0 \}$. We say
that $f$ has finite support, or that $f$ is a function with finite
support, if the support of $f$ is a finite set. If $f$ is a finite
support function, we write $\supportsize{f} ∈ ℕ$ for the cardinal of
the support of $f$.
A notable property of finite-support function, is that they can be
summed: $∑_{x∈X}f(x)$ is well-defined. Indeed, it suffices to sum
over the the (finite!) support of $f$, which, as a finite sum, is
defined.
Additionally, for $f ∈ X ⟶ R$ a finitely supported function and
$g ∈ X -> Y$ an arbitrary function, there is a function
$\extension{g}{f} ∈ Y ⟶ R$, called the extension of $f$ along $g$,
defined as
$$
\extension{g}{f}(y) = ∑_{g(x)=y} f(x)
$$
Note that $\extension{g}{f}$ is a total function even is $g$ is partial
(see the definition of partial functions below).
\begin{implementationhint}
Finite support function are typically implemented as finite maps
(as in Haskell's \verb+Data.Map+ module), where we then interpret
absent bindings as mapping to $0$ (\emph{e.g.} using
\verb+Map.findWithDefault 0+). There are subtleties if we want to
test equality as natively, such data structure distinguishes
bindings to $0$ and absence of bindings. One way to solve this is
to remove any binding to $0$ from the map.
\end{implementationhint}
\item[Partial functions] A partial function $f$ from $A$ to $B$ is a
pair of a subset $U∈\powerset{A}$, called the \emph{domain} of $f$,
and a function $U⟶B$. The set of partial functions from $A$ to $B$
is written $A ⇀ B$. We write $f(a)$ for the image of $a∈U$.
We write $f⊆g$, for partial functions $f$ and $g$ with respective domains $U$
and $V$, if $U ⊆ V$ and $∀a∈U. f(a)=g(a)$. When $f⊆g$, we write
$g⧵f$ for the partial function with support $V⧵U $ defined as:
$$
g⧵f(a) = g(a)
$$
For two partial functions $f$ and $g$ with respective domains $U$
and $V$, such that $∀a∈U∩V. f(a)=g(a)$, we write $f⊎g$ for the partial function
of domain $U∪V$ defined as:
$$
f⊎g(a) = \left\{
\begin{array}{ll}
f(a) & \mbox{if }a∈U\\
g(a) & \mbox{if }a∈V
\end{array}
\right.
$$
Note that if $U∩V=∅$, the condition $∀a∈U∩V. f(a)=g(a)$ holds
vacuously, hence $f⊎g$ is defined.\unsure{Maybe a better symbol for
this ``gluing'' union.}
We say that a partial function has finite domain if its domain is
a finite subset.
\begin{implementationhint}
A partial function $A⇀B$ can be implemented as a function
\verb+A -> Maybe B+, provided that its domain is decidable. Mostly we are
interested in finite domain partial function which are faithfully
represented by finite maps (in the sense of \verb+Data.Map+). The $f⊎g$
gluing union can be implemented using \verb+Data.Map.Merge.mergeA+.
\end{implementationhint}
\item[Remainder] For any $a∈ℤ$ and $b∈ℕ$, let us write $\rem{a}{b}$
for the unique $0⩽r<b$ such that $a=qb+r$.
\item[Projection] For a cartesian product $X=X_1×…× X_n$ with element $x =
(x_1, \dots, x_n)$, we define the \textit{projection onto the $i^{th}$ component}
$\pi_i∈X⟶X_i$ as \[\pi_i(x)=x_i,\] for all $i \leq n$.
\end{description}
\section{Definitions}
\label{sec:definitions}
\begin{description}
\item[System of identifiers] A set $A$ is said to \emph{have
identifiers} if there is a set, written $\idsof{A}$ and an
injective function $\id ∈ A ⟶ \idsof{A}$.
When an item $a∈A$ such that $\id(a) = h$ is clear from the context,
we will often identify $a$ and $h$.
\begin{implementationhint}
In implementations, identifiers are typically realised by
cryptographic hash functions, which are injective for all intents
and purposes.
\end{implementationhint}
\item[Agent id] We assume a set $\agentids$ of identifiers
representing the agents interacting on the blockchain. Furthermore
$\agentids$ is assumed to come with a total order, which we write as
$⩽$.
\begin{implementationhint}
In a concrete implementation agent ids would be public
cryptographic keys and signatures, depending on how what the id is
used for. In an executable specification, agent ids can be
anything which uniquely identifies an agent; let's call it an
\emph{abstract} agent id. When translating from an executable
specification to concrete blocks, we need to maintain a mapping of
abstract agent ids to public-private key pairs, so that we can
sign what needs to be signed.
\end{implementationhint}
\begin{currentvalue}
In Cardano, the total order of $\agentids$ is the lexicographic
ordering on the public keys.
\end{currentvalue}\unsure{We are actually not completely
sure about this. This is tracked by
\href{https://iohk.myjetbrains.com/youtrack/issue/CDEC-163}{CDEC-163}.}
\item[Stake distribution] A \emph{stake distribution} is a function
$d ∈ \agentids ⟶ ℕ$ with finite support. We write
$\stakedistributions$ for the set of stake distributions.
\item[Slot] An integer.
\item[Seeds] We assume a commutative monoid $\seeds$ of \emph{seeds}. The monoid
operations are written multiplicatively.
\item[Stake repartition] A stake repartition is a function
$r ∈ \stakerepartitions ⊆ \agentids ⟶ \mathbb{Q}$ with finite
support, and such that $r(a) ⩾ 0$ for all $a$. And such that
$∑_{a∈\agentids} r(a) = 1$.
Repartition are used as part of transaction output to allocate stake
to parties which are not necessarily the recipient of the
output. Agent $a$ will receive stake in proportion $r(a)$ (with
subtleties due to rounding, see
Section~\ref{sec:derived-functions}).
\item[Transaction] Transactions have a system of identifiers
$\txids$.
A transaction $t∈\txs$ consists of
\begin{record}
\item[Inputs] A non-empty list of pairs in
$\nelists{(\txids × ℕ)}$.
An input $in = (tx, ix) ∈ \txids × ℕ$ should be read as a pointer to an (expectedly unspent)
output, addressed by the transaction $tx$ in which it was created, and
its index $ix$ in the list of outputs of $tx$. We write
\begin{itemize}
\item $\intrans{in} = tx$
\item $\inindex{in} = ix$
\end{itemize}
\item[Outputs] A non-empty list of triples in
$\nelists{(\agentids × ℕ × \stakerepartitions)}$.\improvement{This
only embodies pay-to-public-key schemes. For pay-to-script and
such, we will need further refinements.}
For an output $out = (id, q, r)$, we write
\begin{itemize}
\item $\recipient{out} = id$
\item $\amount{out} = q$
\item $\repartition{out} = r$
\end{itemize}
\item[Witnesses] A non-empty list $w∈\nelists{\agentids}$ of agent
ids. In an implementation these ids would be realised by
cryptographic signatures.
\end{record}
\item[Delegation graph] A delegation graph is a function $g ∈
\agentids ⟶ \agentids$. The initial delegation graph is defined as
the identitity function $\initialdelegation(a) = a$.
Given a delegation graph $g$, we write $\transitivefix{g}$ for the
partial function defined as
$$
\transitivefix{g}(a)=a' \iff ∃n. g^n(a) = a'∧ g(a') = a'
$$
\item[Block] Blocks have a system of identifier $\blockids$. There is
a distinguished $b_0∈ \blockids$, called the genesis identifier,
which is not in the image of $\id∈ \blocks ⟶ \blockids$.
Block come in two flavours \emph{regular blocks} and \emph{epoch
boundary blocks}, defined below.
\item[Regular block]
A regular block $b∈\rblocks ⊆ \blocks$
consists of
\begin{record}
\item[predecessor] A block identifier
\item[slot number] The slot at which the block has been issued
\item[issuer] The identifier of the agent who issued this block. In
an implementation, this would be realised by a cryptographic
signature.
\item[transactions] A list of transactions
\item[delegation certificates] A list of pairs in
$\lists{(\agentids×\agentids)}$. For a delegation certificate
$c = (D,d)∈\agentids×\agentids$, we write
\begin{itemize}
\item $\delegator{c}=D$
\item $\delegatee{c}=d$
\end{itemize}
\begin{implementationhint}
In a concrete implementation, these certificates would be
cryptographically signed by $D$, to ensure that $D$ is indeed
authorising $d$ to sign blocks for them.
\end{implementationhint}
\item[seed computation] Any of the following
\begin{description}
\item[Nothing] An element of the singleton type $\{⋆\}$.
\item[Commitment] A finite-domain partial function $\agentids⇀\seeds×\seeds$.
\begin{implementationhint}
The idea here is that the first seed is the commitment, in the
form of a partial function from agent id to encrypted shares
(in the sense of secret sharing), while the second message is
a proof that the shares are correct.
In this specification, we intend the two messages to be equal,
but this would be replaced, in the implementation, by the
statement that the proof validates the shares.
\end{implementationhint}
\item[Opening] A finite-domain partial function $\agentids⇀\seeds$.
\item[Recovery] A finitely supported function
$r∈\agentids→\agentids⇀\seeds$, such that for all $a$ in the
domain, $r(a)$ has finite domain (partial functions are a commutative monoid
under $⊎$. This monoid is actually partial, but we will ensure
that it is only used when defined).
\begin{implementationhint}
We want to understand $r(a)(a')$ as the decryption (by agent $a$) of the
share created by agent $a'$ and sent to agent $a$. So $r(a)$ is the set
of all the shares that $a$ decrypted.
In the specification, we, again, implement the decrypted
shares as the whole, plain text, seed.
\end{implementationhint}
\end{description}
\end{record}
\item[Epoch boundary blocks] An epoch boundary block
$b∈\bblocks⊆\blocks$ consists in
\begin{record}
\item[predecessor] A block identifier
\item[slot number] The slot at which the boundary takes place
\end{record}
\begin{implementationhint}
In Cardano, boundary blocks contain a lot more information but (up
to the injectivity-of-hashes hypothesis) this information is
determined by the above. It will affect however the actual hash of
the epoch boundary block, it is therefore infeasible to concretise
an epoch boundary block without knowing the blockchain up to the
predecessor. The concretisation of epoch boundary block is
therefore not a pure function.
\end{implementationhint}
\end{description}
\section{Parameters}
\label{sec:parameters}
\subsection{Validation parameters}
\label{sec:validation-parameters}
This section lists parameters of the validation rules. The concrete
instantiation of most of these parameters in Cardano is specified in
Section~\ref{sec:params}. They are kept abstract in the validation
rules to highlight that the rules can be stated independently of their
concrete value, which simplifies the specification.
\begin{description}
\item[Slot leader] We assume a function
$\slotleader{⋅}{⋅}{⋅} ∈ \stakedistributions×\seeds×ℕ ⟶ \agentids$,
which, given a stake distribution and a source of randomness, maps
each subsequent slot to an agent id. This function is defined in
Section~\ref{sec:slot-leader}.
\item[Current slot] The current slot is a parameter of the validation
rules desribed in this document (\emph{i.e.} it doesn't make sense
in general to ask whether, say, a chain is valid, only that it is
valid \emph{at the current slot}).
This parameter is not instantiated in Section~\ref{sec:params}
because it actually varies. In an implementation, the current slot
would be a function of the wall-clock time. The role of the current
slot is to prevent attacks where a malicious slot leader at slot
$i+1$ would try to issue a block without acknowledging the block
issued by the slot leader at slot $i$.
\item[Height] We assume a height function
$\height{⋅} ∈ \lists{\blocks} ⟶ ℕ$. It is usually necessary, for the
sake of good behaviour of the system to assume that
$\height{b₁,…,b_n} < \height{b₁,…,b_n,b_{n+1}}$, though it is not
necessary for the specification itself. A typical such function is
the length of the list, though more refined criterion are usually
chosen. This function is defined in Section~\ref{sec:height}.
\item[Chain quality] We assume a function $\quality{⋅} ∈ ℕ ⟶ ℕ$, which
maps a number of blocks into a number of blocks. The meaning of the
chain qualitity function is that, assuming that a block at depth $k$
will never be rolled back (see Section~\ref{sec:conf-param}), then
the chain will never roll back more than $\quality{k}$ slots. This
function is defined in Section~\ref{sec:chain-quality}.\unsure{I put
the chain quality here because it is at a rather prominent place in
the code, it is never directly used in the specification, rather the
phases below are. So we may skip this and only introduce chain
quality in Section~\ref{sec:params}.}
\item[Secret-sharing phases] We assume three subsets of $ℕ$
$$
\commitphase, \openphase, \recoveryphase ∈ \powerset{ℕ}
$$
These are intended as subsets of the slots within an epoch. They are
expected to be intervals, in that for all $a<b<c$ such that
$a∈\commitphase$ and $c∈\commitphase$, we have $b∈\commitphase$
(respectively $\openphase$, $\recoveryphase$). It is also expected
that for $x ∈ \commitphase$, $y∈\openphase$, and $z∈\recoveryphase$,
we have $x<y<z$. These subsets are defined in
Section~\ref{sec:vss-phases}.
\improvement{This paragraph is pretty horrible to read, just because the
subscripts are so long.}
\end{description}
\subsection{Configuration parameters}
\label{sec:conf-param}
This section document parameters of nodes, which are set via
configuration arguments.
\begin{description}
\item[Maximum mempool size] We assume a number $\maxmempoolsize ∈ ℕ$(
representing the maximum allowed size for a mempool (see
Section~\ref{sec:entering-mempool}).
\begin{currentvalue}
At time of writing, in the implementation of Cardano, the maximum
mempool size is 200.
\end{currentvalue}
\end{description}
\subsection{Chain parameters}
\label{sec:chain-parameters}
This section lists the parameters of a Cardano block chain. They are
specified in the initial state and can be further modified by updates.
\begin{description}
\item[k] This entire specification is parameterised by a natural
number $k$. It comes from the Ouroboros paper: it is the depth after
which a block is considered stable, and will never rollback under
any circumstance.
\begin{currentvalue}
In Cardano, $k=2160$
\end{currentvalue}
\item[Initial stake distribution] We assume an \emph{initial stake
distribution} $\initialdistribution ∈ \stakedistributions$.
Addresses in the support of the initial stake distribution are
referred to as \emph{redeem address}. These address can't receive
new coins in the chain.\info{This is not entirely accurate. In the
Cardano data types there are Redeem address which are not in the
support of the initial distribution, nothing can be done with
them. It may be more accurate to split the type of agent ids in
two disjoint subsets.}
\item[Initial seed] A distinguished seed $\initialseed ∈ \seeds$.
\item[Minimum fee] We assume a function $\minimumfee{⋅} ∈ \txs ⟶ ℕ$,
called the minimum fee function.\info{It's not clear that the
minimum fee, as is currently implemented, is indeed a function of
the (abstract represention of) the transaction. This may create
mismatches in tests.}
\item[Initial transactions] We assume a finite subset $\txinit ⊆ \txs$
of transactions. The intent behind $\txinit$ is that these
transactions are present ``in the initial state''. They represent
the initial assets in the system. Their inputs are
meaningless.\improvement{We may want to compute the initial
distribution based on $\txinit$.}
\item[Epoch] We assume a pair or functions $\epoch{⋅}∈ℕ⟶ℕ$ and
$\epochslot{⋅}∈ℕ⟶ℕ$, the \emph{epoch decomposition} of a slot, such
that~--~writing $(\epoch{⋅}, \epochslot{⋅})$ for the function, in
$ℕ⟶ℕ×ℕ$, which maps a slot $s$ to
$(\epoch{s}, \epochslot{s})$~--~$(\epoch{⋅}, \epochslot{⋅})$ is a
strictly increasing function, from the natural ordering of $ℕ$ to
the lexicographic product of the natural ordering of $ℕ$ with
itself.\improvement{We may want to additionally impose that the
inverse image of $e×ℕ$ is downward closed.}\improvement{Layout is
broken in this paragraph.}\improvement{It will probably be clearer
to give a name to $(\epoch{⋅}, \epochslot{⋅})$ rather than
referring to it symbolically. And define the two projection in
terms of this function, like is done in the rest of the text,
rather than the other way around.}
\begin{currentvalue}
For reference, $\epoch{s}$ and $\epochslot{s}$, are defined, in
the bootstrap era of Cardano, of as the unique numbers such that
$s=\epoch{s}\cdot 10k+\epochslot{s}$ and $0⩽ \epochslot{s} < 10k$.
\end{currentvalue}
\item[Bootstrap stakeholders] We assume a finite set
$\bootstrapstakeholders ⊆ \agentids$. The bootstrap stakeholders receive all the
stake during the bootstrap era.\unsure{For the sake of simplicity, I
assume, for the time being, that the bootstrap stakeholders all
get the same share of stake of each output. This is not necessary
in cardano, but it is the case in practice. We can refine later if
we so wish}
We assume a stake repartition
$\bootstraprepartition ∈ \stakerepartitions$ which allocates stake
to each bootstrap stakeholder in equal proportion. That is
$$
\bootstraprepartition(a) = \left\{
\begin{array}{cl}
\displaystyle{\frac{1}{\supportsize{r}}}& \mbox{if $a∈\bootstrapstakeholders$}\\
0 & \mbox{otherwise}
\end{array}\right.
$$
We will also assume a function $\selectrichman{⋅} ∈ ℕ ⟶ \bootstrapstakeholders$
which selects one of the bootstrap stakeholder based on the value of an unspent
output. In a concrete implementation this function needs to have
good randomness properties.
\end{description}
\section{Extending a chain}
\label{sec:adding-block}
This section specifies whether a block can extend a given chain. That
is we have one version of history (forks are handled in
Section~\ref{sec:chain-selection}), and we are receiving a block. If
the block passes the validation rules of this section, then the
history is one block longer.
A sequence $b₁,…,b_n$ is said to be a \emph{valid chain} if
$b₁,…,b_{n-1}$ is a valid chain,
and $b_n$ is a \emph{valid extension} of $b₁,…,b_{n-1}$.
\subsection{Boundary block}
\label{sec:boundary-block}
A boundary block $b∈\bblocks$ is a valid extension of a valid chain
$b_1,…,b_n$ if all of the following hold
\begin{description}
\item[Predecessor] The predecessor of $b$ is $b_n$ or, if $n=0$, the predecessor
of $b$ is the genesis identifier $b₀$.
\item[Not future slot] The slot number is no larger than the current
slot.
\item[Not past slot] The slot number of $b$ is larger than the slot.
number of $b_n$
\item[At boundary] Let $s$ be the slot number of $b$, $\epochslot{s} =
0$ (note that it implies, in particular, that $\epoch{b_n}<\epoch{s}$).
\end{description}
\subsection{Regular block}
\label{sec:regular-blocks}
A regular block $b∈\rblocks$ is a valid extension of a valid chain
$b_1,…,b_n$ if all of the following hold
\begin{description}
\item[Predecessor] The predecessor of $b$ is $b_n$ or, if $n=0$, the predecessor
of $b$ is the genesis identifier $b₀$.
\item[Not future slot] The slot number is no larger than the current
slot.
\item[Not past slot] The slot number of $b$ is larger than the slot.
number of $b_n$
\item[No boundary-crossing] Let $s_b$ be the slot number of $b$ and
$s_n$ be the slot number of $b_n$, then $\epoch{s_b}=\epoch{s_n}$
(this condition imposes that epochs be started by epoch boundary blocks).
\item[Issuer] Let $i$ be the issuer of $b$, and let $l$ be the slot
leader at the slot of $b$:
$$
l = \slotleader{\epochdistribution{b_1,…,b_n}}{\epochseed{b_1,…,b_n}}{\epochslot{slot}}
$$
See Section~\ref{sec:derived-functions} for the definitions of
$\epochdistribution{⋅}$ and $\epochseed{⋅}$.
\improvement{this doesn't read too well, improve.}
Then, $i$ must be transitively authorised by $l$ in that:
$$
i = \transitivefix{\delegations{b₁,…,b_n}}(l)
$$
Note that, by definition, there is (at most) a single agent
authorised by $l$ (it may be $l$ itself, if no delegation certificate
has been issued). See Section~\ref{sec:derived-functions} for the
definition of $\delegations{⋅}$.
\item[Transactions] Each transaction in the block's transactions is
validated according to the following rules.
\begin{description}
\item[Stateless]\hfill
\begin{description}
\item[Valid outputs] All the outputs of the transaction must have
amount $a > 0$.
\item[No double-spending] The list of inputs contains no duplicate.
\item[No redeem output] For every $out∈\outputs{τ}$,
$\initialdistribution(\recipient{out})=0$.
\end{description}
\item[Stateful] Stateful transaction validation rules for a transaction $τ$
are parametrised by a list of transactions $τ_1,…,τ_m$ which we will abridge
as $\overline{τ}$.
Given a valid chain $b₁,…,b_n$ and $b$, the block being validated, such
that $\transactions{b}=t₁,…,t_k$. Then, for the purpose of
stateful validation of the transaction $t_i$, we set
$\overline{τ} = \transactions{b₁},…,\transactions{b_n},t₁,…,t_{i-1}$.
\begin{description}
\item[Unspent inputs] Each input of the transaction $τ$ is
unspent. That is for each $i ∈ \inputs{τ}$
\begin{itemize}
\item $\intrans{i}∈\overline{τ}$ or $\intrans{i} ∈ \txinit$
\item $\inindex{i} ⩽ \length{\outputs{\intrans{i}}}$
\item for each $t ∈ \overline{τ}$, $i ∉ \inputs{t}$.
\end{itemize}
In these conditions, we can extend the function $\recipient{⋅}$
and $\amount{⋅}$, as well as $\repartition{⋅}$, on the $i$ as
\begin{itemize}
\item $\recipient{i} = \recipient{\pos{\inindex{i}}{\outputs{\intrans{i}}}}$
\item $\amount{i} = \amount{\pos{\inindex{i}}{\outputs{\intrans{i}}}}$
\item $\repartition{i} = \repartition{\pos{\inindex{i}}{\outputs{\intrans{i}}}}$
\end{itemize}
\info{Remark: in all this rule, we use implicitly
$\overline{τ}$, to cast $\intrans{i}∈\txids$ to an actual
transaction. }
\item[Conservation of value] The total amount of outputs must not exceed
the total amount of inputs. A minimum fee must be paid.
$$
\minimumfee{τ} + ∑_{o∈\outputs{τ}} \amount{o}⩽ ∑_{i∈\inputs{τ}} \amount{i}
$$
If for every $i∈\inputs{τ}$,
$\initialdistribution{\recipient{i}}>0$, that is all the inputs
are from redeem addresses, then no fee need be paid, and the
rules become:
$$
∑_{o∈\outputs{τ}} \amount{o}⩽ ∑_{i∈\inputs{τ}} \amount{i}
$$
\item[Authorised] The list of witnesses has the same length as the
list of inputs
$$
\length{\witnesses{τ}} = \length{\inputs{τ}}
$$
and for each input, the corresponding witness is the agent id of
the input
$$
∀ 0<k⩽\length{\inputs{τ}}. \recipient{\pos{k}{\inputs{τ}}} =
\pos{k}{\witnesses{τ}}
$$
\end{description}
\item[Bootstrap era] The following conditions must all pass to
validate transactions in the bootstrap era. This specification only
describes the behaviour during the bootstrap era, hence the
following conditions are checked unconditionally.
\begin{description}
\item[Bootstrap stake delegation] For every output $o∈\outputs{τ}$, the
stake is delegated in to the bootstrap stakeholders:
$\repartition{o} = \bootstraprepartition$.
\begin{treacherous}
This is slightly imprecise because the bootstrap repartition
has two representations in Cardano's blockchain: it has a
name (a data constructor), but it can also be represented by a
explicit map. Only the former is actually permitted
\end{treacherous}
\end{description}
\end{description}
\item[Delegation certificates] Let
$\overline{c}=\delegationcertificates{b}$ be the list of delegation
certificates of $b$. Then for any two $c₁,c₂∈\overline{c}$, it must
hold that $\delegator{c₁}≠\delegator{c₂}$.
Note that this prevents any agent which has issued a delegation certificate to
another party from issuing any block: they \emph{must} be signed by the
delegatee (or, transitively, by the agent authorised to sign instead of the
delegatee). That is, until the agent issues a new delegation certificate to
itself, which, in effect, revokes any previous delegation certificate. See
also the definition of $\transitivefix{g}$ in Section~\ref{sec:definitions}.
\item[Seed computation] This rule divides into different cases, depending on the
content of the seed computation field of the block $b$ (the functions
$\richmen{⋅,⋅}$, $\epochcommitments{⋅}$, $\epochopens{⋅}$, and
$\epochrecoveries{⋅}$ are defined in Section~\ref{sec:derived-functions}).
\begin{description}
\item[Nothing] If there is no message, then no further rule must be
enforced.
\item[Commitment] If there is a commitment message $c ∈
\agentids⇀\seeds×\seeds$ then, and calling its domain $U$,
\begin{description}
\item[Commitment phase] Let $s$ be the current slot, then we must
have $\epochslot{s}∈\commitphase$.
\item[Richmen] We must have
$U⊆\richmen{\delegations{b_1,…,b_n}}{\currentdistribution{b_1,…,b_n}}$.
\item[Valid] For every $a∈U$, let $(m,p) = c(a)$, we must have
$m=p$.
\item[Fresh] Let $V$ be the domain of $\epochcommitments{b_1,…,b_n}$,
we must have $U∩V=∅$.
\end{description}
\item[Open] If there is an opening message $o ∈
\agentids⇀\seeds$ then, calling its domain $U$,
\begin{description}
\item[Opening phase] Let $s$ be the current slot, then we must
have $\epochslot{s}∈\openphase$.
\item[Valid] We must have that $o ⊆ π_1 ∘
\epochcommitments{b_1,…,b_n}$.
\item[Fresh] Let $V$ be the domain of $\epochopens{b_1,…,b_n}$,
we must have $U∩V=∅$.
\end{description}
\item[Recovery] If there is a recovery message $r ∈
\agentids⟶\agentids⇀\seeds$ then, calling its support $U$,
\begin{description}
\item[Recovery phase] Let $s$ be the current slot, then we must
have $\epochslot{s}∈\recoveryphase$.
\item[Valid] For every $a∈U$, we must have that $r(a) = (π_1 ∘ \epochcommitments{b_1,…,b_n})⧵\epochopens{b_1,…,b_n}$.
\item[Fresh] Let $V$ be the domain of $\epochrecoveries{b_1,…,b_n}$,
we must have $U∩V=∅$.
\end{description}
\end{description}
\end{description}
\section{Derived functions}
\label{sec:derived-functions}
This section defines functions which are only defined on valid chains,
per the definition of Section~\ref{sec:adding-block}. The functions
defined in this sections are also used in
Section~\ref{sec:adding-block}. Therefore this section and
Section~\ref{sec:adding-block} are mutually recursive.
Functions which project fields from regular blocks are extended to
epoch boundary blocks by returning the natural trivial value. For
instance, for an epoch boundary block $b$,
$\transactions{b}=\emptylist$
\begin{description}
\item[Last epoch index] For a valid chain, we write
$$
\epochindex{b_1,…,b_n} = \max_{\mathclap{\substack{
0<i<n\\
\epoch{b_i} < \epoch{b_n}
}}} i
$$
for the index in the chain (not the slot) of the last block of the
previous epoch (the current epoch is taken to be the epoch of $b_n$,
the tip of the chain).
If there is no complete epoch (in particular if the chain is empty)
we set $\epochindex{b_1,…,b_n} = 0$.
\item[Stake distribution] Let us define
$\currentdistribution{τ₁,…,τ_n}$ by induction, for a valid sequence
of transactions\improvement{Valid sequence of transaction hasn't
properly been defined, but it's implicit in the definition above,
it would maybe be worth making more precise.}:
\begin{itemize}
\item $\currentdistribution{\emptylist} = \initialdistribution$
\item Inductively, and writing
\begin{itemize}
\item $⌊x⌋$ for the integral part (aka floor) of $x$; \emph{i.e.}
$⌊x⌋$ is the unique integer such that $⌊x⌋ ⩽ x < ⌊x⌋+1$
\item $\kronecker{⋅}{⋅}$ for
\href{https://en.wikipedia.org/wiki/Kronecker_delta}{Kronecker's
delta} function:
$$
\kronecker{i}{j} = \left\{
\begin{array}{ll}
1 & \mbox{if $i=j$}\\
0 & \mbox{otherwise}
\end{array}
\right.
$$
In particular, $\kronecker{i}{j}q = q$ if $i=j$ and $0$
otherwise. Kronecker's delta is used to select summands: it is
the arithmetician's \verb+ifThenElse+ combinator.
\item $\stakeof{o}{a} = \repartition{o}(a)\cdot\amount{o} ∈ \mathbb{Q}$
\item For inputs of $τ_{n+1}$, we extend $\stakeof{⋅}{⋅}$ to
inputs using the validity hypothesis to define $\repartition{i}$ and $\amount{i}$
\end{itemize}
We define
\newcommand{\stakerepartitionformula}[4]{∑_{#2∈#3} \left(
\begin{aligned}
&⌊\stakeof{#2}{#1}⌋\\
&\qquad+\\
&\raisebox{0pt}[0pt][3.5ex]{$\displaystyle{\kronecker{#1}{\selectrichman{\amount{#2}}}\left(\amount{#2} - ∑_{#4∈\agentids}
⌊\stakeof{#2}{#4}⌋\right)}$}
\end{aligned}\right)}
\begin{align*}
\makebox[1em][l]{$\currentdistribution{τ₁,…,τ_n, τ_{n+1}}(a) =$}\\
& \phantom{=} \currentdistribution{τ₁,…τ_n}(a)\\
& - \stakerepartitionformula{a}{i}{\inputs{τ_{n+1}}}{b}\\
& + \stakerepartitionformula{a}{o}{\outputs{τ_{n+1}}}{b}
\end{align*}
That is, the contribution of unspent output $o$ to agent $a$ is
the proportion of the value of $o$ specified by the stake
repartition of $o$ rounded \emph{down} to the nearest integer. The
remaining unallocated stake goes to the bootstrap stakeholder
specified by the $\selectrichman{⋅}$ function, applied to the
total value of $o$.
\begin{treacherous}
The treatment of remainder as specified here is only valid for
the bootstrap era. Outside of the bootstrap era, the remainder
may be different, hence we may have to calculate remainder
differently for transactions of the bootstrap eras, and
transaction posterior to the bootstrap eras. See
Appendix~\ref{sec:delegation-shelley}.
\end{treacherous}
\end{itemize}
We can then extend $\currentdistribution{⋅}$ on valid chains by defining
$$
\currentdistribution{b₁,…,b_n} = \currentdistribution{\transactions{b₁},…,\transactions{b_n}}
$$
Finally we define
$$
\epochdistribution{b₁,…,b_n} = \currentdistribution{b₁,…,b_{\epochindex{b_1,…,b_n}}}
$$
\item[Richmen] For a delegation graph $g$ and a stake distribution
$d∈\stakedistributions$, note that $\extension{g}{d}$ is the stake
distribution corresponding to $d$ except that all the stake of an
agent $a$ has been (transitively) passed to its delegatee.
\newcommand{\threshold}[1]{\mathsf{threshold}(#1)}
We define
$$
\richmen{g}{d} = \{ a ∈ \agentids~|~\extension{g}{d}(a) ⩾
\threshold{∑_{b∈\agentids} d(b)} \}
$$
\improvement{TODO: declare the threshold function as a parameter.}
\item[Seed computation]\hfill
\begin{itemize}
\item Let $c_1,…,c_k$ be the list of partial functions
$\agentids⇀\seeds×\seeds$ extracted from the seed computation
field of the blocks in $b_{\epochindex{b_1,…,b_n}+1},…,b_n$ which
are commitment messages, then define
$$
\epochcommitments{b_1,…,b_n} = c_1 ⊎ … ⊎ c_k
$$
\item Let $o_1,…,o_k$ be the list of partial functions
$\agentids⇀\seeds$ extracted from the seed computation
field of the blocks in $b_{\epochindex{b_1,…,b_n}+1},…,b_n$ which
are opening messages, then define
$$
\epochopens{b_1,…,b_n} = o_1 ⊎ … ⊎ o_k
$$
\item Let $r_1,…,r_k$ be the list of partial functions
$\agentids⇀\agentids⇀\seeds$ extracted from the seed computation
field of the blocks in $b_{\epochindex{b_1,…,b_n}+1},…,b_n$ which
are recovery messages, then define
$$
\epochrecoveries{b_1,…,b_n} = r_1 ⊎ … ⊎ r_k
$$
\end{itemize}
\item[Seed] Let $U$ be the domain of the partial function
$$
r = ⨄_{a∈\agentids}\epochrecoveries{b_1,…,b_{\epochindex{b_1,…,b_n}}}(a)
$$
and $V$ be the domain of the partial function $\epochopens{b_1,…,b_{\epochindex{b_1,…,b_n}}}$.
Then define
$$
\left\{
\begin{array}{lcll}
\epochseed{b_1,…,b_n}&=& \initialseed & \mbox{if $\epochindex{b_1,…,b_n}=0$}\\
\epochseed{b_1,…,b_n}&=&∏_{a∈V}\epochopens{b_1,…,b_{\epochindex{b_1,…,b_n}}}(a) & \mbox{otherwise}\\
&×&∏_{a∈U}r(a)
\end{array}
\right.
$$
\item[Delegation graph] Let us define $\delegations{c₁,…,c_n}$, for a
list of delegation certificates, by induction:
\begin{itemize}
\item $\delegations{\emptylist} = \initialdelegation$
\item $$
\delegations{c₁,…,c_n,(D,d)}(a) = \left\{
\begin{array}{ll}
d & \mbox{if $a=D$}\\
\delegations{c₁,…,c_n}(a) & \mbox{otherwise}
\end{array}\right.
$$
\end{itemize}
We can extend $\delegations{⋅}$ on valid chain by defining
$$
\delegations{b₁,…,b_n} = \delegations{\delegationcertificates{b₁},…,\delegationcertificates{b₁}}
$$
\end{description}