Skip to content

Commit 888e696

Browse files
committed
CDDL: Consolidate scripts across all eras.
* Make native_script fields era-prefixed as and when they are introduced * Add smart constructors for script types in core * Fix script_n_of_k for eras after allegra
1 parent 6fda464 commit 888e696

File tree

20 files changed

+382
-257
lines changed

20 files changed

+382
-257
lines changed

eras/allegra/impl/CHANGELOG.md

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

1212
### `testlib`
1313

14+
* Rename `native_script` -> `allegra_native_script` in CDDL
1415
* Add `auxiliary_data_array` to CDDL for simplification
1516
* Remove `metadata` redefinition in CDDL
1617
* Use fixed-sized `uint .size 8` for `slot` in CDDL for timelock validity intervals

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ hash28 = bytes .size 28
145145
; To compute a script hash, note that you must prepend
146146
; a tag to the bytes of the script before hashing.
147147
; The tag is determined by the language.
148-
; The tags in the Conway era are:
149-
; "\x00" for multisig scripts
148+
; The tags are:
149+
; "\x00" for multisig/native scripts
150150
; "\x01" for Plutus V1 scripts
151151
; "\x02" for Plutus V2 scripts
152152
; "\x03" for Plutus V3 scripts
153+
; "\x04" for Plutus V4 scripts
153154
script_hash = hash28
154155

155156
; This will be deprecated in a future era
@@ -286,13 +287,15 @@ transaction_witness_set =
286287

287288
vkeywitness = [vkey, signature]
288289

289-
; Timelock validity intervals are half-open intervals [a, b).
290+
; Allegra introduces timelock support for native scripts.
291+
; This is the 6-variant native script format used by
292+
; Allegra, Mary, Alonzo, Babbage, and Conway.
290293
;
291-
; invalid_before:
292-
; specifies the left (included) endpoint a.
294+
; Timelock validity intervals are half-open intervals [a, b).
295+
; invalid_before: specifies the left (included) endpoint a.
296+
; invalid_hereafter: specifies the right (excluded) endpoint b.
293297
;
294-
; invalid_hereafter:
295-
; specifies the right (excluded) endpoint b.
298+
; Note: Allegra switched to int64 for script_n_of_k thresholds.
296299
native_script =
297300
[ script_pubkey
298301
// script_all
@@ -317,8 +320,12 @@ min_int64 = -9223372036854775808
317320

318321
max_int64 = 9223372036854775807
319322

323+
; Timelock validity intervals are half-open intervals [a, b).
324+
; This field specifies the left (included) endpoint a.
320325
invalid_before = (4, slot)
321326

327+
; Timelock validity intervals are half-open intervals [a, b).
328+
; This field specifies the right (excluded) endpoint b.
322329
invalid_hereafter = (5, slot)
323330

324331
bootstrap_witness =

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ module Test.Cardano.Ledger.Allegra.CDDL (
1717
auxiliary_data,
1818
auxiliary_data_array,
1919
auxiliary_scripts,
20-
script_pubkey,
21-
script_all,
22-
script_any,
23-
invalid_before,
24-
invalid_hereafter,
20+
allegra_native_script,
2521
) where
2622

2723
import Cardano.Ledger.Allegra (AllegraEra)
@@ -38,16 +34,18 @@ allegraCDDL =
3834
, HIRule $ transaction @AllegraEra
3935
]
4036

41-
native_script :: Rule
42-
native_script =
37+
allegra_native_script :: Rule
38+
allegra_native_script =
4339
comment
44-
[str|Timelock validity intervals are half-open intervals [a, b).
40+
[str|Allegra introduces timelock support for native scripts.
41+
|This is the 6-variant native script format used by
42+
|Allegra, Mary, Alonzo, Babbage, and Conway.
4543
|
46-
| invalid_before:
47-
| specifies the left (included) endpoint a.
44+
|Timelock validity intervals are half-open intervals [a, b).
45+
| invalid_before: specifies the left (included) endpoint a.
46+
| invalid_hereafter: specifies the right (excluded) endpoint b.
4847
|
49-
| invalid_hereafter:
50-
| specifies the right (excluded) endpoint b.
48+
|Note: Allegra switched to int64 for script_n_of_k thresholds.
5149
|]
5250
$ "native_script"
5351
=:= arr [a script_pubkey]
@@ -58,25 +56,25 @@ native_script =
5856
/ arr [a invalid_hereafter]
5957

6058
script_pubkey :: Named Group
61-
script_pubkey = "script_pubkey" =:~ grp [0, a addr_keyhash]
59+
script_pubkey = mkScriptPubkey
6260

6361
script_all :: Named Group
64-
script_all = "script_all" =:~ grp [1, a (arr [0 <+ a native_script])]
62+
script_all = mkScriptAll allegra_native_script
6563

6664
script_any :: Named Group
67-
script_any = "script_any" =:~ grp [2, a (arr [0 <+ a native_script])]
65+
script_any = mkScriptAny allegra_native_script
6866

6967
script_n_of_k :: Named Group
70-
script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> int64, a (arr [0 <+ a native_script])]
68+
script_n_of_k = mkScriptNOfK int64 allegra_native_script
7169

