Skip to content

Commit

Permalink
Final changes via comparison with conway.cddl
Browse files Browse the repository at this point in the history
This is the final set of changes to the Conway
CDDL spec made via comparison with the original
cddl files for Conway.

As of this commit, the remaining changes with the
original cddl are as follows:

- Various fields in crypto were defined with /=
  and are now defined with =. This does not affect
  the semantics, being instead a convention as per
  https://datatracker.ietf.org/doc/html/rfc8610#section-3.9
- The index keys in auxiliary_data are written as
  if they were value and not type keys:
  ```
    39,43c30,34
      <                   / #6.259({? 0 : metadata
      <                             , ? 1 : [* native_script]
      <                             , ? 2 : [* plutus_v1_script]
      <                             , ? 3 : [* plutus_v2_script]
      <                             , ? 4 : [* plutus_v3_script]})
      ---
      >                   / #6.259({? 0 => metadata
      >                             , ? 1 => [* native_script]
      >                             , ? 2 => [* plutus_v1_script]
      >                             , ? 3 => [* plutus_v2_script]
      >                             , ? 4 => [* plutus_v3_script]})
  ```
  This is a simpler formulation with identical semantics.
- The alternatives in 'certificate', 'relay',
  'native_script' and 'gov_action' are encoded
  using type1 choice semantics ('/') rather than
  group choice semantics ('//'). In the context,
  this is an equivalent formulation.
- nonempty_oset has been removed, pending
  explanation of what it means. nonempty_set is
  used instead.
- In various places, null is replaced with nil.
  They are synonyms.
- The names of type parameters are changed;
  typically a is replaced with a0.
- A few rules using references as the bounds in
  ranges are now inlined. This will be fixed once
  input-output-hk/cuddle#29
  is addressed.
- `distinct` is not currently possible to
  implement as a generic function, since `sized`
  is currently specialised to work on values.
  input-output-hk/cuddle#31
  addresses. Until this is fixed, distinct<bytes>
  is instead distinct_bytes.
- tstr is replaced with text. They are synonyms.
- The keys in the 'pool_params' and
  'script_n_of_k' groups are lost. This is due to
  input-output-hk/cuddle#32.
  However, since pool_params is included into an
  array, this does not alter the semantics, only
  the documentation.
- datum_hash is of type datum_hash, not hash32.
  This seems an overlooked item in the original
  cddl.
  • Loading branch information
nc6 authored and Soupstraw committed Aug 1, 2024
1 parent b4306ea commit a62b148
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions eras/conway/impl/src/Cardano/Ledger/Conway/CDDL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{-# HLINT ignore "Use camelCase" #-}
{-# HLINT ignore "Evaluate" #-}

module Cardano.Ledger.Conway.CDDL where
module Cardano.Ledger.Conway.CDDL (conway) where

import Codec.CBOR.Cuddle.Huddle
import Data.Function (($))
Expand All @@ -18,7 +18,10 @@ import GHC.Num (Integer)
import GHC.Show (Show (show))

conway :: Huddle
conway = collectFrom [block, transaction]
conway =
collectFrom $
[block, transaction]
<> [kes_signature, language, potential_languages, signkeyKES]

block :: Rule
block =
Expand Down Expand Up @@ -223,7 +226,7 @@ anchor =
]

vote :: Rule
vote = "vote" =:= int 0 // int 1 // int 2
vote = "vote" =:= 0 ... 2

gov_action_id :: Rule
gov_action_id =
Expand Down Expand Up @@ -572,10 +575,10 @@ plutus_data =
// bounded_bytes

big_int :: Rule
big_int = "big_int" =:= VInt // big_VUInt // big_nint
big_int = "big_int" =:= VInt // big_uint // big_nint

big_VUInt :: Rule
big_VUInt = "big_VUInt" =:= tag 2 bounded_bytes
big_uint :: Rule
big_uint = "big_uint" =:= tag 2 bounded_bytes

big_nint :: Rule
big_nint = "big_nint" =:= tag 3 bounded_bytes
Expand Down Expand Up @@ -661,7 +664,7 @@ costmdls =
[ 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)
, opt $ asKey (3 ... 255) ==> arr [0 <+ a int64] -- Any 8-bit unsigned number can be used as a key.
, 0 <+ asKey (3 ... 255) ==> arr [0 <+ a int64] -- Any 8-bit unsigned number can be used as a key.
]

