Skip to content

Commit 58b7d19

Browse files
Merge pull request #950 from IntersectMBO/fd/pool-reregistrations
Allow pool reregistrations in the POOL state transition relation
2 parents 58e1771 + f66119e commit 58b7d19

File tree

8 files changed

+57
-51
lines changed

8 files changed

+57
-51
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## Conway spec
44

55
### WIP
6+
7+
- Allow reregistration of pools in the POOL transition relation
68
- Implement the fPoolParams field of PState as in the Shelley specification
79
- Add the BBODY transition relation from Shelley
810
- Add the RUPD and TICK transition relations

src/Ledger/Conway/Conformance/Certs.agda

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ open import Ledger.Conway.Specification.Gov.Actions gs
1313
private module Certs = Ledger.Conway.Specification.Certs gs
1414
open Certs public
1515
hiding (DState; GState; CertState; HasCast-DState; HasCast-GState; HasCast-CertState;
16-
_⊢_⇀⦇_,POOL⦈_; _⊢_⇀⦇_,DELEG⦈_; _⊢_⇀⦇_,GOVCERT⦈_;
16+
_⊢_⇀⦇_,DELEG⦈_; _⊢_⇀⦇_,GOVCERT⦈_;
1717
_⊢_⇀⦇_,CERT⦈_; _⊢_⇀⦇_,PRE-CERT⦈_; _⊢_⇀⦇_,POST-CERT⦈_; _⊢_⇀⦇_,CERTS⦈_; ⟦_,_,_⟧ᵈ)
1818
open RwdAddr
1919

@@ -103,20 +103,8 @@ private variable
103103

104104
open GovVote
105105

106-
data _⊢_⇀⦇_,POOL⦈_ : PoolEnv PState DCert PState Type
107106
data _⊢_⇀⦇_,DELEG⦈_ : DelegEnv DState DCert DState Type
108107

109-
data _⊢_⇀⦇_,POOL⦈_ where
110-
POOL-regpool :
111-
∙ kh ∉ dom pools
112-
────────────────────────────────
113-
pp ⊢ ⟦ pools , fPools , retiring ⟧ ⇀⦇ regpool kh poolParams ,POOL⦈
114-
⟦ ❴ kh , poolParams ❵ ∪ˡ pools , fPools , retiring ⟧
115-
116-
POOL-retirepool :
117-
────────────────────────────────
118-
pp ⊢ ⟦ pools , fPools , retiring ⟧ ⇀⦇ retirepool kh e ,POOL⦈ ⟦ pools , fPools , ❴ kh , e ❵ ∪ˡ retiring ⟧
119-
120108
data _⊢_⇀⦇_,DELEG⦈_ where
121109
DELEG-delegate : let open PParams pp in
122110
∙ (c ∉ dom rwds d ≡ keyDeposit)

