Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Conway CDDL using Cuddle #4437

Merged
merged 11 commits into from
Jul 25, 2024
Merged

Test Conway CDDL using Cuddle #4437

merged 11 commits into from
Jul 25, 2024

Conversation

nc6
Copy link
Contributor

@nc6 nc6 commented Jun 25, 2024

Description

This PR introduces cuddle, a Haskell library for declaring and validating CDDL documents.

This is then used to reflect the Conway CDDL specification (in eras/conway/impl/src/Cardano/Ledger/Conway/CDDL.hs) using a DSL known as Huddle.

libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Cuddle.hs introduces utilities to run CDDL conformance tests using cuddle. These are currently based on a Huddle declaration, but it would be equally possible to use a native CDDL specification combined with cuddle's CBOR generators.

eras/conway/impl/test/Test/Cardano/Ledger/Conway/Binary/CddlSpec.hs then introduces a new set of tests based in the Huddle conway specification. The existing test suite is left untouched for now.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • When applicable, versions are updated in .cabal and CHANGELOG.md files according to the
    versioning process.
  • The version bounds in .cabal files for all affected packages are updated. If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
  • All visible changes are prepended to the latest section of a CHANGELOG.md for the affected packages. New section is never added with the code changes. (See RELEASING.md)
  • Code is formatted with fourmolu (use scripts/fourmolize.sh)
  • Cabal files are formatted (use scripts/cabal-format.sh)
  • hie.yaml has been updated (use scripts/gen-hie.sh)
  • Self-reviewed the diff

Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!!! I am loving it!!! ❤️

Looks like you've used an older CDDL spec as reference, could you please go through and compare to an up-to-date version and make necessary adjustments?

I haven't gone through the whole PR, but as soon as all current comments are addressed I'll do a thorough review.

This PR pretty much takes care of #4125 and #4126

There are more to go: #4461 and #4462 and then some other ideas that we've discussed

eras/conway/impl/cardano-ledger-conway.cabal Outdated Show resolved Hide resolved
eras/conway/impl/src/Cardano/Ledger/Conway/CDDL.hs Outdated Show resolved Hide resolved
eras/conway/impl/src/Cardano/Ledger/Conway/CDDL.hs Outdated Show resolved Hide resolved
eras/conway/impl/src/Cardano/Ledger/Conway/CDDL.hs Outdated Show resolved Hide resolved
eras/conway/impl/src/Cardano/Ledger/Conway/CDDL.hs Outdated Show resolved Hide resolved
eras/conway/impl/src/Cardano/Ledger/Conway/CDDL.hs Outdated Show resolved Hide resolved
eras/conway/impl/src/Cardano/Ledger/Conway/CDDL.hs Outdated Show resolved Hide resolved
eras/conway/impl/src/Cardano/Ledger/Conway/CDDL.hs Outdated Show resolved Hide resolved
@nc6
Copy link
Contributor Author

nc6 commented Jul 5, 2024

Note that I have #4461 addressed, but planned to include that in a subsequent PR to avoid inflating this one.

@nc6 nc6 requested a review from lehins July 5, 2024 07:43
Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor suggestions and question, but nothing critical.

Cuddle/Huddle is an amazing piece of work! Thank you for getting us to this point @nc6!

nc6 added 11 commits July 25, 2024 15:21
This commit introduces a re-implementation of the
Conway CDDL specification using 'cuddle', a
Haskell library for defining and validating CDDL.
This allows us to generate and validate test cases
without resorting to using the external `cddl`
library.
- Fix protocol_param_update definition
- Fix indices for certificates.
- Inputs to a transaction should be inputs, not indices.
- Index is sized
- Fix the alternatives in credential.
- Fix tags for constr.
- script_ref has a tag
- post_alonzo_transaction_output is a map
- voter and gov_action_id are refs, not keywords
- Appropriate size the index tag in redeemers
- Both sides of the redeemers map are arrays, not maps
In particular, updating to this version prevents generating CBOR Maps
with duplicate keys, which can result in parsing errors
Updated with all changes to conway.cddl up to 78b32d5
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.
@nc6 nc6 enabled auto-merge July 25, 2024 13:23
@nc6 nc6 merged commit 88d7885 into master Jul 25, 2024
124 of 126 checks passed
@nc6 nc6 deleted the nc/cuddle branch July 25, 2024 15:07
@nc6 nc6 mentioned this pull request Jul 26, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants