diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b28e2f550a7..510e256dcd0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -130,6 +130,18 @@ This will create a new release that will be available as [latest](https://github Make sure that the `YYYY-MM-DD` part in the tag name is alphabetically greater than the rest, otherwise the release won't be tagged as `latest`. Using the current date should ensure that this is the case. +## CDDL files + +For each era, the serialization protocol is defined by a corresponding cddl file, +located at: `eras//impl/cddl-files/.cddl`. + +These files are generated using [cuddle](/~https://github.com/input-output-hk/cuddle), +based on the Haskell definitions in: `eras//impl/testlib/Test/Cardano/Ledger//CDDL.hs`. + +To modify the cddl files for a given era: +1. Edit the CDDL.hs file for the desired era to reflect your changes +2. Regenerate the cddl files by running `./scripts/gen-cddl.sh` + ## Testing the Haskell programs The tests can be run with cabal. diff --git a/eras/allegra/impl/cddl-files/allegra.cddl b/eras/allegra/impl/cddl-files/allegra.cddl index a2e765d1249..f8845393ac2 100644 --- a/eras/allegra/impl/cddl-files/allegra.cddl +++ b/eras/allegra/impl/cddl-files/allegra.cddl @@ -142,7 +142,7 @@ move_instantaneous_reward = [0 / 1, {* stake_credential => delta_coin} / coin] ; ; invalid_before: ; specifies the left (included) endpoint a. -; +; ; invalid_hereafter: ; specifies the right (excluded) endpoint b. ; @@ -215,7 +215,7 @@ reward_account = h'E090000000000000000000000000000000000000000000000000000000' ; "\x00" for multisig scripts ; "\x01" for Plutus V1 scripts ; "\x02" for Plutus V2 scripts -; "\x03" for Plutus V3 scripts +; "\x03" for Plutus V3 scripts ; script_hash = $hash28 @@ -266,7 +266,7 @@ transaction_witness_set = {? 0 : [* vkeywitness] ; which poses a problem for testing. We need to be able to ; generate random valid data for testing implementation of ; our encoders/decoders. Which means we cannot use the actual -; definition here and we hard code the value to 1/2 +; definition here and we hard code the value to 1/2 ; unit_interval = #6.30([1, 2]) diff --git a/eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/CDDL.hs b/eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/CDDL.hs index d57223aaacc..46cd63b25bf 100644 --- a/eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/CDDL.hs +++ b/eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/CDDL.hs @@ -32,7 +32,7 @@ native_script = | | invalid_before: | specifies the left (included) endpoint a. - | + | | invalid_hereafter: | specifies the right (excluded) endpoint b. |] diff --git a/eras/alonzo/impl/cddl-files/alonzo.cddl b/eras/alonzo/impl/cddl-files/alonzo.cddl index d8bec78833d..f0a7be99778 100644 --- a/eras/alonzo/impl/cddl-files/alonzo.cddl +++ b/eras/alonzo/impl/cddl-files/alonzo.cddl @@ -91,7 +91,7 @@ big_uint = #6.2(bounded_bytes) ; the same ; 2) every transaction_index must be strictly smaller than the length of ; transaction_bodies -; NEW: +; NEW: ; invalid_transactions ; block = [header @@ -205,7 +205,7 @@ move_instantaneous_reward = [0 / 1, {* stake_credential => delta_coin} / coin] ; ; invalid_before: ; specifies the left (included) endpoint a. -; +; ; invalid_hereafter: ; specifies the right (excluded) endpoint b. ; @@ -386,7 +386,7 @@ script_data_hash = $hash32 ; "\x00" for multisig scripts ; "\x01" for Plutus V1 scripts ; "\x02" for Plutus V2 scripts -; "\x03" for Plutus V3 scripts +; "\x03" for Plutus V3 scripts ; script_hash = $hash28 @@ -403,7 +403,7 @@ transaction = [transaction_body ; 3: time to live ; 8: validity interval start ; 13: collateral -; NEW: +; NEW: ; 11: script_data_hash ; 13: set transaction_input ; 14: required_signers @@ -442,7 +442,7 @@ transaction_metadatum_label = uint transaction_output = [address, amount : value, ? datum_hash : $hash32] ; -; NEW: +; NEW: ; 3: [* plutus_script ] ; 4: [* plutus_data ] ; 5: redeemers @@ -467,7 +467,7 @@ transaction_witness_set = {? 0 : [* vkeywitness] ; which poses a problem for testing. We need to be able to ; generate random valid data for testing implementation of ; our encoders/decoders. Which means we cannot use the actual -; definition here and we hard code the value to 1/2 +; definition here and we hard code the value to 1/2 ; unit_interval = #6.30([1, 2]) @@ -502,11 +502,11 @@ multi_host_name = (2, dns_name) ; operational_cert = ($kes_vkey, uint, uint, $signature) -; pool_keyhash: operator -; coin: pledge -; coin: cost -; unit_interval: margin -; set: pool_owners +; pool_keyhash: operator +; coin: pledge +; coin: cost +; unit_interval: margin +; set: pool_owners ; pool_params = (pool_keyhash , vrf_keyhash diff --git a/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs b/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs index a136f35b601..e97f89bda87 100644 --- a/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs +++ b/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs @@ -51,7 +51,7 @@ block = | the same | 2) every transaction_index must be strictly smaller than the length of | transaction_bodies - |NEW: + |NEW: | invalid_transactions |] $ "block" @@ -94,7 +94,7 @@ transaction_body = | 3: time to live | 8: validity interval start |13: collateral - |NEW: + |NEW: | 11: script_data_hash | 13: set transaction_input | 14: required_signers @@ -264,7 +264,7 @@ transaction_witness_set :: Rule transaction_witness_set = comment [str| - |NEW: + |NEW: | 3: [* plutus_script ] | 4: [* plutus_data ] | 5: redeemers @@ -419,7 +419,7 @@ native_script = | | invalid_before: | specifies the left (included) endpoint a. - | + | | invalid_hereafter: | specifies the right (excluded) endpoint b. |] diff --git a/eras/babbage/impl/cddl-files/babbage.cddl b/eras/babbage/impl/cddl-files/babbage.cddl index 1dfecfbdc35..7ea1f2e4434 100644 --- a/eras/babbage/impl/cddl-files/babbage.cddl +++ b/eras/babbage/impl/cddl-files/babbage.cddl @@ -213,7 +213,7 @@ move_instantaneous_reward = [0 / 1, {* stake_credential => delta_coin} / coin] ; ; invalid_before: ; specifies the left (included) endpoint a. -; +; ; invalid_hereafter: ; specifies the right (excluded) endpoint b. ; @@ -397,7 +397,7 @@ script_data_hash = $hash32 ; "\x00" for multisig scripts ; "\x01" for Plutus V1 scripts ; "\x02" for Plutus V2 scripts -; "\x03" for Plutus V3 scripts +; "\x03" for Plutus V3 scripts ; script_hash = $hash28 @@ -418,7 +418,7 @@ transaction = [transaction_body ; 3: time to live ; 8: validity interval start ; 13: collateral inputs -; NEW: +; NEW: ; 16: collateral return ; 17: total collateral ; 18: reference inputs @@ -461,7 +461,7 @@ transaction_metadatum_label = uint transaction_output = shelley_transaction_output / babbage_transaction_output ; -; NEW: +; NEW: ; 6: [* plutus_v2_script] ; transaction_witness_set = {? 0 : [* vkeywitness] @@ -485,7 +485,7 @@ transaction_witness_set = {? 0 : [* vkeywitness] ; which poses a problem for testing. We need to be able to ; generate random valid data for testing implementation of ; our encoders/decoders. Which means we cannot use the actual -; definition here and we hard code the value to 1/2 +; definition here and we hard code the value to 1/2 ; unit_interval = #6.30([1, 2]) @@ -520,11 +520,11 @@ multi_host_name = (2, dns_name) ; operational_cert = ($kes_vkey, uint, uint, $signature) -; pool_keyhash: operator -; coin: pledge -; coin: cost -; unit_interval: margin -; set: pool_owners +; pool_keyhash: operator +; coin: pledge +; coin: cost +; unit_interval: margin +; set: pool_owners ; pool_params = (pool_keyhash , vrf_keyhash diff --git a/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs b/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs index 435108a03c1..a2ae46610a6 100644 --- a/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs +++ b/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs @@ -117,7 +117,7 @@ transaction_body = | 3: time to live | 8: validity interval start |13: collateral inputs - |NEW: + |NEW: | 16: collateral return | 17: total collateral | 18: reference inputs @@ -250,7 +250,7 @@ transaction_witness_set :: Rule transaction_witness_set = comment [str| - |NEW: + |NEW: | 6: [* plutus_v2_script] |] $ "transaction_witness_set" diff --git a/eras/conway/impl/cddl-files/conway.cddl b/eras/conway/impl/cddl-files/conway.cddl index d561a1d9737..e70b001772b 100644 --- a/eras/conway/impl/cddl-files/conway.cddl +++ b/eras/conway/impl/cddl-files/conway.cddl @@ -496,7 +496,7 @@ script_data_hash = $hash32 ; "\x00" for multisig scripts ; "\x01" for Plutus V1 scripts ; "\x02" for Plutus V2 scripts -; "\x03" for Plutus V3 scripts +; "\x03" for Plutus V3 scripts ; script_hash = $hash28 @@ -577,7 +577,7 @@ transaction_witness_set = {? 0 : nonempty_set ; which poses a problem for testing. We need to be able to ; generate random valid data for testing implementation of ; our encoders/decoders. Which means we cannot use the actual -; definition here and we hard code the value to 1/2 +; definition here and we hard code the value to 1/2 ; unit_interval = #6.30([1, 2]) @@ -632,11 +632,11 @@ parameter_change_action = (0 , protocol_param_update , policy_hash / nil) -; pool_keyhash: operator -; coin: pledge -; coin: cost -; unit_interval: margin -; set: pool_owners +; pool_keyhash: operator +; coin: pledge +; coin: cost +; unit_interval: margin +; set: pool_owners ; pool_params = (pool_keyhash , vrf_keyhash @@ -686,7 +686,7 @@ stake_vote_deleg_cert = (10, stake_credential, pool_keyhash, drep) stake_vote_reg_deleg_cert = (13, stake_credential, pool_keyhash, drep, coin) -treasury_withdrawals_action = (2, {reward_account => coin}, policy_hash / nil) +treasury_withdrawals_action = (2, {* reward_account => coin}, policy_hash / nil) unreg_cert = (8, stake_credential, coin) @@ -695,7 +695,7 @@ unreg_drep_cert = (17, drep_credential, coin) update_committee = (4 , gov_action_id / nil , set - , {committee_cold_credential => epoch_no} + , {* committee_cold_credential => epoch_no} , unit_interval) update_drep_cert = (18, drep_credential, anchor / nil) diff --git a/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs b/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs index a2ab0e4c1bc..a7cca6c3749 100644 --- a/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs +++ b/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs @@ -243,7 +243,7 @@ hard_fork_initiation_action = treasury_withdrawals_action :: Named Group treasury_withdrawals_action = "treasury_withdrawals_action" - =:~ grp [2, a (mp [asKey reward_account ==> coin]), policy_hash / VNil] + =:~ grp [2, a (mp [0 <+ asKey reward_account ==> coin]), policy_hash / VNil] no_confidence :: Named Group no_confidence = "no_confidence" =:~ grp [3, gov_action_id / VNil] @@ -255,7 +255,7 @@ update_committee = [ 4 , gov_action_id / VNil , a (set committee_cold_credential) - , a (mp [asKey committee_cold_credential ==> epoch_no]) + , a (mp [0 <+ asKey committee_cold_credential ==> epoch_no]) , a unit_interval ] @@ -522,11 +522,11 @@ committee_hot_credential = "committee_hot_credential" =:= credential pool_params :: Named Group pool_params = comment - [str| pool_keyhash: operator - | coin: pledge - | coin: cost - | unit_interval: margin - | set: pool_owners + [str| pool_keyhash: operator + | coin: pledge + | coin: cost + | unit_interval: margin + | set: pool_owners |] $ "pool_params" =:~ grp diff --git a/eras/shelley/impl/cddl-files/shelley.cddl b/eras/shelley/impl/cddl-files/shelley.cddl index 8ecd10a9b60..a7b5d23bcf5 100644 --- a/eras/shelley/impl/cddl-files/shelley.cddl +++ b/eras/shelley/impl/cddl-files/shelley.cddl @@ -195,7 +195,7 @@ reward_account = h'E090000000000000000000000000000000000000000000000000000000' ; "\x00" for multisig scripts ; "\x01" for Plutus V1 scripts ; "\x02" for Plutus V2 scripts -; "\x03" for Plutus V3 scripts +; "\x03" for Plutus V3 scripts ; script_hash = $hash28 @@ -249,7 +249,7 @@ transaction_witness_set = {? 0 : [* vkeywitness] ; which poses a problem for testing. We need to be able to ; generate random valid data for testing implementation of ; our encoders/decoders. Which means we cannot use the actual -; definition here and we hard code the value to 1/2 +; definition here and we hard code the value to 1/2 ; unit_interval = #6.30([1, 2]) diff --git a/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs index 1ed5ca32290..c3c5b3090fd 100644 --- a/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs +++ b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs @@ -378,7 +378,7 @@ script_hash = | "\x00" for multisig scripts | "\x01" for Plutus V1 scripts | "\x02" for Plutus V2 scripts - | "\x03" for Plutus V3 scripts + | "\x03" for Plutus V3 scripts |] $ "script_hash" =:= hash28 diff --git a/libs/cardano-ledger-core/testlib/Test/Cardano/Ledger/Core/Binary/CDDL.hs b/libs/cardano-ledger-core/testlib/Test/Cardano/Ledger/Core/Binary/CDDL.hs index 17c248ae423..2a937b79791 100644 --- a/libs/cardano-ledger-core/testlib/Test/Cardano/Ledger/Core/Binary/CDDL.hs +++ b/libs/cardano-ledger-core/testlib/Test/Cardano/Ledger/Core/Binary/CDDL.hs @@ -195,7 +195,7 @@ unit_interval = |which poses a problem for testing. We need to be able to |generate random valid data for testing implementation of |our encoders/decoders. Which means we cannot use the actual - |definition here and we hard code the value to 1/2 + |definition here and we hard code the value to 1/2 |] $ "unit_interval" =:= tag 30 (arr [1, 2]) diff --git a/scripts/gen-cddl.sh b/scripts/gen-cddl.sh index 01ac5014d7a..0febae21059 100755 --- a/scripts/gen-cddl.sh +++ b/scripts/gen-cddl.sh @@ -6,10 +6,12 @@ eras=("shelley" "allegra" "mary" "alonzo" "babbage" "conway") for era in ${eras[@]}; do - changed=$(git diff --name-only origin/master -- 'eras/${era}/impl/testlib/Test/Cardano/Ledger/${era^}/CDDL.hs') + changed=$(git diff --name-only origin/master -- "eras/${era}/impl/testlib/Test/Cardano/Ledger/${era^}/CDDL.hs" | xargs) if [[ -n "$changed" ]]; then + echo "Generating cddl for $era..." cabal run cardano-ledger-$era:exe:huddle-cddl + echo "Regenerated ${era}.cddl" fi done