src/Ledger/Conway/Conformance/Certs/Properties.agda

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module Ledger.Conway.Conformance.Certs.Properties (gs : _) (open GovStructure gs
88
open import Data.Maybe.Properties
99
open import Relation.Nullary.Decidable
1010

11+
open import Ledger.Conway.Specification.Certs.Properties.Computational gs
12+
using (Computational-POOL)
1113
open import Ledger.Conway.Specification.Gov.Actions gs hiding (yes; no)
1214
open import Ledger.Conway.Conformance.Certs gs
1315

@@ -38,7 +40,7 @@ instance
3840
(dereg c md) case lookupDeposit deposits (CredentialDeposit c) of λ where
3941
(yes ((k , d) , _))
4042
case
41-
¿ (c , 0) ∈ rewards
43+
¿ (c , 0) ∈ rewards
4244
× (CredentialDeposit c , d) ∈ deposits
4345
× (md ≡ nothing ⊎ md ≡ just d)
4446
¿ of λ where
@@ -76,17 +78,6 @@ instance
7678
Computational-DELEG .completeness de ds (reg c d) _ (DELEG-reg p)
7779
rewrite dec-yes (¿ c ∉ dom (DState.rewards ds) × (d ≡ DelegEnv.pparams de .PParams.keyDeposit ⊎ d ≡ 0) ¿) p .proj₂ = refl
7880

79-
Computational-POOL : Computational _⊢_⇀⦇_,POOL⦈_ String
80-
Computational-POOL .computeProof _ ps (regpool c _) =
81-
case ¬? (c ∈? dom (pools ps)) of λ where
82-
(yes p) success (-, POOL-regpool p)
83-
(no ¬p) failure (genErrors ¬p)
84-
Computational-POOL .computeProof _ _ (retirepool c e) = success (-, POOL-retirepool)
85-
Computational-POOL .computeProof _ _ _ = failure "Unexpected certificate in POOL"
86-
Computational-POOL .completeness _ ps (regpool c _) _ (POOL-regpool ¬p)
87-
rewrite dec-no (c ∈? dom (pools ps)) ¬p = refl
88-
Computational-POOL .completeness _ _ (retirepool _ _) _ POOL-retirepool = refl
89-
9081
Computational-GOVCERT : Computational _⊢_⇀⦇_,GOVCERT⦈_ String
9182
Computational-GOVCERT .computeProof ce gs (regdrep c d _) =
9283
let open CertEnv ce; open GState gs; open PParams pp in
@@ -148,8 +139,8 @@ instance
148139
... | success _ | refl = refl
149140
Computational-CERT .completeness ce cs
150141
dCert@(regpool c poolParams) cs' (CERT-pool h)
151-
with computeProof (CertEnv.pp ce) (CertState.pState cs) dCert | completeness _ _ _ _ h
152-
... | success _ | refl = refl
142+
with completeness _ _ _ _ h
143+
... | refl = refl
153144
Computational-CERT .completeness ce cs
154145
dCert@(retirepool c e) cs' (CERT-pool h)
155146
with completeness _ _ _ _ h

src/Ledger/Conway/Conformance/Equivalence.agda

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ getValidCertDepositsCERTS {Γ} {s} {cert ∷ _} deposits wf (run-∷ (C.CERT-del
193193
(getValidCertDepositsCERTS _ (lemUpdCert (L.CertEnv.pp Γ) (certDepositsC s) deposits cert wf) rs)
194194
getValidCertDepositsCERTS {Γ} {s} {cert ∷ _} deposits wf (run-∷ (C.CERT-deleg (C.DELEG-reg x)) rs)
195195
= L.reg (getValidCertDepositsCERTS _ (lemUpdCert (L.CertEnv.pp Γ) (certDepositsC s) deposits cert wf) rs)
196-
getValidCertDepositsCERTS {Γ} {s} {cert ∷ _} deposits wf (run-∷ (C.CERT-pool (C.POOL-regpool _)) rs)
196+
getValidCertDepositsCERTS {Γ} {s} {cert ∷ _} deposits wf (run-∷ (C.CERT-pool L.POOL-regpool) rs)
197197
= L.regpool (getValidCertDepositsCERTS _ (lemUpdCert (L.CertEnv.pp Γ) (certDepositsC s) deposits cert wf) rs)
198198
getValidCertDepositsCERTS {Γ} {s} {cert ∷ _} deposits wf (run-∷ (C.CERT-pool C.POOL-retirepool) rs)
199199
= L.retirepool (getValidCertDepositsCERTS _ (lemUpdCert (L.CertEnv.pp Γ) (certDepositsC s) deposits cert wf) rs)
@@ -270,7 +270,7 @@ lemCERTS'DepositsC (run-[] C.CERT-post) = refl
270270
lemCERTS'DepositsC (run-∷ (C.CERT-deleg (C.DELEG-delegate _)) rs) = lemCERTS'DepositsC rs
271271
lemCERTS'DepositsC (run-∷ (C.CERT-deleg (C.DELEG-dereg _)) rs) = lemCERTS'DepositsC rs
272272
lemCERTS'DepositsC (run-∷ (C.CERT-deleg (C.DELEG-reg _)) rs) = lemCERTS'DepositsC rs
273-
lemCERTS'DepositsC (run-∷ (C.CERT-pool (C.POOL-regpool _)) rs) = lemCERTS'DepositsC rs
273+
lemCERTS'DepositsC (run-∷ (C.CERT-pool L.POOL-regpool ) rs) = lemCERTS'DepositsC rs
274274
lemCERTS'DepositsC (run-∷ (C.CERT-pool C.POOL-retirepool ) rs) = lemCERTS'DepositsC rs
275275
lemCERTS'DepositsC (run-∷ (C.CERT-vdel (C.GOVCERT-regdrep _)) rs) = lemCERTS'DepositsC rs
276276
lemCERTS'DepositsC (run-∷ (C.CERT-vdel (C.GOVCERT-deregdrep _)) rs) = lemCERTS'DepositsC rs
@@ -358,9 +358,9 @@ opaque
358358
, cong-updateGDep {pp} cert {deps₁ .proj₂} {deps₂ .proj₂} ⟩ eqd) rs
359359
in deps₂' , eqd' , run-∷ (C.CERT-deleg (C.DELEG-reg h)) rs'
360360

361-
castCERTS' {Γ} deps₁ deps₂ deps₁' eqd (run-∷ (C.CERT-pool {dCert = cert} (C.POOL-regpool h)) rs) =
361+
castCERTS' {Γ} deps₁ deps₂ deps₁' eqd (run-∷ (C.CERT-pool {dCert = cert} L.POOL-regpool) rs) =
362362
let deps₂' , eqd' , rs' = castCERTS' deps₁ deps₂ deps₁' eqd rs
363-
in deps₂' , eqd' , run-∷ (C.CERT-pool (C.POOL-regpool h)) rs'
363+
in deps₂' , eqd' , run-∷ (C.CERT-pool L.POOL-regpool) rs'
364364

365365
castCERTS' {Γ} deps₁ deps₂ deps₁' eqd (run-∷ (C.CERT-pool {dCert = cert} C.POOL-retirepool) rs) =
366366
let deps₂' , eqd' , rs' = castCERTS' deps₁ deps₂ deps₁' eqd rs

src/Ledger/Conway/Conformance/Equivalence/Certs.agda

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ instance
171171
DELEGToConf .convⁱ (reg* _ _) (L.DELEG-reg h) = C.DELEG-reg h
172172

173173
POOLToConf : {pp s dcert s'} pp L.⊢ s ⇀⦇ dcert ,POOL⦈ s' ⭆ pp C.⊢ s ⇀⦇ dcert ,POOL⦈ s'
174-
POOLToConf .convⁱ _ (L.POOL-regpool h) = C.POOL-regpool h
174+
POOLToConf .convⁱ _ L.POOL-regpool = C.POOL-regpool
175175
POOLToConf .convⁱ _ L.POOL-retirepool = C.POOL-retirepool
176176

177177
GOVCERTToConf : {Γ s dcert dcerts s'}
@@ -223,10 +223,6 @@ instance
223223
DELEGFromConf .convⁱ _ (C.DELEG-dereg (h , _)) = L.DELEG-dereg h
224224
DELEGFromConf .convⁱ _ (C.DELEG-reg h) = L.DELEG-reg h
225225

226-
POOLFromConf : {pp s dcert s'} pp C.⊢ s ⇀⦇ dcert ,POOL⦈ s' ⭆ pp L.⊢ s ⇀⦇ dcert ,POOL⦈ s'
227-
POOLFromConf .convⁱ _ (C.POOL-regpool h) = L.POOL-regpool h
228-
POOLFromConf .convⁱ _ C.POOL-retirepool = L.POOL-retirepool
229-
230226
GOVCERTFromConf : {Γ s dcert s'}
231227
Γ C.⊢ s ⇀⦇ dcert ,GOVCERT⦈ s' ⭆
232228
Γ L.⊢ conv s ⇀⦇ dcert ,GOVCERT⦈ conv s'

src/Ledger/Conway/Foreign/HSLedger/Certs.agda

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ open import Ledger.Conway.Foreign.HSLedger.PParams
88

99
open import Ledger.Conway.Conformance.Certs govStructure using (⟦_,_,_,_⟧ᵈ; ⟦_,_,_⟧ᵛ; DState; GState; CertEnv)
1010

11+
open import Ledger.Conway.Specification.Certs.Properties.Computational govStructure
12+
using (Computational-POOL)
1113
open import Ledger.Conway.Conformance.Certs.Properties govStructure
1214
using ( Computational-DELEG
1315
; Computational-GOVCERT
14-
; Computational-POOL
1516
)
1617

1718
instance

src/Ledger/Conway/Specification/Certs.lagda.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ open import Ledger.Prelude.Numeric.UnitInterval
1515
1616
module Ledger.Conway.Specification.Certs (gs : _) (open GovStructure gs) where
1717
18-
open import Ledger.Conway.Specification.Gov.Actions gs
18+
open import Ledger.Conway.Specification.Gov.Actions gs hiding (yes; no)
1919
open RwdAddr
2020
open PParams
2121
```
@@ -469,17 +469,50 @@ data _⊢_⇀⦇_,DELEG⦈_ : DelegEnv → DState → DCert → DState → Type
469469

470470
### Auxiliary POOL transition system
471471

472+
??? info "Differences with the Shelley Specification"
473+
474+
We are deviating in style from the Shelley specification here. In the
475+
Shelley specification (Figure 25), the POOL transition system has three rules.
476+
Here we use a single rule to register and to reregister pools, which is the way
477+
in which the Haskell implementation does it as well.
478+
479+
Note, in particular, how the regpool rule only sets the pool parameters of
480+
the current epoch only if the pool is not already registered. And conversely,
481+
the future pool parameters are updated only if the pool is already registered.
482+
472483
```agda
484+
isPoolRegistered : Pools -> KeyHash -> Maybe StakePoolParams
485+
isPoolRegistered ps kh = lookupᵐ? ps kh
486+
473487
data _⊢_⇀⦇_,POOL⦈_ : PoolEnv → PState → DCert → PState → Type where
474488
475489
POOL-regpool :
476-
∙ kh ∉ dom pools
477-
────────────────────────────────
478-
pp ⊢ ⟦ pools , fPools , retiring ⟧ ⇀⦇ regpool kh poolParams ,POOL⦈ ⟦ ❴ kh , poolParams ❵ ∪ˡ pools , fPools , retiring ⟧
490+
let
491+
fPool' =
492+
if isPoolRegistered pools kh
493+
then ❴ kh , poolParams ❵ ∪ˡ fPools
494+
else fPools
495+
in
496+
────────────────────────────────
497+
pp ⊢ ⟦ pools
498+
, fPools
499+
, retiring
500+
⟧ ⇀⦇ regpool kh poolParams ,POOL⦈ ⟦
501+
pools ∪ˡ ❴ kh , poolParams ❵
502+
, fPool'
503+
, retiring ∣ ❴ kh ❵ ᶜ
504+
479505
480506
POOL-retirepool :
481507
────────────────────────────────
482-
pp ⊢ ⟦ pools , fPools , retiring ⟧ ⇀⦇ retirepool kh e ,POOL⦈ ⟦ pools , fPools , ❴ kh , e ❵ ∪ˡ retiring ⟧
508+
pp ⊢ ⟦ pools
509+
, fPools
510+
, retiring
511+
⟧ ⇀⦇ retirepool kh e ,POOL⦈ ⟦
512+
pools
513+
, fPools
514+
, ❴ kh , e ❵ ∪ˡ retiring
515+
483516
```
484517

485518

src/Ledger/Conway/Specification/Certs/Properties/Computational.agda

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,10 @@ instance
5858
rewrite dec-yes (¿ c ∉ dom (DState.rewards stᵈ) × (d ≡ DelegEnv.pparams de .PParams.keyDeposit ⊎ d ≡ 0) ¿) p .proj₂ = refl
5959

6060
Computational-POOL : Computational _⊢_⇀⦇_,POOL⦈_ String
61-
Computational-POOL .computeProof _ stᵖ (regpool c _) =
62-
let open PState stᵖ in
63-
case ¬? (c ∈? dom pools) of λ where
64-
(yes p) success (-, POOL-regpool p)
65-
(no ¬p) failure (genErrors ¬p)
61+
Computational-POOL .computeProof _ stᵖ (regpool c _) = success (-, POOL-regpool)
6662
Computational-POOL .computeProof _ _ (retirepool c e) = success (-, POOL-retirepool)
6763
Computational-POOL .computeProof _ _ _ = failure "Unexpected certificate in POOL"
68-
Computational-POOL .completeness _ stᵖ (regpool c _) _ (POOL-regpool ¬p)
69-
rewrite dec-no (c ∈? dom (PState.pools stᵖ)) ¬p = refl
64+
Computational-POOL .completeness _ stᵖ (regpool c _) _ POOL-regpool = refl
7065
Computational-POOL .completeness _ _ (retirepool _ _) _ POOL-retirepool = refl
7166

7267
Computational-GOVCERT : Computational _⊢_⇀⦇_,GOVCERT⦈_ String
@@ -123,8 +118,8 @@ instance
123118
... | success _ | refl = refl
124119
Computational-CERT .completeness ce cs
125120
dCert@(regpool c poolParams) cs' (CERT-pool h)
126-
with computeProof (CertEnv.pp ce) (pState cs) dCert | completeness _ _ _ _ h
127-
... | success _ | refl = refl
121+
with completeness _ _ _ _ h
122+
... | refl = refl
128123
Computational-CERT .completeness ce cs
129124
dCert@(retirepool c e) cs' (CERT-pool h)
130125
with completeness _ _ _ _ h

0 commit comments

Comments
 (0)