Skip to content

Commit 8f3bb11

Browse files
authored
Implement missing parts from StakePoolParams specification (#1294)
* Add vrf field to StakePoolParams * Add precondition for a pool to be registered before retirement * Add pp minPoolCost and enforce min cost on pool registration * Add precondition about Emax for pool retirement * Change rewardAccount to RewardAddress for stake pools
1 parent 193d640 commit 8f3bb11

11 files changed

Lines changed: 125 additions & 56 deletions

File tree

build-tools/static/hs-src/src/MAlonzo/Code/Ledger/Dijkstra/Foreign/API.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import MAlonzo.Code.Ledger.Dijkstra.Foreign.Cert as X
2121
import MAlonzo.Code.Ledger.Dijkstra.Foreign.Chain as X
2222
(ChainState(..), Block(..), chainStep)
2323
import MAlonzo.Code.Ledger.Dijkstra.Foreign.Certs as X
24-
( StakePoolParams(..), PState(..), DelegEnv(..), GovCertEnv(..), CertEnv(..), DState(..), DCert(..), GState(..), CertState(..)
24+
( StakePoolParams(..), PState(..), DelegEnv(..), GovCertEnv(..), PoolEnv(..), CertEnv(..), DState(..), DCert(..), GState(..), CertState(..)
2525
, delegStep, govCertStep, poolStep)
2626
import MAlonzo.Code.Ledger.Dijkstra.Foreign.Entities as X
2727
(EntitiesEnv(..), entitiesStep, SubEntitiesEnv(..), subentitiesStep)

formal-ledger-test/src/Test/LedgerImplementation.lagda.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module Implementation where
6161
6262
PlutusScript = ℕ × (List Data → Bool)
6363
ScriptHash = ℕ
64+
VRF = ℕ
6465
6566
ExUnits = ℕ × ℕ
6667
ExUnit-CommutativeMonoid =

src/Ledger/Core/Foreign/Crypto/Structure.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ HSCryptoStructure : CryptoStructure
3232
HSCryptoStructure = record {
3333
pkk = HSPKKScheme
3434
; ScriptHash =
35+
; VRF =
3536
}
3637

3738
open CryptoStructure HSCryptoStructure

src/Ledger/Core/Specification/Crypto.lagda.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ record CryptoStructure : Type₁ where
7777
7878
open isHashableSet khs renaming (THash to KeyHash) hiding (DecEq-T) public
7979
80-
-- TODO: KES and VRF
80+
field VRF : Type
81+
⦃ DecEq-VRF ⦄ : DecEq VRF
82+
83+
-- TODO: KES
8184
```
8285
-->

src/Ledger/Dijkstra/Foreign/Certs.agda

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ instance
5959
• fieldPrefix "ce"
6060
Conv-CertEnv = autoConvert CertEnv
6161

62+
HsTy-PoolEnv = autoHsType PoolEnv
63+
⊣ withConstructor "MkPoolEnv"
64+
• fieldPrefix "pe"
65+
Conv-PoolEnv = autoConvert PoolEnv
66+
6267
HsTy-CertState = autoHsType CertState ⊣ withConstructor "MkCertState"
6368
Conv-CertState = autoConvert CertState
6469

@@ -69,7 +74,7 @@ deleg-step = to (compute Computational-DELEG)
6974

7075
{-# COMPILE GHC deleg-step as delegStep #-}
7176

72-
pool-step : HsType (PParams PState DCert ComputationResult String PState)
77+
pool-step : HsType (PoolEnv PState DCert ComputationResult String PState)
7378
pool-step = to (compute Computational-POOL)
7479

7580
{-# COMPILE GHC pool-step as poolStep #-}

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

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ record StakePoolParams : Type where
3030
cost : Coin
3131
margin : UnitInterval
3232
pledge : Coin
33-
rewardAccount : Credential
33+
rewardAccount : RewardAddress
34+
vrf : VRF
3435
3536
CCHotKeys : Type
3637
CCHotKeys = Credential ⇀ Maybe Credential
@@ -127,8 +128,10 @@ record DelegEnv : Type where
127128
pools : Pools
128129
delegatees : ℙ Credential
129130
130-
PoolEnv : Type
131-
PoolEnv = PParams
131+
record PoolEnv : Type where
132+
field
133+
epoch : Epoch
134+
pp : PParams
132135
133136
record GovCertEnv : Type where
134137
field
@@ -139,6 +142,8 @@ record GovCertEnv : Type where
139142

140143
<!--
141144
```agda
145+
open StakePoolParams
146+
142147
IsConwayCert? : IsConwayCert ⁇¹
143148
IsConwayCert? {x} .dec with x
144149
... | regdrep _ _ _ = yes tt
@@ -166,6 +171,10 @@ record HasPools {a} (A : Type a) : Type a where
166171
field PoolsOf : A → Pools
167172
open HasPools ⦃...⦄ public
168173
174+
record HasFuturePools {a} (A : Type a) : Type a where
175+
field FuturePoolsOf : A → Pools
176+
open HasFuturePools ⦃...⦄ public
177+
169178
record HasRetiring {a} (A : Type a) : Type a where
170179
field RetiringOf : A → Retiring
171180
open HasRetiring ⦃...⦄ public
@@ -234,6 +243,9 @@ instance
234243
HasPools-PState : HasPools PState
235244
HasPools-PState .PoolsOf = PState.pools
236245
246+
HasFuturePools-PState : HasFuturePools PState
247+
HasFuturePools-PState .FuturePoolsOf = PState.fPools
248+
237249
HasDeposits-PState : HasDeposits PState
238250
HasDeposits-PState .DepositsOf = PState.deposits
239251
@@ -282,12 +294,13 @@ instance
282294
HasEpoch-CertEnv : HasEpoch CertEnv
283295
HasEpoch-CertEnv .EpochOf = CertEnv.epoch
284296
285-
unquoteDecl HasCast-CertEnv HasCast-DState HasCast-PState HasCast-GState HasCast-CertState HasCast-DelegEnv HasCast-GovCertEnv = derive-HasCast
297+
unquoteDecl HasCast-CertEnv HasCast-DState HasCast-PState HasCast-GState HasCast-CertState HasCast-DelegEnv HasCast-PoolEnv HasCast-GovCertEnv = derive-HasCast
286298
( (quote CertEnv , HasCast-CertEnv)
287299
∷ (quote DState , HasCast-DState)
288300
∷ (quote PState , HasCast-PState)
289301
∷ (quote GState , HasCast-GState)
290302
∷ (quote CertState , HasCast-CertState)
303+
∷ (quote PoolEnv , HasCast-PoolEnv)
291304
∷ (quote GovCertEnv , HasCast-GovCertEnv)
292305
∷ [ (quote DelegEnv , HasCast-DelegEnv) ])
293306
@@ -312,7 +325,7 @@ private variable
312325
mc : Maybe Credential
313326
delegatees : ℙ Credential
314327
dCert : DCert
315-
e : Epoch
328+
e e' : Epoch
316329
vs : List GovVote
317330
kh : KeyHash
318331
mkh : Maybe KeyHash
@@ -408,44 +421,53 @@ data _⊢_⇀⦇_,POOL⦈_ : PoolEnv → PState → DCert → PState → Type wh
408421
409422
POOL-reg :
410423
∙ ¬ (IsPoolRegistered pools kh)
424+
∙ ¬ (poolParams .vrf ∈ mapˢ vrf (range pools ∪ range fPools))
425+
∙ NetworkIdOf (poolParams .rewardAccount) ≡ NetworkId
426+
∙ pp .minPoolCost ≤ poolParams .cost
411427
────────────────────────────────
412-
pp ⊢ ⟦ pools
413-
, fPools
414-
, retiring
415-
, deposits
416-
⟧ ⇀⦇ regpool kh poolParams ,POOL⦈ ⟦
417-
pools ∪ˡ ❴ kh , poolParams ❵
418-
, fPools
419-
, retiring
420-
, deposits ∪ˡ ❴ kh , pp .poolDeposit ❵
421-
428+
⟦ e , pp ⟧ ⊢ ⟦ pools
429+
, fPools
430+
, retiring
431+
, deposits
432+
⟧ ⇀⦇ regpool kh poolParams ,POOL⦈ ⟦
433+
pools ∪ˡ ❴ kh , poolParams ❵
434+
, fPools
435+
, retiring
436+
, deposits ∪ˡ ❴ kh , pp .poolDeposit ❵
437+
422438
423439
POOL-rereg :
424440
∙ IsPoolRegistered pools kh
441+
∙ ¬ (poolParams .vrf ∈ mapˢ vrf (range (pools ∣ ❴ kh ❵ ᶜ) ∪ range (fPools ∣ ❴ kh ❵ ᶜ)))
442+
∙ NetworkIdOf (poolParams .rewardAccount) ≡ NetworkId
443+
∙ pp .minPoolCost ≤ poolParams .cost
425444
────────────────────────────────
426-
pp ⊢ ⟦ pools
427-
, fPools
428-
, retiring
429-
, deposits
430-
⟧ ⇀⦇ regpool kh poolParams ,POOL⦈ ⟦
431-
pools
432-
, ❴ kh , poolParams ❵ ∪ˡ fPools
433-
, retiring ∣ ❴ kh ❵ ᶜ
434-
, deposits
435-
445+
⟦ e , pp ⟧ ⊢ ⟦ pools
446+
, fPools
447+
, retiring
448+
, deposits
449+
⟧ ⇀⦇ regpool kh poolParams ,POOL⦈ ⟦
450+
pools
451+
, ❴ kh , poolParams ❵ ∪ˡ fPools
452+
, retiring ∣ ❴ kh ❵ ᶜ
453+
, deposits
454+
436455
437456
POOL-retirepool :
457+
∙ IsPoolRegistered pools kh
458+
∙ e < e'
459+
∙ e' ≤ e + pp .Emax
438460
────────────────────────────────
439-
pp ⊢ ⟦ pools
440-
, fPools
441-
, retiring
442-
, deposits
443-
⟧ ⇀⦇ retirepool kh e ,POOL⦈ ⟦
444-
pools
445-
, fPools
446-
, ❴ kh , e ❵ ∪ˡ retiring
447-
, deposits
448-
461+
⟦ e , pp ⟧ ⊢ ⟦ pools
462+
, fPools
463+
, retiring
464+
, deposits
465+
⟧ ⇀⦇ retirepool kh e' ,POOL⦈ ⟦
466+
pools
467+
, fPools
468+
, ❴ kh , e' ❵ ∪ˡ retiring
469+
, deposits
470+
449471
```
450472

451473
## `GOVCERT`{.AgdaDatatype} Transition System
@@ -482,7 +504,7 @@ data _⊢_⇀⦇_,CERT⦈_ : CertEnv → CertState → DCert → CertState →
482504
⟦ e , pp , cc ⟧ ⊢ ⟦ stᵈ , stᵖ , stᵍ ⟧ ⇀⦇ dCert ,CERT⦈ ⟦ stᵈ' , stᵖ , stᵍ ⟧
483505
484506
CERT-pool :
485-
pp ⊢ stᵖ ⇀⦇ dCert ,POOL⦈ stᵖ'
507+
⟦ e , pp ⟧ ⊢ stᵖ ⇀⦇ dCert ,POOL⦈ stᵖ'
486508
────────────────────────────────
487509
⟦ e , pp , cc ⟧ ⊢ ⟦ stᵈ , stᵖ , stᵍ ⟧ ⇀⦇ dCert ,CERT⦈ ⟦ stᵈ , stᵖ' , stᵍ ⟧
488510

src/Ledger/Dijkstra/Specification/Certs/Properties/Computational.lagda.md

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ open GovStructure govStructure
2222
open RewardAddress
2323
2424
open Computational ⦃...⦄
25+
open StakePoolParams
26+
open PoolEnv
27+
open PParams
2528
2629
instance
2730
Computational-DELEG : Computational _⊢_⇀⦇_,DELEG⦈_ String
@@ -55,21 +58,51 @@ instance
5558
... | no ¬p = ⊥-elim (¬p (p , q))
5659
5760
Computational-POOL : Computational _⊢_⇀⦇_,POOL⦈_ String
58-
Computational-POOL .computeProof _ stᵖ (regpool c _)
61+
Computational-POOL .computeProof _ stᵖ (regpool c poolParams)
5962
with ¿ IsPoolRegistered (PoolsOf stᵖ) c ¿
60-
... | yes p = success (-, (POOL-rereg p))
61-
... | no ¬p = success (-, (POOL-reg ¬p))
62-
Computational-POOL .computeProof _ stᵖ (retirepool c e) = success (-, POOL-retirepool)
63+
Computational-POOL .computeProof Γ stᵖ (regpool c poolParams) | yes p
64+
with ¿ ¬ (poolParams .vrf ∈ mapˢ vrf (range (PoolsOf stᵖ ∣ ❴ c ❵ ᶜ) ∪ range (FuturePoolsOf stᵖ ∣ ❴ c ❵ ᶜ)))
65+
∙ NetworkIdOf (poolParams .rewardAccount) ≡ NetworkId
66+
∙ Γ .pp .minPoolCost ≤ poolParams .cost ¿
67+
... | yes q = success (-, POOL-rereg (p , q))
68+
... | no ¬q = failure (genErrors ¬q)
69+
Computational-POOL .computeProof Γ stᵖ (regpool c poolParams) | no ¬p
70+
with ¿ ¬ (poolParams .vrf ∈ mapˢ vrf (range (PoolsOf stᵖ) ∪ range (FuturePoolsOf stᵖ)))
71+
∙ NetworkIdOf (poolParams .rewardAccount) ≡ NetworkId
72+
∙ Γ .pp .minPoolCost ≤ poolParams .cost ¿
73+
... | yes q = success (-, (POOL-reg (¬p , q)))
74+
... | no ¬q = failure (genErrors ¬q)
75+
Computational-POOL .computeProof Γ stᵖ (retirepool c e')
76+
with ¿ IsPoolRegistered (PoolsOf stᵖ) c
77+
∙ Γ .epoch < e'
78+
∙ e' ≤ Γ .epoch + Γ .pp .Emax ¿
79+
... | yes p = success (-, POOL-retirepool p)
80+
... | no ¬q = failure (genErrors ¬q)
6381
Computational-POOL .computeProof _ stᵖ _ = failure "Unexpected certificate in POOL"
64-
Computational-POOL .completeness _ stᵖ (regpool c _) _ (POOL-reg p)
82+
Computational-POOL .completeness Γ stᵖ (regpool c poolParams) _ (POOL-reg (p , q))
6583
with ¿ IsPoolRegistered (PoolsOf stᵖ) c ¿
66-
... | yes p' = ⊥-elim (p p')
67-
... | no _ = refl
68-
Computational-POOL .completeness _ stᵖ (regpool c _) _ (POOL-rereg p)
84+
... | yes r = ⊥-elim (p r)
85+
... | no ¬r
86+
with ¿ ¬ (poolParams .vrf ∈ mapˢ vrf (range (PoolsOf stᵖ) ∪ range (FuturePoolsOf stᵖ)))
87+
∙ NetworkIdOf (poolParams .rewardAccount) ≡ NetworkId
88+
∙ Γ .pp .minPoolCost ≤ poolParams .cost ¿
89+
... | yes _ = refl
90+
... | no ¬s = ⊥-elim (¬s q)
91+
Computational-POOL .completeness Γ stᵖ (regpool c poolParams) _ (POOL-rereg (p , q))
6992
with ¿ IsPoolRegistered (PoolsOf stᵖ) c ¿
93+
... | no ¬r = ⊥-elim (¬r p)
94+
... | yes r
95+
with ¿ ¬ (poolParams .vrf ∈ mapˢ vrf (range (PoolsOf stᵖ ∣ ❴ c ❵ ᶜ) ∪ range (FuturePoolsOf stᵖ ∣ ❴ c ❵ ᶜ)))
96+
∙ NetworkIdOf (poolParams .rewardAccount) ≡ NetworkId
97+
∙ Γ .pp .minPoolCost ≤ poolParams .cost ¿
98+
... | yes _ = refl
99+
... | no ¬s = ⊥-elim (¬s q)
100+
Computational-POOL .completeness Γ stᵖ (retirepool c e) _ (POOL-retirepool p)
101+
with ¿ IsPoolRegistered (PoolsOf stᵖ) c
102+
∙ Γ .epoch < e
103+
∙ e ≤ Γ .epoch + Γ .pp .Emax ¿
70104
... | yes _ = refl
71-
... | no ¬p = ⊥-elim (¬p p)
72-
Computational-POOL .completeness _ _ (retirepool _ _) _ POOL-retirepool = refl
105+
... | no ¬q = ⊥-elim (¬q p)
73106
74107
Computational-GOVCERT : Computational _⊢_⇀⦇_,GOVCERT⦈_ String
75108
Computational-GOVCERT .computeProof ce cs (regdrep c d _) =
@@ -99,7 +132,7 @@ instance
99132
Computational-CERT : Computational _⊢_⇀⦇_,CERT⦈_ String
100133
Computational-CERT .computeProof ce cs dCert
101134
with computeProof ⟦ PParamsOf ce , PoolsOf cs , dom (DRepsOf cs) ⟧ (DStateOf cs) dCert
102-
| computeProof (PParamsOf ce) (PStateOf cs) dCert
135+
| computeProof ⟦ EpochOf ce , PParamsOf ce (PStateOf cs) dCert
103136
| computeProof ⟦ EpochOf ce , PParamsOf ce , ColdCredentialsOf ce ⟧ cs dCert
104137
105138
... | success (_ , h) | _ | _ = success (-, CERT-deleg h)
@@ -119,13 +152,13 @@ instance
119152
... | success _ | refl = refl
120153
Computational-CERT .completeness ce cs
121154
dCert@(regpool c poolParams) cs' (CERT-pool h)
122-
with computeProof (CertEnv.pp ce) (CertState.pState cs) dCert
155+
with computeProof ⟦ EpochOf ce , PParamsOf ce ⟧ (PStateOf cs) dCert
123156
| completeness _ _ _ _ h
124157
... | success _ | refl = refl
125158
Computational-CERT .completeness ce cs
126159
dCert@(retirepool c e) cs' (CERT-pool h)
127-
with completeness _ _ _ _ h
128-
... | refl = refl
160+
with computeProof ⟦ EpochOf ce , PParamsOf ce ⟧ (PStateOf cs) dCert | completeness _ _ _ _ h
161+
... | success _ | refl = refl
129162
Computational-CERT .completeness Γ cs
130163
(regdrep c d an) _ (CERT-gov (GOVCERT-regdrep p))
131164
rewrite dec-yes

src/Ledger/Dijkstra/Specification/PParams.lagda.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ record PParams : Type where
118118
b : ℕ
119119
keyDeposit : Coin
120120
poolDeposit : Coin
121+
minPoolCost : Coin
121122
monetaryExpansion : UnitInterval -- formerly: rho
122123
treasuryCut : UnitInterval -- formerly: tau
123124
coinsPerUTxOByte : Coin
@@ -220,6 +221,7 @@ module PParamsUpdate where
220221
a b : Maybe ℕ
221222
keyDeposit : Maybe Coin
222223
poolDeposit : Maybe Coin
224+
minPoolCost : Maybe Coin
223225
monetaryExpansion : Maybe UnitInterval
224226
treasuryCut : Maybe UnitInterval
225227
coinsPerUTxOByte : Maybe Coin
@@ -275,6 +277,7 @@ module PParamsUpdate where
275277
∷ is-just b
276278
∷ is-just keyDeposit
277279
∷ is-just poolDeposit
280+
∷ is-just minPoolCost
278281
∷ is-just monetaryExpansion
279282
∷ is-just treasuryCut
280283
∷ is-just coinsPerUTxOByte
@@ -371,6 +374,7 @@ module PParamsUpdate where
371374
; b = U.b ?↗ P.b
372375
; keyDeposit = U.keyDeposit ?↗ P.keyDeposit
373376
; poolDeposit = U.poolDeposit ?↗ P.poolDeposit
377+
; minPoolCost = U.minPoolCost ?↗ P.minPoolCost
374378
; monetaryExpansion = U.monetaryExpansion ?↗ P.monetaryExpansion
375379
; treasuryCut = U.treasuryCut ?↗ P.treasuryCut
376380
; coinsPerUTxOByte = U.coinsPerUTxOByte ?↗ P.coinsPerUTxOByte

src/Ledger/Dijkstra/Specification/PoolReap.lagda.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ data _⊢_⇀⦇_,POOLREAP⦈_ : ⊤ → PoolReapState → Epoch → PoolReapSta
6161
retired = retiring ⁻¹ e
6262
6363
rewardAccounts : KeyHash ⇀ Credential
64-
rewardAccounts = mapValues rewardAccount (pools ∣ retired)
64+
rewardAccounts = mapValues (CredentialOf ∘ rewardAccount) (pools ∣ retired)
6565
6666
rewardAccounts' : Credential ⇀ Coin
6767
rewardAccounts' = aggregateBy (rewardAccounts ˢ) depositsᵖ

src/Ledger/Dijkstra/Specification/Ratify.lagda.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ module AcceptedBySPO (delegatees : VoteDelegs)
255255
defaultVote : KeyHash → Vote
256256
defaultVote kh = case lookupᵐ? pools kh of λ where
257257
nothing → Vote.no
258-
(just p) → case lookupᵐ? delegatees (StakePoolParams.rewardAccount p) , gaType action of
258+
(just p) → case lookupᵐ? delegatees (CredentialOf (StakePoolParams.rewardAccount p)) , gaType action of
259259
λ where
260260
( _ , TriggerHardFork ) → Vote.no
261261
( just vDelegNoConfidence , NoConfidence ) → Vote.yes

0 commit comments

Comments
 (0)