7270
invalid_before :: Named Group
73-
invalid_before = "invalid_before" =:~ grp [4, a slot]
71+
invalid_before = mkInvalidBefore
7472

7573
invalid_hereafter :: Named Group
76-
invalid_hereafter = "invalid_hereafter" =:~ grp [5, a slot]
74+
invalid_hereafter = mkInvalidHereafter
7775

7876
auxiliary_scripts :: Rule
79-
auxiliary_scripts = "auxiliary_scripts" =:= arr [0 <+ a native_script]
77+
auxiliary_scripts = "auxiliary_scripts" =:= arr [0 <+ a allegra_native_script]
8078

8179
auxiliary_data_array :: Rule
8280
auxiliary_data_array =
@@ -134,6 +132,6 @@ transaction_witness_set =
134132
"transaction_witness_set"
135133
=:= mp
136134
[ opt $ idx 0 ==> arr [0 <+ a vkeywitness]
137-
, opt $ idx 1 ==> arr [0 <+ a native_script]
135+
, opt $ idx 1 ==> arr [0 <+ a allegra_native_script]
138136
, opt $ idx 2 ==> arr [0 <+ a bootstrap_witness]
139137
]

eras/alonzo/impl/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
### `testlib`
2727

28+
* Rename `plutus_script` -> `plutus_v1_script` in CDDL
29+
* Add `plutus_v1_script` to CDDL exports
2830
* Add `auxiliary_data_map` to CDDL for simplification
2931
* Remove redefinition of `auxiliary_data_hash` from CDDL
3032
* Use fixed-sized `uint .size 8` for `slot` and `block_number` in CDDL for header

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,12 @@ policy_id = script_hash
153153
; To compute a script hash, note that you must prepend
154154
; a tag to the bytes of the script before hashing.
155155
; The tag is determined by the language.
156-
; The tags in the Conway era are:
157-
; "\x00" for multisig scripts
156+
; The tags are:
157+
; "\x00" for multisig/native scripts
158158
; "\x01" for Plutus V1 scripts
159159
; "\x02" for Plutus V2 scripts
160160
; "\x03" for Plutus V3 scripts
161+
; "\x04" for Plutus V4 scripts
161162
script_hash = hash28
162163

163164
hash28 = bytes .size 28
@@ -436,28 +437,30 @@ network_id = 0/ 1
436437

437438
;
438439
; NEW:
439-
; 3: [* plutus_script ]
440+
; 3: [* plutus_v1_script ]
440441
; 4: [* plutus_data ]
441442
; 5: redeemers
442443
transaction_witness_set =
443444
{ ? 0 : [* vkeywitness]
444445
, ? 1 : [* native_script]
445446
, ? 2 : [* bootstrap_witness]
446-
, ? 3 : [* plutus_script]
447+
, ? 3 : [* plutus_v1_script]
447448
, ? 4 : [* plutus_data]
448449
, ? 5 : redeemers
449450
}
450451

451452

452453
vkeywitness = [vkey, signature]
453454

454-
; Timelock validity intervals are half-open intervals [a, b).
455+
; Allegra introduces timelock support for native scripts.
456+
; This is the 6-variant native script format used by
457+
; Allegra, Mary, Alonzo, Babbage, and Conway.
455458
;
456-
; invalid_before:
457-
; specifies the left (included) endpoint a.
459+
; Timelock validity intervals are half-open intervals [a, b).
460+
; invalid_before: specifies the left (included) endpoint a.
461+
; invalid_hereafter: specifies the right (excluded) endpoint b.
458462
;
459-
; invalid_hereafter:
460-
; specifies the right (excluded) endpoint b.
463+
; Note: Allegra switched to int64 for script_n_of_k thresholds.
461464
native_script =
462465
[ script_pubkey
463466
// script_all
@@ -474,10 +477,14 @@ script_all = (1, [* native_script])
474477

475478
script_any = (2, [* native_script])
476479

477-
script_n_of_k = (3, n : uint, [* native_script])
480+
script_n_of_k = (3, n : int64, [* native_script])
478481

482+
; Timelock validity intervals are half-open intervals [a, b).
483+
; This field specifies the left (included) endpoint a.
479484
invalid_before = (4, slot)
480485

486+
; Timelock validity intervals are half-open intervals [a, b).
487+
; This field specifies the right (excluded) endpoint b.
481488
invalid_hereafter = (5, slot)
482489

483490
bootstrap_witness =
@@ -488,7 +495,9 @@ bootstrap_witness =
488495
]
489496

