Skip to content

Commit ae10611

Browse files
committed
CDDL: Typeclass-based huddle impl for Babbage.
Repeat the same additions as core, shelley, allegra, mary and alonzo.
1 parent 251d8b5 commit ae10611

File tree

6 files changed

+661
-77
lines changed

6 files changed

+661
-77
lines changed

eras/babbage/impl/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.13.0.0
44

5+
* Add `cddl` sub-library, and `generate-cddl` executable.
56
* Remove deprecated functions `txOutData`, `txOutDataHash`, `txOutScript`
67
* Remove deprecated type `Babbage`
78
* Removed deprecated accessor functions:
@@ -26,6 +27,10 @@
2627
* Add `EraTxLevel` instance
2728
* Add `mkCollateralTxIn`
2829

30+
### `cddl`
31+
32+
* Add full `HuddleSpec`.
33+
2934
### `testlib`
3035

3136
* Add `plutus_v2_script` to CDDL exports

eras/babbage/impl/cardano-ledger-babbage.cabal

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,50 @@ library
9999
transformers,
100100
validation-selective,
101101

102+
library cddl
103+
exposed-modules:
104+
Cardano.Ledger.Babbage.HuddleSpec
105+
106+
visibility: public
107+
hs-source-dirs: cddl/lib
108+
default-language: Haskell2010
109+
ghc-options:
110+
-Wall
111+
-Wcompat
112+
-Wincomplete-record-updates
113+
-Wincomplete-uni-patterns
114+
-Wredundant-constraints
115+
-Wpartial-fields
116+
-Wunused-packages
117+
118+
build-depends:
119+
base,
120+
cardano-ledger-alonzo:cddl,
121+
cardano-ledger-babbage,
122+
cuddle >=0.4,
123+
heredoc,
124+
125+
executable generate-cddl
126+
main-is: Main.hs
127+
hs-source-dirs: cddl/exe
128+
other-modules: Paths_cardano_ledger_babbage
129+
default-language: Haskell2010
130+
ghc-options:
131+
-Wall
132+
-Wcompat
133+
-Wincomplete-record-updates
134+
-Wincomplete-uni-patterns
135+
-Wredundant-constraints
136+
-Wpartial-fields
137+
-Wunused-packages
138+
139+
build-depends:
140+
base,
141+
cardano-ledger-binary:testlib >=1.5,
142+
cddl,
143+
directory,
144+
filepath,
145+
102146
library testlib
103147
exposed-modules:
104148
Test.Cardano.Ledger.Babbage.Arbitrary

eras/babbage/impl/cddl-files/babbage.cddl

Lines changed: 39 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,20 @@ block =
1010
, transaction_bodies : [* transaction_body]
1111
, transaction_witness_sets : [* transaction_witness_set]
1212
, auxiliary_data_set : {* transaction_index => auxiliary_data}
13-
, invalid_transactions : [* transaction_index]
13+
, invalid_transactions : [* transaction_index] ; new
1414
]
1515

1616

1717
header = [header_body, body_signature : kes_signature]
1818