transaction_metadatum :: Rule
Expand Down Expand Up @@ -693,13 +696,16 @@ auxiliary_data =
[ "transaction_metadata" ==> metadata -- Shelley-ma
, "auxiliary_scripts" ==> arr [0 <+ a native_script]
]
// smp
[ 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])
]
// 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])
]
)

vkeywitness :: Rule
vkeywitness = "vkeywitness" =:= arr [a vkey, a signature]
Expand Down Expand Up @@ -753,11 +759,10 @@ invalid_hereafter = "invalid_hereafter" =:~ grp [5, a slot_no]
coin :: Rule
coin = "coin" =:= VUInt

multiasset :: (Show a, IsType0 a) => a -> Rule
multiasset x =
"multiasset_"
<> T.pack (show x)
=:= mp [1 <+ asKey policy_id ==> mp [1 <+ asKey asset_name ==> x]]
multiasset :: IsType0 a => a -> GRuleCall
multiasset = binding $ \x ->
"multiasset"
=:= mp [1 <+ asKey policy_id ==> mp [1 <+ asKey asset_name ==> x]]

policy_id :: Rule
policy_id = "policy_id" =:= scripthash
Expand Down Expand Up @@ -887,31 +892,31 @@ script =
--------------------------------------------------------------------------------

hash28 :: Rule
hash28 = "hash28" =:= VBytes `sized` (28 :: Word64)
hash28 = "$hash28" =:= VBytes `sized` (28 :: Word64)

hash32 :: Rule
hash32 = "hash32" =:= VBytes `sized` (32 :: Word64)
hash32 = "$hash32" =:= VBytes `sized` (32 :: Word64)

vkey :: Rule
vkey = "vkey" =:= VBytes `sized` (32 :: Word64)
vkey = "$vkey" =:= VBytes `sized` (32 :: Word64)

vrf_vkey :: Rule
vrf_vkey = "vrf_vkey" =:= VBytes `sized` (32 :: Word64)
vrf_vkey = "$vrf_vkey" =:= VBytes `sized` (32 :: Word64)

vrf_cert :: Rule
vrf_cert = "vrf_cert" =:= arr [a VBytes, a (VBytes `sized` (80 :: Word64))]
vrf_cert = "$vrf_cert" =:= arr [a VBytes, a (VBytes `sized` (80 :: Word64))]

kes_vkey :: Rule
kes_vkey = "kes_vkey" =:= VBytes `sized` (32 :: Word64)
kes_vkey = "$kes_vkey" =:= VBytes `sized` (32 :: Word64)

kes_signature :: Rule
kes_signature = "kes_signature" =:= VBytes `sized` (448 :: Word64)
kes_signature = "$kes_signature" =:= VBytes `sized` (448 :: Word64)

signkeyKES :: Rule
signkeyKES = "signkeyKES" =:= VBytes `sized` (64 :: Word64)

signature :: Rule
signature = "signature" =:= VBytes `sized` (64 :: Word64)
signature = "$signature" =:= VBytes `sized` (64 :: Word64)

--------------------------------------------------------------------------------
-- Extras
Expand All @@ -922,10 +927,13 @@ signature = "signature" =:= VBytes `sized` (64 :: Word64)
-- 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])
set = binding $ \x -> "set" =:= tag 258 (arr [0 <+ a x]) // sarr [0 <+ a x]

nonempty_set :: IsType0 t0 => t0 -> GRuleCall
nonempty_set = binding $ \x -> "nonempty_set" =:= tag 258 (arr [1 <+ a x])
nonempty_set = binding $ \x ->
"nonempty_set"
=:= tag 258 (arr [1 <+ a x])
// sarr [1 <+ a x]

positive_int :: Rule
positive_int = "positive_int" =:= 1 ... 18446744073709551615
Expand Down

0 comments on commit a62b148

Please sign in to comment.