-
Notifications
You must be signed in to change notification settings - Fork 155
/
Conway.hs
255 lines (235 loc) · 7.32 KB
/
Conway.hs
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
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Test.Cardano.Ledger.Conformance.ExecSpecRule.Conway () where
import Cardano.Ledger.BaseTypes (Inject (..), StrictMaybe (..))
import Cardano.Ledger.Conway (Conway)
import Cardano.Ledger.Conway.Core (Era (..), EraPParams, PParamsUpdate)
import Cardano.Ledger.Conway.Governance (EnactState, GovProcedures)
import Cardano.Ledger.Conway.PParams (THKD (..))
import Cardano.Ledger.Conway.Rules (ConwayGovPredFailure)
import Cardano.Ledger.Conway.Tx (AlonzoTx)
import Constrained
import Control.DeepSeq (NFData)
import Data.Bifunctor (Bifunctor (..))
import qualified Data.List.NonEmpty as NE
import qualified Data.Text as T
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import qualified Lib as Agda
import Test.Cardano.Ledger.Conformance (
ExecSpecRule (..),
SpecTranslate (..),
computationResultToEither,
)
import Test.Cardano.Ledger.Conformance.SpecTranslate.Conway (
GovProceduresSpecTransCtx,
OpaqueErrorString (..),
)
import Test.Cardano.Ledger.Constrained.Conway (
IsConwayUniv,
govEnvSpec,
govProceduresSpec,
govProposalsSpec,
utxoEnvSpec,
utxoStateSpec,
utxoTxSpec,
)
data ConwayGovExecContext era
= ConwayGovExecContext
(GovProceduresSpecTransCtx (EraCrypto era))
(EnactState era)
deriving (Generic)
deriving instance EraPParams era => Eq (ConwayGovExecContext era)
deriving instance EraPParams era => Show (ConwayGovExecContext era)
instance HasSimpleRep (ConwayGovExecContext era)
instance
( IsConwayUniv fn
, EraPParams era
, HasSpec fn (EnactState era)
) =>
HasSpec fn (ConwayGovExecContext era)
instance c ~ EraCrypto era => Inject (ConwayGovExecContext era) (GovProceduresSpecTransCtx c) where
inject (ConwayGovExecContext x _) = x
instance Inject (ConwayGovExecContext era) (EnactState era) where
inject (ConwayGovExecContext _ x) = x
agdaCompatiblePPU :: IsConwayUniv fn => Term fn (PParamsUpdate Conway) -> Pred fn
agdaCompatiblePPU ppup =
match ppup $
\cppMinFeeA
cppMinFeeB
cppMaxBBSize
cppMaxTxSize
cppMaxBHSize
cppKeyDeposit
cppPoolDeposit
cppEMax
cppNOpt
cppA0
cppRho
cppTau
_cppProtocolVersion
cppMinPoolCost
cppCoinsPerUTxOByte
cppCostModels
cppPrices
cppMaxTxExUnits
cppMaxBlockExUnits
cppMaxValSize
cppCollateralPercentage
cppMaxCollateralInputs
cppPoolVotingThresholds
cppDRepVotingThresholds
cppCommitteeMinSize
cppCommitteeMaxTermLength
cppGovActionLifetime
cppGovActionDeposit
cppDRepDeposit
cppDRepActivity
cppMinFeeRefScriptCostPerByte ->
-- TODO enable pparam updates once they're properly
-- implemented in the spec
mconcat
[ isModified cppMinFeeA
, isUnmodified cppMinFeeB
, isUnmodified cppMaxBBSize
, isUnmodified cppMaxTxSize
, isUnmodified cppMaxBHSize
, isUnmodified cppKeyDeposit
, isUnmodified cppPoolDeposit
, isUnmodified cppEMax
, isUnmodified cppNOpt
, isUnmodified cppA0
, isUnmodified cppRho
, isUnmodified cppTau
, isUnmodified cppMinPoolCost
, isUnmodified cppCoinsPerUTxOByte
, isUnmodified cppCostModels
, isUnmodified cppPrices
, isUnmodified cppMaxTxExUnits
, isUnmodified cppMaxBlockExUnits
, isUnmodified cppMaxValSize
, isUnmodified cppCollateralPercentage
, isUnmodified cppMaxCollateralInputs
, isUnmodified cppPoolVotingThresholds
, isUnmodified cppDRepVotingThresholds
, isUnmodified cppCommitteeMinSize
, isUnmodified cppCommitteeMaxTermLength
, isUnmodified cppGovActionLifetime
, isUnmodified cppGovActionDeposit
, isUnmodified cppDRepDeposit
, isUnmodified cppDRepActivity
, isUnmodified cppMinFeeRefScriptCostPerByte
]
where
isUnmodified ::
( HasSpec fn a
, Typeable gs
, IsNormalType a
, IsConwayUniv fn
) =>
Term fn (THKD gs StrictMaybe a) ->
Pred fn
isUnmodified x =
caseOn
x
(branch $ const True)
(branch $ const False)
isModified ::
( HasSpec fn a
, Typeable gs
, IsNormalType a
, IsConwayUniv fn
) =>
Term fn (THKD gs StrictMaybe a) ->
Pred fn
isModified x =
caseOn
x
(branch $ const False)
(branch $ const True)
instance
( NFData (SpecRep (ConwayGovPredFailure Conway))
, IsConwayUniv fn
) =>
ExecSpecRule fn "GOV" Conway
where
type ExecContext fn "GOV" Conway = ConwayGovExecContext Conway
environmentSpec = govEnvSpec
stateSpec = govProposalsSpec
signalSpec env st = govProceduresSpec env st <> constrained agdaConstraints
where
agdaConstraints :: Term fn (GovProcedures Conway) -> Pred fn
agdaConstraints procs = match @fn procs $ \_ props ->
forAll props $ \prop ->
match prop $ \_ _ govAction _ ->
caseOn
govAction
(branch $ \_ ppup _ -> agdaCompatiblePPU ppup)
(branch $ \_ _ -> True)
(branch $ \_ _ -> True)
(branch $ const True)
(branch $ \_ _ _ _ -> True)
(branch $ \_ _ -> True)
(branch $ const True)
execContextSpec = TrueSpec
runAgdaRule env st sig =
first (\e -> OpaqueErrorString (T.unpack e) NE.:| [])
. computationResultToEither
$ Agda.govStep env st sig
instance
forall fn.
IsConwayUniv fn =>
ExecSpecRule fn "UTXO" Conway
where
environmentSpec = utxoEnvSpec
stateSpec = utxoStateSpec
signalSpec env st = utxoTxSpec env st <> constrained agdaConstraints
where
agdaConstraints :: Term fn (AlonzoTx Conway) -> Pred fn
agdaConstraints tx = match @fn tx $ \txBody _ _ _ ->
match txBody $
\_ctbSpendInputs
_ctbCollateralInputs
_ctbReferenceInputs
ctbOutputs
_ctbCollateralReturn
_ctbTotalCollateral
_ctbCerts
_ctbWithdrawals
_ctbTxfee
_ctbVldt
_ctbReqSignerHashes
_ctbMint
_ctbScriptIntegrityHash
_ctbAdHash
_ctbTxNetworkId
_ctbVotingProcedures
_ctbProposalProcedures
_ctbCurrentTreasuryValue
_ctbTreasuryDonation ->
match ctbOutputs $
\outs -> forAll outs $
\x -> match x $
\txOut _ -> match txOut $
\_ _ dat _ ->
caseOn
dat
(branch $ const True)
(branch $ const True)
(branch $ const False)
runAgdaRule env st sig =
first (\e -> OpaqueErrorString (T.unpack e) NE.:| [])
. computationResultToEither
$ Agda.utxoStep env st sig