19-
; block_body_size: merkle triple root
20-
; vrf_result: NEW, replaces nonce_vrf and leader_vrf
2119
header_body =
2220
[ block_number : block_number
2321
, slot : slot
2422
, prev_hash : hash32/ nil
2523
, issuer_vkey : vkey
2624
, vrf_vkey : vrf_vkey
27-
, vrf_result : vrf_cert
28-
, block_body_size : uint
25+
, vrf_result : vrf_cert ; replaces nonce_vrf and leader_vrf
26+
, block_body_size : uint ; merkle triple root
2927
, block_body_hash : hash32
3028
, operational_cert
3129
, protocol_version
@@ -66,32 +64,24 @@ major_protocol_version = 0 .. 9
6664

6765
kes_signature = bytes .size 448
6866

69-
; 2: fee
70-
; 3: time to live
71-
; 8: validity interval start
72-
; 13: collateral inputs
73-
; NEW:
74-
; 16: collateral return
75-
; 17: total collateral
76-
; 18: reference inputs
7767
transaction_body =
7868
{ 0 : set<transaction_input>
7969
, 1 : [* transaction_output]
80-
, 2 : coin
81-
, ? 3 : slot
70+
, 2 : coin ; fee
71+
, ? 3 : slot ; time to live
8272
, ? 4 : [* certificate]
8373
, ? 5 : withdrawals
8474
, ? 6 : update
8575
, ? 7 : auxiliary_data_hash
86-
, ? 8 : slot
76+
, ? 8 : slot ; validity interval start
8777
, ? 9 : mint
8878
, ? 11 : script_data_hash
89-
, ? 13 : set<transaction_input>
79+
, ? 13 : set<transaction_input> ; collateral
9080
, ? 14 : required_signers
9181
, ? 15 : network_id
92-
, ? 16 : transaction_output
93-
, ? 17 : coin
94-
, ? 18 : set<transaction_input>
82+
, ? 16 : transaction_output ; collateral return
83+
, ? 17 : coin ; total collateral
84+
, ? 18 : set<transaction_input> ; reference inputs
9585
}
9686

9787

@@ -103,8 +93,6 @@ transaction_id = hash32
10393

10494
; Both of the Alonzo and Babbage style TxOut formats are equally valid
10595
; and can be used interchangeably.
106-
; NEW:
107-
; babbage_transaction_output
10896
transaction_output = shelley_transaction_output/ babbage_transaction_output
10997

11098
shelley_transaction_output = [address, amount : value, ? datum_hash : hash32]
@@ -174,11 +162,13 @@ hash28 = bytes .size 28
174162

175163
asset_name = bytes .size (0 .. 32)
176164

177-
; NEW starting with babbage
178-
; datum_option
179-
; script_ref
180165
babbage_transaction_output =
181-
{0 : address, 1 : value, ? 2 : datum_option, ? 3 : script_ref}
166+
{ 0 : address
167+
, 1 : value
168+
, ? 2 : datum_option ; new
169+
, ? 3 : script_ref ; new
170+
}
171+
182172

183173
datum_option = [0, hash32// 1, data]
184174

@@ -230,8 +220,6 @@ script_ref = #6.24(bytes .cbor script)
230220
script = [0, native_script// 1, plutus_v1_script// 2, plutus_v2_script]
231221

232222
; Allegra introduces timelock support for native scripts.
233-
; This is the 6-variant native script format used by
234-
; Allegra, Mary, Alonzo, Babbage, and Conway.
235223
;
236224
; Timelock validity intervals are half-open intervals [a, b).
237225
; script_invalid_before: specifies the left (included) endpoint a.
@@ -317,6 +305,7 @@ pool_keyhash = hash28
317305

318306
pool_registration_cert = (3, pool_params)
319307

308+
; Pool parameters for stake pool registration
320309
pool_params =
321310
( operator : pool_keyhash
322311
, vrf_keyhash : vrf_keyhash
@@ -404,51 +393,29 @@ update = [proposed_protocol_parameter_updates, epoch]
404393

405394
proposed_protocol_parameter_updates = {* genesis_hash => protocol_param_update}
406395

407-
; 0: minfee A
408-
; 1: minfee B
409-
; 2: max block body size
410-
; 3: max transaction size
411-
; 4: max block header size
412-
; 5: key deposit
413-
; 6: pool deposit
414-
; 7: maximum epoch
415-
; 8: n_opt: desired number of stake pools
416-
; 9: pool pledge influence
417-
; 10: expansion rate
418-
; 11: treasury growth rate
419-
; 14: protocol version
420-
; 16: min pool cost
421-
; 17: ada per utxo byte
422-
; 18: cost models for script languages
423-
; 19: execution costs
424-
; 20: max tx ex units
425-
; 21: max block ex units
426-
; 22: max value size
427-
; 23: collateral percentage
428-
; 24: max collateral inputs
429396
protocol_param_update =
430-
{ ? 0 : uint
431-
, ? 1 : uint
432-
, ? 2 : uint .size 4
433-
, ? 3 : uint .size 4
434-
, ? 4 : uint .size 2
435-
, ? 5 : coin
436-
, ? 6 : coin
437-
, ? 7 : epoch_interval
438-
, ? 8 : uint .size 2
439-
, ? 9 : nonnegative_interval
440-
, ? 10 : unit_interval
441-
, ? 11 : unit_interval
442-
, ? 14 : protocol_version
443-
, ? 16 : coin
444-
, ? 17 : coin
445-
, ? 18 : cost_models
446-
, ? 19 : ex_unit_prices
447-
, ? 20 : ex_units
448-
, ? 21 : ex_units
449-
, ? 22 : uint
450-
, ? 23 : uint
451-
, ? 24 : uint
397+
{ ? 0 : uint ; minfee A
398+
, ? 1 : uint ; minfee B
399+
, ? 2 : uint .size 4 ; max block body size
400+
, ? 3 : uint .size 4 ; max transaction size
401+
, ? 4 : uint .size 2 ; max block header size
402+
, ? 5 : coin ; key deposit
403+
, ? 6 : coin ; pool deposit
404+
, ? 7 : epoch_interval ; maximum epoch
405+
, ? 8 : uint .size 2 ; n_opt: desired number of stake pools
406+
, ? 9 : nonnegative_interval ; pool pledge influence
407+
, ? 10 : unit_interval ; expansion rate
408+
, ? 11 : unit_interval ; treasury growth rate
409+
, ? 14 : [protocol_version] ; protocol version
410+
, ? 16 : coin ; min pool cost
411+
, ? 17 : coin ; ada per utxo byte
412+
, ? 18 : cost_models ; cost models for script languages
413+
, ? 19 : ex_unit_prices ; execution costs
414+
, ? 20 : ex_units ; max tx ex units
415+
, ? 21 : ex_units ; max block ex units
416+
, ? 22 : uint ; max value size
417+
, ? 23 : uint ; collateral percentage
418+
, ? 24 : uint ; max collateral inputs
452419
}
453420

454421

@@ -460,8 +427,6 @@ positive_int = 1 .. max_word64
460427

461428
max_word64 = 18446744073709551615
462429

463-
; 0: Plutus v1
464-
; 1: Plutus v2
465430
cost_models = {? 0 : [166*166 int64], ? 1 : [175*175 int64]}
466431

467432
ex_unit_prices = [mem_price : positive_interval, step_price : positive_interval]
@@ -541,9 +506,6 @@ required_signers = set<addr_keyhash>
541506

542507
network_id = 0/ 1
543508

544-
;
545-
; NEW:
546-
; 6: [* plutus_v2_script]
547509
transaction_witness_set =
548510
{ ? 0 : [* vkeywitness]
549511
, ? 1 : [* native_script]

eras/babbage/impl/cddl/exe/Main.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Main where
2+
3+
import Cardano.Ledger.Babbage.HuddleSpec (babbageCDDL)
4+
import Paths_cardano_ledger_babbage (getDataFileName)
5+
import System.Directory (createDirectoryIfMissing)
6+
import System.FilePath (takeDirectory)
7+
import Test.Cardano.Ledger.Binary.Cuddle (writeSpec)
8+
9+
main :: IO ()
10+
main = do
11+
outputPath <- getDataFileName "cddl-files/babbage.cddl"
12+
createDirectoryIfMissing True (takeDirectory outputPath)
13+
writeSpec babbageCDDL outputPath
14+
putStrLn $ "Generated CDDL file at: " ++ outputPath

0 commit comments

Comments
 (0)