diff --git a/eras/allegra/impl/cddl-files/allegra.cddl b/eras/allegra/impl/cddl-files/allegra.cddl index 1bba4196aa1..a2e765d1249 100644 --- a/eras/allegra/impl/cddl-files/allegra.cddl +++ b/eras/allegra/impl/cddl-files/allegra.cddl @@ -299,11 +299,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 6c19fdc937c..435108a03c1 100644 --- a/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs +++ b/eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/CDDL.hs @@ -144,7 +144,7 @@ transaction_body = ] -- TODO: Allow for adding to the comments of a Rule in order to not have to --- redifine them in the subsequent eras. +-- redefine them in the subsequent eras. script_data_hash :: Rule script_data_hash = comment diff --git a/eras/conway/impl/cardano-ledger-conway.cabal b/eras/conway/impl/cardano-ledger-conway.cabal index b93d6d1d133..d64816ff2d1 100644 --- a/eras/conway/impl/cardano-ledger-conway.cabal +++ b/eras/conway/impl/cardano-ledger-conway.cabal @@ -168,12 +168,11 @@ library testlib cardano-ledger-shelley:{cardano-ledger-shelley, testlib}, cardano-strict-containers, containers, - cuddle >=0.3.1.0, cuddle >=0.3.2, data-default, deepseq, generic-random, - here, + heredoc, microlens, microlens-mtl, mtl, diff --git a/eras/conway/impl/cddl-files/conway.cddl b/eras/conway/impl/cddl-files/conway.cddl index a1946f0744c..d561a1d9737 100644 --- a/eras/conway/impl/cddl-files/conway.cddl +++ b/eras/conway/impl/cddl-files/conway.cddl @@ -71,6 +71,10 @@ anchor = [anchor_url : url, anchor_data_hash : $hash32] asset_name = bytes .size (0 .. 32) +; metadata: shelley +; transaction_metadata: shelley-ma +; #6.259(0 ==> metadata): alonzo onwards +; auxiliary_data = metadata / [transaction_metadata : metadata , auxiliary_scripts : [* native_script]] @@ -82,6 +86,11 @@ auxiliary_data = metadata auxiliary_data_hash = $hash32 +babbage_transaction_output = {0 : address + , 1 : value + , ? 2 : datum_option + , ? 3 : script_ref} + big_int = int / big_uint / big_nint big_nint = #6.3(bounded_bytes) @@ -89,10 +98,11 @@ big_nint = #6.3(bounded_bytes) big_uint = #6.2(bounded_bytes) ; Valid blocks must also satisfy the following two constraints: -; 1) the length of transaction_bodies and transaction_witness_sets -; must be the same -; 2) every transaction_index must be strictly smaller than the -; length of transaction_bodies +; 1. the length of transaction_bodies and transaction_witness_sets +; must be the same +; 2. every transaction_index must be strictly smaller than the +; length of transaction_bodies +; block = [header , transaction_bodies : [* transaction_body] , transaction_witness_sets : [* transaction_witness_set] @@ -145,21 +155,26 @@ committee_cold_credential = credential committee_hot_credential = credential -constitution = [anchor, scripthash / nil] +constitution = [anchor, script_hash / nil] -; The format for costmdls is flexible enough to allow adding Plutus -; built-ins and language versions in the future. -costmdls = {? 0 : [* int64] - , ? 1 : [* int64] - , ? 2 : [* int64] - , * 3 .. 255 => [* int64]} +; The format for cost_models is flexible enough to allow adding +; Plutus built-ins and language versions in the future. +; +; Plutus v1: only 166 integers are used, but more are accepted (and ignored) +; Plutus v2: only 175 integers are used, but more are accepted (and ignored) +; Plutus v3: only 223 integers are used, but more are accepted (and ignored) +; +; Any 8-bit unsigned number can be used as a key. +; +cost_models = {? 0 : [* int64] + , ? 1 : [* int64] + , ? 2 : [* int64] + , * 3 .. 255 => [* int64]} -credential = [0, addr_keyhash // 1, scripthash] +credential = [0, addr_keyhash // 1, script_hash] data = #6.24(bytes .cbor plutus_data) -datum_hash = $hash32 - datum_option = [0, $hash32 // 1, data] ; A type for distinct values. @@ -174,7 +189,7 @@ distinct_VBytes = bytes .size 8 dns_name = text .size (0 .. 128) -drep = [0, addr_keyhash // 1, scripthash // 2 // 3] +drep = [0, addr_keyhash // 1, script_hash // 2 // 3] drep_credential = credential @@ -235,6 +250,8 @@ major_protocol_version = 1 .. 10 metadata = {* transaction_metadatum_label => transaction_metadatum} +metadata_hash = $hash32 + mint = multiasset native_script = [script_pubkey @@ -263,10 +280,12 @@ plutus_data = constr / big_int / bounded_bytes -; The real type of plutus_v1_script, plutus_v2_script and plutus_v3_script is bytes. -; However, because we enforce uniqueness when many scripts are supplied, -; we need to hack around for tests in order to avoid generating duplicates, -; since the cddl tool we use for roundtrip testing doesn't generate distinct collections. +; The real type of plutus_v1_script, plutus_v2_script and +; plutus_v3_script is bytes. However, because we enforce +; uniqueness when many scripts are supplied, we need to hack +; 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 @@ -274,15 +293,13 @@ plutus_v2_script = distinct_VBytes plutus_v3_script = distinct_VBytes -policy_hash = scripthash +policy_hash = script_hash -policy_id = scripthash +policy_id = script_hash pool_keyhash = $hash28 -pool_metadata = [url, pool_metadata_hash] - -pool_metadata_hash = $hash32 +pool_metadata = [url, metadata_hash] pool_voting_thresholds = [unit_interval , unit_interval @@ -298,21 +315,43 @@ positive_coin = 1 .. 18446744073709551615 positive_int = 1 .. 18446744073709551615 -post_alonzo_transaction_output = {0 : address - , 1 : value - , ? 2 : datum_option - , ? 3 : script_ref} - potential_languages = 0 .. 255 -pre_babbage_transaction_output = [address - , amount : value - , ? datum_hash : datum_hash] - proposal_procedure = [deposit : coin, reward_account, gov_action, anchor] proposal_procedures = nonempty_set +; 0: minfee A +; 1: minfee B +; 2: max block body size +; 3: max transaction size +; 4: max block header size +; 5: key deposit +; 6: pool deposit +; 7: maximum epoch +; 8: n_opt: desired number of stake pools +; 9: pool pledge influence +; 10: expansion rate +; 11: treasury growth rate +; 16: min pool cost +; 17: ada per utxo byte +; 18: cost models for script languages +; 19: execution costs +; 20: max tx ex units +; 21: max block ex units +; 22: max value size +; 23: collateral percentage +; 24: max collateral inputs +; 25: pool voting thresholds +; 26: drep voting thresholds +; 27: min committee size +; 28: committee term limit +; 29: governance action validity period +; 30: governance action deposit +; 31: drep deposit +; 32: drep inactivity period +; 33: minfee refscriptcoinsperbyte +; protocol_param_update = {? 0 : coin , ? 1 : coin , ? 2 : uint .size 4 @@ -327,7 +366,7 @@ protocol_param_update = {? 0 : coin , ? 11 : unit_interval , ? 16 : coin , ? 17 : coin - , ? 18 : costmdls + , ? 18 : cost_models , ? 19 : ex_unit_prices , ? 20 : ex_units , ? 21 : ex_units @@ -346,10 +385,19 @@ protocol_param_update = {? 0 : coin protocol_version = [major_protocol_version, uint] +; 0: spend +; 1: mint +; 2: cert +; 3: reward +; 4: voting +; 5: proposing +; redeemer_tag = 0 / 1 / 2 / 3 / 4 / 5 -; Flat Array support is included for backwards compatibility and will be removed in the next era. -; It is recommended for tools to adopt using a Map instead of Array going forward. +; Flat Array support is included for backwards compatibility and +; will be removed in the next era. It is recommended for tools to +; adopt using a Map instead of Array going forward. +; redeemers = [+ [tag : redeemer_tag , index : uint .size 4 , data : plutus_data @@ -373,85 +421,90 @@ script = [0, native_script // 3, plutus_v3_script] ; This is a hash of data which may affect evaluation of a script. -; This data consists of: -; - The redeemers from the transaction_witness_set (the value of field 5). -; - The datums from the transaction_witness_set (the value of field 4). -; - The value in the costmdls map corresponding to the script's language -; (in field 18 of protocol_param_update.) -; (In the future it may contain additional protocol parameters.) -; -; Since this data does not exist in contiguous form inside a transaction, it needs -; to be independently constructed by each recipient. -; -; The bytestring which is hashed is the concatenation of three things: -; redeemers || datums || language views -; The redeemers are exactly the data present in the transaction witness set. -; Similarly for the datums, if present. If no datums are provided, the middle -; field is omitted (i.e. it is the empty/null bytestring). -; -; language views CDDL: -; { * language => script_integrity_data } -; -; This must be encoded canonically, using the same scheme as in -; RFC7049 section 3.9: -; - Maps, strings, and bytestrings must use a definite-length encoding -; - Integers must be as small as possible. -; - The expressions for map length, string length, and bytestring length -; must be as short as possible. -; - The keys in the map must be sorted as follows: -; - If two keys have different lengths, the shorter one sorts earlier. -; - If two keys have the same length, the one with the lower value -; in (byte-wise) lexical order sorts earlier. -; -; For PlutusV1 (language id 0), the language view is the following: -; - the value of costmdls map at key 0 (in other words, the script_integrity_data) -; is encoded as an indefinite length list and the result is encoded as a bytestring. -; (our apologies) -; For example, the script_integrity_data corresponding to the all zero costmodel for V1 -; would be encoded as (in hex): -; 58a89f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff -; - the language ID tag is also encoded twice. first as a uint then as -; a bytestring. (our apologies) -; Concretely, this means that the language version for V1 is encoded as -; 4100 in hex. -; For PlutusV2 (language id 1), the language view is the following: -; - the value of costmdls map at key 1 is encoded as an definite length list. -; For example, the script_integrity_data corresponding to the all zero costmodel for V2 -; would be encoded as (in hex): -; 98af0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -; - the language ID tag is encoded as expected. -; Concretely, this means that the language version for V2 is encoded as -; 01 in hex. -; For PlutusV3 (language id 2), the language view is the following: -; - the value of costmdls map at key 2 is encoded as a definite length list. -; -; Note that each Plutus language represented inside a transaction must have -; a cost model in the costmdls protocol parameter in order to execute, -; regardless of what the script integrity data is. -; -; Finally, note that in the case that a transaction includes datums but does not -; include the redeemers field, the script data format becomes (in hex): -; [ A0 | datums | A0 ] -; corresponding to a CBOR empty map and an empty map for language view. -; This empty redeeemer case has changed from the previous eras, since default -; representation for redeemers has been changed to a map. Also whenever redeemers are -; supplied either as a map or as an array they must contain at least one element, -; therefore there is no way to override this behavior by providing a custom -; representation for empty redeemers. +; This data consists of: +; - The redeemers from the transaction_witness_set (the value of field 5). +; - The datums from the transaction_witness_set (the value of field 4). +; - The value in the cost_models map corresponding to the script's language +; (in field 18 of protocol_param_update.) +; (In the future it may contain additional protocol parameters.) +; +; Since this data does not exist in contiguous form inside a transaction, it needs +; to be independently constructed by each recipient. +; +; The bytestring which is hashed is the concatenation of three things: +; redeemers || datums || language views +; The redeemers are exactly the data present in the transaction witness set. +; Similarly for the datums, if present. If no datums are provided, the middle +; field is omitted (i.e. it is the empty/null bytestring). +; +; language views CDDL: +; { * language => script_integrity_data } +; +; This must be encoded canonically, using the same scheme as in +; RFC7049 section 3.9: +; - Maps, strings, and bytestrings must use a definite-length encoding +; - Integers must be as small as possible. +; - The expressions for map length, string length, and bytestring length +; must be as short as possible. +; - The keys in the map must be sorted as follows: +; - If two keys have different lengths, the shorter one sorts earlier. +; - If two keys have the same length, the one with the lower value +; in (byte-wise) lexical order sorts earlier. +; +; For PlutusV1 (language id 0), the language view is the following: +; - the value of cost_models map at key 0 (in other words, the script_integrity_data) +; is encoded as an indefinite length list and the result is encoded as a bytestring. +; (our apologies) +; For example, the script_integrity_data corresponding to the all zero costmodel for V1 +; would be encoded as (in hex): +; 58a89f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff +; - the language ID tag is also encoded twice. first as a uint then as +; a bytestring. (our apologies) +; Concretely, this means that the language version for V1 is encoded as +; 4100 in hex. +; For PlutusV2 (language id 1), the language view is the following: +; - the value of cost_models map at key 1 is encoded as an definite length list. +; For example, the script_integrity_data corresponding to the all zero costmodel for V2 +; would be encoded as (in hex): +; 98af0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +; - the language ID tag is encoded as expected. +; Concretely, this means that the language version for V2 is encoded as +; 01 in hex. +; For PlutusV3 (language id 2), the language view is the following: +; - the value of cost_models map at key 2 is encoded as a definite length list. +; +; Note that each Plutus language represented inside a transaction must have +; a cost model in the cost_models protocol parameter in order to execute, +; regardless of what the script integrity data is. +; +; Finally, note that in the case that a transaction includes datums but does not +; include the redeemers field, the script data format becomes (in hex): +; [ A0 | datums | A0 ] +; corresponding to a CBOR empty map and an empty map for language view. +; This empty redeeemer case has changed from the previous eras, since default +; representation for redeemers has been changed to a map. Also whenever redeemers are +; supplied either as a map or as an array they must contain at least one element, +; therefore there is no way to override this behavior by providing a custom +; representation for empty redeemers. +; script_data_hash = $hash32 -script_ref = #6.24(bytes .cbor script) - ; To compute a script hash, note that you must prepend ; a tag to the bytes of the script before hashing. ; The tag is determined by the language. ; The tags in the Conway era are: -; "\x00" for multisig scripts -; "\x01" for Plutus V1 scripts -; "\x02" for Plutus V2 scripts -; "\x03" for Plutus V3 scripts +; "\x00" for multisig scripts +; "\x01" for Plutus V1 scripts +; "\x02" for Plutus V2 scripts +; "\x03" for Plutus V3 scripts +; +script_hash = $hash28 + +script_ref = #6.24(bytes .cbor script) + +; hash32: datum_hash ; -scripthash = $hash28 +shelley_transaction_output = [address, amount : value, ? $hash32] signkeyKES = bytes .size 64 @@ -498,9 +551,9 @@ transaction_metadatum = {* transaction_metadatum => transaction_metadatum} transaction_metadatum_label = uint .size 8 ; Both of the Alonzo and Babbage style TxOut formats are equally valid -; and can be used interchangeably -transaction_output = pre_babbage_transaction_output - / post_alonzo_transaction_output +; and can be used interchangeably +; +transaction_output = shelley_transaction_output / babbage_transaction_output transaction_witness_set = {? 0 : nonempty_set , ? 1 : nonempty_set @@ -536,15 +589,16 @@ vkeywitness = [$vkey, $signature] vote = 0 .. 2 -; Constitutional Committee Hot KeyHash: 0 -; Constitutional Committee Hot ScriptHash: 1 -; DRep KeyHash: 2 -; DRep ScriptHash: 3 -; StakingPool KeyHash: 4 +; 0: constitutional committee hot keyhash +; 1: constitutional committee hot script_hash +; 2: drep keyhash +; 3: drep script_hash +; 4: stakingpool keyhash +; voter = [0, addr_keyhash - // 1, scripthash + // 1, script_hash // 2, addr_keyhash - // 3, scripthash + // 3, script_hash // 4, addr_keyhash] voting_procedure = [vote, anchor / nil] @@ -565,6 +619,8 @@ invalid_before = (4, slot_no) invalid_hereafter = (5, slot_no) +; dns_name: An SRV DNS record +; multi_host_name = (2, dns_name) new_constitution = (5, gov_action_id / nil, constitution) @@ -576,6 +632,12 @@ parameter_change_action = (0 , protocol_param_update , policy_hash / nil) +; pool_keyhash: operator +; coin: pledge +; coin: cost +; unit_interval: margin +; set: pool_owners +; pool_params = (pool_keyhash , vrf_keyhash , coin @@ -606,6 +668,8 @@ script_pubkey = (0, addr_keyhash) single_host_addr = (0, port / nil, ipv4 / nil, ipv6 / nil) +; dns_name: An A or AAAA DNS record +; single_host_name = (1, port / nil, dns_name) stake_delegation = (2, stake_credential, pool_keyhash) diff --git a/eras/conway/impl/huddle-cddl/Main.hs b/eras/conway/impl/huddle-cddl/Main.hs index ed955dbac7c..4f8512d8103 100644 --- a/eras/conway/impl/huddle-cddl/Main.hs +++ b/eras/conway/impl/huddle-cddl/Main.hs @@ -2,10 +2,7 @@ module Main where import Paths_cardano_ledger_conway import Test.Cardano.Ledger.Binary.Cuddle (writeSpec) -import qualified Test.Cardano.Ledger.Conway.CDDL as Conway +import Test.Cardano.Ledger.Conway.CDDL (conwayCDDL) --- Generate cddl files for all relevant specifications main :: IO () -main = do - specFile <- getDataFileName "cddl-files/conway.cddl" - writeSpec Conway.conway specFile +main = writeSpec conwayCDDL =<< getDataFileName "cddl-files/conway.cddl" diff --git a/eras/conway/impl/test/Test/Cardano/Ledger/Conway/Binary/CddlSpec.hs b/eras/conway/impl/test/Test/Cardano/Ledger/Conway/Binary/CddlSpec.hs index 633fb15d5db..294a2091ffd 100644 --- a/eras/conway/impl/test/Test/Cardano/Ledger/Conway/Binary/CddlSpec.hs +++ b/eras/conway/impl/test/Test/Cardano/Ledger/Conway/Binary/CddlSpec.hs @@ -22,14 +22,13 @@ import Test.Cardano.Ledger.Binary.Cuddle ( ) import Test.Cardano.Ledger.Common import Test.Cardano.Ledger.Conway.Binary.Cddl (readConwayCddlFiles) -import qualified Test.Cardano.Ledger.Conway.CDDL as ConwayCDDL +import Test.Cardano.Ledger.Conway.CDDL (conwayCDDL) spec :: Spec spec = do - newSpec - describe "CDDL" $ - beforeAllCddlFile 3 readConwayCddlFiles $ do - let v = eraProtVerHigh @Conway + describe "CDDL" $ do + let v = eraProtVerHigh @Conway + describe "Ruby-based" $ beforeAllCddlFile 3 readConwayCddlFiles $ do cddlRoundTripCborSpec @(Value Conway) v "positive_coin" cddlRoundTripCborSpec @(Value Conway) v "value" cddlRoundTripAnnCborSpec @(TxBody Conway) v "transaction_body" @@ -41,32 +40,29 @@ spec = do cddlRoundTripCborSpec @(Datum Conway) v "datum_option" cddlRoundTripAnnCborSpec @(TxWits Conway) v "transaction_witness_set" cddlRoundTripCborSpec @(PParamsUpdate Conway) v "protocol_param_update" - cddlRoundTripCborSpec @CostModels v "costmdls" + cddlRoundTripCborSpec @CostModels v "cost_models" cddlRoundTripAnnCborSpec @(Redeemers Conway) v "redeemers" cddlRoundTripAnnCborSpec @(Tx Conway) v "transaction" cddlRoundTripCborSpec @(VotingProcedure Conway) v "voting_procedure" cddlRoundTripCborSpec @(ProposalProcedure Conway) v "proposal_procedure" cddlRoundTripCborSpec @(GovAction Conway) v "gov_action" cddlRoundTripCborSpec @(TxCert Conway) v "certificate" - -newSpec :: Spec -newSpec = describe "Huddle" $ specWithHuddle ConwayCDDL.conway 100 $ do - let v = eraProtVerHigh @Conway - huddleRoundTripCborSpec @(Value Conway) v "positive_coin" - huddleRoundTripCborSpec @(Value Conway) v "value" - huddleRoundTripCborSpec @(Datum Conway) v "datum_option" - huddleRoundTripCborSpec @CostModels v "costmdls" - huddleRoundTripCborSpec @(VotingProcedure Conway) v "voting_procedure" - huddleRoundTripCborSpec @(PParamsUpdate Conway) v "protocol_param_update" - huddleRoundTripCborSpec @(ProposalProcedure Conway) v "proposal_procedure" - huddleRoundTripCborSpec @(GovAction Conway) v "gov_action" - huddleRoundTripCborSpec @(TxCert Conway) v "certificate" - huddleRoundTripCborSpec @(TxOut Conway) v "transaction_output" - huddleRoundTripAnnCborSpec @(TxBody Conway) v "transaction_body" - huddleRoundTripAnnCborSpec @(TxAuxData Conway) v "auxiliary_data" - huddleRoundTripAnnCborSpec @(Timelock Conway) v "native_script" - huddleRoundTripAnnCborSpec @(Data Conway) v "plutus_data" - huddleRoundTripAnnCborSpec @(Script Conway) v "script" - huddleRoundTripAnnCborSpec @(TxWits Conway) v "transaction_witness_set" - huddleRoundTripAnnCborSpec @(Redeemers Conway) v "redeemers" - huddleRoundTripAnnCborSpec @(Tx Conway) v "transaction" + describe "Huddle" $ specWithHuddle conwayCDDL 100 $ do + huddleRoundTripCborSpec @(Value Conway) v "positive_coin" + huddleRoundTripCborSpec @(Value Conway) v "value" + huddleRoundTripAnnCborSpec @(TxBody Conway) v "transaction_body" + huddleRoundTripAnnCborSpec @(TxAuxData Conway) v "auxiliary_data" + huddleRoundTripAnnCborSpec @(Timelock Conway) v "native_script" + huddleRoundTripAnnCborSpec @(Data Conway) v "plutus_data" + huddleRoundTripCborSpec @(TxOut Conway) v "transaction_output" + huddleRoundTripAnnCborSpec @(Script Conway) v "script" + huddleRoundTripCborSpec @(Datum Conway) v "datum_option" + huddleRoundTripAnnCborSpec @(TxWits Conway) v "transaction_witness_set" + huddleRoundTripCborSpec @(PParamsUpdate Conway) v "protocol_param_update" + huddleRoundTripCborSpec @CostModels v "cost_models" + huddleRoundTripAnnCborSpec @(Redeemers Conway) v "redeemers" + huddleRoundTripAnnCborSpec @(Tx Conway) v "transaction" + huddleRoundTripCborSpec @(VotingProcedure Conway) v "voting_procedure" + huddleRoundTripCborSpec @(ProposalProcedure Conway) v "proposal_procedure" + huddleRoundTripCborSpec @(GovAction Conway) v "gov_action" + huddleRoundTripCborSpec @(TxCert Conway) v "certificate" 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 390348143e3..a2ab0e4c1bc 100644 --- a/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs +++ b/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs @@ -8,41 +8,90 @@ {-# HLINT ignore "Use camelCase" #-} {-# HLINT ignore "Evaluate" #-} -module Test.Cardano.Ledger.Conway.CDDL (conway) where +module Test.Cardano.Ledger.Conway.CDDL ( + module Test.Cardano.Ledger.Babbage.CDDL, + module Test.Cardano.Ledger.Conway.CDDL, +) where import Codec.CBOR.Cuddle.Huddle import Data.Function (($)) -import Data.Semigroup ((<>)) -import Data.String.Here (here) import Data.Word (Word64) import GHC.Num (Integer) -import Test.Cardano.Ledger.Core.Binary.CDDL -import Test.Cardano.Ledger.Shelley.CDDL ( - bootstrap_witness, - port, - single_host_addr, - transaction_index, - transaction_metadatum, - vkeywitness, +import Test.Cardano.Ledger.Babbage.CDDL hiding ( + auxiliary_data, + babbage_transaction_output, + block, + certificate, + certificates, + cost_models, + dns_name, + ex_unit_prices, + header, + header_body, + invalid_before, + invalid_hereafter, + language, + major_protocol_version, + metadata, + mint, + multi_host_name, + native_script, + next_major_protocol_version, + nonempty_set, + operational_cert, + 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, + script_all, + script_any, + script_data_hash, + script_pubkey, + script_ref, + set, + shelley_transaction_output, + single_host_name, + transaction, + transaction_body, + transaction_input, + transaction_metadatum_label, + transaction_output, + transaction_witness_set, + url, + value, + withdrawals, ) - -conway :: Huddle -conway = - collectFrom $ - [block, transaction] - <> [kes_signature, language, potential_languages, signkeyKES] +import Text.Heredoc + +conwayCDDL :: Huddle +conwayCDDL = + collectFrom + [ block + , transaction + , kes_signature + , language + , potential_languages + , signkeyKES + ] block :: Rule block = comment - [here| - Valid blocks must also satisfy the following two constraints: - 1) the length of transaction_bodies and transaction_witness_sets - must be the same - 2) every transaction_index must be strictly smaller than the - length of transaction_bodies - - |] + [str|Valid blocks must also satisfy the following two constraints: + |1. the length of transaction_bodies and transaction_witness_sets + | must be the same + |2. every transaction_index must be strictly smaller than the + | length of transaction_bodies + |] $ "block" =:= arr [ a header @@ -174,7 +223,7 @@ gov_action = / arr [a info_action] policy_hash :: Rule -policy_hash = "policy_hash" =:= scripthash +policy_hash = "policy_hash" =:= script_hash parameter_change_action :: Named Group parameter_change_action = @@ -220,7 +269,7 @@ constitution = "constitution" =:= arr [ a anchor - , a (scripthash / VNil) + , a (script_hash / VNil) ] info_action :: Rule @@ -229,18 +278,17 @@ info_action = "info_action" =:= int 6 voter :: Rule voter = comment - [here| - Constitutional Committee Hot KeyHash: 0 - Constitutional Committee Hot ScriptHash: 1 - DRep KeyHash: 2 - DRep ScriptHash: 3 - StakingPool KeyHash: 4 - |] + [str|0: constitutional committee hot keyhash + |1: constitutional committee hot script_hash + |2: drep keyhash + |3: drep script_hash + |4: stakingpool keyhash + |] $ "voter" =:= arr [0, a addr_keyhash] - / arr [1, a scripthash] + / arr [1, a script_hash] / arr [2, a addr_keyhash] - / arr [3, a scripthash] + / arr [3, a script_hash] / arr [4, a addr_keyhash] anchor :: Rule @@ -276,104 +324,101 @@ transaction_input = transaction_output :: Rule transaction_output = comment - [here| - Both of the Alonzo and Babbage style TxOut formats are equally valid - and can be used interchangeably - |] + [str|Both of the Alonzo and Babbage style TxOut formats are equally valid + |and can be used interchangeably + |] $ "transaction_output" - =:= pre_babbage_transaction_output - / post_alonzo_transaction_output - -pre_babbage_transaction_output :: Rule -pre_babbage_transaction_output = - "pre_babbage_transaction_output" - =:= arr - [ a address - , "amount" ==> value - , opt ("datum_hash" ==> datum_hash) - ] + =:= shelley_transaction_output + / babbage_transaction_output -post_alonzo_transaction_output :: Rule -post_alonzo_transaction_output = - "post_alonzo_transaction_output" +shelley_transaction_output :: Rule +shelley_transaction_output = + comment + [str|hash32: datum_hash + |] + $ "shelley_transaction_output" + =:= arr [a address, "amount" ==> value, opt $ a hash32] + +babbage_transaction_output :: Rule +babbage_transaction_output = + "babbage_transaction_output" =:= mp [ idx 0 ==> address , idx 1 ==> value - , opt (idx 2 ==> datum_option) -- datum option - , opt (idx 3 ==> script_ref) -- script reference + , opt $ idx 2 ==> datum_option + , opt $ idx 3 ==> script_ref ] script_data_hash :: Rule script_data_hash = comment - [here| - This is a hash of data which may affect evaluation of a script. - This data consists of: - - The redeemers from the transaction_witness_set (the value of field 5). - - The datums from the transaction_witness_set (the value of field 4). - - The value in the costmdls map corresponding to the script's language - (in field 18 of protocol_param_update.) - (In the future it may contain additional protocol parameters.) - - Since this data does not exist in contiguous form inside a transaction, it needs - to be independently constructed by each recipient. - - The bytestring which is hashed is the concatenation of three things: - redeemers || datums || language views - The redeemers are exactly the data present in the transaction witness set. - Similarly for the datums, if present. If no datums are provided, the middle - field is omitted (i.e. it is the empty/null bytestring). - - language views CDDL: - { * language => script_integrity_data } - - This must be encoded canonically, using the same scheme as in - RFC7049 section 3.9: - - Maps, strings, and bytestrings must use a definite-length encoding - - Integers must be as small as possible. - - The expressions for map length, string length, and bytestring length - must be as short as possible. - - The keys in the map must be sorted as follows: - - If two keys have different lengths, the shorter one sorts earlier. - - If two keys have the same length, the one with the lower value - in (byte-wise) lexical order sorts earlier. - - For PlutusV1 (language id 0), the language view is the following: - - the value of costmdls map at key 0 (in other words, the script_integrity_data) - is encoded as an indefinite length list and the result is encoded as a bytestring. - (our apologies) - For example, the script_integrity_data corresponding to the all zero costmodel for V1 - would be encoded as (in hex): - 58a89f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff - - the language ID tag is also encoded twice. first as a uint then as - a bytestring. (our apologies) - Concretely, this means that the language version for V1 is encoded as - 4100 in hex. - For PlutusV2 (language id 1), the language view is the following: - - the value of costmdls map at key 1 is encoded as an definite length list. - For example, the script_integrity_data corresponding to the all zero costmodel for V2 - would be encoded as (in hex): - 98af0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 - - the language ID tag is encoded as expected. - Concretely, this means that the language version for V2 is encoded as - 01 in hex. - For PlutusV3 (language id 2), the language view is the following: - - the value of costmdls map at key 2 is encoded as a definite length list. - - Note that each Plutus language represented inside a transaction must have - a cost model in the costmdls protocol parameter in order to execute, - regardless of what the script integrity data is. - - Finally, note that in the case that a transaction includes datums but does not - include the redeemers field, the script data format becomes (in hex): - [ A0 | datums | A0 ] - corresponding to a CBOR empty map and an empty map for language view. - This empty redeeemer case has changed from the previous eras, since default - representation for redeemers has been changed to a map. Also whenever redeemers are - supplied either as a map or as an array they must contain at least one element, - therefore there is no way to override this behavior by providing a custom - representation for empty redeemers. - |] + [str|This is a hash of data which may affect evaluation of a script. + |This data consists of: + | - The redeemers from the transaction_witness_set (the value of field 5). + | - The datums from the transaction_witness_set (the value of field 4). + | - The value in the cost_models map corresponding to the script's language + | (in field 18 of protocol_param_update.) + |(In the future it may contain additional protocol parameters.) + | + |Since this data does not exist in contiguous form inside a transaction, it needs + |to be independently constructed by each recipient. + | + |The bytestring which is hashed is the concatenation of three things: + | redeemers || datums || language views + |The redeemers are exactly the data present in the transaction witness set. + |Similarly for the datums, if present. If no datums are provided, the middle + |field is omitted (i.e. it is the empty/null bytestring). + | + |language views CDDL: + |{ * language => script_integrity_data } + | + |This must be encoded canonically, using the same scheme as in + |RFC7049 section 3.9: + | - Maps, strings, and bytestrings must use a definite-length encoding + | - Integers must be as small as possible. + | - The expressions for map length, string length, and bytestring length + | must be as short as possible. + | - The keys in the map must be sorted as follows: + | - If two keys have different lengths, the shorter one sorts earlier. + | - If two keys have the same length, the one with the lower value + | in (byte-wise) lexical order sorts earlier. + | + |For PlutusV1 (language id 0), the language view is the following: + | - the value of cost_models map at key 0 (in other words, the script_integrity_data) + | is encoded as an indefinite length list and the result is encoded as a bytestring. + | (our apologies) + | For example, the script_integrity_data corresponding to the all zero costmodel for V1 + | would be encoded as (in hex): + | 58a89f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff + | - the language ID tag is also encoded twice. first as a uint then as + | a bytestring. (our apologies) + | Concretely, this means that the language version for V1 is encoded as + | 4100 in hex. + |For PlutusV2 (language id 1), the language view is the following: + | - the value of cost_models map at key 1 is encoded as an definite length list. + | For example, the script_integrity_data corresponding to the all zero costmodel for V2 + | would be encoded as (in hex): + | 98af0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + | - the language ID tag is encoded as expected. + | Concretely, this means that the language version for V2 is encoded as + | 01 in hex. + |For PlutusV3 (language id 2), the language view is the following: + | - the value of cost_models map at key 2 is encoded as a definite length list. + | + |Note that each Plutus language represented inside a transaction must have + |a cost model in the cost_models protocol parameter in order to execute, + |regardless of what the script integrity data is. + | + |Finally, note that in the case that a transaction includes datums but does not + |include the redeemers field, the script data format becomes (in hex): + |[ A0 | datums | A0 ] + |corresponding to a CBOR empty map and an empty map for language view. + |This empty redeeemer case has changed from the previous eras, since default + |representation for redeemers has been changed to a map. Also whenever redeemers are + |supplied either as a map or as an array they must contain at least one element, + |therefore there is no way to override this behavior by providing a custom + |representation for empty redeemers. + |] $ "script_data_hash" =:= hash32 certificate :: Rule @@ -397,21 +442,6 @@ certificate = / arr [a unreg_drep_cert] / arr [a update_drep_cert] -stake_registration :: Named Group -stake_registration = - comment "This will be deprecated in a future era" $ - "stake_registration" =:~ grp [0, a stake_credential] - -stake_deregistration :: Named Group -stake_deregistration = - comment "This will be deprecated in a future era" $ - "stake_deregistration" =:~ grp [1, a stake_credential] - -stake_delegation :: Named Group -stake_delegation = - "stake_delegation" - =:~ grp [2, a stake_credential, a pool_keyhash] - -- POOL pool_registration :: Named Group pool_registration = "pool_registration" =:~ grp [3, a pool_params] @@ -472,24 +502,14 @@ unreg_drep_cert = "unreg_drep_cert" =:~ grp [17, a drep_credential, a coin] update_drep_cert :: Named Group update_drep_cert = "update_drep_cert" =:~ grp [18, a drep_credential, anchor / VNil] -credential :: Rule -credential = - "credential" - =:= arr - [0, a addr_keyhash] - / arr [1, a scripthash] - drep :: Rule drep = "drep" =:= arr [0, a addr_keyhash] - / arr [1, a scripthash] + / arr [1, a script_hash] / arr [2] -- always abstain / arr [3] -- always no confidence -stake_credential :: Rule -stake_credential = "stake_credential" =:= credential - drep_credential :: Rule drep_credential = "drep_credential" =:= credential @@ -501,38 +521,43 @@ committee_hot_credential = "committee_hot_credential" =:= credential pool_params :: Named Group pool_params = - "pool_params" - =:~ grp - [ "operator" ==> pool_keyhash - , "vrf_keyhash" ==> vrf_keyhash - , "pledge" ==> coin - , "cost" ==> coin - , "margin" ==> unit_interval - , "reward_account" ==> reward_account - , "pool_owners" ==> set addr_keyhash - , "relays" ==> arr [0 <+ a relay] - , "pool_metadata" ==> (pool_metadata / VNil) - ] + comment + [str| pool_keyhash: operator + | coin: pledge + | coin: cost + | unit_interval: margin + | set: pool_owners + |] + $ "pool_params" + =:~ grp + [ "operator" ==> pool_keyhash + , "vrf_keyhash" ==> vrf_keyhash + , "pledge" ==> coin + , "cost" ==> coin + , "margin" ==> unit_interval + , "reward_account" ==> reward_account + , "pool_owners" ==> set addr_keyhash + , "relays" ==> arr [0 <+ a relay] + , "pool_metadata" ==> (pool_metadata / VNil) + ] dns_name :: Rule dns_name = "dns_name" =:= VText `sized` (0 :: Word64, 128 :: Word64) single_host_name :: Named Group single_host_name = - "single_host_name" - =:~ grp - [ 1 - , port / VNil - , a dns_name -- An A or AAAA DNS record - ] + comment + [str|dns_name: An A or AAAA DNS record + |] + $ "single_host_name" =:~ grp [1, port / VNil, a dns_name] multi_host_name :: Named Group multi_host_name = - "multi_host_name" - =:~ grp - [ 2 - , a dns_name -- A SRV DNS record - ] + comment + [str|dns_name: An SRV DNS record + |] + $ "multi_host_name" + =:~ grp [2, a dns_name] relay :: Rule relay = @@ -541,50 +566,82 @@ relay = / arr [a single_host_name] / arr [a multi_host_name] -pool_metadata :: Rule -pool_metadata = "pool_metadata" =:= arr [a url, a pool_metadata_hash] - url :: Rule url = "url" =:= VText `sized` (0 :: Word64, 128 :: Word64) +pool_metadata :: Rule +pool_metadata = "pool_metadata" =:= arr [a url, a metadata_hash] + withdrawals :: Rule withdrawals = "withdrawals" =:= mp [1 <+ asKey reward_account ==> coin] protocol_param_update :: Rule protocol_param_update = - "protocol_param_update" - =:= mp - [ opt (idx 0 ==> coin) -- minfee A - , opt (idx 1 ==> coin) -- minfee B - , opt (idx 2 ==> (VUInt `sized` (4 :: Word64))) -- max block body size - , opt (idx 3 ==> (VUInt `sized` (4 :: Word64))) -- max transaction size - , opt (idx 4 ==> (VUInt `sized` (2 :: Word64))) -- max block header size - , opt (idx 5 ==> coin) -- key deposit - , opt (idx 6 ==> coin) -- pool deposit - , opt (idx 7 ==> epoch_interval) -- maximum epoch - , opt (idx 8 ==> (VUInt `sized` (2 :: Word64))) -- n_opt: desired number of stake pools - , opt (idx 9 ==> nonnegative_interval) -- pool pledge influence - , opt (idx 10 ==> unit_interval) -- expansion rate - , opt (idx 11 ==> unit_interval) -- treasury growth rate - , opt (idx 16 ==> coin) -- min pool cost - , opt (idx 17 ==> coin) -- ada per utxo byte - , opt (idx 18 ==> costmdls) -- cost models for script languages - , opt (idx 19 ==> ex_unit_prices) -- execution costs - , opt (idx 20 ==> ex_units) -- max tx ex units - , opt (idx 21 ==> ex_units) -- max block ex units - , opt (idx 22 ==> (VUInt `sized` (4 :: Word64))) -- max value size - , opt (idx 23 ==> (VUInt `sized` (2 :: Word64))) -- collateral percentage - , opt (idx 24 ==> (VUInt `sized` (2 :: Word64))) -- max collateral inputs - , opt (idx 25 ==> pool_voting_thresholds) -- pool voting thresholds - , opt (idx 26 ==> drep_voting_thresholds) -- DRep voting thresholds - , opt (idx 27 ==> (VUInt `sized` (2 :: Word64))) -- min committee size - , opt (idx 28 ==> epoch_interval) -- committee term limit - , opt (idx 29 ==> epoch_interval) -- governance action validity period - , opt (idx 30 ==> coin) -- governance action deposit - , opt (idx 31 ==> coin) -- DRep deposit - , opt (idx 32 ==> epoch_interval) -- DRep inactivity period - , opt (idx 33 ==> nonnegative_interval) -- MinFee RefScriptCoinsPerByte - ] + comment + [str| 0: minfee A + | 1: minfee B + | 2: max block body size + | 3: max transaction size + | 4: max block header size + | 5: key deposit + | 6: pool deposit + | 7: maximum epoch + | 8: n_opt: desired number of stake pools + | 9: pool pledge influence + |10: expansion rate + |11: treasury growth rate + |16: min pool cost + |17: ada per utxo byte + |18: cost models for script languages + |19: execution costs + |20: max tx ex units + |21: max block ex units + |22: max value size + |23: collateral percentage + |24: max collateral inputs + |25: pool voting thresholds + |26: drep voting thresholds + |27: min committee size + |28: committee term limit + |29: governance action validity period + |30: governance action deposit + |31: drep deposit + |32: drep inactivity period + |33: minfee refscriptcoinsperbyte + |] + $ "protocol_param_update" + =:= mp + [ opt (idx 0 ==> coin) + , opt (idx 1 ==> coin) + , opt (idx 2 ==> (VUInt `sized` (4 :: Word64))) + , opt (idx 3 ==> (VUInt `sized` (4 :: Word64))) + , opt (idx 4 ==> (VUInt `sized` (2 :: Word64))) + , opt (idx 5 ==> coin) + , opt (idx 6 ==> coin) + , opt (idx 7 ==> epoch_interval) + , opt (idx 8 ==> (VUInt `sized` (2 :: Word64))) + , opt (idx 9 ==> nonnegative_interval) + , opt (idx 10 ==> unit_interval) + , opt (idx 11 ==> unit_interval) + , opt (idx 16 ==> coin) + , opt (idx 17 ==> coin) + , opt (idx 18 ==> cost_models) + , opt (idx 19 ==> ex_unit_prices) + , opt (idx 20 ==> ex_units) + , opt (idx 21 ==> ex_units) + , opt (idx 22 ==> (VUInt `sized` (4 :: Word64))) + , opt (idx 23 ==> (VUInt `sized` (2 :: Word64))) + , opt (idx 24 ==> (VUInt `sized` (2 :: Word64))) + , opt (idx 25 ==> pool_voting_thresholds) + , opt (idx 26 ==> drep_voting_thresholds) + , opt (idx 27 ==> (VUInt `sized` (2 :: Word64))) + , opt (idx 28 ==> epoch_interval) + , opt (idx 29 ==> epoch_interval) + , opt (idx 30 ==> coin) + , opt (idx 31 ==> coin) + , opt (idx 32 ==> epoch_interval) + , opt (idx 33 ==> nonnegative_interval) + ] pool_voting_thresholds :: Rule pool_voting_thresholds = @@ -630,11 +687,13 @@ transaction_witness_set = plutus_v1_script :: Rule plutus_v1_script = comment - ( "The real type of plutus_v1_script, plutus_v2_script and plutus_v3_script is bytes.\n" - <> "However, because we enforce uniqueness when many scripts are supplied,\n" - <> "we need to hack around for tests in order to avoid generating duplicates,\n" - <> "since the cddl tool we use for roundtrip testing doesn't generate distinct collections.\n" - ) + [str|The real type of plutus_v1_script, plutus_v2_script and + |plutus_v3_script is bytes. However, because we enforce + |uniqueness when many scripts are supplied, we need to hack + |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_v2_script :: Rule @@ -643,34 +702,13 @@ plutus_v2_script = "plutus_v2_script" =:= distinct VBytes plutus_v3_script :: Rule plutus_v3_script = "plutus_v3_script" =:= distinct VBytes -plutus_data :: Rule -plutus_data = - "plutus_data" - =:= constr plutus_data - / smp [0 <+ asKey plutus_data ==> plutus_data] - / sarr [0 <+ a plutus_data] - / big_int - / bounded_bytes - -constr :: IsType0 x => x -> GRuleCall -constr = binding $ \x -> - "constr" - =:= tag 121 (arr [0 <+ a x]) - / tag 122 (arr [0 <+ a x]) - / tag 123 (arr [0 <+ a x]) - / tag 124 (arr [0 <+ a x]) - / tag 125 (arr [0 <+ a x]) - / tag 126 (arr [0 <+ a x]) - / tag 127 (arr [0 <+ a x]) - -- similarly for tag range: 6.1280 .. 6.1400 inclusive - / tag 102 (arr [a VUInt, a $ arr [0 <+ a x]]) - redeemers :: Rule redeemers = comment - ( "Flat Array support is included for backwards compatibility and will be removed in the next era.\n" - <> "It is recommended for tools to adopt using a Map instead of Array going forward." - ) + [str|Flat Array support is included for backwards compatibility and + |will be removed in the next era. It is recommended for tools to + |adopt using a Map instead of Array going forward. + |] $ "redeemers" =:= sarr [ 1 @@ -696,16 +734,21 @@ redeemers = redeemer_tag :: Rule redeemer_tag = - "redeemer_tag" - =:= int 0 -- Spending - / int 1 -- Minting - / int 2 -- Certifying - / int 3 -- Rewarding - / int 4 -- Voting - / int 5 -- Proposing - -ex_units :: Rule -ex_units = "ex_units" =:= arr ["mem" ==> VUInt, "steps" ==> VUInt] + comment + [str|0: spend + |1: mint + |2: cert + |3: reward + |4: voting + |5: proposing + |] + $ "redeemer_tag" + =:= int 0 + / int 1 + / int 2 + / int 3 + / int 4 + / int 5 ex_unit_prices :: Rule ex_unit_prices = @@ -725,19 +768,24 @@ language = potential_languages :: Rule potential_languages = "potential_languages" =:= 0 ... 255 --- The format for costmdls is flexible enough to allow adding Plutus built-ins and language --- versions in the future. --- -costmdls :: Rule -costmdls = +cost_models :: Rule +cost_models = comment - "The format for costmdls is flexible enough to allow adding Plutus\n built-ins and language versions in the future." - $ "costmdls" + [str|The format for cost_models is flexible enough to allow adding + |Plutus built-ins and language versions in the future. + | + |Plutus v1: only 166 integers are used, but more are accepted (and ignored) + |Plutus v2: only 175 integers are used, but more are accepted (and ignored) + |Plutus v3: only 223 integers are used, but more are accepted (and ignored) + | + |Any 8-bit unsigned number can be used as a key. + |] + $ "cost_models" =:= mp - [ opt $ idx 0 ==> arr [0 <+ a int64] -- Plutus v1, only 166 integers are used, but more are accepted (and ignored) - , opt $ idx 1 ==> arr [0 <+ a int64] -- Plutus v2, only 175 integers are used, but more are accepted (and ignored) - , opt $ idx 2 ==> arr [0 <+ a int64] -- Plutus v3, only 223 integers are used, but more are accepted (and ignored) - , 0 <+ asKey (3 ... 255) ==> arr [0 <+ a int64] -- Any 8-bit unsigned number can be used as a key. + [ opt $ idx 0 ==> arr [0 <+ a int64] + , opt $ idx 1 ==> arr [0 <+ a int64] + , opt $ idx 2 ==> arr [0 <+ a int64] + , 0 <+ asKey (3 ... 255) ==> arr [0 <+ a int64] ] transaction_metadatum_label :: Rule @@ -754,22 +802,27 @@ metadata = auxiliary_data :: Rule auxiliary_data = - "auxiliary_data" - =:= metadata -- Shelley - / sarr - [ "transaction_metadata" ==> metadata -- Shelley-ma - , "auxiliary_scripts" ==> arr [0 <+ a native_script] - ] - / tag - 259 - ( mp - [ opt (idx 0 ==> metadata) -- Alonzo and beyond - , opt (idx 1 ==> arr [0 <+ a native_script]) - , opt (idx 2 ==> arr [0 <+ a plutus_v1_script]) - , opt (idx 3 ==> arr [0 <+ a plutus_v2_script]) - , opt (idx 4 ==> arr [0 <+ a plutus_v3_script]) - ] - ) + comment + [str| metadata: shelley + | transaction_metadata: shelley-ma + |#6.259(0 ==> metadata): alonzo onwards + |] + $ "auxiliary_data" + =:= metadata + / sarr + [ "transaction_metadata" ==> metadata + , "auxiliary_scripts" ==> arr [0 <+ a native_script] + ] + / tag + 259 + ( mp + [ opt (idx 0 ==> metadata) + , opt (idx 1 ==> arr [0 <+ a native_script]) + , opt (idx 2 ==> arr [0 <+ a plutus_v1_script]) + , opt (idx 3 ==> arr [0 <+ a plutus_v2_script]) + , opt (idx 4 ==> arr [0 <+ a plutus_v3_script]) + ] + ) native_script :: Rule native_script = @@ -795,6 +848,9 @@ script_all = "script_all" =:~ grp [1, a (arr [0 <+ a native_script])] script_any :: Named Group script_any = "script_any" =:~ grp [2, a (arr [0 <+ a native_script])] +script_ref :: Rule +script_ref = "script_ref" =:= tag 24 (VBytes `cbor` script) + script_n_of_k :: Named Group script_n_of_k = "script_n_of_k" @@ -811,21 +867,12 @@ multiasset = binding $ \x -> "multiasset" =:= mp [1 <+ asKey policy_id ==> mp [1 <+ asKey asset_name ==> x]] -policy_id :: Rule -policy_id = "policy_id" =:= scripthash - -asset_name :: Rule -asset_name = "asset_name" =:= VBytes `sized` (0 :: Word64, 32 :: Word64) - value :: Rule value = "value" =:= coin / sarr [a coin, a (multiasset positive_coin)] mint :: Rule mint = "mint" =:= multiasset nonZeroInt64 -network_id :: Rule -network_id = "network_id" =:= int 0 / int 1 - epoch_no :: Rule epoch_no = "epoch_no" =:= VUInt `sized` (8 :: Word64) @@ -838,46 +885,6 @@ slot_no = "slot_no" =:= VUInt `sized` (8 :: Word64) block_no :: Rule block_no = "block_no" =:= VUInt `sized` (8 :: Word64) -auxiliary_data_hash :: Rule -auxiliary_data_hash = "auxiliary_data_hash" =:= hash32 - -pool_metadata_hash :: Rule -pool_metadata_hash = "pool_metadata_hash" =:= hash32 - --- To compute a script hash, note that you must prepend --- a tag to the bytes of the script before hashing. --- The tag is determined by the language. --- The tags in the Conway era are: --- "\x00" for multisig scripts --- "\x01" for Plutus V1 scripts --- "\x02" for Plutus V2 scripts --- "\x03" for Plutus V3 scripts -scripthash :: Rule -scripthash = - comment - ( "To compute a script hash, note that you must prepend\n" - <> "a tag to the bytes of the script before hashing.\n" - <> "The tag is determined by the language.\n" - <> "The tags in the Conway era are:\n" - <> "\"\\x00\" for multisig scripts\n" - <> "\"\\x01\" for Plutus V1 scripts\n" - <> "\"\\x02\" for Plutus V2 scripts\n" - <> "\"\\x03\" for Plutus V3 scripts\n" - ) - $ "scripthash" =:= hash28 - -datum_hash :: Rule -datum_hash = "datum_hash" =:= hash32 - -data' :: Rule -data' = "data" =:= tag 24 (VBytes `cbor` plutus_data) - -datum_option :: Rule -datum_option = "datum_option" =:= arr [0, a hash32] / arr [1, a data'] - -script_ref :: Rule -script_ref = "script_ref" =:= tag 24 (VBytes `cbor` script) - script :: Rule script = "script" @@ -886,13 +893,17 @@ 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. - +-- | 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 = binding $ \x -> "set" =:= tag 258 (arr [0 <+ a x]) / sarr [0 <+ a x] +-- | 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 = binding $ \x -> "nonempty_set" diff --git a/eras/shelley/impl/cddl-files/shelley.cddl b/eras/shelley/impl/cddl-files/shelley.cddl index af0e95325d3..8ecd10a9b60 100644 --- a/eras/shelley/impl/cddl-files/shelley.cddl +++ b/eras/shelley/impl/cddl-files/shelley.cddl @@ -286,11 +286,11 @@ multisig_pubkey = (0, addr_keyhash) ; 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/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs index 4fcf1d785b5..1ed5ca32290 100644 --- a/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs +++ b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/CDDL.hs @@ -187,11 +187,11 @@ credential = "credential" =:= arr [0, a addr_keyhash] / arr [1, a script_hash] 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