Skip to content

Commit

Permalink
Merge pull request #4828 from IntersectMBO/td/fix-committee-cc-cddl
Browse files Browse the repository at this point in the history
Fix cddl for `update_committee` cold credential
  • Loading branch information
lehins authored Jan 10, 2025
2 parents 10687c7 + d4ff3a1 commit 7573580
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 52 deletions.
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<era>/impl/cddl-files/<era>.cddl`.

These files are generated using [cuddle](/~https://github.com/input-output-hk/cuddle),
based on the Haskell definitions in: `eras/<era>/impl/testlib/Test/Cardano/Ledger/<era>/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.
Expand Down
6 changes: 3 additions & 3 deletions eras/allegra/impl/cddl-files/allegra.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ native_script =
|
| invalid_before:
| specifies the left (included) endpoint a.
|
|
| invalid_hereafter:
| specifies the right (excluded) endpoint b.
|]
Expand Down
22 changes: 11 additions & 11 deletions eras/alonzo/impl/cddl-files/alonzo.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
;
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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])

Expand Down Expand Up @@ -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<addr_keyhash>: pool_owners
; pool_keyhash: operator
; coin: pledge
; coin: cost
; unit_interval: margin
; set<addr_keyhash>: pool_owners
;
pool_params = (pool_keyhash
, vrf_keyhash
Expand Down
8 changes: 4 additions & 4 deletions eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -264,7 +264,7 @@ transaction_witness_set :: Rule
transaction_witness_set =
comment
[str|
|NEW:
|NEW:
| 3: [* plutus_script ]
| 4: [* plutus_data ]
| 5: redeemers
Expand Down Expand Up @@ -419,7 +419,7 @@ native_script =
|
| invalid_before:
| specifies the left (included) endpoint a.
|
|
| invalid_hereafter:
| specifies the right (excluded) endpoint b.
|]
Expand Down
20 changes: 10 additions & 10 deletions eras/babbage/impl/cddl-files/babbage.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
;
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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])

Expand Down Expand Up @@ -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<addr_keyhash>: pool_owners
; pool_keyhash: operator
; coin: pledge
; coin: cost
; unit_interval: margin
; set<addr_keyhash>: pool_owners
;
pool_params = (pool_keyhash
, vrf_keyhash
Expand Down
4 changes: 2 additions & 2 deletions eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -250,7 +250,7 @@ transaction_witness_set :: Rule
transaction_witness_set =
comment
[str|
|NEW:
|NEW:
| 6: [* plutus_v2_script]
|]
$ "transaction_witness_set"
Expand Down
18 changes: 9 additions & 9 deletions eras/conway/impl/cddl-files/conway.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -577,7 +577,7 @@ transaction_witness_set = {? 0 : nonempty_set<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])

Expand Down Expand Up @@ -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<addr_keyhash>: pool_owners
; pool_keyhash: operator
; coin: pledge
; coin: cost
; unit_interval: margin
; set<addr_keyhash>: pool_owners
;
pool_params = (pool_keyhash
, vrf_keyhash
Expand Down Expand Up @@ -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)

Expand All @@ -695,7 +695,7 @@ unreg_drep_cert = (17, drep_credential, coin)
update_committee = (4
, gov_action_id / nil
, set<committee_cold_credential>
, {committee_cold_credential => epoch_no}
, {* committee_cold_credential => epoch_no}
, unit_interval)

update_drep_cert = (18, drep_credential, anchor / nil)
Expand Down
14 changes: 7 additions & 7 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
]

Expand Down Expand Up @@ -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<addr_keyhash>: pool_owners
[str| pool_keyhash: operator
| coin: pledge
| coin: cost
| unit_interval: margin
| set<addr_keyhash>: pool_owners
|]
$ "pool_params"
=:~ grp
Expand Down
4 changes: 2 additions & 2 deletions eras/shelley/impl/cddl-files/shelley.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
4 changes: 3 additions & 1 deletion scripts/gen-cddl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7573580

Please sign in to comment.