forked from IntersectMBO/cardano-ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchain.tex
2062 lines (1924 loc) · 67.2 KB
/
chain.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
\section{Blockchain layer}
\label{sec:chain}
This chapter introduces the view of the blockchain layer as required for the
ledger. This includes in particular the information required for the epoch
boundary and its rewards calculation as described in Section~\ref{sec:epoch}. It
also covers the transitions that keep track of produced blocks in order to
calculate rewards and penalties for stake pools.
The main transition rule is $\mathsf{CHAIN}$ which calls the subrules
$\mathsf{NEWEPOCH}$ and $\mathsf{UPDN}$, $\mathsf{VRF}$ and $\mathsf{BBODY}$.
\subsection{Block Definitions}
\label{sec:defs-blocks}
\begin{figure*}[htb]
\emph{Abstract types}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\var{h} & \HashHeader & \text{hash of a block header}\\
\var{hb} & \HashBBody & \text{hash of a block body}\\
\var{bn} & \BlockNo & \text{block number}\\
\end{array}
\end{equation*}
%
\emph{Operational Certificate}
%
\begin{equation*}
\OCert =
\left(
\begin{array}{r@{~\in~}lr}
\var{vk_{hot}} & \VKeyEv & \text{operational (hot) key}\\
\var{n} & \N & \text{certificate issue number}\\
c_0 & \KESPeriod & \text{start KES period}\\
\sigma & \Sig & \text{cold key signature}\\
\end{array}
\right)
\end{equation*}
%
\emph{Block Header Body}
%
\begin{equation*}
\BHBody =
\left(
\begin{array}{r@{~\in~}lr}
\var{prev} & \HashHeader^? & \text{hash of previous block header}\\
\var{vk} & \VKey & \text{block issuer}\\
\var{vrfVk} & \VKey & \text{VRF verification key}\\
\var{blockno} & \BlockNo & \text{block number}\\
\var{slot} & \Slot & \text{block slot}\\
\eta & \Seed & \text{nonce}\\
\var{prf}_{\eta} & \Proof & \text{nonce proof}\\
\ell & \unitInterval & \text{leader election value}\\
\var{prf_{\ell}} & \Proof & \text{leader election proof}\\
\var{bsize} & \N & \text{size of the block body}\\
\var{bhash} & \HashBBody & \text{block body hash}\\
\var{oc} & \OCert & \text{operational certificate}\\
\var{pv} & \ProtVer & \text{protocol version}\\
\end{array}
\right)
\end{equation*}
%
\emph{Block Types}
%
\begin{equation*}
\begin{array}{r@{~\in~}l@{\qquad=\qquad}l}
\var{bh}
& \BHeader
& \BHBody \times \Sig
\\
\var{b}
& \Block
& \BHeader \times \seqof{\Tx}
\end{array}
\end{equation*}
\emph{Abstract functions}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\bhHash{} & \BHeader \to \HashHeader
& \text{hash of a block header} \\
\bHeaderSize{} & \BHeader \to \N
& \text{size of a block header} \\
\bBodySize{} & \seqof{\Tx} \to \N
& \text{size of a block body} \\
\slotToSeed{} & \Slot \to \Seed
& \text{convert a slot to a seed} \\
\prevHashToNonce{} & \HashHeader^? \to \Seed
& \text{convert an optional header hash to a seed} \\
\fun{bbodyhash} & \seqof{\Tx} \to \HashBBody \\
\end{array}
\end{equation*}
%
\emph{Accessor Functions}
\begin{equation*}
\begin{array}{r@{~\in~}l@{~~~~~~~~~~}r@{~\in~}lr}
\fun{bheader} & \Block \to \BHeader &
\fun{bhbody} & \BHeader \to \BHBody \\
\fun{hsig} & \BHeader \to \Sig &
\fun{bbody} & \Block \to \seqof{\Tx} \\
\fun{bvkcold} & \BHBody \to \VKey &
\fun{bvkvrf} & \BHBody \to \VKey \\
\fun{bprev} & \BHBody \to \HashHeader^? &
\fun{bslot} & \BHBody \to \Slot \\
\fun{bblockno} & \BHBody \to \BlockNo &
\fun{bnonce} & \BHBody \to \Seed \\
\fun{\bprfn{}} & \BHBody \to \Proof &
\fun{bleader} & \BHBody \to \N \\
\fun{\bprfl{}} & \BHBody \to \Proof &
\fun{hBbsize} & \BHBody \to \N \\
\fun{bhash} & \BHBody \to \HashBBody &
\fun{bocert} & \BHBody \to \OCert \\
\end{array}
\end{equation*}
%
\caption{Block Definitions}
\label{fig:defs:blocks}
\end{figure*}
\clearpage
\subsection{MIR Transition}
\label{sec:mir-trans}
The transition which moves the instantaneous rewards is $\mathsf{MIR}$.
Figure~\ref{fig:ts-types:mir} defines the types for the transition.
It has no environment or signal, and the state is $\EpochState$.
\begin{figure}
\emph{MIR Transitions}
\begin{equation*}
\vdash \var{\_} \trans{mir}{} \var{\_} \subseteq
\powerset (\EpochState \times \EpochState)
\end{equation*}
\caption{MIR transition-system types}
\label{fig:ts-types:mir}
\end{figure}
Figure~\ref{fig:rules:mir} defines the MIR state transition.
If the reserve and treasury pots are large enough to cover the sum
of the corresponding instantaneous rewards,
the reward accounts are increased by the appropriate amount
and the two pots are decreased appropriately.
In either case, if the pots are large enough or not,
we reset both of the instantaneous reward mappings back to the empty mapping.
\begin{figure}[ht]
\begin{equation}\label{eq:mir}
\inference[MIR]
{
(\var{rewards},~\var{delegations},~
\var{ptrs},~\var{fGenDelegs},~\var{genDelegs},~\var{i_{rwd}})
\leteq \var{ds}
\\
(\var{treasury},~\var{reserves})\leteq\var{acnt}
&
(\var{irReserves},~\var{irTreasury})\leteq\var{i_{rwd}}
\\~\\
\var{irwdR}\leteq
\left\{
\fun{addr_{rwd}}~\var{hk}\mapsto\var{val}
~\vert~\var{hk}\mapsto\var{val}\in(\dom{rewards})\restrictdom\var{irReserves}
\right\}
\\
\var{irwdT}\leteq
\left\{
\fun{addr_{rwd}}~\var{hk}\mapsto\var{val}
~\vert~\var{hk}\mapsto\var{val}\in(\dom{rewards})\restrictdom\var{irTreasury}
\right\}
\\~\\
\var{totR}\leteq\sum\limits_{\wcard\mapsto v\in\var{irwdR}}v
&
\var{totT}\leteq\sum\limits_{\wcard\mapsto v\in\var{irwdT}}v
\\
\var{totR}\leq\var{reserves}
&
\var{totT}\leq\var{treasury}
\\~\\
\var{rewards'}\leteq\var{rewards}\unionoverridePlus\var{irwdR}\unionoverridePlus\var{irwdT}
\\
\var{ds'} \leteq
(\varUpdate{\var{rewards}'},~\var{delegations},~
\var{ptrs},~\var{fGenDelegs},~\var{genDelegs},
~(\varUpdate{\emptyset},~\varUpdate{\emptyset}))
}
{
\vdash
{\left(\begin{array}{c}
\var{acnt} \\
\var{ss} \\
(\var{us},~(\var{ds},~\var{ps})) \\
\var{prevPP} \\
\var{pp} \\
\end{array}\right)}
\trans{mir}{}
{\left(\begin{array}{c}
\varUpdate{(\varUpdate{\var{treasury}-\var{totT}},~\varUpdate{\var{reserves}-\var{totR}})} \\
\var{ss} \\
(\var{us},~(\varUpdate{\var{ds'}},~\var{ps})) \\
\var{prevPP} \\
\var{pp} \\
\end{array}\right)}
}
\end{equation}
\nextdef
\begin{equation}\label{eq:mir-skip}
\inference[MIR-Skip]
{
(\var{rewards},~\var{delegations},~
\var{ptrs},~\var{fGenDelegs},~\var{genDelegs},~\var{i_{rwd}})
\leteq \var{ds}
\\
(\var{treasury},~\var{reserves})\leteq\var{acnt}
&
(\var{irReserves},~\var{irTreasury})\leteq\var{i_{rwd}}
\\~\\
\var{irwdR}\leteq
\left\{
\fun{addr_{rwd}}~\var{hk}\mapsto\var{val}
~\vert~\var{hk}\mapsto\var{val}\in(\dom{rewards})\restrictdom\var{irReserves}
\right\}
\\
\var{irwdT}\leteq
\left\{
\fun{addr_{rwd}}~\var{hk}\mapsto\var{val}
~\vert~\var{hk}\mapsto\var{val}\in(\dom{rewards})\restrictdom\var{irTreasury}
\right\}
\\~\\
\var{totR}\leteq\sum\limits_{\wcard\mapsto v\in\var{irwdR}}v
&
\var{totT}\leteq\sum\limits_{\wcard\mapsto v\in\var{irwdT}}v
\\
\var{totR}>\var{reserves}~\lor~\var{totT}>\var{treasury}
\\~\\
\var{ds'} \leteq
(\var{rewards},~\var{delegations},~
\var{ptrs},~\var{fGenDelegs},~\var{genDelegs},
~(\varUpdate{\emptyset},~\varUpdate{\emptyset}))
}
{
\vdash
{\left(\begin{array}{c}
\var{acnt} \\
\var{ss} \\
(\var{us},~(\var{ds},~\var{ps})) \\
\var{prevPP} \\
\var{pp} \\
\end{array}\right)}
\trans{mir}{}
{\left(\begin{array}{c}
\var{acnt} \\
\var{ss} \\
(\var{us},~(\varUpdate{\var{ds'}},~\var{ps})) \\
\var{prevPP} \\
\var{pp} \\
\end{array}\right)}
}
\end{equation}
\caption{MIR rules}
\label{fig:rules:mir}
\end{figure}
\subsection{New Epoch Transition}
\label{sec:new-epoch-trans}
For the transition to a new epoch ($\mathsf{NEWEPOCH}$), the environment is
given in Figure~\ref{fig:ts-types:newepoch}, it consists of
\begin{itemize}
\item The current slot.
\item The set of genesis keys.
\end{itemize}
The new epoch state is given in Figure~\ref{fig:ts-types:newepoch}, it consists
of
\begin{itemize}
\item The number of the last epoch.
\item The information about produced blocks for each stake pool during the previous epoch.
\item The information about produced blocks for each stake pool during the current epoch.
\item The old epoch state.
\item An optional rewards update.
\item The stake pool distribution of the epoch.
\end{itemize}
\begin{figure}
\emph{New Epoch states}
\begin{equation*}
\NewEpochState =
\left(
\begin{array}{r@{~\in~}lr}
\var{e_\ell} & \Epoch & \text{last epoch} \\
\var{b_{prev}} & \BlocksMade & \text{blocks made last epoch} \\
\var{b_{cur}} & \BlocksMade & \text{blocks made this epoch} \\
\var{es} & \EpochState & \text{epoch state} \\
\var{ru} & \RewardUpdate^? & \text{reward update} \\
\var{pd} & \PoolDistr & \text{pool stake distribution} \\
\end{array}
\right)
\end{equation*}
%
\emph{New Epoch Transitions}
\begin{equation*}
\vdash \var{\_} \trans{newepoch}{\_} \var{\_} \subseteq
\powerset (\NewEpochState \times \Epoch \times \NewEpochState)
\end{equation*}
%
\emph{Helper function}
\begin{align*}
& \fun{calculatePoolDistr} \in \Snapshot \to \PoolDistr \\
& \fun{calculatePoolDistr}~(\var{stake},~\var{delegs},~\var{poolParams}) = \\
& ~~~\left\{\var{hk_p}\mapsto(\sigma,~\fun{poolVRF}~\var{p})
~\Big\vert~
{
\begin{array}{r@{~\in~}l}
\var{hk_p}\mapsto\sigma & \var{sd} \\
\var{hk_p}\mapsto\var{p} & \var{poolParams}
\end{array}
}
\right\}\\
& ~~~~\where \\
& ~~~~~~~~~\var{total} = \sum_{\_ \mapsto c\in\var{stake}} c \\
& ~~~~~~~~~\var{sd} = \fun{aggregate_{+}}~\left(\var{delegs}^{-1}\circ
\left\{\left(
\var{hk}, \frac{\var{c}}{\var{total}}
\right) \vert (\var{hk},
\var{c}) \in \var{stake}
\right\}\right) \\
\end{align*}
\caption{NewEpoch transition-system types}
\label{fig:ts-types:newepoch}
\end{figure}
Figure~\ref{fig:rules:new-epoch} defines the new epoch state transition. It has three rules.
The first rule describes the change in the case of $e$ being equal to the next epoch $e_\ell+ 1$.
It also calls the $\mathsf{MIR}$ and $\mathsf{EPOCH}$ rules and checks that the reward update
is net neutral with respect to the Ada in the system.
This should always hold (by the definition of the $\fun{createRUpd}$ function)
and is present only for extra assurance and for help in proving
that Ada is preserved by this transition.
The second rule deals with the case when the epoch signal $e$ is not one greater than the
current epoch \var{e_\ell}. This rule does not change the state.
The third rule is nearly the same as the first rule, only there is no reward update to apply.
This third rule is defined for completeness, but in practice we hope that it is never used,
since it only applies in the case that epoch $e$ processed no blocks after the first
$\StabilityWindow$-many slots.
In the first case, the new epoch state is updated as follows:
\begin{itemize}
\item The epoch is set to the new epoch $e$.
\item The mapping for the blocks produced by each stake pool for the previous epoch
is set to the current such mapping.
\item The mapping for the blocks produced by each stake pool for the current epoch
is set to the empty map.
\item The epoch state is updated with: first applying the rewards update \var{ru},
then calling the $\mathsf{MIR}$ transition, and finally by calling the
$\mathsf{EPOCH}$ transition.
\item The rewards update is set to \Nothing.
\item The new pool distribution \var{pd}' is calculated from the delegation map and
stake allocation of the previous epoch.
\end{itemize}
\begin{figure}[ht]
\begin{equation}\label{eq:new-epoch}
\inference[New-Epoch]
{
e = e_\ell + 1
&
\var{ru} \neq \Nothing
&
(\Delta t,~\Delta r,~\var{rs},~\Delta f)\leteq\var{ru}
\\
\Delta t+~\Delta r+\left(\sum\limits_{\wcard\mapsto v\in\var{rs}} v\right)+\Delta f=0
\\
\var{es'}\leteq\fun{applyRUpd}~\var{ru}~\var{es}
&
{
\vdash
\var{es'}
\trans{\hyperref[fig:rules:mir]{mir}}{}\var{es''}
}
&
{
\vdash
\var{es''}
\trans{\hyperref[fig:rules:epoch]{epoch}}{\var{e}}\var{es'''}
}
\\~\\
{\begin{array}{r@{~\leteq~}l}
(\var{acnt},~\var{ss},~\wcard,~\wcard,~\wcard) & \var{es'''} \\
(\wcard,~\var{pstake_{set}},~\wcard,~\wcard) & \var{ss} \\
\var{pd'} & \fun{calculatePoolDistr}~\var{pstake_{set}} \\
\end{array}}
}
{
\vdash
{\left(\begin{array}{c}
\var{e_\ell} \\
\var{b_{prev}} \\
\var{b_{cur}} \\
\var{es} \\
\var{ru} \\
\var{pd} \\
\end{array}\right)}
\trans{newepoch}{\var{e}}
{\left(\begin{array}{c}
\varUpdate{\var{e}} \\
\varUpdate{\var{b_{cur}}} \\
\varUpdate{\emptyset} \\
\varUpdate{\var{es'''}} \\
\varUpdate{\Nothing} \\
\varUpdate{\var{pd}'} \\
\end{array}\right)}
}
\end{equation}
\nextdef
\begin{equation}\label{eq:not-new-epoch}
\inference[Not-New-Epoch]
{
(e_\ell,~\wcard,~\wcard,~\wcard,~\wcard,~\wcard,~\wcard)\leteq\var{nes}
&
e \neq e_\ell + 1
}
{
\vdash\var{nes}\trans{newepoch}{\var{e}} \var{nes}
}
\end{equation}
\nextdef
\begin{equation}\label{eq:no-reward-update}
\inference[No-Reward-Update]
{
(e_\ell,~\wcard,~\wcard,~\wcard,~\var{ru},~\wcard,~\wcard)\leteq\var{nes}
&
e = e_\ell + 1
&
\var{ru} = \Nothing
\\
{
\vdash
\var{es}
\trans{\hyperref[fig:rules:mir]{mir}}{}\var{es''}
}
&
{
\vdash
\var{es''}
\trans{\hyperref[fig:rules:epoch]{epoch}}{\var{e}}\var{es'''}
}
\\~\\
{\begin{array}{r@{~\leteq~}l}
(\var{acnt},~\var{ss},~\wcard,~\wcard,~\wcard) & \var{es'''} \\
(\wcard,~\var{pstake_{set}},~\wcard,~\wcard) & \var{ss} \\
\var{pd'} & \fun{calculatePoolDistr}~\var{pstake_{set}} \\
\end{array}}
}
{
\vdash
{\left(\begin{array}{c}
\var{e_\ell} \\
\var{b_{prev}} \\
\var{b_{cur}} \\
\var{es} \\
\var{ru} \\
\var{pd} \\
\end{array}\right)}
\trans{newepoch}{\var{e}}
{\left(\begin{array}{c}
\varUpdate{\var{e}} \\
\varUpdate{\var{b_{cur}}} \\
\varUpdate{\emptyset} \\
\varUpdate{\var{es'''}} \\
\var{ru} \\
\varUpdate{\var{pd}'} \\
\end{array}\right)}
}
\end{equation}
\caption{New Epoch rules}
\label{fig:rules:new-epoch}
\end{figure}
\clearpage
\subsection{Tick Nonce Transition}
\label{sec:tick-nonce-trans}
The Tick Nonce Transition is responsible for updating the epoch nonce and the
previous hash nonce at the start of an epoch. Its environment is shown in
Figure~\ref{fig:ts-types:ticknonce} and consists of the protocol parameters
$\var{pp}$, the candidate nonce $\eta_c$ and the previous header hash as a
nonce. Its state consists of the epoch nonce $\eta_0$ and the previous hash
nonce.
\begin{figure}
\emph{Tick Nonce environments}
\begin{equation*}
\TickNonceEnv =
\left(
\begin{array}{r@{~\in~}lr}
\var{pp} & \PParams & \text{protocol parameters} \\
\eta_c & \Seed & \text{candidate nonce} \\
\eta_\var{ph} & \Seed & \text{previous header hash as nonce} \\
\end{array}
\right)
\end{equation*}
%
\emph{Tick Nonce states}
\begin{equation*}
\TickNonceState =
\left(
\begin{array}{r@{~\in~}lr}
\eta_0 & \Seed & \text{epoch nonce} \\
\eta_h & \Seed & \text{seed generated from hash of previous epoch} \\
\end{array}
\right)
\end{equation*}
\label{fig:ts-types:ticknonce}
\end{figure}
The signal to the transition rule $\mathsf{TICKN}$ is a marker indicating
whether we are in a new epoch. If we are in a new epoch, we update the epoch
nonce and the previous hash. Otherwise, we do nothing.
\begin{figure}[ht]
\begin{equation}\label{eq:tick-nonce-notnewepoch}
\inference[Not-New-Epoch]
{ }
{
{\begin{array}{c}
\var{pp} \\
\eta_c \\
\eta_\var{ph} \\
\end{array}}
\vdash
{\left(\begin{array}{c}
\eta_0 \\
\eta_h \\
\end{array}\right)}
\trans{tickn}{\mathsf{False}}
{\left(\begin{array}{c}
\eta_0 \\
\eta_h \\
\end{array}\right)}
}
\end{equation}
\nextdef
\begin{equation}\label{eq:tick-nonce-newepoch}
\inference[New-Epoch]
{
\eta_e \leteq \fun{extraEntropy}~\var{pp}
}
{
{\begin{array}{c}
\var{pp} \\
\eta_c \\
\eta_\var{ph} \\
\end{array}}
\vdash
{\left(\begin{array}{c}
\eta_0 \\
\eta_h \\
\end{array}\right)}
\trans{tickn}{\mathsf{True}}
{\left(\begin{array}{c}
\varUpdate{\eta_c \seedOp \eta_h \seedOp \eta_e} \\
\varUpdate{\eta_\var{ph}} \\
\end{array}\right)}
}
\end{equation}
\caption{Tick Nonce rules}
\label{fig:rules:tick-nonce}
\end{figure}
\subsection{Update Nonce Transition}
\label{sec:update-nonces-trans}
The Update Nonce Transition updates the nonces until the randomness gets fixed.
The environment is shown in Figure~\ref{fig:ts-types:updnonce} and consists of
the block nonce $\eta$.
The update nonce state is shown in Figure~\ref{fig:ts-types:updnonce} and consists of
the candidate nonce $\eta_c$ and the evolving nonce $\eta_v$.
\begin{figure}
\emph{Update Nonce environments}
\begin{equation*}
\UpdateNonceEnv =
\left(
\begin{array}{r@{~\in~}lr}
\eta & \Seed & \text{new nonce} \\
\end{array}
\right)
\end{equation*}
%
\emph{Update Nonce states}
\begin{equation*}
\UpdateNonceState =
\left(
\begin{array}{r@{~\in~}lr}
\eta_v & \Seed & \text{evolving nonce} \\
\eta_c & \Seed & \text{candidate nonce} \\
\end{array}
\right)
\end{equation*}
%
\emph{Update Nonce Transitions}
\begin{equation*}
\_ \vdash \var{\_} \trans{updn}{\_} \var{\_} \subseteq
\powerset (\UpdateNonceEnv
\times \UpdateNonceState
\times \Slot
\times \UpdateNonceState
)
\end{equation*}
\caption{UpdNonce transition-system types}
\label{fig:ts-types:updnonce}
\end{figure}
The transition rule $\mathsf{UPDN}$ takes the slot \var{s} as signal. There are
two different cases for $\mathsf{UPDN}$: one where \var{s} is not yet
\StabilityWindow{} slots from the beginning of the next epoch and one where
\var{s} is less than \StabilityWindow{} slots until the start of the next epoch.
Note that in \ref{eq:update-both}, the nonce candidate $\eta_c$ transitions to
$\eta_v\seedOp\eta$, not $\eta_c\seedOp\eta$. The reason for this is that even
though the nonce candidate is frozen sometime during the epoch, we want the two
nonces to again be equal at the start of a new epoch (so that the entropy added
near the end of the epoch is not discarded).
\begin{figure}[ht]
\begin{equation}\label{eq:update-both}
\inference[Update-Both]
{
s < \fun{firstSlot}~((\epoch{s}) + 1) - \StabilityWindow
}
{
{\begin{array}{c}
\eta \\
\end{array}}
\vdash
{\left(\begin{array}{c}
\eta_v \\
\eta_c \\
\end{array}\right)}
\trans{updn}{\var{s}}
{\left(\begin{array}{c}
\varUpdate{\eta_v\seedOp\eta} \\
\varUpdate{\eta_v\seedOp\eta} \\
\end{array}\right)}
}
\end{equation}
\nextdef
\begin{equation}\label{eq:only-evolve}
\inference[Only-Evolve]
{
s \geq \fun{firstSlot}~((\epoch{s}) + 1) - \StabilityWindow
}
{
{\begin{array}{c}
\eta \\
\end{array}}
\vdash
{\left(\begin{array}{c}
\eta_v \\
\eta_c \\
\end{array}\right)}
\trans{updn}{\var{s}}
{\left(\begin{array}{c}
\varUpdate{\eta_v\seedOp\eta} \\
\eta_c \\
\end{array}\right)}
}
\end{equation}
\caption{Update Nonce rules}
\label{fig:rules:update-nonce}
\end{figure}
\subsection{Reward Update Transition}
\label{sec:reward-update-trans}
The Reward Update Transition calculates a new $\RewardUpdate$ to apply in a
$\mathsf{NEWEPOCH}$ transition. The environment is shown in
Figure~\ref{fig:ts-types:reward-update}, it consists of the produced blocks
mapping \var{b} and the epoch state \var{es}. Its state is an optional reward
update.
\begin{figure}
\emph{Reward Update environments}
\begin{equation*}
\RUpdEnv =
\left(
\begin{array}{r@{~\in~}lr}
\var{b} & \BlocksMade & \text{blocks made} \\
\var{es} & \EpochState & \text{epoch state} \\
\end{array}
\right)
\end{equation*}
%
\emph{Reward Update Transitions}
\begin{equation*}
\_ \vdash \var{\_} \trans{rupd}{\_} \var{\_} \subseteq
\powerset (\RUpdEnv \times \RewardUpdate^? \times \Slot \times \RewardUpdate^?)
\end{equation*}
\caption{Reward Update transition-system types}
\label{fig:ts-types:reward-update}
\end{figure}
The transition rules are shown in Figure~\ref{fig:rules:reward-update}. There
are three cases, one which computes a new reward update, one which leaves the
rewards update unchanged as it has not yet been applied and finally one that
leaves the reward update unchanged as the transition was started too early.
The signal of the transition rule $\mathsf{RUPD}$ is the slot \var{s}. The
execution of the transition role is as follows:
\begin{itemize}
\item If the current reward update \var{ru} is empty and \var{s} is greater than
the sum of the first slot of its epoch and the duration \RandomnessStabilisationWindow, then a
new rewards update is calculated and the state is updated.
(Note the errata in Section~\ref{sec:errata:stability-windows}.)
\item If the current reward update \var{ru} is not \Nothing, i.e., a reward
update has already been calculated but not yet applied, then the state is not updated.
\item If the current reward update \var{ru} is empty and \var{s} is less than or equal to the sum
of the first slot of its epoch and the duration to start rewards \RandomnessStabilisationWindow,
then the state is not updated.
\end{itemize}
\begin{figure}[ht]
\begin{equation}\label{eq:reward-update}
\inference[Create-Reward-Update]
{
s > \fun{firstSlot}~(\epoch{s}) + \RandomnessStabilisationWindow
&
ru = \Nothing
\\~\\
ru' \leteq \createRUpd{\SlotsPerEpoch}{b}{es}{\MaxLovelaceSupply}
}
{
{\begin{array}{c}
\var{b} \\
\var{es} \\
\end{array}}
\vdash
\var{ru}\trans{rupd}{\var{s}}\varUpdate{\var{ru}'}
}
\end{equation}
\nextdef
\begin{equation}\label{eq:reward-update-exists}
\inference[Reward-Update-Exists]
{
ru \neq \Nothing
}
{
{\begin{array}{c}
\var{b} \\
\var{es} \\
\end{array}}
\vdash
\var{ru}\trans{rupd}{\var{s}}\var{ru}
}
\end{equation}
\nextdef
\begin{equation}\label{eq:reward-too-early}
\inference[Reward-Too-Early]
{
ru = \Nothing
\\
s \leq \fun{firstSlot}~(\epoch{s}) + \RandomnessStabilisationWindow
}
{
{\begin{array}{c}
\var{b} \\
\var{es} \\
\end{array}}
\vdash
\var{ru}\trans{rupd}{\var{s}}\var{ru}
}
\end{equation}
\caption{Reward Update rules}
\label{fig:rules:reward-update}
\end{figure}
\subsection{Chain Tick Transition}
\label{sec:tick-trans}
The Chain Tick Transition performs some chain level
upkeep. The environment consists of a set of genesis keys, and the state is the
epoch specific state necessary for the $\mathsf{NEWEPOCH}$ transition.
Part of the upkeep is updating the genesis key delegation mapping
according to the future delegation mapping.
For each genesis key, we adopt the most recent delegation in $\var{fGenDelegs}$
that is past the current slot, and any future genesis key delegations past the current
slot is removed. The helper function $\fun{adoptGenesisDelegs}$ accomplishes the update.
\begin{figure}
\emph{Chain Tick Transitions}
\begin{equation*}
\vdash \var{\_} \trans{tick}{\_} \var{\_} \subseteq
\powerset (\NewEpochState \times \Slot \times \NewEpochState)
\end{equation*}
\caption{Tick transition-system types}
\label{fig:ts-types:tick}
%
\emph{helper function}
\begin{align*}
& \fun{adoptGenesisDelegs} \in \EpochState \to \Slot \to EpochState
\\
& \fun{adoptGenesisDelegs}~\var{es}~\var{slot} = \var{es'}
\\
& ~~~~\where
\\
& ~~~~~~~~~~
(\var{acnt},~\var{ss},(\var{us},(\var{ds},\var{ps})),~\var{prevPp},~\var{pp})
\leteq\var{es}
\\
& ~~~~~~~~~~
(~\var{rewards},~\var{delegations},~\var{ptrs},
~\var{fGenDelegs},~\var{genDelegs},~\var{i_{rwd}})\leteq\var{ds}
\\
& ~~~~~~~~~~\var{curr}\leteq
\{
(\var{s},~\var{gkh})\mapsto(\var{vkh},~\var{vrf})\in\var{fGenDelegs}
~\mid~
\var{s}\leq\var{slot}
\}
\\
& ~~~~~~~~~~\var{fGenDelegs'}\leteq
\var{fGenDelegs}\setminus\var{curr}
\\
& ~~~~~~~~~~\var{genDelegs'}\leteq
\left\{
\var{gkh}\mapsto(\var{vkh},~\var{vrf})
~\mathrel{\Bigg|}~
{
\begin{array}{l}
(\var{s},~\var{gkh})\mapsto(\var{vkh},~\var{vrf})\in\var{curr}\\
\var{s}=\max\{s'~\mid~(s',~\var{gkh})\in\dom{\var{curr}}\}
\end{array}
}
\right\}
\\
& ~~~~~~~~~~\var{ds'}\leteq
(\var{rewards},~\var{delegations},~\var{ptrs},
~\var{fGenDelegs'},~\var{genDelegs}\unionoverrideRight\var{genDelegs'},~\var{i_{rwd}})
\\
& ~~~~~~~~~~\var{es'}\leteq
(\var{acnt},~\var{ss},(\var{us},(\var{ds'},\var{ps})),~\var{prevPp},~\var{pp})
\end{align*}
\end{figure}
The $\mathsf{TICK}$ transition rule is shown in Figure~\ref{fig:rules:tick}.
The signal is a slot \var{s}.
Three transitions are done:
\begin{itemize}
\item The $\mathsf{NEWEPOCH}$ transition performs any state change needed if it is the first
block of a new epoch.
\item The $\mathsf{RUPD}$ creates the reward update if it is late enough in the epoch.
\textbf{Note} that for every block header, either $\mathsf{NEWEPOCH}$ or $\mathsf{RUPD}$
will be the identity transition, and so, for instance, it does not matter if $\mathsf{RUPD}$
uses $\var{nes}$ or $\var{nes}'$ to obtain the needed state.
\end{itemize}
\begin{figure}[ht]
\begin{equation}\label{eq:tick}
\inference[Tick]
{
{
\vdash
\var{nes}
\trans{\hyperref[fig:rules:new-epoch]{newepoch}}{\epoch{slot}}
\var{nes}'
}
\\~\\
(\wcard,~\var{b_{prev}},~\wcard,~\var{es},~\wcard,~\wcard)\leteq\var{nes} \\
\\~\\
{
{\begin{array}{c}
\var{b_{prev}} \\
\var{es} \\
\end{array}}
\vdash \var{ru'}\trans{\hyperref[fig:rules:reward-update]{rupd}}{\var{slot}} \var{ru''}
}
\\~\\
(\var{e_\ell'},~\var{b_{prev}'},~\var{b_{cur}'},~\var{es'},~\var{ru'},~\var{pd'})
\leteq\var{nes'}
\\
\var{es''}\leteq\fun{adoptGenesisDelegs}~\var{es'}~\var{slot}
\\
\var{nes''}\leteq
(\var{e_\ell'},~\var{b_{prev}'},~\var{b_{cur}'},~\var{es''},~\var{ru''},~\var{pd'})
\\~\\
}
{
\vdash\var{nes}\trans{tick}{\var{slot}}\varUpdate{\var{nes''}}
}
\end{equation}
\caption{Tick rules}
\label{fig:rules:tick}
\end{figure}
\clearpage
\subsection{Operational Certificate Transition}
\label{sec:oper-cert-trans}
The Operational Certificate Transition environment consists of the genesis key
delegation map $\var{genDelegs}$ and the set of stake pools $\var{stpools}$. Its state
is the mapping of operation certificate issue numbers. Its signal is a block
header.
\begin{figure}
\emph{Operational Certificate environments}
\begin{equation*}
\OCertEnv =
\left(
\begin{array}{r@{~\in~}lr}
\var{stpools} & \powerset{\type{KeyHash}} & \text{stake pools} \\
\var{genDelegs} & \powerset{\type{KeyHash}} & \text{genesis key delegates}\\
\end{array}
\right)
\end{equation*}
%
\emph{Operational Certificate Transitions}
\begin{equation*}
\var{\_} \vdash \var{\_} \trans{ocert}{\_} \var{\_} \subseteq
\powerset (\OCertEnv \times \KeyHash_{pool} \mapsto \N \times \BHeader \times \KeyHash_{pool} \mapsto \N)
\end{equation*}
%
\emph{Operational Certificate helper function}
\begin{align*}
& \fun{currentIssueNo} \in \OCertEnv \to (\KeyHash_{pool} \mapsto \N)
\to \KeyHash_{pool}
\to \N^? \\
& \fun{currentIssueNo}~(\var{stpools}, \var{genDelegs})~ \var{cs} ~\var{hk} =
\begin{cases}
\var{hk}\mapsto \var{n} \in \var{cs} & n \\
\var{hk} \in \var{stpools} & 0 \\
\var{hk} \in \var{genDelegs} & 0 \\
\text{otherwise} & \Nothing
\end{cases}
\end{align*}
\caption{OCert transition-system types}
\label{fig:ts-types:ocert}
\end{figure}
The transition rule is shown in Figure~\ref{fig:rules:ocert}. From the block
header body \var{bhb} we first extract the following:
\begin{itemize}
\item The operational certificate, consisting of the hot key \var{vk_{hot}},
the certificate issue number \var{n}, the KES period start \var{c_0} and the cold key
signature.
\item The cold key \var{vk_{cold}}.
\item The slot \var{s} for the block.
\item The number of KES periods that have elapsed since the start period on the certificate.
\end{itemize}
Using this we verify the preconditions of the operational certificate state
transition which are the following:
\begin{itemize}
\item The KES period of the slot in the block header body must be greater than or equal to
the start value \var{c_0} listed in the operational certificate,
and less than $\MaxKESEvo$-many KES periods after \var{c_0}.
The value of $\MaxKESEvo$ is the agreed-upon lifetime of an operational certificate,
see \cite{delegation_design}.
\item \var{hk} exists as key in the mapping of certificate issues numbers to a KES
period \var{m} and that period is less than or equal to \var{n}.
\item The signature $\tau$ can be verified with the cold verification key
\var{vk_{cold}}.
\item The KES signature $\sigma$ can be verified with the hot verification key
\var{vk_{hot}}.
\end{itemize}
After this, the transition system updates the operational certificate state by
updating the mapping of operational certificates where it overwrites the entry
of the key \var{hk} with the KES period \var{n}.
\begin{figure}[ht]