From 20f7583f182a60fd46070b2051937814de59d8c1 Mon Sep 17 00:00:00 2001 From: Aniket Deshpande Date: Fri, 24 Oct 2025 19:59:18 +0530 Subject: [PATCH 1/5] CDDL: Switch to explicit exports in core. * Rename distinct_VBytes to distinct_bytes for consistency. * Add mkHashSized to make hash{28,32,64,448}. --- eras/conway/impl/cddl-files/conway.cddl | 8 +- eras/dijkstra/impl/cddl-files/dijkstra.cddl | 10 +-- .../Test/Cardano/Ledger/Core/Binary/CDDL.hs | 75 ++++++++++++++++--- 3 files changed, 74 insertions(+), 19 deletions(-) diff --git a/eras/conway/impl/cddl-files/conway.cddl b/eras/conway/impl/cddl-files/conway.cddl index a7afa409716..9395aa7d82e 100644 --- a/eras/conway/impl/cddl-files/conway.cddl +++ b/eras/conway/impl/cddl-files/conway.cddl @@ -321,11 +321,11 @@ invalid_hereafter = (5, slot_no) ; around for tests in order to avoid generating duplicates, since ; the cddl tool we use for roundtrip testing doesn't generate ; distinct collections. -plutus_v1_script = distinct_VBytes +plutus_v1_script = distinct_bytes ; A type for distinct values. ; The type parameter must support .size, for example: bytes or uint -distinct_VBytes = +distinct_bytes = bytes .size 8 / bytes .size 16 / bytes .size 20 @@ -333,9 +333,9 @@ distinct_VBytes = / bytes .size 30 / bytes .size 32 -plutus_v2_script = distinct_VBytes +plutus_v2_script = distinct_bytes -plutus_v3_script = distinct_VBytes +plutus_v3_script = distinct_bytes certificates = nonempty_oset diff --git a/eras/dijkstra/impl/cddl-files/dijkstra.cddl b/eras/dijkstra/impl/cddl-files/dijkstra.cddl index 10eef6f761c..5973847163e 100644 --- a/eras/dijkstra/impl/cddl-files/dijkstra.cddl +++ b/eras/dijkstra/impl/cddl-files/dijkstra.cddl @@ -327,11 +327,11 @@ credential = [0, addr_keyhash// 1, script_hash] ; around for tests in order to avoid generating duplicates, since ; the cddl tool we use for roundtrip testing doesn't generate ; distinct collections. -plutus_v1_script = distinct_VBytes +plutus_v1_script = distinct_bytes ; A type for distinct values. ; The type parameter must support .size, for example: bytes or uint -distinct_VBytes = +distinct_bytes = bytes .size 8 / bytes .size 16 / bytes .size 20 @@ -339,11 +339,11 @@ distinct_VBytes = / bytes .size 30 / bytes .size 32 -plutus_v2_script = distinct_VBytes +plutus_v2_script = distinct_bytes -plutus_v3_script = distinct_VBytes +plutus_v3_script = distinct_bytes -plutus_v4_script = distinct_VBytes +plutus_v4_script = distinct_bytes certificates = nonempty_oset 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 dd458b291a1..cb80ab44103 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 @@ -1,25 +1,66 @@ +{-# LANGUAGE AllowAmbiguousTypes #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} {-# LANGUAGE NoImplicitPrelude #-} {- HLINT ignore "Use camelCase" -} {- HLINT ignore "Evaluate" -} -module Test.Cardano.Ledger.Core.Binary.CDDL where +module Test.Cardano.Ledger.Core.Binary.CDDL ( + -- * Base sized bytes + hash28, + hash32, + hash64, + bytes80, + hash448, + + -- * Misc. + coin, + positive_coin, + address, + reward_account, + addr_keyhash, + pool_keyhash, + vrf_keyhash, + vkey, + vrf_vkey, + vrf_cert, + kes_vkey, + kes_signature, + signkeyKES, + signature, + big_int, + minInt64, + maxInt64, + negInt64, + posInt64, + nonZeroInt64, + int64, + positive_int, + maxWord32, + posWord32, + unit_interval, + nonnegative_interval, + distinct, + bounded_bytes, +) where import Codec.CBOR.Cuddle.Huddle import Data.Function (($)) import Data.Semigroup ((<>)) import qualified Data.Text as T import Data.Word (Word64) +import GHC.Base (error) import GHC.Show (Show (show)) import Text.Heredoc import Prelude (Integer) --------------------------------------------------------------------------------- --- Base Types --------------------------------------------------------------------------------- coin :: Rule coin = "coin" =:= VUInt @@ -94,15 +135,23 @@ pool_keyhash = "pool_keyhash" =:= hash28 vrf_keyhash :: Rule vrf_keyhash = "vrf_keyhash" =:= hash32 --------------------------------------------------------------------------------- --- Crypto --------------------------------------------------------------------------------- +mkHashSized :: Word64 -> Rule +mkHashSized size = "hash" <> T.pack (show size) =:= VBytes `sized` size hash28 :: Rule -hash28 = "hash28" =:= VBytes `sized` (28 :: Word64) +hash28 = mkHashSized 28 hash32 :: Rule -hash32 = "hash32" =:= VBytes `sized` (32 :: Word64) +hash32 = mkHashSized 32 + +hash64 :: Rule +hash64 = mkHashSized 64 + +bytes80 :: Rule +bytes80 = "bytes80" =:= VBytes `sized` (80 :: Word64) + +hash448 :: Rule +hash448 = mkHashSized 448 vkey :: Rule vkey = "vkey" =:= VBytes `sized` (32 :: Word64) @@ -226,10 +275,16 @@ distinct x = |The type parameter must support .size, for example: bytes or uint |] $ "distinct_" - <> T.pack (show x) + <> show' x =:= (x `sized` (8 :: Word64)) / (x `sized` (16 :: Word64)) / (x `sized` (20 :: Word64)) / (x `sized` (24 :: Word64)) / (x `sized` (30 :: Word64)) / (x `sized` (32 :: Word64)) + where + show' :: Value s -> T.Text + show' = \case + VBytes -> T.pack "bytes" + VUInt -> T.pack "uint" + _ -> error "Unsupported Value for `distinct`" From 135bfb196db70f33c7a5f3032d2dffd8850ec942 Mon Sep 17 00:00:00 2001 From: Aniket Deshpande Date: Mon, 27 Oct 2025 16:31:59 +0530 Subject: [PATCH 2/5] CDDL: Switch to explicit exports for all eras. * Remove duplicate mint and value definitions in alonzo. --- .../Test/Cardano/Ledger/Allegra/CDDL.hs | 18 +++-- .../Test/Cardano/Ledger/Alonzo/CDDL.hs | 30 +++---- .../Test/Cardano/Ledger/Babbage/CDDL.hs | 23 +----- .../Test/Cardano/Ledger/Conway/CDDL.hs | 79 ++++++++++++------- .../Test/Cardano/Ledger/Dijkstra/CDDL.hs | 27 +------ .../testlib/Test/Cardano/Ledger/Mary/CDDL.hs | 14 ++-- .../Test/Cardano/Ledger/Shelley/CDDL.hs | 30 ++++++- 7 files changed, 116 insertions(+), 105 deletions(-) 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 ed8416bec5f..5625925b556 100644 --- a/eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/CDDL.hs +++ b/eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/CDDL.hs @@ -12,19 +12,23 @@ module Test.Cardano.Ledger.Allegra.CDDL ( module Test.Cardano.Ledger.Shelley.CDDL, - module Test.Cardano.Ledger.Allegra.CDDL, + allegraCDDL, + transaction_witness_set, + auxiliary_data, + metadata, + auxiliary_scripts, + script_pubkey, + script_all, + script_any, + invalid_before, + invalid_hereafter, ) where import Cardano.Ledger.Allegra (AllegraEra) import Cardano.Ledger.Core (Era) import Codec.CBOR.Cuddle.Huddle import Data.Function (($)) -import Test.Cardano.Ledger.Shelley.CDDL hiding ( - block, - transaction, - transaction_body, - transaction_witness_set, - ) +import Test.Cardano.Ledger.Shelley.CDDL import Text.Heredoc allegraCDDL :: Huddle 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 d18897cb8c8..91a2e384d17 100644 --- a/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs +++ b/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs @@ -10,7 +10,17 @@ module Test.Cardano.Ledger.Alonzo.CDDL ( module Test.Cardano.Ledger.Mary.CDDL, - module Test.Cardano.Ledger.Alonzo.CDDL, + alonzoCDDL, + certificates, + auxiliary_data_hash, + required_signers, + network_id, + native_script, + redeemers, + constr, + ex_unit_prices, + ex_units, + positive_interval, ) where import Cardano.Ledger.Alonzo (AlonzoEra) @@ -19,21 +29,9 @@ import Data.Function (($)) import Data.Word (Word64) import Test.Cardano.Ledger.Mary.CDDL hiding ( auxiliary_data, - block, header, - header_body, - mint, - native_script, - proposed_protocol_parameter_updates, - protocol_param_update, - protocol_version, - script_n_of_k, - transaction, - transaction_body, - transaction_output, transaction_witness_set, update, - value, ) import Text.Heredoc @@ -435,9 +433,3 @@ network_id = "network_id" =:= int 0 / int 1 auxiliary_data_hash :: Rule auxiliary_data_hash = "auxiliary_data_hash" =:= hash32 - -mint :: Rule -mint = "mint" =:= multiasset int64 - -value :: Rule -value = "value" =:= coin / sarr [a coin, a (multiasset VUInt)] 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 e3c0d44ebc1..b859001b759 100644 --- a/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs +++ b/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs @@ -10,32 +10,17 @@ module Test.Cardano.Ledger.Babbage.CDDL ( module Test.Cardano.Ledger.Alonzo.CDDL, - module Test.Cardano.Ledger.Babbage.CDDL, + babbageCDDL, + operational_cert, + babbage_transaction_output, + plutus_data, ) where import Cardano.Ledger.Babbage (BabbageEra) import Codec.CBOR.Cuddle.Huddle import Data.Word (Word64) import Test.Cardano.Ledger.Alonzo.CDDL hiding ( - auxiliary_data, - block, - cost_models, - header, - header_body, - language, operational_cert, - plutus_data, - plutus_script, - proposed_protocol_parameter_updates, - protocol_param_update, - protocol_version, - script_data_hash, - script_n_of_k, - transaction, - transaction_body, - transaction_output, - transaction_witness_set, - update, ) import Text.Heredoc import Prelude hiding ((/)) 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 ea095b8b744..475ad7184cd 100644 --- a/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs +++ b/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs @@ -10,7 +10,58 @@ module Test.Cardano.Ledger.Conway.CDDL ( module Test.Cardano.Ledger.Babbage.CDDL, - module Test.Cardano.Ledger.Conway.CDDL, + conwayCDDL, + oset, + potential_languages, + pool_registration, + pool_retirement, + reg_cert, + unreg_cert, + vote_deleg_cert, + stake_vote_deleg_cert, + stake_reg_deleg_cert, + vote_reg_deleg_cert, + stake_vote_reg_deleg_cert, + auth_committee_hot_cert, + resign_committee_cold_cert, + reg_drep_cert, + unreg_drep_cert, + update_drep_cert, + block_no, + slot_no, + set, + transaction_input, + withdrawals, + mint, + nonempty_set, + voting_procedures, + anchor, + hard_fork_initiation_action, + treasury_withdrawals_action, + no_confidence, + update_committee, + new_constitution, + info_action, + gov_action_id, + policy_hash, + shelley_transaction_output, + nonempty_oset, + epoch_interval, + ex_unit_prices, + pool_voting_thresholds, + drep_voting_thresholds, + plutus_v1_script, + plutus_v2_script, + plutus_v3_script, + script_pubkey, + script_all, + script_any, + script_n_of_k, + invalid_before, + invalid_hereafter, + metadata, + shelley_auxiliary_data, + shelley_ma_auxiliary_data, ) where import Cardano.Ledger.Conway (ConwayEra) @@ -21,50 +72,24 @@ import Data.Text (Text) import Data.Word (Word64) import GHC.Num (Integer) import Test.Cardano.Ledger.Babbage.CDDL hiding ( - auxiliary_data, - block, certificate, certificates, - cost_models, - dns_name, ex_unit_prices, - header, - header_body, invalid_before, invalid_hereafter, - language, metadata, mint, - multi_host_name, multiasset, native_script, nonempty_set, - plutus_v1_script, - plutus_v2_script, - pool_metadata, - pool_params, - pool_registration, - pool_retirement, - protocol_param_update, - protocol_version, - redeemer_tag, redeemers, - relay, required_signers, script_all, script_any, - script_data_hash, script_pubkey, set, - shelley_transaction_output, - single_host_name, - transaction, - transaction_body, transaction_input, transaction_metadatum_label, - transaction_output, - transaction_witness_set, - url, value, withdrawals, ) diff --git a/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs b/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs index 780056848aa..55f9657ebb7 100644 --- a/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs +++ b/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs @@ -9,8 +9,8 @@ {- HLINT ignore "Evaluate" -} module Test.Cardano.Ledger.Dijkstra.CDDL ( - module Test.Cardano.Ledger.Dijkstra.CDDL, module Test.Cardano.Ledger.Conway.CDDL, + dijkstraCDDL, ) where import Cardano.Ledger.Dijkstra (DijkstraEra) @@ -20,30 +20,7 @@ import Data.Function (($)) import Data.Word (Word64) import GHC.Num (Integer) import Test.Cardano.Ledger.Conway.CDDL hiding ( - alonzo_auxiliary_data, - auxiliary_data, - block, - certificate, - certificates, - cost_models, - gov_action, - header, - header_body, - language, - native_script, - parameter_change_action, - proposal_procedure, - proposal_procedures, - protocol_param_update, - protocol_version, - redeemers, - script_data_hash, - single_host_name, - transaction, - transaction_body, - transaction_metadatum_label, - transaction_output, - transaction_witness_set, + ) import Text.Heredoc diff --git a/eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/CDDL.hs b/eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/CDDL.hs index 8984cfb361e..0c22696217f 100644 --- a/eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/CDDL.hs +++ b/eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/CDDL.hs @@ -11,7 +11,12 @@ module Test.Cardano.Ledger.Mary.CDDL ( module Test.Cardano.Ledger.Allegra.CDDL, - module Test.Cardano.Ledger.Mary.CDDL, + maryCDDL, + multiasset, + mint, + value, + policy_id, + asset_name, ) where import Cardano.Ledger.Core (Era) @@ -19,12 +24,7 @@ import Cardano.Ledger.Mary (MaryEra) import Codec.CBOR.Cuddle.Huddle import Data.Function (($)) import Data.Word (Word64) -import Test.Cardano.Ledger.Allegra.CDDL hiding ( - block, - transaction, - transaction_body, - transaction_output, - ) +import Test.Cardano.Ledger.Allegra.CDDL hiding (transaction_output) maryCDDL :: Huddle maryCDDL = 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 5b462b81a37..a9b63f9f0cc 100644 --- a/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs +++ b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs @@ -12,7 +12,35 @@ module Test.Cardano.Ledger.Shelley.CDDL ( module Test.Cardano.Ledger.Core.Binary.CDDL, - module Test.Cardano.Ledger.Shelley.CDDL, + shelleyCDDL, + nonempty_set, + transaction_metadatum_label, + transaction_metadatum, + set, + transaction_input, + transaction_output, + certificate, + withdrawals, + update, + metadata_hash, + header, + transaction_index, + vkeywitness, + bootstrap_witness, + script_hash, + major_protocol_version, + epoch, + nonce, + genesis_hash, + operational_cert, + stake_registration, + stake_deregistration, + transaction_id, + stake_delegation, + stake_credential, + credential, + port, + single_host_addr, ) where import Cardano.Ledger.BaseTypes (getVersion) From 9e6a05745034f127585ba3b50efab51c564556d8 Mon Sep 17 00:00:00 2001 From: Aniket Deshpande Date: Mon, 27 Oct 2025 16:56:08 +0530 Subject: [PATCH 3/5] CDDL: Rename some core fieldnames consistently. --- eras/allegra/impl/cddl-files/allegra.cddl | 10 ++- eras/alonzo/impl/cddl-files/alonzo.cddl | 12 ++-- .../Test/Cardano/Ledger/Alonzo/CDDL.hs | 2 +- eras/babbage/impl/cddl-files/babbage.cddl | 12 ++-- .../Test/Cardano/Ledger/Babbage/CDDL.hs | 2 +- eras/conway/impl/cddl-files/conway.cddl | 22 +++--- .../Test/Cardano/Ledger/Conway/CDDL.hs | 4 +- eras/dijkstra/impl/cddl-files/dijkstra.cddl | 28 ++++---- .../Test/Cardano/Ledger/Dijkstra/CDDL.hs | 4 +- eras/mary/impl/cddl-files/mary.cddl | 10 ++- eras/shelley/impl/cddl-files/shelley.cddl | 6 +- .../Test/Cardano/Ledger/Shelley/CDDL.hs | 2 +- .../Test/Cardano/Ledger/Core/Binary/CDDL.hs | 68 ++++++++----------- 13 files changed, 98 insertions(+), 84 deletions(-) diff --git a/eras/allegra/impl/cddl-files/allegra.cddl b/eras/allegra/impl/cddl-files/allegra.cddl index 206f7bb8fc3..13bea52c9fb 100644 --- a/eras/allegra/impl/cddl-files/allegra.cddl +++ b/eras/allegra/impl/cddl-files/allegra.cddl @@ -267,9 +267,9 @@ protocol_param_update = nonnegative_interval = #6.30([uint, positive_int]) -positive_int = 1 .. maxWord64 +positive_int = 1 .. max_word64 -maxWord64 = 18446744073709551615 +max_word64 = 18446744073709551615 nonce = [0// 1, bytes .size 32] @@ -305,7 +305,11 @@ script_any = (2, [* native_script]) script_n_of_k = (3, n : int64, [* native_script]) -int64 = -9223372036854775808 .. 9223372036854775807 +int64 = min_int64 .. max_int64 + +min_int64 = -9223372036854775808 + +max_int64 = 9223372036854775807 invalid_before = (4, uint) diff --git a/eras/alonzo/impl/cddl-files/alonzo.cddl b/eras/alonzo/impl/cddl-files/alonzo.cddl index eec84365f25..5ff9d2ca5db 100644 --- a/eras/alonzo/impl/cddl-files/alonzo.cddl +++ b/eras/alonzo/impl/cddl-files/alonzo.cddl @@ -330,9 +330,9 @@ protocol_param_update = nonnegative_interval = #6.30([uint, positive_int]) -positive_int = 1 .. maxWord64 +positive_int = 1 .. max_word64 -maxWord64 = 18446744073709551615 +max_word64 = 18446744073709551615 nonce = [0// 1, bytes .size 32] @@ -349,7 +349,11 @@ language = 0 ; See Plutus' `ParamName` for parameter ordering cost_model = [166*166 int64] -int64 = -9223372036854775808 .. 9223372036854775807 +int64 = min_int64 .. max_int64 + +min_int64 = -9223372036854775808 + +max_int64 = 9223372036854775807 ex_unit_prices = [mem_price : positive_interval, step_price : positive_interval] @@ -558,5 +562,5 @@ auxiliary_scripts = [* native_script] transaction = [transaction_body, transaction_witness_set, bool, auxiliary_data/ nil] -signkeyKES = bytes .size 64 +signkey_kes = bytes .size 64 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 91a2e384d17..9b75bb15995 100644 --- a/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs +++ b/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs @@ -42,7 +42,7 @@ alonzoCDDL = , HIRule transaction , HIRule kes_signature , HIRule language - , HIRule signkeyKES + , HIRule signkey_kes ] block :: Rule diff --git a/eras/babbage/impl/cddl-files/babbage.cddl b/eras/babbage/impl/cddl-files/babbage.cddl index ec5087979b8..84bddf2f93b 100644 --- a/eras/babbage/impl/cddl-files/babbage.cddl +++ b/eras/babbage/impl/cddl-files/babbage.cddl @@ -415,15 +415,19 @@ protocol_param_update = nonnegative_interval = #6.30([uint, positive_int]) -positive_int = 1 .. maxWord64 +positive_int = 1 .. max_word64 -maxWord64 = 18446744073709551615 +max_word64 = 18446744073709551615 ; 0: Plutus v1 ; 1: Plutus v2 cost_models = {? 0 : [166*166 int64], ? 1 : [175*175 int64]} -int64 = -9223372036854775808 .. 9223372036854775807 +int64 = min_int64 .. max_int64 + +min_int64 = -9223372036854775808 + +max_int64 = 9223372036854775807 ex_unit_prices = [mem_price : positive_interval, step_price : positive_interval] @@ -578,5 +582,5 @@ transaction = ; 1: Plutus v2 language = 0/ 1 -signkeyKES = bytes .size 64 +signkey_kes = bytes .size 64 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 b859001b759..190676d68ca 100644 --- a/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs +++ b/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs @@ -32,7 +32,7 @@ babbageCDDL = , HIRule transaction , HIRule kes_signature , HIRule language - , HIRule signkeyKES + , HIRule signkey_kes ] block :: Rule diff --git a/eras/conway/impl/cddl-files/conway.cddl b/eras/conway/impl/cddl-files/conway.cddl index 9395aa7d82e..5161784f36c 100644 --- a/eras/conway/impl/cddl-files/conway.cddl +++ b/eras/conway/impl/cddl-files/conway.cddl @@ -23,7 +23,7 @@ language = 0/ 1/ 2 potential_languages = 0 .. 255 -signkeyKES = bytes .size 64 +signkey_kes = bytes .size 64 certificate = [ stake_registration @@ -228,9 +228,9 @@ hash28 = bytes .size 28 asset_name = bytes .size (0 .. 32) -positive_coin = 1 .. maxWord64 +positive_coin = 1 .. max_word64 -maxWord64 = 18446744073709551615 +max_word64 = 18446744073709551615 ; NEW starting with babbage ; datum_option @@ -309,7 +309,11 @@ script_any = (2, [* native_script]) script_n_of_k = (3, n : int64, [* native_script]) -int64 = -9223372036854775808 .. 9223372036854775807 +int64 = min_int64 .. max_int64 + +min_int64 = -9223372036854775808 + +max_int64 = 9223372036854775807 invalid_before = (4, slot_no) @@ -425,13 +429,13 @@ withdrawals = {+ reward_account => coin} auxiliary_data_hash = hash32 -mint = {+ policy_id => {+ asset_name => nonZeroInt64}} +mint = {+ policy_id => {+ asset_name => nonzero_int64}} -nonZeroInt64 = negInt64/ posInt64 +nonzero_int64 = negative_int64/ positive_int64 -negInt64 = -9223372036854775808 .. -1 +negative_int64 = min_int64 .. -1 -posInt64 = 1 .. 9223372036854775807 +positive_int64 = 1 .. max_int64 ; This is a hash of data which may affect evaluation of a script. ; This data consists of: @@ -586,7 +590,7 @@ epoch_interval = uint .size 4 nonnegative_interval = #6.30([uint, positive_int]) -positive_int = 1 .. maxWord64 +positive_int = 1 .. max_word64 ; The format for cost_models is flexible enough to allow adding ; Plutus built-ins and language versions in the future. 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 475ad7184cd..a8df86a828d 100644 --- a/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs +++ b/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs @@ -103,7 +103,7 @@ conwayCDDL = , HIRule kes_signature , HIRule language , HIRule potential_languages - , HIRule signkeyKES + , HIRule signkey_kes , -- Certificates HIRule certificate , HIGroup stake_registration @@ -841,7 +841,7 @@ value :: Rule value = "value" =:= coin / sarr [a coin, a (multiasset positive_coin)] mint :: Rule -mint = "mint" =:= mp [1 <+ asKey policy_id ==> mp [1 <+ asKey asset_name ==> nonZeroInt64]] +mint = "mint" =:= mp [1 <+ asKey policy_id ==> mp [1 <+ asKey asset_name ==> nonzero_int64]] epoch_no :: Rule epoch_no = "epoch_no" =:= VUInt `sized` (8 :: Word64) diff --git a/eras/dijkstra/impl/cddl-files/dijkstra.cddl b/eras/dijkstra/impl/cddl-files/dijkstra.cddl index 5973847163e..2a6b7ae6c98 100644 --- a/eras/dijkstra/impl/cddl-files/dijkstra.cddl +++ b/eras/dijkstra/impl/cddl-files/dijkstra.cddl @@ -23,7 +23,7 @@ language = 0/ 1/ 2 potential_languages = 0 .. 255 -signkeyKES = bytes .size 64 +signkey_kes = bytes .size 64 certificate = [ stake_registration @@ -228,9 +228,9 @@ hash28 = bytes .size 28 asset_name = bytes .size (0 .. 32) -positive_coin = 1 .. maxWord64 +positive_coin = 1 .. max_word64 -maxWord64 = 18446744073709551615 +max_word64 = 18446744073709551615 ; NEW starting with babbage ; datum_option @@ -311,7 +311,11 @@ script_any = (2, [* native_script]) script_n_of_k = (3, n : int64, [* native_script]) -int64 = -9223372036854775808 .. 9223372036854775807 +int64 = min_int64 .. max_int64 + +min_int64 = -9223372036854775808 + +max_int64 = 9223372036854775807 invalid_before = (4, slot_no) @@ -431,13 +435,13 @@ withdrawals = {+ reward_account => coin} auxiliary_data_hash = hash32 -mint = {+ policy_id => {+ asset_name => nonZeroInt64}} +mint = {+ policy_id => {+ asset_name => nonzero_int64}} -nonZeroInt64 = negInt64/ posInt64 +nonzero_int64 = negative_int64/ positive_int64 -negInt64 = -9223372036854775808 .. -1 +negative_int64 = min_int64 .. -1 -posInt64 = 1 .. 9223372036854775807 +positive_int64 = 1 .. max_int64 ; This is a hash of data which may affect evaluation of a script. ; This data consists of: @@ -587,7 +591,7 @@ protocol_param_update = , ? 33 : nonnegative_interval ; minfee refScript coins per byte , ? 34 : uint .size 4 ; max refScript size per block , ? 35 : uint .size 4 ; max refScript size per tx - , ? 36 : posWord32 ; refScript cost stride + , ? 36 : positive_word32 ; refScript cost stride , ? 37 : positive_interval ; refScript cost multiplier } @@ -596,7 +600,7 @@ epoch_interval = uint .size 4 nonnegative_interval = #6.30([uint, positive_int]) -positive_int = 1 .. maxWord64 +positive_int = 1 .. max_word64 ; The format for cost_models is flexible enough to allow adding ; Plutus built-ins and language versions in the future. @@ -637,9 +641,9 @@ drep_voting_thresholds = ] -posWord32 = 1 .. maxWord32 +positive_word32 = 1 .. max_word32 -maxWord32 = 4294967295 +max_word32 = 4294967295 positive_interval = #6.30([positive_int, positive_int]) diff --git a/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs b/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs index 55f9657ebb7..47dcef25c1a 100644 --- a/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs +++ b/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs @@ -32,7 +32,7 @@ dijkstraCDDL = , HIRule kes_signature , HIRule language , HIRule potential_languages - , HIRule signkeyKES + , HIRule signkey_kes , -- Certificates HIRule certificate , HIGroup stake_registration @@ -322,7 +322,7 @@ protocol_param_update = , opt (idx 33 ==> nonnegative_interval) //- "minfee refScript coins per byte" , opt (idx 34 ==> (VUInt `sized` (4 :: Word64))) //- "max refScript size per block" , opt (idx 35 ==> (VUInt `sized` (4 :: Word64))) //- "max refScript size per tx" - , opt (idx 36 ==> posWord32) //- "refScript cost stride" + , opt (idx 36 ==> positive_word32) //- "refScript cost stride" , opt (idx 37 ==> positive_interval) //- "refScript cost multiplier" ] diff --git a/eras/mary/impl/cddl-files/mary.cddl b/eras/mary/impl/cddl-files/mary.cddl index a7416e3f8eb..2830c7aff64 100644 --- a/eras/mary/impl/cddl-files/mary.cddl +++ b/eras/mary/impl/cddl-files/mary.cddl @@ -275,9 +275,9 @@ protocol_param_update = nonnegative_interval = #6.30([uint, positive_int]) -positive_int = 1 .. maxWord64 +positive_int = 1 .. max_word64 -maxWord64 = 18446744073709551615 +max_word64 = 18446744073709551615 nonce = [0// 1, bytes .size 32] @@ -285,7 +285,11 @@ metadata_hash = hash32 mint = multiasset -int64 = -9223372036854775808 .. 9223372036854775807 +int64 = min_int64 .. max_int64 + +min_int64 = -9223372036854775808 + +max_int64 = 9223372036854775807 transaction_witness_set = {? 0 : [* vkeywitness], ? 1 : [* native_script], ? 2 : [* bootstrap_witness]} diff --git a/eras/shelley/impl/cddl-files/shelley.cddl b/eras/shelley/impl/cddl-files/shelley.cddl index 7e4f6e683ba..3ec98f95e80 100644 --- a/eras/shelley/impl/cddl-files/shelley.cddl +++ b/eras/shelley/impl/cddl-files/shelley.cddl @@ -265,9 +265,9 @@ protocol_param_update = nonnegative_interval = #6.30([uint, positive_int]) -positive_int = 1 .. maxWord64 +positive_int = 1 .. max_word64 -maxWord64 = 18446744073709551615 +max_word64 = 18446744073709551615 nonce = [0// 1, bytes .size 32] @@ -317,5 +317,5 @@ transaction_metadatum = transaction = [transaction_body, transaction_witness_set, transaction_metadata/ nil] -signkeyKES = bytes .size 64 +signkey_kes = bytes .size 64 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 a9b63f9f0cc..3cfe573552d 100644 --- a/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs +++ b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs @@ -54,7 +54,7 @@ import Text.Heredoc import Prelude hiding ((/)) shelleyCDDL :: Huddle -shelleyCDDL = collectFrom [HIRule $ block @ShelleyEra, HIRule $ transaction @ShelleyEra, HIRule signkeyKES] +shelleyCDDL = collectFrom [HIRule $ block @ShelleyEra, HIRule $ transaction @ShelleyEra, HIRule signkey_kes] block :: forall era. Era era => Rule block = 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 cb80ab44103..feae58e641b 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 @@ -33,18 +33,18 @@ module Test.Cardano.Ledger.Core.Binary.CDDL ( vrf_cert, kes_vkey, kes_signature, - signkeyKES, + signkey_kes, signature, big_int, - minInt64, - maxInt64, - negInt64, - posInt64, - nonZeroInt64, + min_int64, + max_int64, + negative_int64, + positive_int64, + nonzero_int64, int64, positive_int, - maxWord32, - posWord32, + max_word32, + positive_word32, unit_interval, nonnegative_interval, distinct, @@ -65,7 +65,7 @@ coin :: Rule coin = "coin" =:= VUInt positive_coin :: Rule -positive_coin = "positive_coin" =:= (1 :: Integer) ... maxWord64 +positive_coin = "positive_coin" =:= (1 :: Integer) ... max_word64 address :: Rule address = @@ -168,8 +168,8 @@ kes_vkey = "kes_vkey" =:= VBytes `sized` (32 :: Word64) kes_signature :: Rule kes_signature = "kes_signature" =:= VBytes `sized` (448 :: Word64) -signkeyKES :: Rule -signkeyKES = "signkeyKES" =:= VBytes `sized` (64 :: Word64) +signkey_kes :: Rule +signkey_kes = "signkey_kes" =:= VBytes `sized` (64 :: Word64) signature :: Rule signature = "signature" =:= VBytes `sized` (64 :: Word64) @@ -187,46 +187,36 @@ big_uint = "big_uint" =:= tag 2 bounded_bytes big_nint :: Rule big_nint = "big_nint" =:= tag 3 bounded_bytes --- Once https://github.com/input-output-hk/cuddle/issues/29 is in place, replace --- with: --- --- minInt64 :: Rule --- minInt64 = "minInt64" =:= -9223372036854775808 -minInt64 :: Integer -minInt64 = -9223372036854775808 +min_int64 :: Rule +min_int64 = "min_int64" =:= (-9223372036854775808 :: Integer) --- Once https://github.com/input-output-hk/cuddle/issues/29 is in place, replace --- with: --- --- maxInt64 :: Rule --- maxInt64 = "maxInt64" =:= 9223372036854775807 -maxInt64 :: Integer -maxInt64 = 9223372036854775807 +max_int64 :: Rule +max_int64 = "max_int64" =:= (9223372036854775807 :: Integer) -maxWord64 :: Rule -maxWord64 = "maxWord64" =:= (18446744073709551615 :: Integer) +max_word64 :: Rule +max_word64 = "max_word64" =:= (18446744073709551615 :: Integer) -negInt64 :: Rule -negInt64 = "negInt64" =:= minInt64 ... (-1 :: Integer) +negative_int64 :: Rule +negative_int64 = "negative_int64" =:= min_int64 ... (-1 :: Integer) -posInt64 :: Rule -posInt64 = "posInt64" =:= (1 :: Integer) ... maxInt64 +positive_int64 :: Rule +positive_int64 = "positive_int64" =:= (1 :: Integer) ... max_int64 -- | this is the same as the current int64 definition but without zero -nonZeroInt64 :: Rule -nonZeroInt64 = "nonZeroInt64" =:= negInt64 / posInt64 +nonzero_int64 :: Rule +nonzero_int64 = "nonzero_int64" =:= negative_int64 / positive_int64 int64 :: Rule -int64 = "int64" =:= minInt64 ... maxInt64 +int64 = "int64" =:= min_int64 ... max_int64 positive_int :: Rule -positive_int = "positive_int" =:= (1 :: Integer) ... maxWord64 +positive_int = "positive_int" =:= (1 :: Integer) ... max_word64 -maxWord32 :: Rule -maxWord32 = "maxWord32" =:= (4294967295 :: Integer) +max_word32 :: Rule +max_word32 = "max_word32" =:= (4294967295 :: Integer) -posWord32 :: Rule -posWord32 = "posWord32" =:= (1 :: Integer) ... maxWord32 +positive_word32 :: Rule +positive_word32 = "positive_word32" =:= (1 :: Integer) ... max_word32 unit_interval :: Rule unit_interval = From 59d450bf95bbf2dc87ffaaba0ed37ce7b90e14f5 Mon Sep 17 00:00:00 2001 From: Aniket Deshpande Date: Mon, 27 Oct 2025 19:34:23 +0530 Subject: [PATCH 4/5] CDDL: Consolidate (un)tagged (o)set fields in core. * Also, rearrange the exports. --- .../Test/Cardano/Ledger/Allegra/CDDL.hs | 2 +- .../Test/Cardano/Ledger/Alonzo/CDDL.hs | 6 +- .../Test/Cardano/Ledger/Babbage/CDDL.hs | 6 +- .../Test/Cardano/Ledger/Conway/CDDL.hs | 84 +++++++++---------- .../Test/Cardano/Ledger/Dijkstra/CDDL.hs | 28 +++---- .../testlib/Test/Cardano/Ledger/Mary/CDDL.hs | 2 +- .../Test/Cardano/Ledger/Shelley/CDDL.hs | 15 +--- .../Test/Cardano/Ledger/Core/Binary/CDDL.hs | 78 ++++++++++++----- 8 files changed, 121 insertions(+), 100 deletions(-) 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 5625925b556..c3b15a8f51b 100644 --- a/eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/CDDL.hs +++ b/eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/CDDL.hs @@ -97,7 +97,7 @@ transaction_body = |] $ "transaction_body" =:= mp - [ idx 0 ==> set transaction_input + [ idx 0 ==> untagged_set transaction_input , idx 1 ==> arr [0 <+ a transaction_output] , idx 2 ==> coin , opt (idx 3 ==> VUInt) 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 9b75bb15995..712ce89d5d6 100644 --- a/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs +++ b/eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/CDDL.hs @@ -93,7 +93,7 @@ transaction_body = |] $ "transaction_body" =:= mp - [ idx 0 ==> set transaction_input + [ idx 0 ==> untagged_set transaction_input , idx 1 ==> arr [0 <+ a transaction_output] , idx 2 ==> coin , opt (idx 3 ==> VUInt) @@ -104,13 +104,13 @@ transaction_body = , opt (idx 8 ==> VUInt) , opt (idx 9 ==> mint) , opt (idx 11 ==> script_data_hash) - , opt (idx 13 ==> set transaction_input) + , opt (idx 13 ==> untagged_set transaction_input) , opt (idx 14 ==> required_signers) , opt (idx 15 ==> network_id) ] required_signers :: Rule -required_signers = "required_signers" =:= set addr_keyhash +required_signers = "required_signers" =:= untagged_set addr_keyhash transaction_output :: Rule transaction_output = 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 190676d68ca..4df9899b185 100644 --- a/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs +++ b/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs @@ -113,7 +113,7 @@ transaction_body = |] $ "transaction_body" =:= mp - [ idx 0 ==> set transaction_input + [ idx 0 ==> untagged_set transaction_input , idx 1 ==> arr [0 <+ a transaction_output] , idx 2 ==> coin , opt (idx 3 ==> VUInt) @@ -124,12 +124,12 @@ transaction_body = , opt (idx 8 ==> VUInt) , opt (idx 9 ==> mint) , opt (idx 11 ==> script_data_hash) - , opt (idx 13 ==> set transaction_input) + , opt (idx 13 ==> untagged_set transaction_input) , opt (idx 14 ==> required_signers) , opt (idx 15 ==> network_id) , opt (idx 16 ==> transaction_output) , opt (idx 17 ==> coin) - , opt (idx 18 ==> set transaction_input) + , opt (idx 18 ==> untagged_set transaction_input) ] -- TODO: Allow for adding to the comments of a Rule in order to not have to 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 a8df86a828d..88eff069147 100644 --- a/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs +++ b/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs @@ -11,7 +11,6 @@ module Test.Cardano.Ledger.Conway.CDDL ( module Test.Cardano.Ledger.Babbage.CDDL, conwayCDDL, - oset, potential_languages, pool_registration, pool_retirement, @@ -29,11 +28,9 @@ module Test.Cardano.Ledger.Conway.CDDL ( update_drep_cert, block_no, slot_no, - set, transaction_input, withdrawals, mint, - nonempty_set, voting_procedures, anchor, hard_fork_initiation_action, @@ -45,7 +42,6 @@ module Test.Cardano.Ledger.Conway.CDDL ( gov_action_id, policy_hash, shelley_transaction_output, - nonempty_oset, epoch_interval, ex_unit_prices, pool_voting_thresholds, @@ -62,13 +58,19 @@ module Test.Cardano.Ledger.Conway.CDDL ( metadata, shelley_auxiliary_data, shelley_ma_auxiliary_data, + + -- * Sets + maybe_tagged_set, + maybe_tagged_nonempty_set, + maybe_tagged_oset, + maybe_tagged_nonempty_oset, ) where import Cardano.Ledger.Conway (ConwayEra) import Codec.CBOR.Cuddle.Comments ((//-)) import Codec.CBOR.Cuddle.Huddle import Data.Function (($)) -import Data.Text (Text) +import Data.Text qualified as T import Data.Word (Word64) import GHC.Num (Integer) import Test.Cardano.Ledger.Babbage.CDDL hiding ( @@ -81,13 +83,11 @@ import Test.Cardano.Ledger.Babbage.CDDL hiding ( mint, multiasset, native_script, - nonempty_set, redeemers, required_signers, script_all, script_any, script_pubkey, - set, transaction_input, transaction_metadatum_label, value, @@ -186,7 +186,7 @@ transaction_body :: Rule transaction_body = "transaction_body" =:= mp - [ idx 0 ==> set transaction_input + [ idx 0 ==> maybe_tagged_set transaction_input , idx 1 ==> arr [0 <+ a transaction_output] , idx 2 ==> coin , opt (idx 3 ==> slot_no) @@ -196,12 +196,12 @@ transaction_body = , opt (idx 8 ==> slot_no) -- Validity interval start , opt (idx 9 ==> mint) , opt (idx 11 ==> script_data_hash) - , opt (idx 13 ==> nonempty_set transaction_input) + , opt (idx 13 ==> maybe_tagged_nonempty_set transaction_input) , opt (idx 14 ==> required_signers) , opt (idx 15 ==> network_id) , opt (idx 16 ==> transaction_output) , opt (idx 17 ==> coin) - , opt (idx 18 ==> nonempty_set transaction_input) + , opt (idx 18 ==> maybe_tagged_nonempty_set transaction_input) , opt (idx 19 ==> voting_procedures) , opt (idx 20 ==> proposal_procedures) , opt (idx 21 ==> coin) @@ -227,10 +227,10 @@ proposal_procedure = ] proposal_procedures :: Rule -proposal_procedures = "proposal_procedures" =:= nonempty_oset proposal_procedure +proposal_procedures = "proposal_procedures" =:= maybe_tagged_nonempty_oset proposal_procedure certificates :: Rule -certificates = "certificates" =:= nonempty_oset certificate +certificates = "certificates" =:= maybe_tagged_nonempty_oset certificate gov_action :: Rule gov_action = @@ -275,7 +275,7 @@ update_committee = =:~ grp [ 4 , a $ gov_action_id / VNil - , a (set committee_cold_credential) + , a (maybe_tagged_set committee_cold_credential) , a (mp [0 <+ asKey committee_cold_credential ==> epoch_no]) , a unit_interval ] @@ -325,7 +325,7 @@ gov_action_id = ] required_signers :: Rule -required_signers = "required_signers" =:= nonempty_set addr_keyhash +required_signers = "required_signers" =:= maybe_tagged_nonempty_set addr_keyhash transaction_input :: Rule transaction_input = @@ -540,7 +540,7 @@ pool_params = , "cost" ==> coin , "margin" ==> unit_interval , "reward_account" ==> reward_account - , "pool_owners" ==> set addr_keyhash + , "pool_owners" ==> maybe_tagged_set addr_keyhash , "relays" ==> arr [0 <+ a relay] , "pool_metadata" ==> (pool_metadata / VNil) ] @@ -646,14 +646,14 @@ transaction_witness_set :: Rule transaction_witness_set = "transaction_witness_set" =:= mp - [ opt $ idx 0 ==> nonempty_set vkeywitness - , opt $ idx 1 ==> nonempty_set native_script - , opt $ idx 2 ==> nonempty_set bootstrap_witness - , opt $ idx 3 ==> nonempty_set plutus_v1_script - , opt $ idx 4 ==> nonempty_set plutus_data + [ opt $ idx 0 ==> maybe_tagged_nonempty_set vkeywitness + , opt $ idx 1 ==> maybe_tagged_nonempty_set native_script + , opt $ idx 2 ==> maybe_tagged_nonempty_set bootstrap_witness + , opt $ idx 3 ==> maybe_tagged_nonempty_set plutus_v1_script + , opt $ idx 4 ==> maybe_tagged_nonempty_set plutus_data , opt $ idx 5 ==> redeemers conway_redeemer_tag - , opt $ idx 6 ==> nonempty_set plutus_v2_script - , opt $ idx 7 ==> nonempty_set plutus_v3_script + , opt $ idx 6 ==> maybe_tagged_nonempty_set plutus_v2_script + , opt $ idx 7 ==> maybe_tagged_nonempty_set plutus_v3_script ] plutus_v1_script :: Rule @@ -863,27 +863,19 @@ conway_script = / arr [2, a plutus_v2_script] / arr [3, a plutus_v3_script] --- | Conway era introduces an optional 258 tag for sets, which will --- become mandatory in the second era after Conway. We recommend all the --- tooling to account for this future breaking change sooner rather than --- later, in order to provide a smooth transition for their users. -set :: IsType0 t0 => t0 -> GRuleCall -set = set_len_spec "set" 0 - --- | Conway era introduces an optional 258 tag for sets, which will --- become mandatory in the second era after Conway. We recommend all the --- tooling to account for this future breaking change sooner rather than --- later, in order to provide a smooth transition for their users. -nonempty_set :: IsType0 t0 => t0 -> GRuleCall -nonempty_set = set_len_spec "nonempty_set" 1 - --- | An OSet is a Set that preserves the order of its elements. -oset :: IsType0 t0 => t0 -> GRuleCall -oset = set_len_spec "oset" 0 - --- | An NonEmpty OSet is a NonEmpty Set that preserves the order of its elements. -nonempty_oset :: IsType0 t0 => t0 -> GRuleCall -nonempty_oset = set_len_spec "nonempty_oset" 1 - -set_len_spec :: IsType0 t0 => Text -> Word64 -> t0 -> GRuleCall -set_len_spec label n = binding $ \x -> label =:= tag 258 (arr [n <+ a x]) / sarr [n <+ a x] +-- | Conway era introduces an optional 258 tag for sets, which will become +-- mandatory in the second era after Conway. +mkMaybeTaggedSet :: IsType0 a => T.Text -> Word64 -> a -> GRuleCall +mkMaybeTaggedSet label n = binding $ \x -> label =:= tag 258 (arr [n <+ a x]) / sarr [n <+ a x] + +maybe_tagged_set :: IsType0 a => a -> GRuleCall +maybe_tagged_set = mkMaybeTaggedSet "set" 0 + +maybe_tagged_nonempty_set :: IsType0 a => a -> GRuleCall +maybe_tagged_nonempty_set = mkMaybeTaggedSet "nonempty_set" 1 + +maybe_tagged_oset :: IsType0 a => a -> GRuleCall +maybe_tagged_oset = mkMaybeTaggedSet "oset" 0 + +maybe_tagged_nonempty_oset :: IsType0 a => a -> GRuleCall +maybe_tagged_nonempty_oset = mkMaybeTaggedSet "nonempty_oset" 1 diff --git a/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs b/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs index 47dcef25c1a..c715ea797a1 100644 --- a/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs +++ b/eras/dijkstra/impl/testlib/Test/Cardano/Ledger/Dijkstra/CDDL.hs @@ -115,7 +115,7 @@ transaction_body :: Rule transaction_body = "transaction_body" =:= mp - [ idx 0 ==> set transaction_input + [ idx 0 ==> maybe_tagged_set transaction_input , idx 1 ==> arr [0 <+ a transaction_output] , idx 2 ==> coin , opt (idx 3 ==> slot_no) @@ -125,12 +125,12 @@ transaction_body = , opt (idx 8 ==> slot_no) -- Validity interval start , opt (idx 9 ==> mint) , opt (idx 11 ==> script_data_hash) - , opt (idx 13 ==> nonempty_set transaction_input) + , opt (idx 13 ==> maybe_tagged_nonempty_set transaction_input) , opt (idx 14 ==> guards) , opt (idx 15 ==> network_id) , opt (idx 16 ==> transaction_output) , opt (idx 17 ==> coin) - , opt (idx 18 ==> nonempty_set transaction_input) + , opt (idx 18 ==> maybe_tagged_nonempty_set transaction_input) , opt (idx 19 ==> voting_procedures) , opt (idx 20 ==> proposal_procedures) , opt (idx 21 ==> coin) @@ -140,8 +140,8 @@ transaction_body = guards :: Rule guards = "guards" - =:= nonempty_set addr_keyhash - / nonempty_oset credential + =:= maybe_tagged_nonempty_set addr_keyhash + / maybe_tagged_nonempty_oset credential proposal_procedure :: Rule proposal_procedure = @@ -154,10 +154,10 @@ proposal_procedure = ] proposal_procedures :: Rule -proposal_procedures = "proposal_procedures" =:= nonempty_oset proposal_procedure +proposal_procedures = "proposal_procedures" =:= maybe_tagged_nonempty_oset proposal_procedure certificates :: Rule -certificates = "certificates" =:= nonempty_oset certificate +certificates = "certificates" =:= maybe_tagged_nonempty_oset certificate gov_action :: Rule gov_action = @@ -345,14 +345,14 @@ transaction_witness_set :: Rule transaction_witness_set = "transaction_witness_set" =:= mp - [ opt $ idx 0 ==> nonempty_set vkeywitness - , opt $ idx 1 ==> nonempty_set dijkstra_native_script - , opt $ idx 2 ==> nonempty_set bootstrap_witness - , opt $ idx 3 ==> nonempty_set plutus_v1_script - , opt $ idx 4 ==> nonempty_set plutus_data + [ opt $ idx 0 ==> maybe_tagged_nonempty_set vkeywitness + , opt $ idx 1 ==> maybe_tagged_nonempty_set dijkstra_native_script + , opt $ idx 2 ==> maybe_tagged_nonempty_set bootstrap_witness + , opt $ idx 3 ==> maybe_tagged_nonempty_set plutus_v1_script + , opt $ idx 4 ==> maybe_tagged_nonempty_set plutus_data , opt $ idx 5 ==> redeemers dijkstra_redeemer_tag - , opt $ idx 6 ==> nonempty_set plutus_v2_script - , opt $ idx 7 ==> nonempty_set plutus_v3_script + , opt $ idx 6 ==> maybe_tagged_nonempty_set plutus_v2_script + , opt $ idx 7 ==> maybe_tagged_nonempty_set plutus_v3_script ] -- TODO: adjust with new script purpose diff --git a/eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/CDDL.hs b/eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/CDDL.hs index 0c22696217f..10ad0a3587e 100644 --- a/eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/CDDL.hs +++ b/eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/CDDL.hs @@ -55,7 +55,7 @@ transaction_body :: forall era. Era era => Rule transaction_body = "transaction_body" =:= mp - [ idx 0 ==> set transaction_input + [ idx 0 ==> untagged_set transaction_input , idx 1 ==> arr [0 <+ a transaction_output] , idx 2 ==> coin , opt (idx 3 ==> VUInt) 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 3cfe573552d..c9c5080fe60 100644 --- a/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs +++ b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs @@ -13,10 +13,8 @@ module Test.Cardano.Ledger.Shelley.CDDL ( module Test.Cardano.Ledger.Core.Binary.CDDL, shelleyCDDL, - nonempty_set, transaction_metadatum_label, transaction_metadatum, - set, transaction_input, transaction_output, certificate, @@ -120,7 +118,7 @@ transaction_body :: forall era. Era era => Rule transaction_body = "transaction_body" =:= mp - [ idx 0 ==> set transaction_input + [ idx 0 ==> untagged_set transaction_input , idx 1 ==> arr [0 <+ a transaction_output] , idx 2 ==> coin , idx 3 ==> VUInt @@ -225,7 +223,7 @@ pool_params = , "cost" ==> coin , "margin" ==> unit_interval , "reward_account" ==> reward_account - , "pool_owners" ==> set addr_keyhash + , "pool_owners" ==> untagged_set addr_keyhash , "relays" ==> arr [0 <+ a relay] , "pool_metadata" ==> (pool_metadata / VNil) ] @@ -394,12 +392,3 @@ metadata_hash = "metadata_hash" =:= hash32 nonce :: Rule nonce = "nonce" =:= arr [0] / arr [1, a (VBytes `sized` (32 :: Word64))] - --- Shelley does not support some of the tagged core datastructures that we rely --- on in future eras. In order to have the "correct" common specification in --- core, we override them here -set :: IsType0 t0 => t0 -> GRuleCall -set = binding $ \x -> "set" =:= arr [0 <+ a x] - -nonempty_set :: IsType0 t0 => t0 -> GRuleCall -nonempty_set = binding $ \x -> "nonempty_set" =:= arr [1 <+ a x] 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 feae58e641b..bd689167150 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 @@ -18,23 +18,8 @@ module Test.Cardano.Ledger.Core.Binary.CDDL ( hash32, hash64, bytes80, - hash448, - -- * Misc. - coin, - positive_coin, - address, - reward_account, - addr_keyhash, - pool_keyhash, - vrf_keyhash, - vkey, - vrf_vkey, - vrf_cert, - kes_vkey, - kes_signature, - signkey_kes, - signature, + -- * Numbers big_int, min_int64, max_int64, @@ -45,10 +30,46 @@ module Test.Cardano.Ledger.Core.Binary.CDDL ( positive_int, max_word32, positive_word32, + + -- * Unit intervals unit_interval, nonnegative_interval, + + -- * Distinct uint/bytes, bounded bytes distinct, bounded_bytes, + + -- * Sets + untagged_set, + untagged_nonempty_set, + + -- * Network + + -- * Hashes, keys and certificates + addr_keyhash, + pool_keyhash, + vrf_keyhash, + vkey, + vrf_vkey, + vrf_cert, + kes_vkey, + kes_signature, + signkey_kes, + signature, + + -- * Value + coin, + positive_coin, + + -- * Addresses and accounts + address, + reward_account, + + -- * Protocol version + + -- * Transactions + + -- * Misc. ) where import Codec.CBOR.Cuddle.Huddle @@ -150,9 +171,6 @@ hash64 = mkHashSized 64 bytes80 :: Rule bytes80 = "bytes80" =:= VBytes `sized` (80 :: Word64) -hash448 :: Rule -hash448 = mkHashSized 448 - vkey :: Rule vkey = "vkey" =:= VBytes `sized` (32 :: Word64) @@ -278,3 +296,25 @@ distinct x = VBytes -> T.pack "bytes" VUInt -> T.pack "uint" _ -> error "Unsupported Value for `distinct`" + +untagged_set :: IsType0 a => a -> GRuleCall +untagged_set = binding $ \x -> "set" =:= arr [0 <+ a x] + +untagged_nonempty_set :: IsType0 a => a -> GRuleCall +untagged_nonempty_set = binding $ \x -> "nonempty_set" =:= arr [1 <+ a x] + +-- | The era after dijkstra enforces the 258 tag for sets. +mkTaggedSet :: IsType0 a => T.Text -> Word64 -> a -> GRuleCall +mkTaggedSet label n = binding $ \x -> label =:= tag 258 (arr [n <+ a x]) + +_tagged_set :: IsType0 a => a -> GRuleCall +_tagged_set = mkTaggedSet "set" 0 + +_tagged_nonempty_set :: IsType0 a => a -> GRuleCall +_tagged_nonempty_set = mkTaggedSet "nonempty_set" 1 + +_tagged_oset :: IsType0 a => a -> GRuleCall +_tagged_oset = mkTaggedSet "oset" 0 + +_tagged_nonempty_oset :: IsType0 a => a -> GRuleCall +_tagged_nonempty_oset = mkTaggedSet "nonempty_oset" 1 From 6f3e21d1f6b8467673029c18ba01c2f04f9aec11 Mon Sep 17 00:00:00 2001 From: Aniket Deshpande Date: Wed, 29 Oct 2025 18:12:10 +0530 Subject: [PATCH 5/5] Update cuddle SRP --- cabal.project | 6 ++++++ .../testlib/Test/Cardano/Ledger/Binary/Cuddle.hs | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cabal.project b/cabal.project index a956fa34ee5..9d248fc8fcf 100644 --- a/cabal.project +++ b/cabal.project @@ -24,6 +24,12 @@ source-repository-package --sha256: sha256-DQHX7V1Ci/n7UVKotqGpBLKyiNHkttTu+tvuQqn/e/k= tag: d4b12a415712666e139a19cdc4584423a5397c5f +source-repository-package + type: git + location: https://github.com/input-output-hk/cuddle.git + --sha256: sha256-XplTfcHBwZprhR3NXKgUNGb7kGGbFG4ogn4BVJxtz0s= + tag: 29b8db51bb132e403a91e7ac622184e047b8fede + -- NOTE: If you would like to update the above, -- see CONTRIBUTING.md#to-update-the-referenced-agda-ledger-spec index-state: diff --git a/libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Cuddle.hs b/libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Cuddle.hs index f2f29371e7d..5ebfd6db5fa 100644 --- a/libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Cuddle.hs +++ b/libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Cuddle.hs @@ -35,14 +35,14 @@ import qualified Codec.CBOR.Cuddle.CDDL as Cuddle import qualified Codec.CBOR.Cuddle.CDDL.CTree as Cuddle import qualified Codec.CBOR.Cuddle.CDDL.Resolve as Cuddle import qualified Codec.CBOR.Cuddle.Huddle as Cuddle -import Codec.CBOR.Cuddle.Pretty () +import qualified Codec.CBOR.Cuddle.IndexMappable as Cuddle +import Codec.CBOR.Cuddle.Pretty (PrettyStage) import qualified Codec.CBOR.Encoding as CBOR import qualified Codec.CBOR.Pretty as CBOR import qualified Codec.CBOR.Term as CBOR import qualified Codec.CBOR.Write as CBOR import Data.Data (Proxy (..)) import Data.Foldable (Foldable (..), traverse_) -import Data.Functor.Identity (Identity) import Data.List (unfoldr) import qualified Data.Text as T import qualified Data.Text.Lazy as LT @@ -74,7 +74,7 @@ import Test.QuickCheck.Random (QCGen, mkQCGen) import Text.Pretty.Simple (pShow) data CuddleData = CuddleData - { cddl :: !(Cuddle.CTreeRoot' Identity Cuddle.MonoRef) + { cddl :: !(Cuddle.CTreeRoot Cuddle.MonoReferenced) , numExamples :: !Int } @@ -143,7 +143,7 @@ specWithHuddle :: Cuddle.Huddle -> Int -> SpecWith CuddleData -> Spec specWithHuddle h numExamples = beforeAll $ let cddl = Cuddle.toCDDL h - rCddl = Cuddle.fullResolveCDDL cddl + rCddl = Cuddle.fullResolveCDDL $ Cuddle.mapIndex cddl in case rCddl of Right ct -> pure $ @@ -153,7 +153,8 @@ specWithHuddle h numExamples = } Left nrf -> error $ show nrf -withGenTerm :: CuddleData -> Cuddle.Name -> (CBOR.Term -> Expectation) -> Seeded Expectation +withGenTerm :: + CuddleData -> Cuddle.Name Cuddle.CTreePhase -> (CBOR.Term -> Expectation) -> Seeded Expectation withGenTerm cd n withTerm = Seeded $ \gen -> let terms = take (numExamples cd) $ @@ -289,6 +290,6 @@ writeSpec hddl path = preface = "; This file was auto-generated from huddle. Please do not modify it directly!\n" in withFile path WriteMode $ \h -> do hPutStrLn h preface - hPutDoc h (pretty cddl) + hPutDoc h (pretty $ Cuddle.mapIndex @_ @_ @PrettyStage cddl) -- Write an empty line at the end of the file hPutStrLn h ""