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

Fix mistaken use of dollar sign in cddl files #3725

Merged
merged 1 commit into from
Sep 11, 2023

Conversation

teodanciu
Copy link
Contributor

Description

At the moment , cddl generate that we use for cddl roundtrips does NOT generate values for these types that we prefixed with $.
The types for which values ARE generated correctly that are prefixed with $ (eg: $hash28, $vkey), are also defined in the same way, prefixed by dollar.

It's not very clear from the spec that this should be the case, but running cddl generate makes it clear that it's simply ignoring $required_signers, $treasury_withdrawals_action and $new_committee when defined in the way they are currently in the cddl.

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

`cddl generate` doesn't generate any values when the type is prefixed
with `$`
@teodanciu
Copy link
Contributor Author

If you want to test this yourself, do this:

  1. Create a file a.cddl with this content:
required_signers = nonempty_set<$addr_keyhash>
addr_keyhash          = $hash28
$hash28 /= bytes .size 28
nonempty_set<a> = [+ a]
  1. run: nix-shell -p cddl
  2. run: cddl a.cddl generate 1
  3. observe the error
  4. change first line in a.cddl to required_signers = nonempty_set<addr_keyhash>
  5. run: cddl a.cddl generate 1

The reason we don't get an error in tests is because it's optional this in transaction_body:
, ? 14 : required_signers

Copy link
Contributor

@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.

If only CDDL had a type checker 😉

Very nice find! Thank you.

@teodanciu teodanciu enabled auto-merge (rebase) September 11, 2023 22:22
@teodanciu teodanciu merged commit b9221a7 into master Sep 11, 2023
12 of 14 checks passed
@iohk-bors iohk-bors bot deleted the td/fix-dollar-in-cddl branch September 11, 2023 23:53
@JaredCorduan
Copy link
Contributor

wow, great catch!

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.

None yet

3 participants