forked from IntersectMBO/cardano-ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blockchain-spec.tex
1486 lines (1341 loc) · 47 KB
/
blockchain-spec.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
\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{array}
\usepackage{extarrows}
\usepackage{float}
\usepackage[margin=2.5cm]{geometry}
\usepackage[unicode=true,pdftex,pdfa]{hyperref}
\usepackage[capitalise,noabbrev,nameinlink]{cleveref}
\usepackage[utf8]{inputenc}
\usepackage{latexsym}
\usepackage{listings}
\usepackage{mathpazo} % nice fonts
\usepackage{mathtools}
\usepackage{microtype}
\usepackage[colon]{natbib}
\usepackage[toc,page]{appendix}
%%
%% Package `semantic` can be used for writing inference rules.
%%
\usepackage{semantic}
\usepackage{slashed}
\usepackage{stmaryrd}
\usepackage[colorinlistoftodos,prependcaption,textsize=tiny]{todonotes}
\hypersetup{
pdftitle={Specification of the Blockchain Layer},
breaklinks=true,
bookmarks=true,
colorlinks=false,
linkcolor={blue},
citecolor={blue},
urlcolor={blue},
linkbordercolor={white},
citebordercolor={white},
urlbordercolor={white}
}
\floatstyle{boxed}
\restylefloat{figure}
%% Setup for the semantic package
\setpremisesspace{20pt}
\DeclareMathOperator{\dom}{dom}
\DeclareMathOperator{\range}{range}
%%
\newcommand{\powerset}[1]{\mathbb{P}~#1}
\newcommand\Set[2]{\left\{\,#1\mid#2\,\right\}}
\newcommand{\restrictdom}{\lhd}
\newcommand{\subtractdom}{\mathbin{\slashed{\restrictdom}}}
\newcommand{\restrictrange}{\rhd}
\newcommand{\union}{\cup}
\newcommand{\unionoverride}{\mathbin{\underrightarrow\cup}}
\newcommand{\uniondistinct}{\uplus}
\newcommand{\var}[1]{\mathit{#1}}
\newcommand{\fun}[1]{\mathsf{#1}}
\newcommand{\type}[1]{\mathsf{#1}}
\newcommand{\pp}[1]{\mathsf{#1}}
\newcommand{\size}[1]{\left| #1 \right|}
\newcommand{\trans}[2]{\xlongrightarrow[\textsc{#1}]{#2}}
\newcommand{\stslabel}[1]{\footnotesize{\textsc{#1}}}
\newcommand{\seqof}[1]{#1^{*}}
\newcommand{\serialised}[1]{\llbracket \var{#1} \rrbracket}
\newcommand{\leteq}{\ensuremath{\mathrel{\mathop:}=}}
% Partial and total function aliases
\newcommand{\totalf}{\to}
\newcommand{\partialf}{\mapsto}
%%
%% Types
%%
\newcommand{\Hash}{\type{Hash}} % hashes of various things, including blocks
\newcommand{\Slot}{\type{Slot}}
\newcommand{\SlotCount}{\type{SlotCount}}
\newcommand{\BlockIx}{\type{BlockIx}}
\newcommand{\Block}{\type{Block}}
\newcommand{\DCert}{\type{DCert}}
\newcommand{\Queue}{\type{Q}}
\newcommand{\Tx}{\type{Tx}}
\newcommand{\VKey}{\type{VKey}}
\newcommand{\VKeyGen}{\type{VKey_G}}
\newcommand{\Sig}{\type{Sig}}
\newcommand{\Data}{\type{Data}}
\newcommand{\DelegState}{\type{DIState}}
\newcommand{\ProtParams}{\type{PParams}} % protocol parameters
\newcommand{\ProtPm}{\ensuremath{\type{Ppm}}}
\newcommand{\maxblocksize}{\pp{maxBlockSize}}
\newcommand{\maxheadersize}{\pp{maxHeaderSize}}
\newcommand{\Nothing}{\Diamond}
%%
%% Function and relation names
%%
\newcommand{\bsizename}{bSize}
\newcommand{\bhdrsizename}{bHeaderSize}
\newcommand{\verifyname}{verify}
\newcommand{\isebbname}{bIsEBB}
\newcommand{\bcertsname}{bCerts}
\newcommand{\bhsigname}{bhSig}
\newcommand{\bhissuername}{bhIssuer}
%%
%% Functions and relations
%%
\newcommand{\verify}[3]{\fun{\verifyname} ~ #1 ~ #2 ~ #3}
\newcommand{\bsize}[1]{\fun{\bsizename} ~ #1}
\newcommand{\bhdrsize}[1]{\fun{\bhdrsizename} ~ #1}
\newcommand{\delegation}[2]{\fun{\delegationname} ~ #1 ~ #2}
\newcommand{\signmap}[1]{\fun{\signmapname} ~ #1}
\newcommand{\qrestr}[2]{\fun{\qrestrname} ~ #1 ~ #2}
\newcommand{\trimix}[2]{\fun{\trimixname} ~ #1 ~ #2}
\newcommand{\incixmap}[3]{\fun{\incixmapname} ~ #1 ~ #2 ~ #3}
\newcommand{\hashofblock}[1]{\fun{\hashofblockname} ~ #1}
\newcommand{\blocksizelimit}[2]{\fun{\blocksizelimitname} ~ #1 ~ #2}
\newcommand{\isebb}[1]{\fun{\isebbname} ~ #1}
\newcommand{\bcerts}[1]{\fun{\bcertsname} ~ #1}
\newcommand{\bhsig}[1]{\fun{\bhsigname} ~ #1}
\newcommand{\bhissuer}[1]{\fun{\bhissuername} ~ #1}
\newcommand{\qpop}[1]{\fun{\qpopname} ~ #1}
\newcommand{\qhead}[1]{\fun{\qheadname} ~ #1}
\newcommand{\qpush}[1]{\fun{\qpushname} ~ #1}
% A type alias for a map from a genesis block verification key to a queue of indices
\newcommand{\mapqueue}{\mathcal{Q}}
% comments
\newcommand{\marko}[1]{\todo[size=\small, color=yellow!40, inline]{Marko: #1}}
\newcommand{\transtar}[2]{\xlongrightarrow[\textsc{#1}]{#2}\negthickspace^{*}}
\newtheorem{property}{Property}
\newtheorem{definition}{Definition}
\begin{document}
\title{Specification of the Blockchain Layer}
\author{Marko Dimjašević \\ Nicholas Clarke}
\date{May 2, 2019}
\maketitle
\begin{abstract}
This documents defines inference rules for operations on a blockchain as a
specification of the blockchain layer of Cardano in the Byron release and in
a transition to the Shelley release.
%
In particular, a block validity definition is given, which is accompanied by
small-step operational semantics inference rules.
\end{abstract}
\section*{List of Contributors}
\label{acknowledgements}
Damian Nadales, Yun Lu.
\tableofcontents
\listoffigures
\section{Introduction}
\label{sec:introduction}
The idea behind this document is to formalise what it means for a new block to
be added to the blockchain to be valid.
%
The scope of the document is the Byron release and a transition phase to the
Shelley release of the Cardano blockchain platform.
Unless a new block is valid, it cannot be added to the blockchain and thereby
extend it.
%
This is needed for a system that is subscribed to the blockchain and keeps a
copy of it locally.
%
In particular, this document gives a formalisation that should be
straightforward to implement in a programming language, e.g., in Haskell.
This document is intended to be read in conjunction with \cite{byron_ledger_spec},
which covers the payload carried around in the blockchain. Certain of the
underlying systems and types defined will rely on definitions in that document.
\section{Preliminaries}
\label{sec:preliminaries}
\begin{description}
\item[Powerset] Given a set $\type{X}$, $\powerset{\type{X}}$ is the set of all
the subsets of $X$.
\item[Sequence] Given a set $\type{X}$, $\seqof{\type{X}}$ is a sequence
having elements taken from $\type{X}$.
%
The empty sequence is denoted by $\epsilon$, and given a sequence $\Lambda$,
$\Lambda; x$ is the sequence that results from appending
$x \in \type{X}$ to $\Lambda$.
%
Furthermore, $\epsilon$ is an identity element for sequence joining:
$\epsilon; x = x; \epsilon = x$.
\item[Dropping on sequences] Given a sequence $\Lambda$,
$\Lambda \shortdownarrow n$ is the sequence that is obtained after removing
(dropping) the first $n$ elements from $\Lambda$. If $n \leq 0$ then
$\Lambda \shortdownarrow n = \Lambda$.
\item[Appending with a moving window] Given a sequence $\Lambda$, we define
$$\Lambda ;_w x \leteq (\Lambda; x) \shortdownarrow (\size{\Lambda} + 1 - w)$$
\item[Filtering on sequences] Given a sequence $\Lambda$, and a predicate $p$
on the elements of $\Lambda$, $\fun{filter}~p~\Lambda$ is the sequence that
contains all the elements of $\Lambda$ that satisfy $p$, in the same order
they appear on $\Lambda$.
\item[Option type] An option type in type $A$ is denoted as $A^? = A + \Nothing$. The
$A$ case corresponds to a case when there is a value of type $A$ and the $\Nothing$
case corresponds to a case when there is no value.
\item[Union override] The union override operation is defined in
Figure~\ref{fig:unionoverride}.
%
\begin{figure}
\begin{align*}
\var{K} \restrictdom \var{M}
& = \{ i \mapsto o \mid i \mapsto o \in \var{M}, ~ i \in \var{K} \}
& \text{domain restriction}
\\
\var{K} \subtractdom \var{M}
& = \{ i \mapsto o \mid i \mapsto o \in \var{M}, ~ i \notin \var{K} \}
& \text{domain exclusion}
\\
\var{M} \restrictrange \var{V}
& = \{ i \mapsto o \mid i \mapsto o \in \var{M}, ~ o \in \var{V} \}
& \text{range restriction}
\\
& \unionoverride \in (A \mapsto B) \to (A \mapsto B) \to (A \mapsto B)
& \text{union override}\\
& d_0 \unionoverride d_1 = d_1 \cup (\dom d_1 \subtractdom d_0)
\end{align*}
\caption{Definition of the Union Override Operation}
\label{fig:unionoverride}
\end{figure}
\item[Pattern matching in premises] In the inference-rules premises use
$\var{patt} = \var{exp}$ to pattern-match an expression $\var{exp} $ with a
certain pattern $\var{patt}$. For instance, we use $\Lambda'; x = \Lambda$ to
be able to deconstruct a sequence $\Lambda$ in its last element, and prefix.
If an expression does not match the given pattern, then the premise does not
hold, and the rule cannot trigger.
\item[Maps and partial functions] $A \mapsto B$ denotes a \textbf{partial
function} from $A$ to $B$, which can be seen as a map (dictionary) with
keys in $A$ and values in $B$. Given a map $m \in A \mapsto B$, notation
$a \mapsto b \in m$ is equivalent to $m~ a = b$.
\end{description}
\subsection{Sets}
\label{sec:sets}
There are several standard sets used in the document:
%
\begin{description}
\item[Booleans] The set of booleans is denoted with $\mathbb{B}$ and has two
values, $\mathbb{B} = \{\bot, \top\}$.
\item[Natural numbers] The set of natural numbers is denoted with
$\mathbb{N}$ and defined as $\mathbb{N} = \{0, 1, 2, \dots\}$.
\end{description}
\section{Update interface}
\newcommand{\bupdprop}[1]{\fun{bUpdProp}\ #1}
\newcommand{\bupdvotes}[1]{\fun{bUpdVotes}\ #1}
\newcommand{\bprotver}[1]{\fun{bProtVer}\ #1}
\newcommand{\bendorsment}[1]{\fun{bEndorsment}\ #1}
\newcommand{\UpdatePayload}{\type{UpdatePayload}}
% Imported definitions
\newcommand{\UPIEnv}{\type{UPIEnv}}
\newcommand{\UPIState}{\type{UPIState}}
\newcommand{\UProp}{\type{UProp}}
\newcommand{\Vote}{\ensuremath{\type{Vote}}}
\newcommand{\ProtVer}{\ensuremath{\type{ProtVer}}}
We define a general update interface to abstract over the various update state
transitions which happen when a new block is processed. Figure
\ref{fig:defs:bupi} defines the type of signals used for this system. Figure
\ref{fig:rules:bupi} defines the rules for this system. The two rules handle the
cases where there is or is not an update proposal contained within the block.
\begin{figure}[ht]
\emph{Update interface signals}
\begin{equation*}
\UpdatePayload =
\left(
\begin{array}{r@{~\in~}lr}
\var{mprop} & \UProp^{?} & \text{possible update proposal}\\
\var{votes} & \seqof{\Vote} & \text{votes for update proposals}\\
\var{end} & (\VKey \times \ProtVer) & \text{protocol version endorsment}
\end{array}
\right)
\end{equation*}
\caption{Update interface processing types and functions}
\label{fig:defs:bupi}
\end{figure}
\begin{figure}[ht]
\emph{Update interface processing transitions}
\begin{equation*}
\_ \vdash \var{\_} \trans{bupi}{\_} \var{\_} \subseteq
\powerset (\UPIEnv \times \UPIState \times \UpdatePayload \times \UPIState)
\end{equation*}
\caption{Update interface processing transition-system types}
\label{fig:ts-types:bupi}
\end{figure}
\begin{figure}[ht]
\begin{equation*}
\inference
{ \Gamma \vdash \var{us}
\trans{\hyperlink{byron_ledger_spec_link}{upireg}}{\var{prop}} \var{us'}
\\
\Gamma \vdash \var{us'}
\trans{\hyperlink{byron_ledger_spec_link}{upivotes}}{\var{votes}} \var{us''}
&
\Gamma \vdash \var{us''}
\trans{\hyperlink{byron_ledger_spec_link}{upiend}}{\var{end}} \var{us'''}
}
{
\Gamma \vdash
{\var{us}}
\trans{bupi}
{
\left(
\begin{array}{l}
\var{prop} \\
\var{votes} \\
\var{end}
\end{array}
\right)
}
{\var{us'''}}
}
\end{equation*}
\vspace{20pt}
\begin{equation*}
\inference
{ \Gamma \vdash \var{us}
\trans{\hyperlink{byron_ledger_spec_link}{upivotes}}{\var{votes}} \var{us'}
&
\Gamma \vdash \var{us'}
\trans{\hyperlink{byron_ledger_spec_link}{upiend}}{\var{end}} \var{us''}
}
{
\Gamma \vdash \var{us}
\trans{bupi}{
\left(
\begin{array}{l}
\Nothing \\
\var{votes} \\
\var{end}
\end{array}
\right)
}
\var{us''}
}
\end{equation*}
\caption{Update interface processing rules}
\label{fig:rules:bupi}
\end{figure}
\clearpage
\section{Permissive BFT}
The majority of this specification is concerned with the processing of the
\textit{ledger}; that is, the content (contained in both the block header and
the block body). In addition, however, we must also concern ourselves with the
protocol used to transmit the blocks and whether, according to that protocol, we
may validly extend the chain with a new block (assuming that block forms a valid
extension to the chain under the ledger rules).
Cardano's planned evolution can be split into roughly three eras:
\begin{description}
\item[Byron/Ouroboros] In the Byron/Ouroboros era, the Ouroboros (\cite{ouroboros})
protocol is used to control who is eligible to issue a block, using a stake
distribution mediated by heavyweight delegation certificates. The Byron
payload includes such things as VSS and payloads verified by individual
signatures.
\item[Handover] In the handover era, blocks will be issued according to
Ouroboros BFT (\cite{ouroboros_bft}). The Byron payload will be retained, although
parts of will be superfluous.
\item[Shelley/Praos] In the Shelley/Praos era, blocks will be issued according
to the Ouroboros Praos (\cite{ouroboros_praos}) protocol, with stake distribution
determined according to the new delegation design in \cite{delegation_design}.
\end{description}
During the handover era (as described in this document), while blocks will be
issued according to Ouroboros BFT, they will be validated according to a variant
known as Permissive BFT. This is designed such that it will successfully
validate blocks issued both under Ouroboros and under Ouroboros BFT (with a high
probability - see Appendix \ref{apdx:calculating-t}).
This section therefore will describe the section of the rules concerned with the
Permissive BFT protocol. Note that all of these are concerned only with the
block header, since the block body is entirely concerned with the ledger.
\subsection{Counting signed blocks}
\newcommand{\BSCEnv}{\type{BSCEnv}}
\newcommand{\BSCState}{\type{BSCState}}
To guard against the compromise of a minority of the genesis keys, we require
that in the rolling window of the last $k$ blocks, where $k$ is the chain
stability parameter, the number of blocks signed by keys that $sk_s$ delegated
to is no more than a threshold $k \cdot t$, where $t$ is a constant that will
be picked in the range $1/5 \leq t \leq 1/4$. Initial research suggests setting
$t=0.22$ as a good value. Specifically, given $k=2160$, we would allow a single
genesis key to issue (via delegates) $475$ blocks (since
$2160 \cdot 0.22 = 475.2$), but a $476^{\text{th}}$ block would be rejected.
See Appendix \ref{apdx:calculating-t} for the background on this value. The
abstract constant (nullary functions) related to the protocol are defined in
\cref{fig:defs:proto-abstract-funcs}.
\begin{figure}[ht]
\emph{Abstract functions}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
k & \mathbb{N} & \text{chain stability parameter}\\
t & \left[\frac{1}{5}, \frac{1}{4}\right] & \text{block signature count threshold}\\
\fun{dms} & \DelegState \totalf (\VKeyGen \mapsto \VKey) & \text{delegation-state delegation-map}
\end{array}
\end{equation*}
\caption{Protocol abstract functions}
\label{fig:defs:proto-abstract-funcs}
\end{figure}
Figure \ref{fig:rules:sigcnt} gives the rules for signature counting. We verify
that the key that delegates to the signer of this block has not already signed
more than its allowed threshold of blocks. If there are no delegators for the
given key, or if there is more than one delegator, the rule will fail to trigger.
%
We then update the sequence of signers, and drop those elements that fall
outside the size of the moving window ($k$).
\begin{figure}[ht]
\emph{Block signature count environments}
\begin{equation*}
\BSCEnv =
\left(
\begin{array}{r@{~\in~}lr}
\var{ds} & \DelegState & \text{delegation state} \\
\end{array}
\right)
\end{equation*}
\emph{Block signature count transitions}
\begin{equation*}
\_ \vdash \var{\_} \trans{sigcnt}{\_} \var{\_} \subseteq
\powerset (\BSCEnv \times \seqof{\VKeyGen} \times \VKey \times \seqof{\VKeyGen})
\end{equation*}
\caption{Block signature count transition-system types}
\label{fig:ts-types:sigcnt}
\end{figure}
\begin{figure}[ht]
\begin{equation*}
\inference
{
\{\var{vk_g}\} \leteq \dom{((\fun{dms} ~ \var{ds}) \restrictrange \{\var{vk_d}\})}
& \var{sgs'} \leteq \var{sgs};_k {vk_g} &
\size{\fun{filter}~(=\var{vk_g})~\var{sgs'}} \leq k \cdot t \\
}
{
\var{ds}
\vdash
{\var{sgs}}
\trans{sigcnt}{\var{vk_d}}
{\var{sgs'}}
}
\label{eq:rule:sigcnt}
\end{equation*}
\caption{Block signature count rules}
\label{fig:rules:sigcnt}
\end{figure}
\clearpage
\subsection{Permissive BFT Header Processing}
\newcommand{\PBFTEnv}{\type{PBFTEnv}}
\newcommand{\PBFTState}{\type{PBFTState}}
\newcommand{\Bhead}{\type{BlockHeader}}
\newcommand{\Bhtosign}{\type{BHToSign}}
\newcommand{\bhslotname}{bhSlot}
\newcommand{\bhslot}[1]{\fun{\bhslotname}\ #1}
\newcommand{\bhhashname}{bhHash}
\newcommand{\bhhash}[1]{\fun{\bhhashname}\ #1}
\newcommand{\bhprevhashname}{bhPrevHash}
\newcommand{\bhprevhash}[1]{\fun{\bhprevhashname}\ #1}
\newcommand{\bhtosignname}{bhToSign}
\newcommand{\bhtosign}[1]{\fun{\bhtosignname}\ #1}
During PBFT processing of the block header, we do the following:
\begin{enumerate}
\item We check that the current block is being issued for a slot later than
that of the last block issued.
\item We check that the current block is being issued for a slot no later than
the current slot (as determined by the system clock).
\item We check that the previous block hash contained in the block header
corresponds to the known hash of the previous block.
\item We check that the header signature correctly verifies the ``signed''
content of the header.
\item Finally, we verify and update the state according to the signature
count rules.
\end{enumerate}
\begin{figure}[ht]
\emph{Abstract types}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
bh & \Bhead & \text{Block header}
\end{array}
\end{equation*}
%
\emph{Abstract functions}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\fun{\bhprevhashname} & \Bhead \totalf \Hash & \text{previous header hash} \\
\fun{\bhhashname} & \Bhead \totalf \Hash & \text{header hash} \\
\fun{\bhsigname} & \Bhead \totalf \Sig & \text{block signature} \\
\fun{\bhissuername} & \Bhead \totalf \VKey & \text{block issuer} \\
\fun{\bhslotname} & \Bhead \totalf \Slot & \text{slot for which this block is issued}
\end{array}
\end{equation*}
\caption{Permissive BFT types and functions}
\label{fig:defs:pbft}
\end{figure}
\begin{figure}[ht]
\emph{Permissive BFT environments}
\begin{equation*}
\PBFTEnv =
\left(
\begin{array}{r@{~\in~}lr}
\var{ds} & \DelegState & \text{delegation state} \\
\var{s_{last}} & \Slot & \text{slot for which the last known block was issued} \\
\var{s_{now}} & \Slot & \text{current slot} \\
\end{array}
\right)
\end{equation*}
\emph{Permissive BFT states}
\begin{equation*}
\PBFTState =
\left(
\begin{array}{r@{~\in~}lr}
\var{h} & \Hash & \text{Tip header hash} \\
\var{sgs} & \seqof{\VKeyGen} & \text{Last signers}
\end{array}
\right)
\end{equation*}
\emph{Permissive BFT transitions}
\begin{equation*}
\_ \vdash \var{\_} \trans{pbft}{\_} \var{\_} \subseteq
\powerset (\PBFTEnv \times \PBFTState \times \Bhead \times \PBFTState)
\end{equation*}
\caption{Permissive BFT transition-system types}
\label{fig:ts-types:pbft}
\end{figure}
\begin{figure}[ht]
\begin{equation*}
\inference
{
\var{vk_d} \leteq \bhissuer{bh} & \var{s} \leteq \bhslot{bh}
\\ \var{s} > \var{s_{last}} & \var{s} \leq \var{s_{now}}
\\ \bhprevhash{bh} = \var{h} & \verify{vk_d}{\serialised{\bhtosign{bh}}}{(\bhsig{bh})}
\\
ds
\vdash
\var{sgs} \trans{\hyperref[fig:rules:sigcnt]{sigcnt}}{\var{vk_d}} \var{sgs'}
\\
}
{
\left(
{\begin{array}{c}
\var{ds} \\
\var{s_{last}} \\
\var{s_{now}} \\
\end{array}}
\right)
\vdash
\left(
{\begin{array}{c}
\var{h} \\
\var{sgs}
\end{array}}
\right)
\trans{pbft}{\var{bh}}
\left(
{\begin{array}{c}
\bhhash{bh} \\
\var{sgs}'
\end{array}}
\right)
}
\end{equation*}
\caption{Permissive BFT rules}
\label{fig:rules:pbft}
\end{figure}
\clearpage
\section{Epoch transitions}
\newcommand{\Epoch}{\type{Epoch}}
\newcommand{\ETState}{\type{ETState}}
\newcommand{\ETEnv}{\type{ETEnv}}
\newcommand{\sepochname}{sEpoch}
\newcommand{\sepoch}[2]{\fun{\sepochname}\ #1\ #2}
During each block transition, we must determine whether that block sits on an
epoch boundary and, if so, carry out various actions which are done on that
boundary. In the BFT era, the only computation carried out at the epoch boundary
is the update of protocol versions.
We rely on a function $\fun{\sepochname}$, whose type is given in
\cref{fig:defs:epoch}, to determine the epoch corresponding to a given slot.
%
We do not provide an implementation for such function in this specification,
but in practice a possible way of implementing such function is to rely on map
from the epochs to their corresponding length (given in number of slots they
contain). Such a map would also be required by the database layer to find the
requisite epoch file to look up a given block. We envision that an
implementation may of course choose a more compact representation for this
partial function that only records the changes in epoch length, rather than
storing a length for each epoch.
%
In addition, we rely on abstract constant (nullary function) $\var{ngk}$, which
determines the number of genesis keys.
It is also worth noticing that in the Byron era, the number of slots per-epoch
is fixed to $10 \cdot k$, where $k$ is the chain stability parameter.
Figure \ref{fig:rules:epoch} determines when an epoch change has occurred and
updates the update state to the correct version.
\begin{figure}[ht]
\emph{Abstract functions}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\fun{\sepochname}
& \Slot \totalf \mathbb{N} \totalf \Epoch
& \text{epoch containing this slot} \\
\var{ngk} & \mathbb{N} & \text{number of genesis keys}\\
\end{array}
\end{equation*}
\caption{Epoch transition types and functions}
\label{fig:defs:epoch}
\end{figure}
\begin{figure}[ht]
\emph{Epoch transition environments}
\begin{align*}
& \ETEnv
= \left(
\begin{array}{r@{~\in~}lr}
\var{e_c} & \Epoch & \text{current epoch}
\end{array}\right)
\end{align*}
\emph{Epoch transition states}
\begin{equation*}
\ETState =
\left(
\begin{array}{r@{~\in~}lr}
\var{us} & \UPIState & \text{update interface state}
\end{array}
\right)
\end{equation*}
\emph{Epoch transition transitions}
\begin{equation*}
\_ \vdash \var{\_} \trans{epoch}{\_} \var{\_} \subseteq
\powerset (\ETEnv \times \ETState \times \Slot \times \ETState)
\end{equation*}
\caption{Epoch transition transition-system types}
\label{fig:ts-types:epoch}
\end{figure}
\begin{figure}[ht]
\begin{equation*}
\inference
{
\var{e_c} \geq \sepoch{s}{k}
}
{\var{e_c}
\vdash
{
{\begin{array}{c}
\var{us}
\end{array}
}
}
\trans{epoch}{s}
{
{\begin{array}{c}
\var{us}
\end{array}
}
}
}
\end{equation*}
\vspace{20pt}
\begin{equation*}
\inference
{
\var{e_c} < \sepoch{s}{k}
&
\sepoch{s}{k}\vdash \var{us} \trans{\hyperlink{byron_ledger_spec_link}{upiec}}{} \var{us'}
}
{
\var{e_c}
\vdash
{
{\begin{array}{c}
\var{us}
\end{array}
}
}
\trans{epoch}{s}
{
{\begin{array}{c}
\var{us'}
\end{array}
}
}
}
\end{equation*}
\caption{Epoch transition rules}
\label{fig:rules:epoch}
\end{figure}
\clearpage
\section{Block processing}
\label{sec:block-processing}
\newcommand{\BHEnv}{\type{BHEnv}}
\newcommand{\BHState}{\type{BHState}}
\newcommand{\BBEnv}{\type{BBEnv}}
\newcommand{\BBState}{\type{BBState}}
\newcommand{\bheadname}{bHead}
\newcommand{\bhead}[1]{\fun{\bheadname}\ #1}
\newcommand{\bupdpayloadname}{bUpdPayload}
\newcommand{\bupdpayload}[1]{\fun{\bupdpayloadname}\ #1}
\newcommand{\bslotname}{bSlot}
\newcommand{\bslot}[1]{\fun{\bslotname}\ #1}
\newcommand{\butxo}[1]{\fun{bUtxo}\ #1}
% Imported definitions
\newcommand{\UTxO}{\type{UTxO}}
\newcommand{\UTxOState}{\type{UTxOState}}
\newcommand{\DIEnv}{\type{DIEnv}}
\newcommand{\DIState}{\type{DIState}}
We delineate here between processing the header and body of a block. It's useful
to make this distinction since we may process headers ahead of the
block body, and we have less context available to process headers - in
particular, we must be able to process block headers without the recent history
of block bodies.
\begin{figure}[ht]
\emph{Abstract types}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
b & \Block & \text{block} \\
h & \Hash & \text{hash} \\
\var{data} & \Data & \text{data}
\end{array}
\end{equation*}
%
%
\emph{Abstract functions}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\fun{\bsizename} & \Block \totalf \mathbb{N} & \text{block size in bytes} \\
\fun{\verifyname} & \VKey \times \Data \times \Sig & \text{verification relation} \\
\end{array}
\end{equation*}
\caption{Basic Block-related Types and Functions}
\label{fig:block-defs}
\end{figure}
\subsection{Block header processing}
Processing headers doesn't require any changes to the state, so we simply check
predicates. Figure \ref{eq:func:header-is-valid} gives the validity
predicate for a header. We verify that the block header does not exceed the
maximum size specified in the protocol parameters. The $\maxheadersize{}$
protocol parameter is defined in \cite{byron_ledger_spec}.
\begin{figure}[ht]
\emph{Abstract types}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
bh & \Bhead & \text{block header} \\
bts & \Bhtosign & \text{part of the block header which must be signed}
\end{array}
\end{equation*}
%
\emph{Abstract functions}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\fun{\bheadname} & \Block \totalf \Bhead & \text{block header} \\
\fun{\bhdrsizename} & \Bhead \totalf \mathbb{N} & \text{block header size in bytes}
\end{array}
\end{equation*}
\caption{Block header processing types and functions}
\label{fig:defs:bhead}
\end{figure}
\begin{figure}[ht]
\begin{equation}
\label{eq:func:header-is-valid}
\fun{headerIsValid}~\var{us}~\var{bh} = \maxheadersize \mapsto \var{s_{max}} \in \fun{pps}~\var{us} \Rightarrow \bhdrsize{bh} \leq \var{s_{max}}
\end{equation}
\caption{Block header validity functions}
\end{figure}
\clearpage
\subsection{Block body processing}
During processing of the block body, we perform two main functions:
verification of the body integrity using the proofs contained in the block
header, and update of the various state components. These rules are given in
\cref{fig:rules:bbody}, where the types and the functions used there are
defined in \cref{fig:ts-types:bbody}. The UTxO, delegation, and update state as
well as the $\maxblocksize{}$ protocol parameter are defined in
\cite{byron_ledger_spec}.
Verification is done independently for the three components of the body payload:
UTxO, delegation and update. Each of these three has a hash in the block
header. Note that Byron-era block payload also has an additional component: the
VSS payload. This part of the block is unnecessary during the BFT era, and hence
we do not verify it.
In addition to block verification, we also process the three components of the
payload; UTxO, delegation and update.
\begin{figure}[ht]
\emph{Abstract functions}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\fun{bUtxo} & \Block \totalf (\Tx \times \powerset{(\VKey \times \Sig)}) & \text{block UTxO payload} \\
\fun{\bcertsname} & \Block \totalf \seqof{\DCert}
& \text{block certificates} \\
\fun{bUpdProp} & \Block \totalf \UProp^{?} & \text{block update proposal payload} \\
\fun{bUpdVotes} & \Block \totalf \seqof{\Vote} & \text{block update votes payload} \\
\fun{bProtVer} & \Block \totalf \ProtVer & \text{block protocol version} \\
\fun{bhUtxoHash} & \Bhead \totalf \Hash & \text{UTxO payload hash} \\
\fun{bhDlgHash} & \Bhead \totalf \Hash & \text{delegation payload hash} \\
\fun{bhUpdHash} & \Bhead \totalf \Hash & \text{update payload hash} \\
\fun{hash} & \type{Data} \totalf \Hash & \text{hash function} \\
\end{array}
\end{equation*}
\emph{Derived functions}
\begin{equation*}
\begin{array}{rlr}
\fun{bEndorsment} & \in \Block \to \ProtVer \times \VKey & \text{Protocol version endorsment} \\
\bendorsment{b} & = (\bprotver{b}, (\bhissuername \cdot \bheadname) ~ b)\\
\fun{\bslotname} & \in \Block \to \Slot & \text{Slot for which this block is being issued} \\
\bslot{b} & = (\bhslotname \cdot \bheadname)~b \\
\fun{\bupdpayloadname} & \in \Block \to (\UProp^{?}\times\seqof{\Vote}) & \text{Block update payload} \\
\bupdpayload{b} & = (\bupdprop{b},~\bupdvotes{b})
\end{array}
\end{equation*}
\caption{Block body processing types and functions}
\label{fig:defs:bbody}
\end{figure}
\begin{figure}[ht]
\emph{Block body processing environments}
\begin{equation*}
\BBEnv =
\left(
\begin{array}{r@{~\in~}lr}
\var{pps} & \ProtParams & \text{protocol parameters} \\
\var{e_n} & \Epoch & \text{epoch we are currently processing blocks for} \\
\var{utxo_0} & \UTxO & \text{genesis UTxO}
\end{array}
\right)
\end{equation*}
\emph{Block body processing states}
\begin{equation*}
\BBState =
\left(
\begin{array}{r@{~\in~}lr}
\var{utxoSt} & \UTxOState & \text{UTxO state} \\
\var{ds} & \DIState & \text{delegation state} \\
\var{us} & \UPIState & \text{update interface state}
\end{array}
\right)
\end{equation*}
\emph{Block body processing transitions}
\begin{equation*}
\_ \vdash \var{\_} \trans{bbody}{\_} \var{\_} \subseteq
\powerset (\BBEnv \times \BBState \times \Block \times \BBState)
\end{equation*}
\caption{Block body processing transition-system types}
\label{fig:ts-types:bbody}
\end{figure}
\begin{figure}[ht]
\begin{equation*}
\inference
{ \maxblocksize \mapsto \var{b_{max}} \in \var{pps} && \bsize{b} \leq \var{b_{max}} \\
\var{bh} \leteq \bhead{b} & \var{vk_d} \leteq \bhissuer{\var{bh}} \\
\fun{hash}~(\butxo{b}) = \fun{bhUtxoHash}~\var{bh} &
\fun{hash}~(\bcerts{b}) = \fun{bhDlgHash}~\var{bh} \\
\fun{hash}~(\bupdpayload{b}) = \fun{bhUpdHash}~\var{bh}\\~\\
{\left(
\begin{array}{l}
\bslot{b} \\
\fun{dms}~ ds
\end{array}
\right)}
\vdash \var{us} \trans{\hyperref[fig:rules:bupi]{bupi}}{
{\left(
\begin{array}{l}
\bupdprop{b} \\
\bupdvotes{b} \\
\bendorsment{b}
\end{array}
\right)}
} \var{us'}
\\
{\left(
\begin{array}{l}
\dom{(\fun{dms}~ ds)} \\
\var{e_n}\\
\bslot{b}
\end{array}
\right)}
\vdash \var{ds} \trans{\hyperlink{byron_ledger_spec_link}{deleg}}{\bcerts{b}} \var{ds'} &
{\left(
\begin{array}{l}
\var{utxo_0} \\
\var{pps}
\end{array}
\right)}
\vdash \var{utxoSt}
\trans{\hyperlink{byron_ledger_spec_link}{utxows}}{\butxo{b}} \var{utxoSt'} \\
}
{
\left(
{\begin{array}{l}
\var{pps} \\
\var{e_n} \\
\var{utxo_0}
\end{array}}
\right)
\vdash
{
\left(
{\begin{array}{c}
\var{utxoSt} \\
\var{ds} \\
\var{us}
\end{array}}
\right)
}
\trans{bbody}{\var{b}}
{
\left(
{\begin{array}{c}
\var{utxoSt'} \\