-
Notifications
You must be signed in to change notification settings - Fork 157
/
epoch.tex
1541 lines (1410 loc) · 55.1 KB
/
epoch.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{Rewards and the Epoch Boundary}
\label{sec:epoch}
\newcommand{\UTxOEpState}{\type{UTxOEpState}}
\newcommand{\PlReapState}{\type{PlReapState}}
\newcommand{\NewPParamEnv}{\type{NewPParamEnv}}
\newcommand{\Snapshot}{\type{Snapshot}}
\newcommand{\Snapshots}{\type{Snapshots}}
\newcommand{\SnapshotEnv}{\type{SnapshotEnv}}
\newcommand{\SnapshotState}{\type{SnapshotState}}
\newcommand{\NewPParamState}{\type{NewPParamState}}
\newcommand{\EpochState}{\type{EpochState}}
\newcommand{\BlocksMade}{\type{BlocksMade}}
\newcommand{\Stake}{\type{Stake}}
\newcommand{\RewardUpdate}{\type{RewardUpdate}}
\newcommand{\obligation}[3]{\fun{obligation}~ \var{#1}~ \var{#2}~ \var{#3}}
\newcommand{\reward}[8]{\fun{reward}
~ \var{#1}~ \var{#2}~ \var{#3}~ \var{#4}~ \var{#5}~ \var{#6}~ \var{#7}~ \var{#8}}
\newcommand{\isActive}[4]{\fun{isActive}~ \var{#1}~ \var{#2}~ \var{#3}~ \var{#4}}
\newcommand{\activeStake}[5]{\fun{activeStake}~ \var{#1}~ \var{#2}~ \var{#3}~ \var{#4}~ \var{#5}}
\newcommand{\poolRefunds}[2]{\fun{poolRefunds}~ \var{#1}~ \var{#2}}
\newcommand{\poolStake}[3]{\fun{poolStake}~ \var{#1}~ \var{#2}~ \var{#3}}
\newcommand{\stakeDistr}[3]{\fun{stakeDistr}~ \var{#1}~ \var{#2}~ \var{#3}}
\newcommand{\lReward}[4]{\fun{r_{operator}}~ \var{#1}~ \var{#2}~ \var{#3}~ {#4}}
\newcommand{\mReward}[4]{\fun{r_{member}}~ \var{#1}~ \var{#2}~ \var{#3}~ {#4}}
\newcommand{\mkApparentPerformance}[4]{\fun{mkApparentPerformance}~\var{#1}~{#2}~\var{#3}~\var{#4}}
\newcommand{\createRUpd}[4]{\fun{createRUpd}~\var{#1}~\var{#2}~\var{#3}~\var{#4}}
\newcommand{\getIR}[1]{\fun{getIR}~\var{#1}}
This chapter introduces the epoch boundary transition system and the related reward calculation.
The transition system is defined in Section~\ref{sec:total-epoch},
and involves taking stake distribution snapshots
(Sections~\ref{sec:stake-dist-calc} and~\ref{sec:snapshots}),
retiring stake pools (Section~\ref{sec:pool-reap}),
and performing protocol updates (Section~\ref{sec:pparam-update}).
The reward calculation, defined in Sections~\ref{sec:reward-dist} and~\ref{sec:reward-calc},
distributes the leader election rewards.
\subsection{Overview of the Reward Calculation}
\label{sec:reward-overview}
The rewards for a given epoch $e_i$ involve the two epochs surrounding it.
In particular, the stake distribution will come from the previous epoch
and the rewards will be calculated in the following epoch.
More concretely:
\begin{enumerate}[(A)]%for small alpha-characters within brackets.
\item A stake distribution snapshot is taken at the begining of epoch $e_{i-1}$.
\item The randomness for leader election is fixed during epoch $e_{i-1}$
\item Epoch $e_{i}$ begins.
\item Epoch $e_{i}$ ends.
A snapshot is taken of the stake pool performance during epoch $e_{i}$.
A snapshot is also taken of the fee pot.
\item The snapshots from (D) are stable and the reward calculation can begin.
\item The reward calculation is finished and an update to the ledger state
is ready to be applied.
\item Rewards are given out.
\end{enumerate}
\usetikzlibrary{decorations.pathreplacing}
\begin{tikzpicture}
% axis
\draw[latex-latex] (0,0) -- (11,0) ;
% epoch braces
\draw [decorate,decoration={brace,amplitude=10pt} ,yshift=5pt] (1.03,0) -- (3.97,0)
node [midway, above, yshift=9pt]{$e_{i-1}$};
\draw [decorate,decoration={brace,amplitude=10pt} ,yshift=5pt] (4.03,0) -- (6.97,0)
node [midway, above, yshift=9pt]{$e_{i}$};
\draw [decorate,decoration={brace,amplitude=10pt} ,yshift=5pt] (7.03,0) -- (9.97,0)
node [midway, above, yshift=9pt]{$e_{i+1}$};
% epoch boundaries
\foreach \x in {1,4,7,10}
\draw[shift={(\x,0)}] (0pt,0pt) -- (0pt,-3pt);
\node at (1,-0.5) {A};
\node at (3,-0.5) {B};
\node at (4,-0.5) {C};
\node at (7,-0.5) {D};
\node at (8,-0.5) {E};
\node at (9,-0.5) {F};
\node at (10,-0.5) {G};
\end{tikzpicture}
We must therefore store the last three stake distributions.
The mnemonic ``mark, set, go'' will be used to keep
track of the snapshots, where the label ``mark'' refers to the most recent snapshot,
and ``go'' refers to the snapshot that is ready to be used in the reward calculation.
In the above diagram, the snapshot taken at (A) is labeled ``mark'' during epoch $e_{i-1}$,
``set'' during epoch $e_i$ and ``go'' during epoch $e_{i+1}$. At (G) the snapshot
taken at (A) is no longer needed and will be discarded.
The two main transition systems in this section are:
\begin{itemize}
\item The transition system named $\mathsf{EPOCH}$, which is defined in
Section~\ref{sec:total-epoch}, covers what happens at the epoch boundary,
such as at (A), (C), (D) and (G).
\item The transition named $\mathsf{RUPD}$, which is defined in
Section~\ref{sec:reward-update-trans}, covers the reward calculation that
happens between (E) and (F).
\end{itemize}
\begin{note}
Between time D and E we are concerned with chain growth and stability.
Therefore this duration can be stated as 2k blocks (to state it in slots requires details about
the particular version of the Ouroboros protocol). The duration between F and G is also 2k blocks.
Between E and F a single honest block is enough to ensure a random nonce.
\end{note}
\subsection{Example Illustration of the Reward Cycle}
\label{sec:illustration-reward-cycle}
\definecolor{epochColor}{rgb} {1.00,0.50,0.00}
\definecolor{aliceColor}{rgb} {0.65,0.00,0.00}
\definecolor{bobColor}{rgb} {0.00,0.50,0.00}
\definecolor{bob2Color}{rgb} {0.00,0.95,0.00}
\definecolor{snapshot1}{rgb} {0.00,0.00,0.90}
\definecolor{snapshot2}{rgb} {0.00,0.60,0.90}
\begin{tikzpicture}
% Axis
\draw [thick] (-0.2,0) -- (13,0);
\draw (0,-.2) -- (0, .2);
\draw (3,-.2) -- (3, .2);
\draw (6,-.2) -- (6, .2);
\draw (9,-.2) -- (9, .2);
\draw (12,-.2) -- (12, .2);
\node[align=center, below, color=epochColor] at (1.5,0.5)
{$e_1$};
\node[align=center, below, color=epochColor] at (4.5,0.5)
{$e_2$};
\node[align=center, below, color=epochColor] at (7.5,0.5)
{$e_3$};
\node[align=center, below, color=epochColor] at (10.5,0.5)
{$e_4$};
% Alice
% Alice's circle
\draw [aliceColor, fill] (0,3) circle [radius=0.5];
\node [white] at (0,3) {Alice};
% Alice's delegation line
\draw [->,thick, aliceColor] (0.4,2.65) to (2,0.05);
\node [aliceColor] at (2.2,2) {delegate to Bob};
% Bob
% Bob's circle
\draw [bobColor, fill] (0,-3) circle [radius=0.5];
\node [white] at (0,-3) {Bob};
% Bob's registration line
\draw [->,thick, bobColor] (0.2,-2.50) to (1,-0.05);
\node [align=left, below, bobColor] at (-0.5,-0.5) {initial pool \\ registration};
% Bob's re-registration line
\draw [->,thick, bob2Color] (0.45,-2.65) to (2.90,-0.05);
\node [bob2Color] at (2,-2.8) {re-registration};
% Bob's cached parameter change
\draw [->,thick, bob2Color] (2.9,-0.2) to [out=280, in=180] (3,-2)
to [out=0, in=290] (3.1,-0.2);
% Alice time to re-delegate
\draw [decorate, decoration = {brace, mirror, amplitude=10pt}, aliceColor, thick]
(3.2,-0.2) to (5.9,-0.2);
\node [align=center, below, aliceColor] at (5.1,-0.5)
{Alice's opportunity \\ to re-delegate \\ before Bob's new \\ parameters};
% Bob's blocks
% epoch e3
\draw [fill=bobColor,bobColor] (6.3,-.1) rectangle (6.5,-.3);
\draw [fill=bobColor,bobColor] (6.7,-.1) rectangle (6.9,-.3);
\draw [fill=bobColor,bobColor] (7.4,-.1) rectangle (7.6,-.3);
\draw [fill=bobColor,bobColor] (8.4,-.1) rectangle (8.6,-.3);
\draw [decorate, decoration = {brace, mirror, amplitude=10pt}, bobColor, thick]
(6.2, -0.4) to (8.9,-0.4);
\draw [->,thick, bobColor] (7.6, -0.8) to [out=315,in=200] (8.4, -1.2)
to [] (9.6, -0.9);
% epoch e4
\draw [fill=bob2Color,bob2Color] (9.9,-.1) rectangle (10.1,-.3);
\draw [fill=bob2Color,bob2Color] (10.4,-.1) rectangle (10.6,-.3);
\draw [fill=bob2Color,bob2Color] (10.8,-.1) rectangle (11.0,-.3);
\draw [decorate, decoration = {brace, mirror, amplitude=10pt}, bob2Color, thick]
(9.7, -0.4) to (11.2,-0.4);
\draw [->,thick, bob2Color] (10.6, -0.8) to [out=315,in=200] (11.4, -1.2)
to [] (12.6, -0.9);
% Snapshots
\draw [->,thick, snapshot1] (3,0.3) to [out=90,in=150] (9,0.5)
to [out=330,in=180] (10,-1) to [out=0,in=-135] (12,0) ;
\node [snapshot1] at (2.7,1.2) {mark};
\node [snapshot1] at (6,1.9) {set};
\node [snapshot1] at (9,0.9) {go};
\draw [->,thick, snapshot2] (6,0.3) to [out=90,in=150] (12,0.5)
to [out=330,in=180] (13,-1);
\node [snapshot2] at (5.7,1.2) {mark};
\node [snapshot2] at (9,1.9) {set};
\node [snapshot2] at (12,0.9) {go};
\end{tikzpicture}
Bob registers his stake pool in epoch $e_1$.
Alice delegates to Bob's stake pool in epoch $e_1$.
Just before the end of epoch $e_1$, Bob submits a stake pool re-registration,
changing his pool parameters. The change in parameters is not immediate,
as shown by the curved arrow around the epoch boundary.
A snapshot is taken on the $e_1$/$e_2$ boundary. It is labeled ``mark'' initially.
This snapshot includes Alice's delegation to Bob's pool, and Bob's pool parameters
and listed in the initial pool registration certificate.
If Alice changes her delegation choice any time during epoch $e_2$,
she will never be effected by Bob's change of parameters.
A new snapshot is taken on the $e_2$/$e_3$ boundary.
The previous (darker blue) snapshot is now labeled ``set'', and the new one labeled ``mark''.
The ``set'' snapshot is used for leader election in epoch $e_3$.
On the $e_3$/$e_4$ boundary, the darker blue snapshot is labeled ``go'' and
the lighter blue snapshot is labeled ``set''.
Bob's stake pool performance during epoch $e_3$ (he produced 4 blocks)
will be used with the darker blue snapshot for the rewards which will
be handed out at the beginning of epoch $e_5$.
\subsection{Helper Functions and Accounting Fields}
\label{sec:stake-dist-helpers}
Figure~\ref{fig:funcs:epoch-helper-rewards} defines four helper functions needed
throughout the rest of the section.
\begin{itemize}
\item The function $\fun{obligation}$ calculates the the minimal amount of coin needed to
pay out all deposit refunds.
\item The function $\fun{poolStake}$ filters the stake distribution to one stake pool.
\end{itemize}
%%
%% Figure - Helper Functions for Epoch Rules
%%
\begin{figure}[htb]
\emph{Total possible refunds}
\begin{align*}
& \fun{obligation} \in \PParams \to (\StakeCredential \mapsto \Coin)
\to (\KeyHash_{pool}\mapsto\PoolParam) \to \Coin \\
& \obligation{pp}{rewards}{poolParams} = \\
& ~~~~~
(\fun{keyDeposit}~\var{pp}) \cdot|\var{rewards}| +
(\fun{poolDeposit}~\var{pp}) \cdot|\var{poolParams}| \\
\end{align*}
%
\emph{Filter Stake to one Pool}
\begin{align*}
& \fun{poolStake} \in \KeyHash_{pool} \to (\KeyHash_{stake} \mapsto \KeyHash_{pool})
\to \Stake \to \Stake \\
& \poolStake{hk}{delegs}{stake} =
\dom{(\var{delegs}\restrictrange\{hk\})\restrictdom\var{stake}}
\end{align*}
\caption{Helper Functions used in Rewards and Epoch Boundary}
\label{fig:funcs:epoch-helper-rewards}
\end{figure}
The Figure~\ref{fig:defs:accounting} lists the accounting fields, denoted by $\Acnt$,
which will be used throughout this section. It consists of:
\begin{itemize}
\item The value $\var{treasury}$ tracks the amount of coin currently stored in the treasury.
Initially there will be no way to remove these funds.
\item The value $\var{reserves}$ tracks the amount of coin currently stored in the reserves.
This pot is used to pay rewards.
\end{itemize}
More will be said about the general accounting system in Section~\ref{sec:reward-calc}.
%%
%% Figure - Accounting fields
%%
\begin{figure}[htb]
\emph{Accounting Fields}
\begin{equation*}
\Acnt =
\left(
\begin{array}{r@{~\in~}ll}
\var{treasury} & \Coin & \text{treasury pot}\\
\var{reserves} & \Coin & \text{reserve pot}\\
\end{array}
\right)
\end{equation*}
%
\caption{Accounting fields}
\label{fig:defs:accounting}
\end{figure}
\subsection{Stake Distribution Calculation}
\label{sec:stake-dist-calc}
This section defines the stake distribution calculations.
Figure~\ref{fig:epoch-defs} introduces three new derived types:
\begin{itemize}
\item $\type{BlocksMade}$ represents the number of blocks each stake pool produced
during an epoch.
\item $\type{Stake}$ represents the amount of stake (in $\type{Coin}$) controlled by each
stake pool.
\end{itemize}
%%
%% Figure - Epoch Abstract Types
%%
\begin{figure}[htb]
\emph{Derived types}
%
\begin{equation*}
\begin{array}{r@{~\in~}l@{\qquad=\qquad}lr}
\var{blocks}
& \BlocksMade
& \KeyHash_{pool} \mapsto \N
& \text{blocks made by stake pools} \\
\var{stake}
& \Stake
& \Credential \mapsto \Coin
& \text{stake} \\
\end{array}
\end{equation*}
\caption{Epoch definitions}
\label{fig:epoch-defs}
\end{figure}
The stake distribution calculation is given in Figure~\ref{fig:functions:stake-distribution}.
\begin{itemize}
\item $\fun{aggregate_{+}}$ takes a relation on $A\times B$, where $B$ is any
monoid $(B,+,e)$ and returns a map from each $a\in A$ to the ``sum'' (using
the monoidal $+$ operation) of all $b\in B$ such that $(a, b)\in A\times B$.
\item $\fun{stakeDistr}$ uses the $\fun{aggregate_{+}}$ function and several relations to
compute the stake distribution, mapping each hashkey to the total coin under its control.
Keys that are not both registered and delegated are filtered out.
The relation passed to $\fun{aggregate_{+}}$ is made up of:
\begin{itemize}
\item $\fun{stakeCred_b}^{-1}$, relating credentials to (base) addresses
\item $\left(\fun{addrPtr}\circ\var{ptr}\right)^{-1}$, relating credentials to (pointer)
addresses
\item $\range{utxo}$, relating addresses to coins
\item $\fun{stakeCred_r}^{-1}\circ\var{rewards}$, relating (reward) addresses to coins
\end{itemize}
The notation for relations is explained in Section~\ref{sec:notation-shelley}.
\end{itemize}
%%
%% Figure Functions for Stake Distribution
%%
\begin{figure}[htb]
\emph{Aggregation (for a monoid B)}
%
\begin{align*}
& \fun{aggregate_{+}} \in \powerset{(A \times B)} \to (A\mapsto B) \\
& \fun{aggregate_{+}}~\var{R} = \left\{a\mapsto \sum_{(a,b)\in\var{R}}b
~\mid~a\in\dom\var{R}\right\} \\
\end{align*}
%
\emph{Stake Distribution (using functions and maps as relations)}
%
\begin{align*}
& \fun{stakeDistr} \in \UTxO \to \DState \to \PState \to \Snapshot \\
& \fun{stakeDistr}~{utxo}~{dstate}~{pstate} = \\
& ~~~~ \big((\dom{\var{activeDelegs}})
\restrictdom\left(\fun{aggregate_{+}}~\var{stakeRelation}\right),
~\var{delegations},~\var{poolParams}\big)\\
& \where \\
& ~~~~ (~\var{rewards},~\var{delegations},~\var{ptrs},~\wcard,~\wcard,~\wcard)
= \var{dstate} \\
& ~~~~ (~\var{poolParams},~\wcard,~\wcard) = \var{pstate} \\
& ~~~~ \var{stakeRelation} = \left(
\left(\fun{stakeCred_b}^{-1}\cup\left(\fun{addrPtr}\circ\var{ptr}\right)^{-1}\right)
\circ\left(\range{\var{utxo}}\right)
\right)
\cup \var{rewards} \\
& ~~~~ \var{activeDelegs} =
(\dom{rewards}) \restrictdom \var{delegations} \restrictrange (\dom{poolParams}) \\
\end{align*}
\caption{Stake Distribution Function}
\label{fig:functions:stake-distribution}
\end{figure}
\clearpage
\subsection{Snapshot Transition}
\label{sec:snapshots}
The state transition types for stake distribution snapshots are given in
Figure~\ref{fig:ts-types:snapshot}.
Each snapshot consists of:
\begin{itemize}
\item $\var{stake}$, a stake distribution, which is defined in
Figure~\ref{fig:epoch-defs} as a mapping of credentials to coin.
\item $\var{delegations}$, a delegation map, mapping credentials to stake pools.
\item $\var{poolParameters}$, storing the pool parameters of each stake pool.
\end{itemize}
The type $\type{\Snapshots}$ contains the
information needing to be saved on the epoch boundary:
\begin{itemize}
\item $\var{pstake_{mark}}$, $\var{pstake_{set}}$ and $\var{pstake_{go}}$ are the three
snapshots as explained in Section~\ref{sec:reward-overview}.
\item $\var{feeSS}$ stores the fees which are added to the reward pot during
the next reward update calculation, which is then subtracted from the fee pot
on the epoch boundary.
\end{itemize}
%%
%% Figure - Snapshots Defs
%%
\begin{figure}[htb]
\emph{Snapshots}
\begin{equation*}
\Snapshot =
\left(
\begin{array}{r@{~\in~}ll}
\var{stake} & \Stake & \text{stake distribution}\\
\var{delegations} & \Credential\mapsto\KeyHash_{pool}
& \text{stake delegations}\\
\var{poolParameters} & \KeyHash_{pool} \mapsto \PoolParam & \text{pool parameters }\\
\end{array}
\right)
\end{equation*}
\begin{equation*}
\Snapshots =
\left(
\begin{array}{r@{~\in~}ll}
\var{pstake_{mark}} & \Snapshot & \text{newest stake}\\
\var{pstake_{set}} & \Snapshot & \text{middle stake}\\
\var{pstake_{go}} & \Snapshot & \text{oldest stake}\\
\var{feeSS} & \Coin & \text{fee snapshot}\\
\end{array}
\right)
\end{equation*}
%
\emph{Snapshot transitions}
\begin{equation*}
\_ \vdash
\var{\_} \trans{snap}{} \var{\_}
\subseteq \powerset (\LState \times \Snapshots \times \Snapshots)
\end{equation*}
%
\caption{Snapshot transition-system types}
\label{fig:ts-types:snapshot}
\end{figure}
The snapshot transition rule is given in Figure~\ref{fig:rules:snapshot}.
This transition has no preconditions and results in the following state change:
\begin{itemize}
\item The oldest snapshot is replaced with the penultimate one.
\item The penultimate snapshot is replaced with the newest one.
\item The newest snapshot is replaced with one just calculated.
\item The current fees pot is stored in $\var{feeSS}$. Note that this value will not
change during the epoch, unlike the $\var{fees}$ value in the UTxO state.
\end{itemize}
%%
%% Figure - Snapshot Rule
%%
\begin{figure}[htb]
\begin{equation}\label{eq:snapshot}
\inference[Snapshot]
{
{
\begin{array}{r@{~\leteq~}l}
((\var{utxo},~\wcard,\var{fees},~\wcard),~(\var{dstate},~\var{pstate})) & \var{lstate} \\
\var{stake} & \stakeDistr{utxo}{dstate}{pstate} \\
\end{array}
}
}
{
\begin{array}{r}
\var{lstate} \\
\end{array}
\vdash
\left(
\begin{array}{r}
\var{pstake_{mark}}\\
\var{pstake_{set}}\\
\var{pstake_{go}}\\
\var{feeSS} \\
\end{array}
\right)
\trans{snap}{}
\left(
\begin{array}{r}
\varUpdate{\var{stake}} \\
\varUpdate{\var{pstake_{mark}}} \\
\varUpdate{\var{pstake_{set}}} \\
\varUpdate{\var{fees}} \\
\end{array}
\right)
}
\end{equation}
\caption{Snapshot Inference Rule}
\label{fig:rules:snapshot}
\end{figure}
\clearpage
\subsection{Pool Reaping Transition}
\label{sec:pool-reap}
Figure~\ref{fig:ts-types:pool-reap} defines the types for the pool reap transition,
which is responsible for removing pools slated for retirement in the given epoch.
%%
%% Figure - Pool Reap Defs
%%
\begin{figure}[htb]
\emph{Pool Reap State}
\begin{equation*}
\PlReapState =
\left(
\begin{array}{r@{~\in~}ll}
\var{utxoSt} & \UTxOState & \text{utxo state}\\
\var{acnt} & \Acnt & \text{accounting}\\
\var{dstate} & \DState & \text{delegation state}\\
\var{pstate} & \PState & \text{pool state}\\
\end{array}
\right)
\end{equation*}
%
\emph{Pool Reap transitions}
\begin{equation*}
\_ \vdash \_ \trans{poolreap}{\_} \_ \in
\powerset (\PParams \times \PlReapState \times \Epoch \times \PlReapState)
\end{equation*}
%
\caption{Pool Reap Transition}
\label{fig:ts-types:pool-reap}
\end{figure}
The pool-reap transition rule is given in Figure~\ref{fig:rules:pool-reap}.
This transition has no preconditions and results in the following state change:
\begin{itemize}
\item For each retiring pool, the refund for the pool registration deposit is added to the
pool's registered reward account, provided the reward account is still registered.
\item The sum of all the refunds attached to unregistered reward accounts are added to the
treasury.
\item The deposit pool is reduced by the amount of claimed and unclaimed refunds.
\item Any delegation to a retiring pool is removed.
\item Each retiring pool is removed from all four maps in the pool state.
\end{itemize}
%%
%% Figure - Pool Reap Rule
%%
\begin{figure}[htb]
\begin{equation}\label{eq:pool-reap}
\inference[Pool-Reap]
{
{
\begin{array}{r@{~\leteq~}l}
\var{retired} & \dom{(\var{retiring}^{-1}~\var{e})} \\
\var{pr} & \left\{
\var{hk}\mapsto(\fun{poolDeposit}~\var{pp})
\mid
\var{hk}\in\var{retired}
\right\}\\
\var{rewardAcnts}
& \{\var{hk}\mapsto \fun{poolRAcnt}~\var{pool} \mid
\var{hk}\mapsto\var{pool} \in \var{retired}\restrictdom\var{poolParams} \} \\
\var{rewardAcnts'} & \left\{
a \mapsto
\sum\var{pr}(\var{rewardAcnts}^{-1}(a))
\mathrel{\Big|}
a\in\range{rewardAcnts}
\right\} \\
\var{refunds} & \dom{rewards}\restrictdom\var{rewardAcnts'} \\
\var{mRefunds} & \dom{rewards}\subtractdom\var{rewardAcnts'} \\
\var{refunded} & \sum\limits_{\wcard\mapsto c\in\var{refunds}} c \\
\var{unclaimed} & \sum\limits_{\wcard\mapsto c\in\var{mRefunds}} c \\
\end{array}
}
}
{
\var{pp}
\vdash
\left(
\begin{array}{r}
\var{utxo} \\
\var{deposited} \\
\var{fees} \\
\var{ppup} \\
~ \\
\var{treasury} \\
\var{reserves} \\
~ \\
\var{rewards} \\
\var{delegations} \\
\var{ptrs} \\
\var{genDelegs} \\
\var{fGenDelegs} \\
\var{i_{rwd}} \\
~ \\
\var{poolParams} \\
\var{fPoolParams} \\
\var{retiring} \\
\end{array}
\right)
\trans{poolreap}{e}
\left(
\begin{array}{rcl}
\var{utxo} \\
\varUpdate{\var{deposited}}
& \varUpdate{-}
& \varUpdate{(\var{unclaimed} + \var{refunded})} \\
\var{fees} \\
\var{ppup} \\
~ \\
\varUpdate{\var{treasury}} & \varUpdate{+} & \varUpdate{\var{unclaimed}} \\
\var{reserves} \\
~ \\
\varUpdate{\var{rewards}} & \varUpdate{\unionoverridePlus} & \varUpdate{\var{refunds}} \\
\varUpdate{\var{delegations}} & \varUpdate{\subtractrange} & \varUpdate{\var{retired}} \\
\var{ptrs} \\
\var{genDelegs} \\
\var{fGenDelegs} \\
\var{i_{rwd}}\\
~ \\
\varUpdate{\var{retired}} & \varUpdate{\subtractdom} & \varUpdate{\var{poolParams}} \\
\varUpdate{\var{retired}} & \varUpdate{\subtractdom} & \varUpdate{\var{fPoolParams}} \\
\varUpdate{\var{retired}} & \varUpdate{\subtractdom} & \varUpdate{\var{retiring}} \\
\end{array}
\right)
}
\end{equation}
\caption{Pool Reap Inference Rule}
\label{fig:rules:pool-reap}
\end{figure}
\clearpage
\subsection{Protocol Parameters Update Transition}
\label{sec:pparam-update}
Finally, reaching the epoch boundary may trigger a change in the protocol parameters.
The protocol parameters environment consists of the delegation and pool states,
and the signal is an optional new collection of protocol parameters
The state change is a change of the $\UTxOState$, the $\Acnt$ states and the current $\PParams$.
The type of this state transition is given in Figure~\ref{fig:ts-types:new-proto-param}.
%%
%% Figure - New Proto Param Defs
%%
\begin{figure}[htb]
\emph{New Proto Param environment}
\begin{equation*}
\NewPParamEnv =
\left(
\begin{array}{r@{~\in~}ll}
\var{dstate} & \DState & \text{delegation state}\\
\var{pstate} & \PState & \text{pool state}\\
\end{array}
\right)
\end{equation*}
%
\emph{New Proto Param States}
\begin{equation*}
\NewPParamState =
\left(
\begin{array}{r@{~\in~}ll}
\var{utxoSt} & \UTxOState & \text{utxo state}\\
\var{acnt} & \Acnt & \text{accounting}\\
\var{pp} & \PParams & \text{current protocol parameters}\\
\end{array}
\right)
\end{equation*}
%
\emph{New Proto Param transitions}
\begin{equation*}
\_ \vdash
\var{\_} \trans{newpp}{\_} \var{\_}
\subseteq \powerset (\NewPParamEnv \times \NewPParamState \times \PParams^? \times \NewPParamState)
\end{equation*}
%
\caption{New Proto Param transition-system types}
\label{fig:ts-types:new-proto-param}
%
\emph{Helper Functions}
\begin{align*}
& \fun{updatePpup} \in \UTxOState \to \PParams \to \UTxOState\\
& \fun{updatePpup}~\var{utxoSt}~\var{pp} =
\begin{cases}
(\var{utxo},\var{deposited},\var{fees},(\var{fpup},~\emptyset))
&
\var{canFollow}
\\
(\var{utxo},\var{deposited},\var{fees},(\emptyset,~\emptyset))
&
\text{otherwise} \\
\end{cases}\\
& ~~~\where \\
& ~~~~~~~\var{canFollow} =
\forall\var{ps}\in\range{pup},~
\var{pv}\mapsto\var{v}\in\var{ps}\implies\fun{pvCanFollow}~(\fun{pv}~\var{pp})~\var{v}
\\
& ~~~~~~~(\var{utxo},\var{deposited},\var{fees},(\var{pup},~\var{fpup})) = \var{utxoSt} \\
\end{align*}
\end{figure}
Figure~\ref{fig:rules:new-proto-param} defines the new protocol parameter transition.
The transition has two rules, depending on whether or not the new protocol parameters
meet some requirements.
In particular, we require that the new parameters would not incur a debt of the system that
can not be covered by the reserves, and that the max block size is greater than the sum of the
max transaction size and the max header size.
If the requirements are met, the new protocol parameters are accepted, the proposal is reset,
and the reserves are adjusted to account for changes in the deposits.
Otherwise, the only change is that the proposal is reset.
The $\mathsf{NEWPP}$ rule also cleans up the protocol parameter update proposals,
by calling $\fun{updatePpup}$ on the UTxO state.
The $\fun{updatePpup}$ sets the protocol parameter updates to the future protocol
parameter updates provided the protocol versions all can follow from the
version given in the protocol parameters, or the emptyset otherwise.
In any case, the future protocol parameters update proposals are set to the empty set.
If new protocol parameters are being adopted, then these is the value given to
$\fun{updatePpup}$, otherwise the old parameters are given.
Regarding adjusting the reserves for changes in the deposits, one of three things happens:
\begin{itemize}
\item If the new protocol parameters mean that \textbf{fewer} funds are required in the
deposit pot to cover all possible refunds, then the excess is moved to the reserves.
\item If the new protocol parameters mean that \textbf{more} funds are required in the
deposit pot to cover all possible refunds and the difference is \textbf{less} than
the reserve pot, then funds are moved from the reserve pot to cover the difference.
\item If the new protocol parameters mean that \textbf{more} funds are required in the
deposit pot to cover all possible refunds and the difference is \textbf{more} than
the reserve pot, then Rule~\ref{eq:new-pc-denied} meets the precondition and the
only change of state is that the update proposals are reset.
\end{itemize}
Note that here, unlike most of the inference rules in this document,
the $\var{utxoSt'}$ and the $\var{acnt'}$ do not come from valid UTxO or
accounts transitions in the antecedent. We simply define the consequent
transition using these directly (instead of listing all the fields in both
states in the consequent transition). It is done this way here
for ease of reading.
%%
%% Figure - New Proto Param Rule
%%
\begin{figure}[htb]
\begin{equation}\label{eq:new-pc-accepted}
\hspace{-0.3cm}
\inference[New-Proto-Param-Accept]
{
\var{pp_{new}}\neq\Nothing \\~\\
{\begin{array}{rcl}
(\var{utxo},~\var{deposited},~\var{fees},~\var{ppup}) & \leteq & \var{utxoSt} \\
\var{(\var{rewards},~\wcard,~\wcard,~\wcard,~\wcard,~\var{i_{rwd}})} &
\leteq & \var{dstate}\\
\var{(\var{poolParams},~\wcard,~\wcard)} & \leteq & \var{pstate}\\
\var{oblg_{cur}} & \leteq & \obligation{pp}{rewards}{poolParams} \\
\var{oblg_{new}} & \leteq & \obligation{pp_{new}}{rewards}{poolParams} \\
\var{diff} & \leteq & \var{oblg_{cur}} - \var{oblg_{new}}\\
\end{array}}
\\~\\~\\
\var{oblg_{cur}} = \var{deposited} \\
\var{reserves} + \var{diff} \geq \sum\limits_{\wcard\mapsto\var{val}\in\var{i_{rwd}}} val \\
\fun{maxTxSize}~\var{pp_{new}} + \fun{maxHeaderSize}~\var{pp_{new}} <
\fun{maxBlockSize}~\var{pp_{new}}
\\~\\
\var{utxoSt'} \leteq
\left(\var{utxo},~\varUpdate{oblg_{new}},~\var{fees},~\var{ppup}\right)
\\
\var{utxoSt''} \leteq \fun{updatePpup}~\var{utxoSt'}~\var{pp_{new}}
\\~\\
(\var{treasury},~\var{reserves})\leteq \var{acnt} \\
\var{acnt'} \leteq (\var{treasury},~\varUpdate{reserves + diff}) \\
}
{
\begin{array}{l}
\var{dstate}\\
\var{pstate}\\
\end{array}
\vdash
\left(
\begin{array}{r}
\var{utxoSt} \\
\var{acnt} \\
\var{pp}
\end{array}
\right)
\trans{newpp}{\var{pp_{new}}}
\left(
\begin{array}{rcl}
\varUpdate{utxoSt''}\\
\varUpdate{acnt'} \\
\varUpdate{\var{pp_{new}}} \\
\end{array}
\right)
}
\end{equation}
\nextdef
\begin{equation}\label{eq:new-pc-denied}
\inference[New-Proto-Param-Denied]
{
\left({\begin{array}{c}
\var{pp_{new}}=\Nothing \\
\lor \\
\var{reserves} + \var{diff} < \sum\limits_{\wcard\mapsto\var{val}\in\var{i_{rwd}}} val\\
\lor \\
\fun{maxTxSize}~\var{pp_{new}} + \fun{maxHeaderSize}~\var{pp_{new}} \geq
\fun{maxBlockSize}~\var{pp_{new}}
\end{array}}\right)
\\~\\~\\
{\begin{array}{rcl}
\var{(\var{rewards},~\wcard,~\wcard,~\wcard,~\wcard,~\var{i_{rwd}})} &
\leteq & \var{dstate}\\
\var{(\var{poolParams},~\wcard,~\wcard)} & \leteq & \var{pstate}\\
\var{oblg_{cur}} & \leteq & \obligation{pp}{rewards}{poolParams} \\
\var{oblg_{new}} & \leteq & \obligation{pp_{new}}{rewards}{poolParams} \\
\var{diff} & \leteq & \var{oblg_{cur}} - \var{oblg_{new}}
\end{array}}
\\~\\~\\
\var{utxoSt'} \leteq \fun{updatePpup}~\var{utxoSt}~\var{pp} \\
}
{
\begin{array}{l}
\var{dstate}\\
\var{pstate}\\
\end{array}
\vdash
\left(
\begin{array}{r}
\var{utxoSt} \\
\var{acnt} \\
\var{pp}
\end{array}
\right)
\trans{newpp}{\var{pp_{new}}}
\left(
\begin{array}{rcl}
\varUpdate{utxoSt'}\\
\var{acnt} \\
\var{pp}
\end{array}
\right)
}
\end{equation}
\caption{New Proto Param Inference Rule}
\label{fig:rules:new-proto-param}
\end{figure}
\clearpage
\subsection{Complete Epoch Boundary Transition}
\label{sec:total-epoch}
Finally, it is possible to define the complete epoch boundary transition type,
which is defined in Figure~\ref{fig:ts-types:epoch}.
The transition has no evironment.
The state is made up of the the accounting state, the snapshots, the ledger state and the
protocol parameters.
The transition uses a helper function $\fun{votedValue}$ which returns
the consensus value of update proposals in the event that consensus is met.
\textbf{Note that} $\fun{votedValue}$
\textbf{is only well-defined if } $\var{quorum}$
\textbf{is greater than half the number of core nodes, i.e.}
$\Quorum > |\var{genDelegs}|/2$ \textbf{.}
%%
%% Figure - Epoch Defs
%%
\begin{figure}[htb]
\emph{Epoch States}
\begin{equation*}
\EpochState =
\left(
\begin{array}{r@{~\in~}ll}
\var{acnt} & \Acnt & \text{accounting}\\
\var{ss} & \Snapshots & \text{snapshots}\\
\var{ls} & \LState & \text{ledger state}\\
\var{prevPp} & \PParams & \text{previous protocol parameters}\\
\var{pp} & \PParams & \text{protocol parameters}\\
\end{array}
\right)
\end{equation*}
%
\emph{Epoch transitions}
\begin{equation*}
\vdash
\var{\_} \trans{epoch}{\_} \var{\_}
\subseteq \powerset (\EpochState \times \Epoch \times \EpochState)
\end{equation*}
%
\emph{Accessor Functions}
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\fun{getIR} & \EpochState \to (\StakeCredential \mapsto \Coin)
& \text{get instantaneous rewards} \\
\end{array}
\end{equation*}
%
\emph{Helper Functions}
\begin{align*}
& \fun{votedValue} \in (\KeyHashGen\mapsto\PParamsUpdate) \to \PParams \to \N \to \PParamsUpdate^?\\
& \fun{votedValue}~\var{pup}~\var{pp}~\var{quorum} =
\begin{cases}
\var{pp}\unionoverrideRight\var{p}
& \exists! p\in\range{pup}~(|pup\restrictrange p|\geq \var{quorum}) \\
\Nothing & \text{otherwise} \\
\end{cases}
\end{align*}
%
\caption{Epoch transition-system types}
\label{fig:ts-types:epoch}
\end{figure}
The epoch transition rule calls $\mathsf{SNAP}$, $\mathsf{POOLREAP}$ and $\mathsf{NEWPP}$
in sequence. It also stores the previous protocol parameters in $\var{prevPp}$.
The previous protocol parameters will be used for the reward calculation in the upcoming epoch,
note that they correspond to the epoch for which the rewards are being calculated.
Additionally, this transition also adopts the pool parameters $\var{fPoolParams}$
corresponding to the pool re-registration certificates which we submitted late in the ending epoch.
The ordering of these rules is important.
The stake pools which will be updated by $\var{fPoolParams}$ or
reaped during the $\mathsf{POOLREAP}$ transition must still be a
part of the new snapshot, and so $\mathsf{SNAP}$ must occur before these two actions.
Moreover, $\mathsf{SNAP}$ sets the deposit pot equal to current obligation,
which is a property that is preserved by $\mathsf{POOLREAP}$ and which
is necessary for the preservation of Ada property in the $ \mathsf{NEWPP}$ transition.
%%
%% Figure - Epoch Rule
%%
\begin{figure}[htb]
\begin{equation}\label{eq:epoch}
\inference[Epoch]
{
{
\begin{array}{r}
\var{lstate} \\
\end{array}
}
\vdash
{ \var{ss} }
\trans{\hyperref[fig:rules:snapshot]{snap}}{}
{ \var{ss'} }
\\~\\
(\var{utxoSt},~(\var{dstate},~\var{pstate}))\leteq\var{ls} \\
(\var{poolParams},~\var{fPoolParams},~\var{retiring})\leteq\var{pstate}
\\
\var{pstate'}\leteq(\var{poolParams}\unionoverrideRight\var{fPoolParams},
~\emptyset,~\var{retiring})
\\~\\~\\
\var{pp}
\vdash
\left(
{
\begin{array}{r}
\var{utxoSt} \\
\var{acnt} \\
\var{dstate} \\
\var{pstate'} \\
\end{array}
}
\right)
\trans{\hyperref[fig:rules:pool-reap]{poolreap}}{e}
\left(
{
\begin{array}{rcl}
\var{utxoSt'} \\
\var{acnt'} \\
\var{dstate'} \\
\var{pstate''} \\
\end{array}
}
\right)
\\~\\~\\
\var{(\wcard,~\wcard,~\wcard,~(\var{pup},\wcard))}\leteq\var{utxoSt'}\\
\var{pp_{new}}\leteq\fun{votedValue}~\var{pup}~\var{pp}~\Quorum\\
{
\begin{array}{r}
\var{dstate'}\\
\var{pstate''}\\
\end{array}
}
\vdash
\left(
{