Skip to content

Commit ea7a63f

Browse files
committed
moved rewards check to LEDGER
1 parent e7d61fe commit ea7a63f

File tree

7 files changed

+59
-40
lines changed

7 files changed

+59
-40
lines changed

src/Ledger/Certs.lagda

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,14 @@ data _⊢_⇀⦇_,CERTBASE⦈_ where
466466
wdrlCreds = mapˢ stake (dom wdrls)
467467
validVoteDelegs = voteDelegs ∣^ ( mapˢ (credVoter DRep) (dom dReps)
468468
∪ fromList (noConfidenceRep ∷ abstainRep ∷ []) )
469+
rewards' = constMap wdrlCreds 0 ∪ˡ rewards
469470
in
470-
∙ mapˢ (map₁ stake) (wdrls ˢ) ⊆ rewards ˢ
471-
────────────────────────────────
472471
⟦ e , pp , vs , wdrls , cc ⟧ ⊢
473472
⟦ ⟦ voteDelegs , stakeDelegs , rewards ⟧
474473
, stᵖ
475474
, ⟦ dReps , ccHotKeys ⟧
476475
⟧ ⇀⦇ _ ,CERTBASE⦈
477-
⟦ ⟦ validVoteDelegs , stakeDelegs , constMap wdrlCreds 0 ∪ˡ rewards ⟧
476+
⟦ ⟦ validVoteDelegs , stakeDelegs , rewards'
478477
, stᵖ
479478
, ⟦ refreshedDReps , ccHotKeys ⟧
480479

src/Ledger/Conway/Conformance/Certs.agda

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,19 @@ data _⊢_⇀⦇_,CERT⦈_ : CertEnv → CertState → DCert → CertState → T
200200
data _⊢_⇀⦇_,CERTBASE⦈_ : CertEnv CertState CertState Type where
201201
CERT-base :
202202
let open PParams pp
203-
refresh = mapPartial getDRepVote (fromList vs)
204-
refreshedDReps = mapValueRestricted (const (e + drepActivity)) dReps refresh
205-
wdrlCreds = mapˢ stake (dom wdrls)
203+
refresh = mapPartial getDRepVote (fromList vs)
204+
refreshedDReps = mapValueRestricted (const (e + drepActivity)) dReps refresh
205+
wdrlCreds = mapˢ stake (dom wdrls)
206206
validVoteDelegs = voteDelegs ∣^ (mapˢ (credVoter DRep) (dom dReps) ∪ fromList (noConfidenceRep ∷ abstainRep ∷ []))
207+
rewards' = constMap wdrlCreds 0 ∪ˡ rewards
207208
in
208-
∙ mapˢ (map₁ stake) (wdrls ˢ) ⊆ rewards ˢ
209-
────────────────────────────────
210209
⟦ e , pp , vs , wdrls , cc ⟧ ⊢
211210
⟦ ⟦ voteDelegs , stakeDelegs , rewards , ddep ⟧
212211
, stᵖ
213212
, ⟦ dReps , ccHotKeys , gdep ⟧
214213
215214
⇀⦇ _ ,CERTBASE⦈
216-
⟦ ⟦ validVoteDelegs , stakeDelegs , constMap wdrlCreds 0 ∪ˡ rewards , ddep ⟧
215+
⟦ ⟦ validVoteDelegs , stakeDelegs , rewards' , ddep ⟧
217216
, stᵖ
218217
, ⟦ refreshedDReps , ccHotKeys , gdep ⟧
219218

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,8 @@ instance
194194

195195
goal : ComputationResult String
196196
(∃-syntax (_⊢_⇀⦇_,CERTBASE⦈_ ⟦ CertEnv.epoch ce , pp , votes , wdrls , _ ⟧ st sig))
197-
goal = case ¿ mapˢ (map₁ RwdAddr.stake) (wdrls ˢ) ⊆ rewards ˢ ¿ of λ where
198-
(yes p) success (-, CERT-base (p {_}))
199-
(no ¬p) failure (genErrors ¬p)
200-
Computational-CERTBASE .completeness ce st _ st' (CERT-base p) with
201-
¿ mapˢ (map₁ RwdAddr.stake) (CertEnv.wdrls ce ˢ) ⊆ (st .CertState.dState .DState.rewards) ˢ ¿
202-
... | yes _ = refl
203-
... | no ¬q = ⊥-elim (¬q p)
197+
goal = success (-, CERT-base)
198+
Computational-CERTBASE .completeness ce st _ st' CERT-base = refl
204199