490497

491-
plutus_script = bytes
498+
; Alonzo introduces Plutus smart contracts.
499+
; Plutus V1 scripts are opaque bytestrings.
500+
plutus_v1_script = bytes
492501

493502
; NEW
494503
plutus_data =
@@ -565,7 +574,7 @@ auxiliary_data_array =
565574
auxiliary_scripts = [* native_script]
566575

567576
auxiliary_data_map =
568-
#6.259({? 0 : metadata, ? 1 : [* native_script], ? 2 : [* plutus_script]})
577+
#6.259({? 0 : metadata, ? 1 : [* native_script], ? 2 : [* plutus_v1_script]})
569578

570579
transaction =
571580
[transaction_body, transaction_witness_set, bool, auxiliary_data/ nil]

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

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Test.Cardano.Ledger.Alonzo.CDDL (
1414
certificates,
1515
required_signers,
1616
network_id,
17-
native_script,
17+
plutus_v1_script,
1818
redeemers,
1919
constr,
2020
ex_unit_prices,
@@ -252,25 +252,30 @@ transaction_witness_set =
252252
comment
253253
[str|
254254
|NEW:
255-
| 3: [* plutus_script ]
255+
| 3: [* plutus_v1_script ]
256256
| 4: [* plutus_data ]
257257
| 5: redeemers
258258
|]
259259
$ "transaction_witness_set"
260260
=:= mp
261261
[ opt $ idx 0 ==> arr [0 <+ a vkeywitness]
262-
, opt $ idx 1 ==> arr [0 <+ a native_script]
262+
, opt $ idx 1 ==> arr [0 <+ a allegra_native_script]
263263
, opt $ idx 2 ==> arr [0 <+ a bootstrap_witness]
264-
, opt $ idx 3 ==> arr [0 <+ a plutus_script]
264+
, opt $ idx 3 ==> arr [0 <+ a plutus_v1_script]
265265
, opt $ idx 4 ==> arr [0 <+ a plutus_data]
266266
, opt $ idx 5 ==> redeemers
267267
]
268268

269269
redeemers :: Rule
270270
redeemers = "redeemers" =:= arr [0 <+ a redeemer]
271271

272-
plutus_script :: Rule
273-
plutus_script = "plutus_script" =:= VBytes
272+
plutus_v1_script :: Rule
273+
plutus_v1_script =
274+
comment
275+
[str|Alonzo introduces Plutus smart contracts.
276+
|Plutus V1 scripts are opaque bytestrings.
277+
|]
278+
$ "plutus_v1_script" =:= VBytes
274279

275280
plutus_data :: Rule
276281
plutus_data =
@@ -360,8 +365,8 @@ auxiliary_data_map =
360365
259
361366
( mp
362367
[ opt (idx 0 ==> metadata)
363-
, opt (idx 1 ==> arr [0 <+ a native_script])
364-
, opt (idx 2 ==> arr [0 <+ a plutus_script])
368+
, opt (idx 1 ==> arr [0 <+ a allegra_native_script])
369+
, opt (idx 2 ==> arr [0 <+ a plutus_v1_script])
365370
]
366371
)
367372

@@ -401,28 +406,6 @@ header_body =
401406
, a (protocol_version @AlonzoEra)
402407
]
403408

404-
native_script :: Rule
405-
native_script =
406-
comment
407-
[str|Timelock validity intervals are half-open intervals [a, b).
408-
|
409-
| invalid_before:
410-
| specifies the left (included) endpoint a.
411-
|
412-
| invalid_hereafter:
413-
| specifies the right (excluded) endpoint b.
414-
|]
415-
$ "native_script"
416-
=:= arr [a script_pubkey]
417-
/ arr [a script_all]
418-
/ arr [a script_any]
419-
/ arr [a script_n_of_k]
420-
/ arr [a invalid_before]
421-
/ arr [a invalid_hereafter]
422-
423-
script_n_of_k :: Named Group
424-
script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> VUInt, a (arr [0 <+ a native_script])]
425-
426409
positive_interval :: Rule
427410
positive_interval = "positive_interval" =:= tag 30 (arr [a positive_int, a positive_int])
428411

eras/babbage/impl/CHANGELOG.md

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

2727
### `testlib`
2828

29+
* Add `plutus_v2_script` to CDDL exports
2930
* Hide Shelley CDDL `protocol_version` and re-export a new one for Babbage
3031
* Use fixed-sized `uint .size 8` for `slot` and `block_number` in CDDL for header
3132
* Add `BabbageEraImp`

0 commit comments

Comments
 (0)