Skip to content

Commit aa65580

Browse files
authored
Merge pull request #5394 from IntersectMBO/aniketd/certificate-cddl
CDDL: Consolidate certificates and pool params
2 parents 294247f + 1023572 commit aa65580

File tree

21 files changed

+706
-680
lines changed

21 files changed

+706
-680
lines changed

eras/allegra/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
### `testlib`
1515

16+
* Add CDDL definitions for int64 types: `int64`, `min_int64`, `max_int64`, `negative_int64`, `positive_int64`, `nonzero_int64`
1617
* Rename `native_script` -> `allegra_native_script` in CDDL
1718
* Add `auxiliary_data_array` to CDDL for simplification
1819
* Remove `metadata` redefinition in CDDL

eras/allegra/impl/cddl-files/allegra.cddl

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ vrf_vkey = bytes .size 32
3838
vrf_cert = [bytes, bytes .size 80]
3939

4040
operational_cert =
41-
( hot_vkey : kes_vkey
42-
, sequence_number : uint .size 8
43-
, kes_period : uint
44-
, sigma : signature
41+
( hot_vkey : kes_vkey
42+
, sequence_number : sequence_number
43+
, kes_period : kes_period
44+
, sigma : signature
4545
)
4646

4747
kes_vkey = bytes .size 32
4848

49+
sequence_number = uint .size 8
50+
51+
kes_period = uint .size 8
52+
4953
signature = bytes .size 64
5054

5155
protocol_version = (major_protocol_version, uint)
@@ -121,18 +125,18 @@ address =
121125
coin = uint
122126

123127
certificate =
124-
[ stake_registration
125-
// stake_deregistration
126-
// stake_delegation
127-
// pool_registration
128-
// pool_retirement
129-
// genesis_key_delegation
128+
[ account_registration_cert
129+
// account_unregistration_cert
130+
// delegation_to_stake_pool_cert
131+
// pool_registration_cert
132+
// pool_retirement_cert
133+
// genesis_delegation_cert
130134
// move_instantaneous_rewards_cert
131135
]
132136

133137

134-
; This will be deprecated in a future era
135-
stake_registration = (0, stake_credential)
138+
; This certificate will be deprecated in a future era
139+
account_registration_cert = (0, stake_credential)
136140

137141
stake_credential = credential
138142

@@ -153,14 +157,14 @@ hash28 = bytes .size 28
153157
; "\x04" for Plutus V4 scripts
154158
script_hash = hash28
155159

156-
; This will be deprecated in a future era
157-
stake_deregistration = (1, stake_credential)
160+
; This certificate will be deprecated in a future era
161+
account_unregistration_cert = (1, stake_credential)
158162

159-
stake_delegation = (2, stake_credential, pool_keyhash)
163+
delegation_to_stake_pool_cert = (2, stake_credential, pool_keyhash)
160164

161165
pool_keyhash = hash28
162166

163-
pool_registration = (3, pool_params)
167+
pool_registration_cert = (3, pool_params)
164168

165169
pool_params =
166170
( operator : pool_keyhash
@@ -219,11 +223,11 @@ pool_metadata = [url, bytes]
219223

220224
url = text .size (0 .. 64)
221225

222-
pool_retirement = (4, pool_keyhash, epoch)
226+
pool_retirement_cert = (4, pool_keyhash, epoch)
223227

224228
epoch = uint .size 8
225229

226-
genesis_key_delegation = (5, genesis_hash, genesis_delegate_hash, vrf_keyhash)
230+
genesis_delegation_cert = (5, genesis_hash, genesis_delegate_hash, vrf_keyhash)
227231

228232
genesis_hash = hash28
229233

@@ -278,7 +282,7 @@ positive_int = 1 .. max_word64
278282

279283
max_word64 = 18446744073709551615
280284

281-
nonce = [0// 1, bytes .size 32]
285+
nonce = [0// 1, hash32]
282286

283287
auxiliary_data_hash = hash32
284288

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,27 @@
1313
module Test.Cardano.Ledger.Allegra.CDDL (
1414
module Test.Cardano.Ledger.Shelley.CDDL,
1515
allegraCDDL,
16+
17+
-- * 64-bit integers
18+
int64,
19+
nonzero_int64,
20+
21+
-- * Transaction
1622
transaction_witness_set,
23+
24+
-- * Auxiliary data
1725
auxiliary_data,
1826
auxiliary_data_array,
19-
auxiliary_scripts,
27+
28+
-- * Native scripts
2029
allegra_native_script,
2130
) where
2231

2332
import Cardano.Ledger.Allegra (AllegraEra)
2433
import Cardano.Ledger.Core (Era)
2534
import Codec.CBOR.Cuddle.Huddle
2635
import Data.Function (($))
36+
import GHC.Num (Integer)
2737
import Test.Cardano.Ledger.Shelley.CDDL
2838
import Text.Heredoc
2939

@@ -34,6 +44,25 @@ allegraCDDL =
3444
, HIRule $ transaction @AllegraEra
3545
]
3646

47+
min_int64 :: Rule
48+
min_int64 = "min_int64" =:= (-9223372036854775808 :: Integer)
49+
50+
max_int64 :: Rule
51+
max_int64 = "max_int64" =:= (9223372036854775807 :: Integer)
52+
53+
negative_int64 :: Rule
54+
negative_int64 = "negative_int64" =:= min_int64 ... (-1 :: Integer)
55+
56+
positive_int64 :: Rule
57+
positive_int64 = "positive_int64" =:= (1 :: Integer) ... max_int64
58+
59+
nonzero_int64 :: Rule
60+
nonzero_int64 = "nonzero_int64" =:= negative_int64 / positive_int64
61+
62+
-- | 64-bit signed integers for native script timelock thresholds.
63+
int64 :: Rule
64+
int64 = "int64" =:= min_int64 ... max_int64
65+
3766
allegra_native_script :: Rule
3867
allegra_native_script =
3968
comment
@@ -84,12 +113,14 @@ auxiliary_data_array =
84113
, "auxiliary_scripts" ==> auxiliary_scripts
85114
]
86115

116+
-- | Adds auxiliary_data_array format for batching native scripts with metadata.
87117
auxiliary_data :: Rule
88118
auxiliary_data =
89119
"auxiliary_data"
90120
=:= metadata
91121
/ auxiliary_data_array
92122

123+
-- | Adds validity interval start (index 8) for timelock script support.
93124
transaction_body :: forall era. Era era => Rule
94125
transaction_body =
95126
comment
@@ -127,6 +158,7 @@ transaction =
127158
, a (auxiliary_data / VNil)
128159
]
129160

161+
-- | Uses allegra_native_script with timelock support (invalid_before/hereafter).
130162
transaction_witness_set :: Rule
131163
transaction_witness_set =
132164
"transaction_witness_set"

eras/alonzo/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
### `testlib`
4040

41+
* Add CDDL definitions for Plutus V1 types: `big_int`, `big_uint`, `big_nint`, `bounded_bytes`
4142
* Rename `plutus_script` -> `plutus_v1_script` in CDDL
4243
* Add `plutus_v1_script` to CDDL exports
4344
* Add `auxiliary_data_map` to CDDL for simplification

eras/alonzo/impl/cddl-files/alonzo.cddl

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ vrf_vkey = bytes .size 32
4747
vrf_cert = [bytes, bytes .size 80]
4848

4949
operational_cert =
50-
( hot_vkey : kes_vkey
51-
, sequence_number : uint .size 8
52-
, kes_period : uint
53-
, sigma : signature
50+
( hot_vkey : kes_vkey
51+
, sequence_number : sequence_number
52+
, kes_period : kes_period
53+
, sigma : signature
5454
)
5555

5656
kes_vkey = bytes .size 32
5757

58+
sequence_number = uint .size 8
59+
60+
kes_period = uint .size 8
61+
5862
signature = bytes .size 64
5963

6064
protocol_version = (major_protocol_version, uint)
@@ -166,33 +170,33 @@ hash28 = bytes .size 28
166170
asset_name = bytes .size (0 .. 32)
167171

168172
certificate =
169-
[ stake_registration
170-
// stake_deregistration
171-
// stake_delegation
172-
// pool_registration
173-
// pool_retirement
174-
// genesis_key_delegation
173+
[ account_registration_cert
174+
// account_unregistration_cert
175+
// delegation_to_stake_pool_cert
176+
// pool_registration_cert
177+
// pool_retirement_cert
178+
// genesis_delegation_cert
175179
// move_instantaneous_rewards_cert
176180
]
177181

178182

179-
; This will be deprecated in a future era
180-
stake_registration = (0, stake_credential)
183+
; This certificate will be deprecated in a future era
184+
account_registration_cert = (0, stake_credential)
181185

182186
stake_credential = credential
183187

184188
credential = [0, addr_keyhash// 1, script_hash]
185189

186190
addr_keyhash = hash28
187191

188-
; This will be deprecated in a future era
189-
stake_deregistration = (1, stake_credential)
192+
; This certificate will be deprecated in a future era
193+
account_unregistration_cert = (1, stake_credential)
190194

191-
stake_delegation = (2, stake_credential, pool_keyhash)
195+
delegation_to_stake_pool_cert = (2, stake_credential, pool_keyhash)
192196

193197
pool_keyhash = hash28
194198

195-
pool_registration = (3, pool_params)
199+
pool_registration_cert = (3, pool_params)
196200

197201
pool_params =
198202
( operator : pool_keyhash
@@ -251,11 +255,11 @@ pool_metadata = [url, bytes]
251255

252256
url = text .size (0 .. 64)
253257

254-
pool_retirement = (4, pool_keyhash, epoch)
258+
pool_retirement_cert = (4, pool_keyhash, epoch)
255259

256260
epoch = uint .size 8
257261

258-
genesis_key_delegation = (5, genesis_hash, genesis_delegate_hash, vrf_keyhash)
262+
genesis_delegation_cert = (5, genesis_hash, genesis_delegate_hash, vrf_keyhash)
259263

260264
genesis_hash = hash28
261265

@@ -341,7 +345,7 @@ positive_int = 1 .. max_word64
341345

342346
max_word64 = 18446744073709551615
343347

344-
nonce = [0// 1, bytes .size 32]
348+
nonce = [0// 1, hash32]
345349

346350
cost_models = {* language => cost_model}
347351

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

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@
1111
module Test.Cardano.Ledger.Alonzo.CDDL (
1212
module Test.Cardano.Ledger.Mary.CDDL,
1313
alonzoCDDL,
14-
certificates,
15-
required_signers,
16-
network_id,
14+
15+
-- * Plutus V1 data types
16+
big_int,
17+
bounded_bytes,
18+
19+
-- * Plutus V1 scripts
1720
plutus_v1_script,
18-
redeemers,
1921
constr,
22+
23+
-- * Execution units
2024
ex_unit_prices,
2125
ex_units,
2226
positive_interval,
27+
28+
-- * Redeemers
29+
redeemers,
30+
31+
-- * Transaction
32+
required_signers,
33+
network_id,
2334
) where
2435

2536
import Cardano.Ledger.Alonzo (AlonzoEra)
@@ -180,9 +191,6 @@ script_data_hash =
180191
|]
181192
$ "script_data_hash" =:= hash32
182193

183-
certificates :: Rule
184-
certificates = "certificates" =:= arr [0 <+ a certificate]
185-
186194
protocol_param_update :: Rule
187195
protocol_param_update =
188196
comment
@@ -244,9 +252,12 @@ proposed_protocol_parameter_updates =
244252
"proposed_protocol_parameter_updates"
245253
=:= mp [0 <+ asKey genesis_hash ==> protocol_param_update]
246254

255+
-- | Adds Plutus protocol parameters: cost models, execution units, collateral settings (indices 16-24).
256+
-- Ref: CIP-28
247257
update :: Rule
248258
update = "update" =:= arr [a proposed_protocol_parameter_updates, a epoch]
249259

260+
-- | Adds Plutus V1 scripts (index 3), datums (index 4), and redeemers (index 5) for smart contracts.
250261
transaction_witness_set :: Rule
251262
transaction_witness_set =
252263
comment
@@ -269,6 +280,31 @@ transaction_witness_set =
269280
redeemers :: Rule
270281
redeemers = "redeemers" =:= arr [0 <+ a redeemer]
271282

283+
big_int :: Rule
284+
big_int = "big_int" =:= VInt / big_uint / big_nint
285+
286+
big_uint :: Rule
287+
big_uint = "big_uint" =:= tag 2 bounded_bytes
288+
289+
big_nint :: Rule
290+
big_nint = "big_nint" =:= tag 3 bounded_bytes
291+
292+
bounded_bytes :: Rule
293+
bounded_bytes =
294+
comment
295+
[str|The real bounded_bytes does not have this limit. it instead has
296+
|a different limit which cannot be expressed in CDDL.
297+
|
298+
|The limit is as follows:
299+
| - bytes with a definite-length encoding are limited to size 0..64
300+
| - for bytes with an indefinite-length CBOR encoding, each chunk is
301+
| limited to size 0..64
302+
| ( reminder: in CBOR, the indefinite-length encoding of
303+
| bytestrings consists of a token #2.31 followed by a sequence
304+
| of definite-length encoded bytestrings and a stop code )
305+
|]
306+
$ "bounded_bytes" =:= VBytes `sized` (0 :: Word64, 64 :: Word64)
307+
272308
plutus_v1_script :: Rule
273309
plutus_v1_script =
274310
comment
@@ -370,6 +406,7 @@ auxiliary_data_map =
370406
]
371407
)
372408

409+
-- | Adds auxiliary_data_map format (tag 259).
373410
auxiliary_data :: Rule
374411
auxiliary_data =
375412
comment
@@ -383,6 +420,7 @@ auxiliary_data =
383420
/ auxiliary_data_array
384421
/ auxiliary_data_map
385422

423+
-- | Updates header_body to use Alonzo protocol_version.
386424
header :: Rule
387425
header = "header" =:= arr [a header_body, "body_signature" ==> kes_signature]
388426

0 commit comments

Comments
 (0)