205200
Computational-CERTS : Computational _⊢_⇀⦇_,CERTS⦈_ String
206201
Computational-CERTS = it

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ instance
153153
L.Deposits × L.Deposits
154154
⊢ Γ L.⊢ s ⇀⦇ _ ,CERTBASE⦈ s' ⭆ⁱ λ deposits _
155155
Γ C.⊢ (deposits ⊢conv s) ⇀⦇ _ ,CERTBASE⦈ (deposits ⊢conv s')
156-
CERTBASEToConf .convⁱ deposits (L.CERT-base h) = C.CERT-base h
156+
CERTBASEToConf .convⁱ deposits L.CERT-base = C.CERT-base
157157

158158
DELEGToConf : {Γ s dcert dcerts s'}
159159
(open L.DelegEnv Γ renaming (pparams to pp))
@@ -235,7 +235,7 @@ instance
235235
CERTBASEFromConf : {Γ s s'}
236236
Γ C.⊢ s ⇀⦇ _ ,CERTBASE⦈ s' ⭆
237237
Γ L.⊢ (conv s) ⇀⦇ _ ,CERTBASE⦈ (conv s')
238-
CERTBASEFromConf .convⁱ _ (C.CERT-base h) = L.CERT-base h
238+
CERTBASEFromConf .convⁱ _ C.CERT-base = L.CERT-base
239239

240240
CERTS'FromConf : {Γ s dcerts s'}
241241
ReflexiveTransitiveClosure {sts = C._⊢_⇀⦇_,CERT⦈_} Γ s dcerts s' ⭆

src/Ledger/Conway/Conformance/Ledger.agda

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private variable
3939
s s' s'' : LState
4040
utxoSt' : UTxOState
4141
govSt' : GovState
42-
certState' : CertState
42+
certState' certState'' : CertState
4343
tx : Tx
4444

4545
open UTxOState
@@ -52,18 +52,23 @@ data
5252

5353
LEDGER-V :
5454
let open LState s; txb = tx .body; open TxBody txb; open LEnv Γ
55-
open CertState certState; open DState dState
5655
utxoSt'' = record utxoSt' { deposits = updateDeposits pparams txb (deposits utxoSt') }
5756
wdrlCreds = mapˢ RwdAddr.stake (dom txwdrls)
57+
voteDelegs = certState .CertState.dState .DState.voteDelegs
58+
rewards = certState .CertState.dState .DState.rewards
59+
rewards' = constMap wdrlCreds 0 ∪ˡ rewards
60+
dState = certState .CertState.dState
61+
dState' = record dState { rewards = rewards' }
62+
certState' = record certState { dState = dState' }
5863
in
5964
∙ isValid tx ≡ true
6065
record { LEnv Γ } ⊢ utxoSt ⇀⦇ tx ,UTXOW⦈ utxoSt'
61-
∙ ⟦ epoch slot , pparams , txvote , txwdrls , allColdCreds govSt enactState ⟧ ⊢ certState ⇀⦇ txcerts ,CERTS⦈ certState'
66+
∙ ⟦ epoch slot , pparams , txvote , txwdrls , allColdCreds govSt enactState ⟧ ⊢ certState' ⇀⦇ txcerts ,CERTS⦈ certState''
6267
∙ filterˢ isKeyHash wdrlCreds ⊆ dom voteDelegs
63-
∙ ⟦ txid , epoch slot , pparams , ppolicy , enactState , certState' , dom
64-
rewards ⟧ ⊢ govSt ⇀⦇ txgov txb ,GOVS⦈ govSt'
68+
∙ ⟦ txid , epoch slot , pparams , ppolicy , enactState , certState'' , dom rewards ⟧ ⊢ govSt ⇀⦇ txgov txb ,GOVS⦈ govSt'
69+
∙ wdrlCreds ⊆ dom rewards
6570
────────────────────────────────
66-
Γ ⊢ s ⇀⦇ tx ,LEDGER⦈ ⟦ utxoSt'' , govSt' , certState' ⟧
71+
Γ ⊢ s ⇀⦇ tx ,LEDGER⦈ ⟦ utxoSt'' , govSt' , certState''
6772

