forked from IntersectMBO/cardano-ledger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelegation.tex
1182 lines (1108 loc) · 39.5 KB
/
delegation.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
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{Delegation}
\label{sec:delegation-shelley}
We briefly describe the motivation and context for delegation.
The full context is contained in \cite{delegation_design}.
Stake is said to be \textit{active} in the blockchain protocol when it is
eligible for participation in the leader election. In order for stake to become
active, the associated verification stake credential must be registered and its
staking rights must be delegated to an active stake pool. Individuals who wish
to participate in the protocol can register themselves as a stake pool.
Stake credentials are registered (or deregistered) through the use of
registration (or deregistration) certificates. Registered stake credentials are
delegated through the use of delegation certificates. Finally, stake pools are
registered (or retired) through the use of registration (or retirement)
certificates.
Stake pool retirement is handled a bit differently than stake deregistration.
Stake credentials are considered inactive as soon as a deregistration
certificate is applied to the ledger state. Stake pool retirement certificates,
however, specify the epoch in which it will retire.
Delegation requires the following to be tracked by the ledger state: the
registered stake credentials, the delegation map from registered stake
credentials to stake pools, pointers associated with stake credentials, the
registered stake pools and upcoming stake pool retirements. Additionally, the
blockchain protocol rewards eligible stake and so we must also include a mapping
from active stake credentials to rewards.
Finally, there are two types of delegation certificates available only to the
genesis keys. The genesis keys will still be used for update proposals at the
beginning of the Shelley era, and so there must be a way to maintain the delegation
of these keys to their cold keys. This mapping is also maintained by the
delegation state. There is also a mechanism to transfer rewards directly from
either the reserves pot or the treasury pot to a reward address.
While technically everybody can post such a certificate,
the transaction that contains it must be signed by $\Quorum$-many
genesis key delegates.
\subsection{Delegation Definitions}
\label{sec:deleg-defs}
In \cref{fig:delegation-defs} we give the delegation primitives.
Here we introduce the following primitive datatypes used in delegation:
\begin{itemize}
\item $\DCertRegKey$: a stake credential registration certificate.
\item $\DCertDeRegKey$: a stake credential de-registration certificate.
\item $\DCertDeleg$: a stake credential delegation certificate.
\item $\DCertRegPool$: a stake pool registration certificate.
\item $\DCertRetirePool$: a stake pool retirement certificate.
\item $\DCertGen$: a genesis key delegation certificate.
\item $\DCertMir$: a move instantaneous rewards certificate.
\item $\DCert$: any one of of the seven certificate types above.
\end{itemize}
The following derived types are introduced:
\begin{itemize}
\item $\PoolParam$ represents the parameters found in a stake pool registration certificate
that must be tracked:
\begin{itemize}
\item the pool owners.
\item the pool cost.
\item the pool margin.
\item the pool pledge.
\item the pool reward account.
\item the hash of the VRF verification key.
\item the pool relays.
\item optional pool metadata (a url and a hash).
\end{itemize}
The idea of pool owners is explained in Section 4.4.4 of \cite{delegation_design}.
The pool cost and margin indicate how much more of the rewards pool leaders
get than the members.
The pool pledge is explained in Section 5.1 of \cite{delegation_design}.
The pool reward account is where all pool rewards go.
The pool relays and metadata url are explained in Sections
3.4.4 and 4.2 of \cite{delegation_design}.
\end{itemize}
Accessor functions for certificates and pool parameters are also defined, but
only the $\cwitness{}$ accessor function needs explanation.
It does the following:
\begin{itemize}
\item For a $\DCertRegKey$ certificate, $\fun{cwitness}$ is not defined as
stake key registrations do not require a witness.
\item For a $\DCertDeRegKey$ certificate, $\fun{cwitness}$ returns the hashkey
of the key being de-registered.
\item For a $\DCertDeleg$ certificate, $\fun{cwitness}$ returns the hashkey
of the key that is delegating (and not the key to which the stake in being delegated to).
\item For a $\DCertRegPool$ certificate, $\fun{cwitness}$ returns the hashkey
of the key of the pool operator.
\item For a $\DCertRetirePool$ certificate, $\fun{cwitness}$ returns the hashkey
of the key of the pool operator.
\item For a $\DCertGen$ certificate, $\fun{cwitness}$ returns the hashkey
of the genesis key.
\item For a $\DCertMir$ certificate, $\fun{cwitness}$ is not defined as there is
no single core node or genesis key that posts the certificate.
\end{itemize}
%%
%% Figure - Delegation Definitions
%%
\begin{figure}[htb]
\emph{Abstract types}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\var{url} & \URL & \text{a url}\\
\var{mp} & \MIRPot & \text{either $\ReservesMIR$ or $\TreasuryMIR$}\\
\end{array}
\end{equation*}
%
\emph{Delegation Certificate types}
%
\begin{equation*}
\begin{array}{r@{}c@{}l}
\DCert &=& \DCertRegKey \uniondistinct \DCertDeRegKey \uniondistinct \DCertDeleg \\
&\hfill\uniondistinct\;&
\DCertRegPool \uniondistinct \DCertRetirePool \uniondistinct
\DCertGen\\
&\hfill\uniondistinct\;& \DCertMir
\end{array}
\end{equation*}
%
\emph{Derived types}
\begin{equation*}
\begin{array}{lclr}
\PoolMD
& ~=~
& \URL \times \type{PoolMDHash}
& \text{stake pool metadata} \\
%
\PoolParam
& ~=~
& \powerset{\KeyHash} \times \Coin \times \unitInterval \times \Coin
& \text{stake pool parameters} \\
& & \qquad \times \AddrRWD \times \KeyHash_{vrf} \\
& & \qquad \seqof{\URL} \times \PoolMD^?
\end{array}
\end{equation*}
%
\emph{Certificate Accessor functions}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\cwitness{} & \DCert\setminus(\DCertRegKey\cup\DCertMir) \to \Credential & \text{certificate witness} \\
\fun{regCred} & \DCertRegKey \to \Credential & \text{registered credential} \\
\fun{dpool} & \DCertDeleg \to \KeyHash
& \text{pool being delegated to}
\\
\fun{poolParam} & \DCertRegPool \to \PoolParam
& \text{stake pool}
\\
\fun{retire} & \DCertRetirePool \to \Epoch
& \text{epoch of pool retirement}
\\
\fun{genesisDeleg} & \DCertGen \to (\KeyHashGen,~\KeyHash,~\KeyHash_{vrf})
& \text{genesis delegation}
\\
\fun{credCoinMap} & \DCertMir \to (\StakeCredential \mapsto \Coin)
& \text{moved inst. rewards}
\\
\fun{mirPot} & \DCertMir \to \MIRPot & \text{pot for inst. rewards}
\end{array}
\end{equation*}
%
\emph{Pool Parameter Accessor functions}
%
\begin{equation*}
\begin{array}{r@{~\in~}lr}
\fun{poolOwners} & \PoolParam \to \powerset{\KeyHash}
& \text{stake pool owners}
\\
\fun{poolCost} & \PoolParam \to \Coin
& \text{stake pool cost}
\\
\fun{poolMargin} & \PoolParam \to \unitInterval
& \text{stake pool margin}
\\
\fun{poolPledge} & \PoolParam \to \Coin
& \text{stake pool pledge}
\\
\fun{poolRAcnt} & \PoolParam \to \AddrRWD
& \text{stake pool reward account}
\\
\fun{poolVRF} & \PoolParam \to \KeyHash_{vrf}
& \text{stake pool VRF key hash}
\\
\end{array}
\end{equation*}
\caption{Delegation Definitions}
\label{fig:delegation-defs}
\end{figure}
\clearpage
\subsection{Delegation Transitions}
\label{sec:deleg-trans}
In \cref{fig:delegation-transitions} we give the delegation and stake pool
state transition types. We define two separate parts of the ledger state.
\begin{itemize}
\item $\DState$ keeps track of the delegation state, consisting of:
\begin{itemize}
\item $\var{rewards}$ stores the rewards accumulated by stake credentials.
These are represented by a finite map from reward addresses to the
accumulated rewards.
\item $\var{delegations}$ stores the delegation relation, mapping stake
credentials to the pool to which is delegates.
\item $\var{ptrs}$ maps stake credentials to the position of the
registration certificate in the blockchain. This is needed to lookup the
stake hashkey of a pointer address.
\item $\var{fGenDelegs}$ are the future genesis keys delegations. This variable
is needed because genesis keys can only update their delegation with a
delay of $\StabilityWindow$ slots after submitting the certificate (this is
necessary for header validation, see Section \ref{sec:chain})
\item $\var{genDelegs}$ maps genesis key hashes to hashes of the cold key
delegates.
\item $\var{i_{rwd}}$ stores two maps of stake credentials to $\Coin$,
which is used for moving instantaneous rewards at the epoch boundary.
One map corresponds to rewards taken from the reserves,
and the other corresponds to rewards taken from the treasury.
\end{itemize}
\item $\PState$ keeps track of the stake pool information:
\begin{itemize}
\item $\var{poolParams}$ tracks the parameters associated with each stake pool, such as
their costs and margin.
\item When changes are made to the pool parameters late in an epoch, they are staged
in $\var{fPoolParams}$.
These parameters will be updated by another transition (namely $\mathsf{EPOCH}$)
when the next epoch starts.
\item $\var{retiring}$ tracks stake pool retirements, using a map from hashkeys to
the epoch in which it will retire.
\end{itemize}
\end{itemize}
The operational certificates counters $\var{cs}$ in the stake pool state are a
tool to ensure that blocks containing outdated certificates are rejected.
These certificates are part of the block header.
For a discussion of why this additional mechanism is needed,
see the document~\cite{delegation_design}, and for
the relevant rules, see Section \ref{sec:oper-cert-trans}.
The environment for the state transition for $\DState$ contains the current slot number,
the index for the current certificate pointer, and the account state.
The environment for the state transition for $\PState$ contains the current slot number
and the protocol parameters.
%%
%% Figure - Delegation Transitions
%%
\begin{figure}
\emph{Delegation Types}
\begin{equation*}
\begin{array}{rclclr}
\var{stakeCred} & \in & \StakeCredential & = & (\KeyHash_{stake} \uniondistinct
\HashScr) \\
\var{fGenDelegs} & \in & \FutGenesisDelegation & =
& (\Slot\times\KeyHashGen)\mapsto(\KeyHash\times\KeyHash_{vrf}) \\
\var{ir} & \in & \InstantaneousRewards & =
& (\StakeCredential \mapsto \Coin) \\
& & & & ~~~~\times(\StakeCredential \mapsto \Coin) \\
\end{array}
\end{equation*}
%
\emph{Delegation States}
%
\begin{equation*}
\begin{array}{l}
\DState =
\left(\begin{array}{r@{~\in~}lr}
\var{rewards} & \StakeCredential \mapsto \Coin & \text{rewards}\\
\var{delegations} & \StakeCredential \mapsto \KeyHash_{pool} & \text{delegations}\\
\var{ptrs} & \Ptr \mapsto \StakeCredential & \text{pointer to stake credential}\\
\var{fGenDelegs} & \FutGenesisDelegation & \text{future genesis key delegations}\\
\var{genDelegs} & \GenesisDelegation & \text{genesis key delegations}\\
\var{i_{rwd}} & \InstantaneousRewards & \text{instantaneous rewards}\\
\end{array}
\right)
\\
\\
\PState =
\left(\begin{array}{r@{~\in~}lr}
\var{poolParams} & \KeyHash_{pool} \mapsto \PoolParam
& \text{registered pools to pool parameters}\\
\var{fPoolParams} & \KeyHash_{pool} \mapsto \PoolParam
& \text{future pool parameters}\\
\var{retiring} & \KeyHash_{pool} \mapsto \Epoch & \text{retiring stake pools}\\
\end{array}\right)
\end{array}
\end{equation*}
%
\emph{Delegation Environment}
\begin{equation*}
\DEnv =
\left(
\begin{array}{r@{~\in~}lr}
\var{slot} & \Slot & \text{slot}\\
\var{ptr} & \Ptr & \text{certificate pointer}\\
\var{acnt} & \Acnt & \text{accounting state}
\end{array}
\right)
\end{equation*}
%
\emph{Pool Environment}
\begin{equation*}
\PEnv =
\left(
\begin{array}{r@{~\in~}lr}
\var{slot} & \Slot & \text{slot}\\
\var{pp} & \PParams & \text{protocol parameters}\\
\end{array}
\right)
\end{equation*}
%
\emph{Delegation Transitions}
\begin{equation*}
\_ \vdash \_ \trans{deleg}{\_} \_ \in
\powerset (\DEnv \times \DState \times \DCert \times \DState)
\end{equation*}
%
\begin{equation*}
\_ \vdash \_ \trans{pool}{\_} \_ \in
\powerset (\PEnv \times \PState \times \DCert \times \PState)
\end{equation*}
%
\caption{Delegation Transitions}
\label{fig:delegation-transitions}
\end{figure}
\clearpage
\subsection{Delegation Rules}
\label{sec:deleg-rules}
The rules for registering and delegating stake credentials are given in
\cref{fig:delegation-rules}. Note that section 5.2 of \cite{delegation_design}
describes how a wallet would help a user choose a stake pool, though these
concerns are independent of the ledger rules.
\begin{itemize}
\item Stake credential registration is handled by \cref{eq:deleg-reg}, since it
contains the precondition that the certificate has type $\DCertRegKey$. All
the equations in $\mathsf{DELEG}$ and $\mathsf{POOL}$ follow this same pattern
of matching on certificate type.
There is also a precondition on registration that the hashkey associated with
the certificate witness of the certificate is not already found in the current
reward accounts (which is the source of truth for which stake credentials are registered).
Registration causes the following state transformation:
\begin{itemize}
\item A reward account is created for this key, with a starting balance of zero.
\item The certificate pointer is mapped to the new stake credential.
\end{itemize}
\item Stake credential deregistration is handled by \cref{eq:deleg-dereg}.
There is a precondition that the credential has been registered and that
the reward balance is zero. Deregistration causes the following state
transformation:
\begin{itemize}
\item The key is removed from the collection of registered keys.
\item The reward account is removed.
\item The key is removed from the delegation relation.
\item The certificate pointer is removed.
\end{itemize}
\item Stake credential delegation is handled by \cref{eq:deleg-deleg}.
There is a precondition that the key has been registered.
Delegation causes the following state transformation:
\begin{itemize}
\item The delegation relation is updated so that the stake credential is
delegated to the given stake pool. The use of union override here allows
us to use the same rule to perform both an initial delegation and an
update to an existing delegation.
\end{itemize}
\item Genesis key delegation is handled by \cref{eq:deleg-gen}.
There is a precondition that the genesis key is already in the mapping $\var{genDelegs}$.
Genesis delegation causes the following state transformation:
\begin{itemize}
\item The future genesis delegation relation is updated with the new delegate
to be adopted in $\StabilityWindow$-many slots.
\end{itemize}
\item Moving instantaneous rewards is handled by
\cref{eq:deleg-mir-reserves} and \cref{eq:deleg-mir-treasury}.
There is a precondition that the current slot is early enough in the current
epoch and that the available reserves or treasury are sufficient to pay for the
instantaneous rewards.
\end{itemize}
%%
%% Figure - Delegation Rules
%%
\begin{figure}[hbt]
\centering
\begin{equation}\label{eq:deleg-reg}
\inference[Deleg-Reg]
{
\var{c}\in\DCertRegKey &
hk \leteq \fun{regCred}~{c} &
\var{hk} \notin \dom \var{rewards}
}
{
\begin{array}{r}
\var{slot} \\
\var{ptr} \\
\var{acnt}
\end{array}
\vdash
\left(
\begin{array}{r}
\var{rewards} \\
\var{delegations} \\
\var{ptrs} \\
\var{fGenDelegs} \\
\var{genDelegs} \\
\var{i_{rwd}}
\end{array}
\right)
\trans{deleg}{\var{c}}
\left(
\begin{array}{rcl}
\varUpdate{\var{rewards}} & \varUpdate{\union} & \varUpdate{\{\var{hk} \mapsto 0\}}\\
\var{delegations} \\
\varUpdate{\var{ptrs}} & \varUpdate{\union} & \varUpdate{\{ptr \mapsto \var{hk}\}} \\
\var{fGenDelegs} \\
\var{genDelegs} \\
\var{i_{rwd}}
\end{array}
\right)
}
\end{equation}
\begin{equation}\label{eq:deleg-dereg}
\inference[Deleg-Dereg]
{
\var{c}\in \DCertDeRegKey &
hk \leteq \cwitness{c} &
\var{hk} \mapsto 0 \in \var{rewards}
}
{
\begin{array}{r}
\var{slot} \\
\var{ptr} \\
\var{acnt}
\end{array}
\vdash
\left(
\begin{array}{r}
\var{rewards} \\
\var{delegations} \\
\var{ptrs} \\
\var{fGenDelegs} \\
\var{genDelegs} \\
\var{i_{rwd}}
\end{array}
\right)
\trans{deleg}{\var{c}}
\left(
\begin{array}{rcl}
\varUpdate{\{\var{hk}\}} & \varUpdate{\subtractdom} & \varUpdate{\var{rewards}} \\
\varUpdate{\{\var{hk}\}} & \varUpdate{\subtractdom} & \varUpdate{\var{delegations}} \\
\varUpdate{\var{ptrs}} & \varUpdate{\subtractrange} & \varUpdate{\{\var{hk}\}} \\
\var{fGenDelegs} \\
\var{genDelegs} \\
\var{i_{rwd}}
\end{array}
\right)
}
\end{equation}
\begin{equation}\label{eq:deleg-deleg}
\inference[Deleg-Deleg]
{
\var{c}\in \DCertDeleg & hk \leteq \cwitness{c} & hk \in \dom \var{rewards}
}
{
\begin{array}{r}
\var{slot} \\
\var{ptr} \\
\var{acnt}
\end{array}
\vdash
\left(
\begin{array}{r}
\var{rewards} \\
\var{delegations} \\
\var{ptrs} \\
\var{fGenDelegs} \\
\var{genDelegs} \\
\var{i_{rwd}}
\end{array}
\right)
\trans{deleg}{c}
\left(
\begin{array}{rcl}
\var{rewards} \\
\varUpdate{\var{delegations}} & \varUpdate{\unionoverrideRight}
& \varUpdate{\{\var{hk} \mapsto \dpool c\}} \\
\var{ptrs} \\
\var{fGenDelegs} \\
\var{genDelegs} \\
\var{i_{rwd}}
\end{array}
\right)
}
\end{equation}
\begin{equation}\label{eq:deleg-gen}
\inference[Deleg-Gen]
{
\var{c}\in \DCertGen
& (\var{gkh},~\var{vkh},~\var{vrf})\leteq\fun{genesisDeleg}~{c}
\\
s'\leteq\var{slot}+\StabilityWindow
& \var{gkh}\in\dom{genDelegs}
\\~\\
{
\begin{array}{ l @{\leteq \{(k,~v) ~\mid~(} c @{\mapsto(k,~v))\in~} l @{,~\var{g}\neq\var{gkh}\}} }
\var{cod} & \var{g} & \var{genDelegs} \\
\var{fod} & (\wcard,~\var{g}) & \var{fGenDelegs}
\end{array}
}
\\~\\
{
\begin{array}{ l @{~\leteq~\{} c @{~\mid~\wcard\mapsto} c @{\in~} l @{\}}}
\var{currentOtherColdKeyHashes} & \var{k} & (\var{k},~\wcard) & \var{cod}\\
\var{currentOtherVrfKeyHashes} & \var{v} & (\wcard,~\var{v}) & \var{cod}\\
\var{futureOtherColdKeyHashes} & \var{k} & (\var{k},~\wcard) & \var{fod}\\
\var{futureOtherVrfKeyHashes} & \var{v} & (\wcard,~\var{v}) & \var{fod}\\
\end{array}
}
\\
\var{vkh}\notin\var{currentOtherColdKeyHashes}\union\var{futureOtherColdKeyHashes} \\
\var{vrf}\notin\var{currentOtherVrfKeyHashes}\union\var{futureOtherVrfKeyHashes} \\
\var{fdeleg}\leteq\{(\var{s'},~\var{gkh}) \mapsto (\var{vkh},~\var{vrf})\}
}
{
\begin{array}{r}
\var{slot} \\
\var{ptr} \\
\var{acnt}
\end{array}
\vdash
\left(
\begin{array}{r}
\var{rewards} \\
\var{delegations} \\
\var{ptrs} \\
\var{fGenDelegs} \\
\var{genDelegs} \\
\var{i_{rwd}}
\end{array}
\right)
\trans{deleg}{c}
\left(
\begin{array}{rcl}
\var{rewards} \\
\var{delegations} \\
\var{ptrs} \\
\varUpdate{\var{fGenDelegs}}
& \varUpdate{\unionoverrideRight}
& \varUpdate{fdeleg} \\
\var{genDelegs} \\
\var{i_{rwd}}
\end{array}
\right)
}
\end{equation}
\caption{Delegation Inference Rules}
\label{fig:delegation-rules}
\end{figure}
\begin{figure}[htp]
\centering
\begin{equation}\label{eq:deleg-mir}
\inference[Deleg-Mir]
{
\var{c}\in \DCertMir
\\
slot < \fun{firstSlot}~((\epoch{slot}) + 1) - \fun{StabilityWindow}\\
(\var{irR},~\var{irT})\leteq\var{i_{rwd}}
&
(\var{treasury},~\var{reserves})\leteq\var{acnt}
\\
(\var{pot},~\var{irPot})\leteq
{\begin{cases}
(\var{reserves},~\var{irR}) & \fun{mirPot}~\var{c}=\ReservesMIR \\
(\var{treasury},~\var{irT}) & \fun{mirPot}~\var{c}=\TreasuryMIR
\end{cases}}
\\
\var{combined}\leteq(\fun{mirTarget}~\var{c})\unionoverrideLeft\var{irPot}
\\
\sum\limits_{\wcard\mapsto\var{val}\in\var{combined}} val \leq\var{pot}
\\
\forall \var{r}\in\range{\var{irPot}},~r\geq 0
\\
\var{i_{rwd}'}\leteq
{\begin{cases}
(\var{combined},~\var{irT}) & \fun{mirPot}~\var{c}=\ReservesMIR \\
(\var{irR},~\var{combined}) & \fun{mirPot}~\var{c}=\TreasuryMIR
\end{cases}}
}
{
\begin{array}{r}
\var{slot} \\
\var{ptr} \\
\var{acnt}
\end{array}
\vdash
\left(
\begin{array}{r}
\var{rewards} \\
\var{delegations} \\
\var{ptrs} \\
\var{fGenDelegs} \\
\var{genDelegs} \\
\var{i_{rwd}}
\end{array}
\right)
\trans{deleg}{c}
\left(
\begin{array}{c}
\var{rewards} \\
\var{delegations} \\
\var{ptrs} \\
\var{fGenDelegs}\\
\var{genDelegs} \\
\varUpdate{\var{i_{rwd}'}} \\
\end{array}
\right)
}
\end{equation}
\caption{Move Instantaneous Rewards Inference Rule}
\label{fig:dcert-mir}
\end{figure}
The DELEG rule has ten possible predicate failures:
\begin{itemize}
\item In the case of a key registration certificate, if the staking credential
is already registered, there is a \emph{StakeKeyAlreadyRegistered} failure.
\item In the case of a key deregistration certificate, if the key is not
registered, there is a \emph{StakeKeyNotRegistered} failure.
\item In the case of a key deregistration certificate, if the associated
reward account is non-zero, there is a \emph{StakeKeyNonZeroAccountBalance} failure.
\item In the case of a non-existing stake pool key in a delegation certificate,
there is a \emph{StakeDelegationImpossible} failure.
\item In the case of a pool delegation certificate, there is a
\emph{WrongCertificateType} failure.
\item In the case of a genesis key delegation certificate, if the genesis key is not
in the domain of the genesis delegation mapping, there is a
\emph{GenesisKeyNotInMapping} failure.
\item In the case of a genesis key delegation certificate, if the delegate key is
in the range of the genesis delegation mapping, there is a
\emph{DuplicateGenesisDelegate} failure.
\item In the case of insufficient reserves to pay the instantaneous rewards,
there is a \emph{InsufficientForInstantaneousRewards} failure.
\item In the case that a MIR certificate is issued during the last
$\StabilityWindow$-many slots of the epoch,
there is a \emph{MIRCertificateTooLateinEpoch} failure.
\item In the case of a genesis key delegation certificate, if the VRF key is
in the range of the genesis delegation mapping, there is a
\emph{DuplicateGenesisVRF} failure.
\end{itemize}
\clearpage
\subsection{Stake Pool Rules}
\label{sec:pool-rules}
The rules for updating the part of the ledger state defining the current stake
pools are given in \cref{fig:pool-rules}. The calculation of stake distribution
is described in Section~\ref{sec:stake-dist-calc}.
In the pool rules, the stake pool is identified with the hashkey of the pool operator.
For each rule, again, we first check that a given certificate $c$ is of the correct type.
\begin{itemize}
\item Stake pool registration is handled by \cref{eq:pool-reg}.
It is required that the pool not be currently registered.
Registration causes the following state transformation:
\begin{itemize}
\item The key is added to the set of registered stake pools.
\item The pool's parameters are stored.
\end{itemize}
\item Stake pool parameter updates are handled by \cref{eq:pool-rereg}.
This rule, which also matches on the certificate type $\type{DCertRegPool}$,
is distinguished from \cref{eq:pool-reg} by the requirement that the pool be registered.
Unlike the initial stake pool registrations, the pool parameters will not change
until the next epoch, after stake distribution snapshots are taken.
This gives delegators an entire epoch to respond to changes in stake pool parameters.
The staging is achieved by adding updates to the mapping $\var{fPoolParams}$,
which will override $\var{poolParam}$ with new values in the $\mathsf{EPOCH}$ transition
(see Figure~\cref{fig:rules:epoch}).
This rule also ends stake pool retirements.
Note that $\var{poolParams}$ is \textbf{not} updated.
The registration creation slot does does not change.
\item Stake pool retirements are handled by \cref{eq:pool-ret}.
Given a slot number $\var{slot}$, the application of this rule requires that the
planned retirement epoch $\var{e}$ stated in the certificate is in the future,
i.e.~after $\var{cepoch}$ (the epoch of the current slot number in this context) and
that it is no more than than $\emax$ epochs after the current one.
It is also required that the pool be registered.
Note that imposing the $\emax$ constraint on the system is not strictly necessary.
However, forcing stake pools to announce their retirement a shorter time in
advance will curb the growth of the $\var{retiring}$ list in the ledger state.
The pools scheduled for retirement must be removed from
the $\var{retiring}$ state variable at the end of the epoch they are scheduled
to retire in. This non-signaled transition (triggered, instead, directly by a
change of current slot number in the environment), along with all other transitions
that take place at the epoch boundary, are described in Section~\ref{sec:epoch}.
Retirement causes the following state transformation:
\begin{itemize}
\item The pool is marked to retire on the given epoch.
If it was previously retiring, the retirement epoch is now updated.
\end{itemize}
\end{itemize}
%%
%% Figure - Pool Rules
%%
\begin{figure}[hbt]
\begin{equation}\label{eq:pool-reg}
\inference[Pool-Reg]
{
\var{c}\in\DCertRegPool
& \var{hk} \leteq \cwitness{c}
& \var{pool} \leteq \poolParam{c}
\\
hk \notin \dom \var{poolParams}
& \fun{poolCost}~\var{pool}\geq\fun{minPoolCost}~\var{pp}
}
{
\begin{array}{r}
\var{slot} \\
\var{pp} \\
\end{array}
\vdash
\left(
\begin{array}{r}
\var{poolParams} \\
\var{fPoolParams} \\
\var{retiring} \\
\end{array}
\right)
\trans{pool}{c}
\left(
\begin{array}{rcl}
\varUpdate{\var{poolParams}} & \varUpdate{\union}
& \varUpdate{\{\var{hk} \mapsto \var{pool}\}} \\
\var{fPoolParams} \\
\var{retiring} \\
\end{array}
\right)
}
\end{equation}
\begin{equation}\label{eq:pool-rereg}
\inference[Pool-reReg]
{
\var{c}\in\DCertRegPool
& \var{hk} \leteq \cwitness{c}
& \var{pool} \leteq \poolParam{c}
\\
hk \in \dom \var{poolParams}
& \fun{poolCost}~\var{pool}\geq\fun{minPoolCost}~\var{pp}
}
{
\begin{array}{r}
\var{slot} \\
\var{pp} \\
\end{array}
\vdash
\left(
\begin{array}{r}
\var{poolParams} \\
\var{fPoolParams} \\
\var{retiring} \\
\end{array}
\right)
\trans{pool}{c}
\left(
\begin{array}{rcl}
\var{poolParams} \\
\varUpdate{\var{fPoolParams}} & \varUpdate{\unionoverrideRight}
& \varUpdate{\{\var{hk} \mapsto \var{pool}\}}\\
\varUpdate{\{\var{hk}\}} & \varUpdate{\subtractdom} & \varUpdate{\var{retiring}} \\
\end{array}
\right)
}
\end{equation}
\begin{equation}\label{eq:pool-ret}
\inference[Pool-Retire]
{
\var{c} \in \DCertRetirePool
& hk \leteq \cwitness{c}
& \var{hk} \in \dom \var{poolParams} \\
\var{e} \leteq \retire{c}
& \var{cepoch} \leteq \epoch{slot}
& \var{cepoch} < \var{e} \leq \var{cepoch} + (\fun{emax}~{pp})
}
{
\begin{array}{r}
\var{slot} \\
\var{pp} \\
\end{array}
\vdash
\left(
\begin{array}{r}
\var{poolParams} \\
\var{fPoolParams} \\
\var{retiring} \\
\end{array}
\right)
\trans{pool}{c}
\left(
\begin{array}{rcl}
\var{poolParams} \\
\var{fPoolParams} \\
\varUpdate{\var{retiring}} & \varUpdate{\unionoverrideRight}
& \varUpdate{\{\var{hk} \mapsto \var{e}\}} \\
\end{array}
\right)
}
\end{equation}
\caption{Pool Inference Rule}
\label{fig:pool-rules}
\end{figure}
The POOL rule has four predicate failures:
\begin{itemize}
\item In the case of a pool registration or re-registration certificate,
if specified pool cost parameter is smaller than the value of the
protocol parameter $\mathsf{minPoolCost}$, there is a \emph{StakePoolCostTooLow} failure.
\item In the case of a pool retirement certificate, if the pool key is not in
the domain of the stake pools mapping, there is a
\emph{StakePoolNotRegisteredOnKey} failure.
\item In the case of a pool retirement certificate, if the retirement epoch is
not between the current epoch and the relative maximal epoch from the current
epoch, there is a \emph{StakePoolRetirementWrongEpoch} failure.
\item If the delegation certificate is not of one of the pool types, there is a
\emph{WrongCertificateType} failure.
\end{itemize}
\clearpage
\subsection{Delegation and Pool Combined Rules}
\label{sec:del-pool-rules}
We now combine the delegation and pool transition systems.
Figure~\ref{fig:defs:delpl} gives the state, environment and transition type for the
combined transition.
\begin{figure}[hbt]
\emph{Delegation and Pool Combined Environment}
\begin{equation*}
\DPEnv =
\left(
\begin{array}{r@{~\in~}lr}
\var{slot} & \Slot & \text{slot}\\
\var{ptr} & \Ptr & \text{certificate pointer}\\
\var{pp} & \PParams & \text{protocol parameters}\\
\var{acnt} & \Acnt & \text{accounting state}
\end{array}
\right)
\end{equation*}
%
\emph{Delegation and Pool Combined State}
\begin{equation*}
\DPState =
\left(
\begin{array}{r@{~\in~}lr}
\var{dstate} & \DState & \text{delegation state}\\
\var{pstate} & \PState & \text{pool state}\\
\end{array}
\right)
\end{equation*}
%
\emph{Delegation and Pool Combined Transition}
\begin{equation*}
\_ \vdash \_ \trans{delpl}{\_} \_ \in
\powerset (
\DPEnv \times \DPState \times \DCert \times \DPState)
\end{equation*}
\caption{Delegation and Pool Combined Transition Type}
\label{fig:defs:delpl}
\end{figure}
\clearpage
Figure~\ref{fig:rules:delpl}, gives the rules for the combined transition.
Note that for any given certificate, at most one of the two rules
(\cref{eq:delpl-d} and \cref{eq:delpl-p})
will be successful, since the pool certificates are disjoint from the delegation certificates.
\begin{figure}[hbt]
\emph{Delegation and Pool Combined Rules}
\begin{equation}
\label{eq:delpl-d}
\inference[Delpl-Deleg]
{
&
{
\begin{array}{r}
\var{slot} \\
\var{ptr} \\
\var{acnt}
\end{array}
}
\vdash \var{dstate} \trans{\hyperref[fig:delegation-rules]{deleg}}{c} \var{dstate'}
}
{
\begin{array}{r}
\var{slot} \\
\var{ptr} \\
\var{pp} \\
\var{acnt}
\end{array}
\vdash
\left(
\begin{array}{r}
\var{dstate} \\
\var{pstate}
\end{array}
\right)
\trans{delpl}{c}
\left(
\begin{array}{rcl}
\varUpdate{\var{dstate'}} \\
\var{pstate}
\end{array}
\right)
}
\end{equation}
\begin{equation}
\label{eq:delpl-p}
\inference[Delpl-Pool]
{
&
{
\begin{array}{r}
\var{slot} \\
\var{pp} \\
\end{array}
}
\vdash \var{pstate} \trans{\hyperref[fig:pool-rules]{pool}}{c} \var{pstate'}
}
{
\begin{array}{r}
\var{slot} \\
\var{ptr} \\
\var{pp} \\
\var{acnt}
\end{array}
\vdash
\left(
\begin{array}{r}
\var{dstate} \\
\var{pstate}
\end{array}
\right)
\trans{delpl}{c}
\left(
\begin{array}{rcl}
\var{dstate} \\
\varUpdate{\var{pstate'}}
\end{array}
\right)
}
\end{equation}
\caption{Delegation and Pool Combined Transition Rules}
\label{fig:rules:delpl}
\end{figure}
We now describe a transition system that processes the list of certificates inside a transaction.
It is defined recursively from the transition system in Figure~\ref{fig:rules:delpl} above.
Figure~\ref{fig:type:delegations} defines the types for the delegation certificate sequence
transition.
\begin{figure}[hbt]
\emph{Certificate Sequence Environment}