Skip to content

Commit 38f3b4b

Browse files
committed
CDDL: Consolidate (un)tagged (o)set fields in core.
* Also, rearrange the exports.
1 parent 9e6a057 commit 38f3b4b

File tree

8 files changed

+122
-100
lines changed
  • eras
    • allegra/impl/testlib/Test/Cardano/Ledger/Allegra
    • alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo
    • babbage/impl/testlib/Test/Cardano/Ledger/Babbage
    • conway/impl/testlib/Test/Cardano/Ledger/Conway
    • dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra
    • mary/impl/testlib/Test/Cardano/Ledger/Mary
    • shelley/impl/testlib/Test/Cardano/Ledger/Shelley
  • libs/cardano-ledger-core/testlib/Test/Cardano/Ledger/Core/Binary

8 files changed

+122
-100
lines changed

eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/CDDL.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ transaction_body =
9797
|]
9898
$ "transaction_body"
9999
=:= mp
100-
[ idx 0 ==> set transaction_input
100+
[ idx 0 ==> untagged_set transaction_input
101101
, idx 1 ==> arr [0 <+ a transaction_output]
102102
, idx 2 ==> coin
103103
, opt (idx 3 ==> VUInt)

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ transaction_body =
9393
|]
9494
$ "transaction_body"
9595
=:= mp
96-
[ idx 0 ==> set transaction_input
96+
[ idx 0 ==> untagged_set transaction_input
9797
, idx 1 ==> arr [0 <+ a transaction_output]
9898
, idx 2 ==> coin
9999
, opt (idx 3 ==> VUInt)
@@ -104,13 +104,13 @@ transaction_body =
104104
, opt (idx 8 ==> VUInt)
105105
, opt (idx 9 ==> mint)
106106
, opt (idx 11 ==> script_data_hash)
107-
, opt (idx 13 ==> set transaction_input)
107+
, opt (idx 13 ==> untagged_set transaction_input)
108108
, opt (idx 14 ==> required_signers)
109109
, opt (idx 15 ==> network_id)
110110
]
111111

112112
required_signers :: Rule
113-
required_signers = "required_signers" =:= set addr_keyhash
113+
required_signers = "required_signers" =:= untagged_set addr_keyhash
114114

115115
transaction_output :: Rule
116116
transaction_output =

eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ transaction_body =
113113
|]
114114
$ "transaction_body"
115115
=:= mp
116-
[ idx 0 ==> set transaction_input
116+
[ idx 0 ==> untagged_set transaction_input
117117
, idx 1 ==> arr [0 <+ a transaction_output]
118118
, idx 2 ==> coin
119119
, opt (idx 3 ==> VUInt)
@@ -124,12 +124,12 @@ transaction_body =
124124
, opt (idx 8 ==> VUInt)
125125
, opt (idx 9 ==> mint)
126126
, opt (idx 11 ==> script_data_hash)
127-
, opt (idx 13 ==> set transaction_input)
127+
, opt (idx 13 ==> untagged_set transaction_input)
128128
, opt (idx 14 ==> required_signers)
129129
, opt (idx 15 ==> network_id)
130130
, opt (idx 16 ==> transaction_output)
131131
, opt (idx 17 ==> coin)
132-
, opt (idx 18 ==> set transaction_input)
132+
, opt (idx 18 ==> untagged_set transaction_input)
133133
]
134134

135135
-- TODO: Allow for adding to the comments of a Rule in order to not have to

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
module Test.Cardano.Ledger.Conway.CDDL (
1212
module Test.Cardano.Ledger.Babbage.CDDL,
1313
conwayCDDL,
14-
oset,
1514
potential_languages,
1615
pool_registration,
1716
pool_retirement,
@@ -29,11 +28,9 @@ module Test.Cardano.Ledger.Conway.CDDL (
2928
update_drep_cert,
3029
block_no,
3130
slot_no,
32-
set,
3331
transaction_input,
3432
withdrawals,
3533
mint,
36-
nonempty_set,
3734
voting_procedures,
3835
anchor,
3936
hard_fork_initiation_action,
@@ -45,7 +42,6 @@ module Test.Cardano.Ledger.Conway.CDDL (
4542
gov_action_id,
4643
policy_hash,
4744
shelley_transaction_output,
48-
nonempty_oset,
4945
epoch_interval,
5046
ex_unit_prices,
5147
pool_voting_thresholds,
@@ -62,13 +58,19 @@ module Test.Cardano.Ledger.Conway.CDDL (
6258
metadata,
6359
shelley_auxiliary_data,
6460
shelley_ma_auxiliary_data,
61+
62+
-- * Sets
63+
maybe_tagged_set,
64+
maybe_tagged_nonempty_set,
65+
maybe_tagged_oset,
66+
maybe_tagged_nonempty_oset,
6567
) where
6668

6769
import Cardano.Ledger.Conway (ConwayEra)
6870
import Codec.CBOR.Cuddle.Comments ((//-))
6971
import Codec.CBOR.Cuddle.Huddle
7072
import Data.Function (($))
71-
import Data.Text (Text)
73+
import Data.Text qualified as T
7274
import Data.Word (Word64)
7375
import GHC.Num (Integer)
7476
import Test.Cardano.Ledger.Babbage.CDDL hiding (
@@ -81,15 +83,14 @@ import Test.Cardano.Ledger.Babbage.CDDL hiding (
8183
mint,
8284
multiasset,
8385
native_script,
84-
nonempty_set,
8586
redeemers,
8687
required_signers,
8788
script_all,
8889
script_any,
8990
script_pubkey,
90-
set,
9191
transaction_input,
9292
transaction_metadatum_label,
93+
untagged_set,
9394
value,
9495
withdrawals,
9596
)
@@ -186,7 +187,7 @@ transaction_body :: Rule
186187
transaction_body =
187188
"transaction_body"
188189
=:= mp
189-
[ idx 0 ==> set transaction_input
190+
[ idx 0 ==> maybe_tagged_set transaction_input
190191
, idx 1 ==> arr [0 <+ a transaction_output]
191192
, idx 2 ==> coin
192193
, opt (idx 3 ==> slot_no)
@@ -196,12 +197,12 @@ transaction_body =
196197
, opt (idx 8 ==> slot_no) -- Validity interval start
197198
, opt (idx 9 ==> mint)
198199
, opt (idx 11 ==> script_data_hash)
199-
, opt (idx 13 ==> nonempty_set transaction_input)
200+
, opt (idx 13 ==> maybe_tagged_nonempty_set transaction_input)
200201
, opt (idx 14 ==> required_signers)
201202
, opt (idx 15 ==> network_id)
202203
, opt (idx 16 ==> transaction_output)
203204
, opt (idx 17 ==> coin)
204-
, opt (idx 18 ==> nonempty_set transaction_input)
205+
, opt (idx 18 ==> maybe_tagged_nonempty_set transaction_input)
205206
, opt (idx 19 ==> voting_procedures)
206207
, opt (idx 20 ==> proposal_procedures)
207208
, opt (idx 21 ==> coin)
@@ -227,10 +228,10 @@ proposal_procedure =
227228
]
228229

229230
proposal_procedures :: Rule
230-
proposal_procedures = "proposal_procedures" =:= nonempty_oset proposal_procedure
231+
proposal_procedures = "proposal_procedures" =:= maybe_tagged_nonempty_oset proposal_procedure
231232

232233
certificates :: Rule
233-
certificates = "certificates" =:= nonempty_oset certificate
234+
certificates = "certificates" =:= maybe_tagged_nonempty_oset certificate
234235

235236
gov_action :: Rule
236237
gov_action =
@@ -275,7 +276,7 @@ update_committee =
275276
=:~ grp
276277
[ 4
277278
, a $ gov_action_id / VNil
278-
, a (set committee_cold_credential)
279+
, a (maybe_tagged_set committee_cold_credential)
279280
, a (mp [0 <+ asKey committee_cold_credential ==> epoch_no])
280281
, a unit_interval
281282
]
@@ -325,7 +326,7 @@ gov_action_id =
325326
]
326327

327328
required_signers :: Rule
328-
required_signers = "required_signers" =:= nonempty_set addr_keyhash
329+
required_signers = "required_signers" =:= maybe_tagged_nonempty_set addr_keyhash
329330

330331
transaction_input :: Rule
331332
transaction_input =
@@ -540,7 +541,7 @@ pool_params =
540541
, "cost" ==> coin
541542
, "margin" ==> unit_interval
542543
, "reward_account" ==> reward_account
543-
, "pool_owners" ==> set addr_keyhash
544+
, "pool_owners" ==> maybe_tagged_set addr_keyhash
544545
, "relays" ==> arr [0 <+ a relay]
545546
, "pool_metadata" ==> (pool_metadata / VNil)
546547
]
@@ -646,14 +647,14 @@ transaction_witness_set :: Rule
646647
transaction_witness_set =
647648
"transaction_witness_set"
648649
=:= mp
649-
[ opt $ idx 0 ==> nonempty_set vkeywitness
650-
, opt $ idx 1 ==> nonempty_set native_script
651-
, opt $ idx 2 ==> nonempty_set bootstrap_witness
652-
, opt $ idx 3 ==> nonempty_set plutus_v1_script
653-
, opt $ idx 4 ==> nonempty_set plutus_data
650+
[ opt $ idx 0 ==> maybe_tagged_nonempty_set vkeywitness
651+
, opt $ idx 1 ==> maybe_tagged_nonempty_set native_script
652+
, opt $ idx 2 ==> maybe_tagged_nonempty_set bootstrap_witness
653+
, opt $ idx 3 ==> maybe_tagged_nonempty_set plutus_v1_script
654+
, opt $ idx 4 ==> maybe_tagged_nonempty_set plutus_data
654655
, opt $ idx 5 ==> redeemers conway_redeemer_tag
655-
, opt $ idx 6 ==> nonempty_set plutus_v2_script
656-
, opt $ idx 7 ==> nonempty_set plutus_v3_script
656+
, opt $ idx 6 ==> maybe_tagged_nonempty_set plutus_v2_script
657+
, opt $ idx 7 ==> maybe_tagged_nonempty_set plutus_v3_script
657658
]
658659

659660
plutus_v1_script :: Rule
@@ -863,27 +864,19 @@ conway_script =
863864
/ arr [2, a plutus_v2_script]
864865
/ arr [3, a plutus_v3_script]
865866

866-
-- | Conway era introduces an optional 258 tag for sets, which will
867-
-- become mandatory in the second era after Conway. We recommend all the
868-
-- tooling to account for this future breaking change sooner rather than
869-
-- later, in order to provide a smooth transition for their users.
870-
set :: IsType0 t0 => t0 -> GRuleCall
871-
set = set_len_spec "set" 0
872-
873-
-- | Conway era introduces an optional 258 tag for sets, which will
874-
-- become mandatory in the second era after Conway. We recommend all the
875-
-- tooling to account for this future breaking change sooner rather than
876-
-- later, in order to provide a smooth transition for their users.
877-
nonempty_set :: IsType0 t0 => t0 -> GRuleCall
878-
nonempty_set = set_len_spec "nonempty_set" 1
879-
880-
-- | An OSet is a Set that preserves the order of its elements.
881-
oset :: IsType0 t0 => t0 -> GRuleCall
882-
oset = set_len_spec "oset" 0
883-
884-
-- | An NonEmpty OSet is a NonEmpty Set that preserves the order of its elements.
885-
nonempty_oset :: IsType0 t0 => t0 -> GRuleCall
886-
nonempty_oset = set_len_spec "nonempty_oset" 1
887-
888-
set_len_spec :: IsType0 t0 => Text -> Word64 -> t0 -> GRuleCall
889-
set_len_spec label n = binding $ \x -> label =:= tag 258 (arr [n <+ a x]) / sarr [n <+ a x]
867+
-- | Conway era introduces an optional 258 tag for sets, which will become
868+
-- mandatory in the second era after Conway.
869+
mkMaybeTaggedSet :: IsType0 a => T.Text -> Word64 -> a -> GRuleCall
870+
mkMaybeTaggedSet label n = binding $ \x -> label =:= tag 258 (arr [n <+ a x]) / sarr [n <+ a x]
871+
872+
maybe_tagged_set :: IsType0 a => a -> GRuleCall
873+
maybe_tagged_set = mkMaybeTaggedSet "set" 0
874+
875+
maybe_tagged_nonempty_set :: IsType0 a => a -> GRuleCall
876+
maybe_tagged_nonempty_set = mkMaybeTaggedSet "nonempty_set" 1
877+
878+
maybe_tagged_oset :: IsType0 a => a -> GRuleCall
879+
maybe_tagged_oset = mkMaybeTaggedSet "oset" 0
880+
881+
maybe_tagged_nonempty_oset :: IsType0 a => a -> GRuleCall
882+
maybe_tagged_nonempty_oset = mkMaybeTaggedSet "nonempty_oset" 1

eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ transaction_body :: Rule
115115
transaction_body =
116116
"transaction_body"
117117
=:= mp
118-
[ idx 0 ==> set transaction_input
118+
[ idx 0 ==> maybe_tagged_set transaction_input
119119
, idx 1 ==> arr [0 <+ a transaction_output]
120120
, idx 2 ==> coin
121121
, opt (idx 3 ==> slot_no)
@@ -125,12 +125,12 @@ transaction_body =
125125
, opt (idx 8 ==> slot_no) -- Validity interval start
126126
, opt (idx 9 ==> mint)
127127
, opt (idx 11 ==> script_data_hash)
128-
, opt (idx 13 ==> nonempty_set transaction_input)
128+
, opt (idx 13 ==> maybe_tagged_nonempty_set transaction_input)
129129
, opt (idx 14 ==> guards)
130130
, opt (idx 15 ==> network_id)
131131
, opt (idx 16 ==> transaction_output)
132132
, opt (idx 17 ==> coin)
133-
, opt (idx 18 ==> nonempty_set transaction_input)
133+
, opt (idx 18 ==> maybe_tagged_nonempty_set transaction_input)
134134
, opt (idx 19 ==> voting_procedures)
135135
, opt (idx 20 ==> proposal_procedures)
136136
, opt (idx 21 ==> coin)
@@ -140,8 +140,8 @@ transaction_body =
140140
guards :: Rule
141141
guards =
142142
"guards"
143-
=:= nonempty_set addr_keyhash
144-
/ nonempty_oset credential
143+
=:= maybe_tagged_nonempty_set addr_keyhash
144+
/ maybe_tagged_nonempty_oset credential
145145

146146
proposal_procedure :: Rule
147147
proposal_procedure =
@@ -154,10 +154,10 @@ proposal_procedure =
154154
]
155155

156156
proposal_procedures :: Rule
157-
proposal_procedures = "proposal_procedures" =:= nonempty_oset proposal_procedure
157+
proposal_procedures = "proposal_procedures" =:= maybe_tagged_nonempty_oset proposal_procedure
158158

159159
certificates :: Rule
160-
certificates = "certificates" =:= nonempty_oset certificate
160+
certificates = "certificates" =:= maybe_tagged_nonempty_oset certificate
161161

162162
gov_action :: Rule
163163
gov_action =
@@ -345,14 +345,14 @@ transaction_witness_set :: Rule
345345
transaction_witness_set =
346346
"transaction_witness_set"
347347
=:= mp
348-
[ opt $ idx 0 ==> nonempty_set vkeywitness
349-
, opt $ idx 1 ==> nonempty_set dijkstra_native_script
350-
, opt $ idx 2 ==> nonempty_set bootstrap_witness
351-
, opt $ idx 3 ==> nonempty_set plutus_v1_script
352-
, opt $ idx 4 ==> nonempty_set plutus_data
348+
[ opt $ idx 0 ==> maybe_tagged_nonempty_set vkeywitness
349+
, opt $ idx 1 ==> maybe_tagged_nonempty_set dijkstra_native_script
350+
, opt $ idx 2 ==> maybe_tagged_nonempty_set bootstrap_witness
351+
, opt $ idx 3 ==> maybe_tagged_nonempty_set plutus_v1_script
352+
, opt $ idx 4 ==> maybe_tagged_nonempty_set plutus_data
353353
, opt $ idx 5 ==> redeemers dijkstra_redeemer_tag
354-
, opt $ idx 6 ==> nonempty_set plutus_v2_script
355-
, opt $ idx 7 ==> nonempty_set plutus_v3_script
354+
, opt $ idx 6 ==> maybe_tagged_nonempty_set plutus_v2_script
355+
, opt $ idx 7 ==> maybe_tagged_nonempty_set plutus_v3_script
356356
]
357357

358358
-- TODO: adjust with new script purpose

eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/CDDL.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ transaction_body :: forall era. Era era => Rule
5555
transaction_body =
5656
"transaction_body"
5757
=:= mp
58-
[ idx 0 ==> set transaction_input
58+
[ idx 0 ==> untagged_set transaction_input
5959
, idx 1 ==> arr [0 <+ a transaction_output]
6060
, idx 2 ==> coin
6161
, opt (idx 3 ==> VUInt)

eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
module Test.Cardano.Ledger.Shelley.CDDL (
1414
module Test.Cardano.Ledger.Core.Binary.CDDL,
1515
shelleyCDDL,
16-
nonempty_set,
1716
transaction_metadatum_label,
1817
transaction_metadatum,
19-
set,
2018
transaction_input,
2119
transaction_output,
2220
certificate,
@@ -120,7 +118,7 @@ transaction_body :: forall era. Era era => Rule
120118
transaction_body =
121119
"transaction_body"
122120
=:= mp
123-
[ idx 0 ==> set transaction_input
121+
[ idx 0 ==> untagged_set transaction_input
124122
, idx 1 ==> arr [0 <+ a transaction_output]
125123
, idx 2 ==> coin
126124
, idx 3 ==> VUInt
@@ -225,7 +223,7 @@ pool_params =
225223
, "cost" ==> coin
226224
, "margin" ==> unit_interval
227225
, "reward_account" ==> reward_account
228-
, "pool_owners" ==> set addr_keyhash
226+
, "pool_owners" ==> untagged_set addr_keyhash
229227
, "relays" ==> arr [0 <+ a relay]
230228
, "pool_metadata" ==> (pool_metadata / VNil)
231229
]
@@ -394,12 +392,3 @@ metadata_hash = "metadata_hash" =:= hash32
394392

395393
nonce :: Rule
396394
nonce = "nonce" =:= arr [0] / arr [1, a (VBytes `sized` (32 :: Word64))]
397-
398-
-- Shelley does not support some of the tagged core datastructures that we rely
399-
-- on in future eras. In order to have the "correct" common specification in
400-
-- core, we override them here
401-
set :: IsType0 t0 => t0 -> GRuleCall
402-
set = binding $ \x -> "set" =:= arr [0 <+ a x]
403-
404-
nonempty_set :: IsType0 t0 => t0 -> GRuleCall
405-
nonempty_set = binding $ \x -> "nonempty_set" =:= arr [1 <+ a x]

0 commit comments

Comments
 (0)