6873

6974
LEDGER-I : let open LState s; txb = tx .body; open TxBody txb; open LEnv Γ in
@@ -72,8 +77,8 @@ data
7277
────────────────────────────────
7378
Γ ⊢ s ⇀⦇ tx ,LEDGER⦈ ⟦ utxoSt' , govSt , certState ⟧
7479

75-
pattern LEDGER-V⋯ w x y z t = LEDGER-V (w , x , y , z , t)
76-
pattern LEDGER-I⋯ y z = LEDGER-I (y , z)
80+
pattern LEDGER-V⋯ w x y z t u = LEDGER-V (w , x , y , z , t , u)
81+
pattern LEDGER-I⋯ y z = LEDGER-I (y , z)
7782

7883
_⊢_⇀⦇_,LEDGERS⦈_ : LEnv LState List Tx LState Type
7984
_⊢_⇀⦇_,LEDGERS⦈_ = ReflexiveTransitiveClosure {sts = _⊢_⇀⦇_,LEDGER⦈_}

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,46 @@ instance
7676
computeProof = case isValid ≟ true of λ where
7777
(yes p) do
7878
(utxoSt' , utxoStep) computeUtxow utxoΓ utxoSt tx
79-
(certSt' , certStep) computeCerts certΓ certState txcerts
80-
let wdrlCreds = mapˢ RwdAddr.stake (dom txwdrls)
81-
wdrlsCheck case ¿ filterˢ isKeyHash wdrlCreds ⊆ dom (certState .CertState.dState .DState.voteDelegs) ¿ of λ where
79+
let rewards = certState .CertState.dState .DState.rewards
80+
wdrlCreds = mapˢ RwdAddr.stake (dom txwdrls)
81+
rewards' = constMap wdrlCreds 0 ∪ˡ rewards
82+
dState = certState .CertState.dState
83+
dState' = record dState { rewards = rewards' }
84+
certState' = record certState { dState = dState' }
85+
(certState'' , certStep) computeCerts certΓ certState' txcerts
86+
wdrlsCheck case ¿ filterˢ isKeyHash wdrlCreds ⊆ dom (certState' .CertState.dState .DState.voteDelegs) ¿ of λ where
8287
(yes q) success q
8388
(no ¬q) failure (genErrors ¬q)
84-
(govSt' , govStep) computeGov (govΓ certSt') (rmOrphanDRepVotes (conv certSt') govSt) (txgov txb)
85-
success (_ , LEDGER-V⋯ p utxoStep certStep wdrlsCheck govStep)
89+
(govSt' , govStep) computeGov (govΓ certState'') (rmOrphanDRepVotes (conv certState'') govSt) (txgov txb)
90+
rwdsCheck case ¿ wdrlCreds ⊆ dom rewards ¿ of λ where
91+
(yes q) success q
92+
(no ¬q) failure (genErrors ¬q)
93+
success (_ , LEDGER-V⋯ p utxoStep certStep wdrlsCheck govStep λ { x rwdsCheck x })
8694
(no ¬p) do
8795
(utxoSt' , utxoStep) computeUtxow utxoΓ utxoSt tx
8896
success (_ , LEDGER-I⋯ (¬-not ¬p) utxoStep)
8997

9098
completeness : s' Γ ⊢ s ⇀⦇ tx ,LEDGER⦈ s' (proj₁ <$> computeProof) ≡ success s'
91-
completeness ls' (LEDGER-V⋯ v utxoStep certStep u govStep)
99+
completeness ls' (LEDGER-V⋯ v utxoStep certStep u govStep t)
92100
with isValid ≟ true
93101
... | no ¬v = contradiction v ¬v
94102
... | yes refl
95103
with computeUtxow utxoΓ utxoSt tx | complete _ _ _ _ utxoStep
96104
... | success (utxoSt' , _) | refl
97-
with computeCerts certΓ certState txcerts | complete _ _ _ _ certStep
98-
... | success (certSt' , _) | refl
105+
using rewards certState .CertState.dState .DState.rewards
106+
using wdrlCreds mapˢ RwdAddr.stake (dom txwdrls)
107+
using rewards' constMap wdrlCreds 0 ∪ˡ rewards
108+
using dState certState .CertState.dState
109+
using dState' record dState { rewards = rewards' }
110+
using certState' record certState { dState = dState' }
111+
with computeCerts certΓ certState' txcerts | complete _ _ _ _ certStep
112+
... | success (certState'' , _) | refl
99113
with dec-yes ¿ filterˢ isKeyHash (mapˢ RwdAddr.stake (dom txwdrls)) ⊆ dom (certState .CertState.dState .DState.voteDelegs) ¿ (λ { x u x })
100114
... | (_ , p)
101-
with computeGov (govΓ certSt') (rmOrphanDRepVotes (conv certSt') govSt ) (txgov txb) | complete {STS = _⊢_⇀⦇_,GOVS⦈_} (govΓ certSt') _ _ _ govStep
102-
... | success (govSt' , _) | refl rewrite p = refl
115+
with computeGov (govΓ certState'') (rmOrphanDRepVotes (conv certState'') govSt ) (txgov txb) | complete {STS = _⊢_⇀⦇_,GOVS⦈_} (govΓ certState'') _ _ _ govStep
116+
... | success (govSt' , _) | refl
117+
with dec-yes ¿ (mapˢ RwdAddr.stake (dom txwdrls)) ⊆ dom (certState .CertState.dState .DState.rewards) ¿ (λ {x t x})
118+
... | (_ , q) rewrite p rewrite q = refl
103119
completeness ls' (LEDGER-I⋯ i utxoStep)
104120
with isValid ≟ true
105121
... | yes refl = case i of λ ()

src/Ledger/Ledger.lagda

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private variable
8989
s s' s'' : LState
9090
utxoSt utxoSt' : UTxOState
9191
govSt govSt' : GovState
92-
certState certState' : CertState
92+
certState certState' certState'' : CertState
9393
tx : Tx
9494
slot : Slot
9595
ppolicy : Maybe ScriptHash
@@ -110,13 +110,18 @@ data _⊢_⇀⦇_,LEDGER⦈_ : LEnv → LState → Tx → LState → Type where
110110
open TxBody txb
111111
\end{code}
112112
\begin{code}
113-
rewards = certState .dState .rewards
113+
rewards = certState' .dState .rewards
114114
wdrlCreds = mapˢ RwdAddr.stake (dom txwdrls)
115+
rewards' = constMap wdrlCreds 0 ∪ˡ rewards
116+
dState = certState .CertState.dState
117+
dState' = record dState { rewards = rewards' }
118+
certState' = record certState { dState = dState' }
119+
voteDelegs = certState' .CertState.dState .voteDelegs
115120
in
116121
∙ isValid tx ≡ true
117122
∙ ⟦ slot , pp , treasury ⟧ ⊢ utxoSt ⇀⦇ tx ,UTXOW⦈ utxoSt'
118-
∙ ⟦ epoch slot , pp , txvote , txwdrls , allColdCreds govSt enactState ⟧ ⊢ certState ⇀⦇ txcerts ,CERTS⦈ certState'
119-
∙ filterˢ isKeyHash wdrlCreds ⊆ dom (certState .dState .voteDelegs)
123+
∙ ⟦ epoch slot , pp , txvote , txwdrls , allColdCreds govSt enactState ⟧ ⊢ certState' ⇀⦇ txcerts ,CERTS⦈ certState''
124+
∙ filterˢ isKeyHash wdrlCreds ⊆ dom voteDelegs
120125
∙ ⟦ txid , epoch slot , pp , ppolicy , enactState , certState' , dom rewards ⟧ ⊢ rmOrphanDRepVotes certState' govSt ⇀⦇ txgov txb ,GOVS⦈ govSt'
121126
────────────────────────────────
122127
⟦ slot , ppolicy , pp , enactState , treasury ⟧ ⊢ ⟦ utxoSt , govSt , certState ⟧ ⇀⦇ tx ,LEDGER⦈ ⟦ utxoSt' , govSt' , certState' ⟧

0 commit comments

Comments
 (0)